:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e0dfda;
  --text: #1b1b1a;
  --text-2: #52514e;
  --muted: #76756f;
  --accent: #2a78d6;
  --accent-ink: #1f5fae;
  --accent-soft: #e6f0fb;
  --bar: #2a78d6;
  --track: #ecebe7;
  --good: #1a7f3c;     --good-soft: #e3f4e8;
  --warning: #9a6700;  --warning-soft: #fff4d6;
  --serious: #b4501b;  --serious-soft: #fde9dd;
  --critical: #c0322f; --critical-soft: #fde4e3;
  --neutral: #5f5e5a;  --neutral-soft: #ecebe7;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413;
    --surface: #1d1d1c;
    --surface-2: #262625;
    --border: #353533;
    --text: #f3f2ee;
    --text-2: #c3c2b7;
    --muted: #9b9a92;
    --accent: #3987e5;
    --accent-ink: #8bbcf3;
    --accent-soft: #1d2d42;
    --bar: #3987e5;
    --track: #2c2c2a;
    --good: #5cc47e;     --good-soft: #17301f;
    --warning: #e3b341;  --warning-soft: #33290f;
    --serious: #ec8a55;  --serious-soft: #3a2316;
    --critical: #f07370; --critical-soft: #3b1b1a;
    --neutral: #b5b4ac;  --neutral-soft: #2c2c2a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
a { color: var(--accent-ink); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .4rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Yläpalkki */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .92rem; }
.nav a:hover, .nav a.active { background: var(--surface-2); color: var(--text); }
.userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--text-2); }
.subnav { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.subnav .inner { max-width: 1180px; margin: 0 auto; padding: 6px 16px; display: flex; gap: 4px; flex-wrap: wrap; }
.subnav a { color: var(--text-2); text-decoration: none; padding: 4px 10px; border-radius: 6px; font-size: .88rem; }
.subnav a.active, .subnav a:hover { background: var(--surface); color: var(--text); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
main.narrow { max-width: 820px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card.tight { padding: 14px 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 18px; }

/* Avainluvut */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: .85rem; }
.tile .value { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.tile .hint { color: var(--muted); font-size: .8rem; }

/* Vaakapalkit (yksi sarja, arvo palkin päässä) */
.bars { width: 100%; border-collapse: collapse; }
.bars td { padding: 5px 0; vertical-align: middle; font-size: .9rem; }
.bars td.lbl { width: 42%; padding-right: 12px; color: var(--text); }
.bars td.val { width: 64px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); padding-left: 8px; }
.bar-track { height: 14px; background: var(--track); border-radius: 0 4px 4px 0; position: relative; }
.bar-fill { height: 14px; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bars tr:hover .bar-fill { filter: brightness(1.12); }

.progress { height: 10px; background: var(--track); border-radius: 0 4px 4px 0; overflow: hidden; }
.progress > div { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }

/* Taulukot */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); padding: 8px 10px; white-space: nowrap; font-size: .82rem; }
table.data td { border-bottom: 1px solid var(--border); padding: 9px 10px; vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.inactive td { color: var(--muted); }

/* Tilamerkit: väri + ikoni + teksti */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge::before { font-size: .75em; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.good::before { content: "✓"; }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.warning::before { content: "●"; }
.badge.serious { background: var(--serious-soft); color: var(--serious); }
.badge.serious::before { content: "▲"; }
.badge.critical { background: var(--critical-soft); color: var(--critical); }
.badge.critical::before { content: "✕"; }
.badge.neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge.neutral::before { content: "○"; }
.badge.plain::before { content: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--surface-2); border-radius: 6px; padding: 1px 7px; font-size: .8rem; color: var(--text-2); }
.chip.risk { background: var(--critical-soft); color: var(--critical); }

/* Ilmoitukset */
.notice { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; border: 1px solid var(--border); background: var(--surface); }
.notice.info { background: var(--accent-soft); border-color: transparent; }
.notice.success { background: var(--good-soft); border-color: transparent; }
.notice.warn { background: var(--warning-soft); border-color: transparent; }
.notice.error { background: var(--critical-soft); border-color: transparent; color: var(--critical); }
.notice ul { margin: 6px 0 0; padding-left: 20px; }

/* Lomakkeet */
form.stacked .field { margin-bottom: 18px; }
label.lbl, .field > .lbl { display: block; font-weight: 600; margin-bottom: 6px; }
.help { color: var(--muted); font-size: .85rem; margin: -2px 0 8px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=url], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 14px; }
.options label, label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; cursor: pointer; padding: 4px 0; }
.options input, label.check input { margin-top: 4px; accent-color: var(--accent); }
.scale { display: flex; gap: 6px; flex-wrap: wrap; }
.scale label { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer;
  border-radius: 8px; padding: 8px 16px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.small { padding: 4px 10px; font-size: .84rem; }
.btn.link { border: 0; background: none; padding: 0; color: var(--accent-ink); font-weight: 500; text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.tool-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tool-item:last-child { border-bottom: 0; }
.tool-item .name { font-weight: 600; }
.empty { text-align: center; padding: 24px 12px; color: var(--muted); }

.hero { padding: 40px 0 16px; }
.hero h1 { font-size: 2rem; }
.lead { font-size: 1.05rem; color: var(--text-2); max-width: 680px; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; padding: 8px 0 8px 40px; position: relative; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 6px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }

details summary { cursor: pointer; font-weight: 600; }
.email-preview { border: 1px solid var(--border); border-radius: 8px; width: 100%; height: 420px; background: #fff; }
pre.quote { white-space: pre-wrap; font: inherit; margin: 0; }
.quote-list { list-style: none; padding: 0; margin: 0; }
.quote-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.quote-list li:last-child { border-bottom: 0; }

@media (max-width: 640px) {
  .hero h1 { font-size: 1.5rem; }
  .bars td.lbl { width: 46%; }
  .card { padding: 16px; }
}
