/* Raportointi – Rakmentor. Sama paletti kuin tarjouskoneessa: Charcoal, Glacier, Stone. */
:root {
  --ink: #1F2329;
  --char: #3B404C;
  --char-2: #555B68;
  --mute: #6B6F78;
  --glacier: #CFE1ED;
  --glacier-2: #E6EFF5;
  --glacier-3: #F2F7FA;
  --deep: #9DBFD6;
  --stone: #D0CFC4;
  --stone-2: #E2E2DB;
  --paper: #F6F7F6;
  --white: #FFFFFF;
  --blue: #2E75B6;
  --red: #B3261E;
  --red-bg: #FBEAE9;
  --amber-bg: #FFF4D6;
  --green: #2E7D4F;
  --green-bg: #E5F2EA;
  --radius: 6px;
  --font: "Hanken Grotesk", "Liberation Sans", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 15px; color: var(--ink); background: var(--paper); }
body { margin: 0; min-height: 100vh; }
h1, h2, h3 { color: var(--char); margin: 0; line-height: 1.2; }
h1 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .6em; line-height: 1.5; }
a { color: var(--blue); }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--mute); }
.small { font-size: .85rem; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 2rem; padding: 0 28px; height: 60px;
  background: var(--stone-2); border-bottom-right-radius: 18px; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; color: var(--char); }
.brand img { height: 22px; }
.brand span { font-weight: 600; padding-left: .75rem; border-left: 1px solid var(--stone); }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { text-decoration: none; color: var(--char-2); padding: .45rem .8rem; border-radius: var(--radius); font-weight: 500; }
.topbar nav a:hover { background: var(--stone); color: var(--ink); }
.topbar nav a.active { background: var(--char); color: var(--white); }
.user { margin-left: auto; font-size: .9rem; color: var(--char-2); display: flex; gap: .75rem; align-items: center; }

main { padding: 28px; max-width: 1400px; margin: 0 auto; }
main:focus { outline: none; }

/* ---------------------------------------------------------------- controls */
button, .btn {
  font: inherit; font-weight: 600; font-size: .92rem; border-radius: var(--radius); cursor: pointer;
  padding: .55rem 1rem; border: 1px solid var(--stone); background: var(--white); color: var(--char);
  display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; line-height: 1.2;
}
button:hover, .btn:hover { border-color: var(--char-2); }
button.primary { background: var(--char); border-color: var(--char); color: var(--white); }
button.primary:hover { background: var(--ink); }
button.ghost { border-color: transparent; background: transparent; color: var(--blue); padding: .35rem .5rem; font-weight: 500; }
button.ghost:hover { background: var(--glacier-3); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--white);
  border: 1px solid var(--stone); border-radius: var(--radius); padding: .5rem .6rem; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--char-2); outline: 2px solid var(--glacier); outline-offset: 0; }
textarea { resize: vertical; line-height: 1.45; min-height: 4.5em; }
label.field { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--char-2); font-weight: 500; }
label.field.overridden input { border-color: var(--blue); background: var(--glacier-3); }
label.field.need input { border-color: #C9A227; background: var(--amber-bg); }
.grid { display: grid; gap: .9rem 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }

/* ---------------------------------------------------------------- list view */
.list-head { display: flex; align-items: end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.list-head h1 { margin-right: auto; }
.list-head input { width: 280px; }
.list-head select { width: 160px; }
table.list { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: .82rem; font-weight: 600; color: var(--white); background: var(--char); padding: .7rem .9rem; }
table.list td { padding: .7rem .9rem; border-top: 1px solid var(--stone-2); vertical-align: middle; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: var(--glacier-3); }
.nro { font-weight: 700; color: var(--char); font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: .25rem; justify-content: flex-end; }
.nro { font-weight: 700; color: var(--char); font-variant-numeric: tabular-nums; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--char); color: #fff; padding: .7rem 1.1rem; border-radius: var(--radius); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 60; font-size: .92rem; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--red); }
.loading { padding: 3rem; color: var(--mute); }
.signin { max-width: 420px; margin: 12vh auto; background: var(--white); border-radius: var(--radius); padding: 2rem; }
.signin h1 { margin-bottom: .6rem; }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; background: var(--stone-2); color: var(--char); white-space: nowrap; }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.err { background: var(--red-bg); color: var(--red); }
.pill.warn { background: var(--amber-bg); color: #7A5B00; }
.pill.info { background: var(--glacier); }

/* ---------------------------------------------------------------- suodatinrivi */
.filters {
  position: sticky; top: 60px; z-index: 15; background: var(--paper); border-bottom: 1px solid var(--stone-2);
  padding: 12px 28px; display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: end;
}
.filters .f { display: flex; flex-direction: column; gap: .25rem; font-size: .78rem; font-weight: 600; color: var(--char-2); }
.filters select, .filters input { padding: .4rem .5rem; font-size: .9rem; }
.filters input[type=date] { width: 9.5rem; }
.filters select { width: auto; min-width: 9rem; max-width: 15rem; }
.chips { display: flex; gap: .3rem; flex-wrap: wrap; }
.chip { font-weight: 500; font-size: .86rem; padding: .38rem .7rem; border-radius: 99px; background: var(--white); }
.chip[aria-pressed=true] { background: var(--char); border-color: var(--char); color: var(--white); }
.filters .reset { margin-left: auto; align-self: center; }
.filters.busy ~ main { opacity: .55; transition: opacity .15s; }

/* ---------------------------------------------------------------- sivu */
.page-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin-right: auto; }
.seg { display: inline-flex; border: 1px solid var(--stone); border-radius: var(--radius); overflow: hidden; background: var(--white); }
.seg button { border: 0; border-radius: 0; font-weight: 500; padding: .45rem .8rem; }
.seg button + button { border-left: 1px solid var(--stone); }
.seg button[aria-pressed=true] { background: var(--char); color: var(--white); }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--white); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.kpi .lbl { font-size: .82rem; color: var(--char-2); font-weight: 600; }
.kpi .val { font-size: 1.65rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; }
.kpi .sub { font-size: .82rem; color: var(--mute); }
.kpi button.link { all: unset; cursor: pointer; }
.kpi button.link:hover .val, .kpi button.link:focus-visible .val { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.delta-up { color: var(--green); font-weight: 600; }
.delta-down { color: var(--red); font-weight: 600; }

.cards { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; margin-bottom: 16px; }
.card { background: var(--white); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card h2 { font-size: 1rem; margin-bottom: .2rem; }
.card .note { font-size: .82rem; color: var(--mute); margin-bottom: .6rem; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--char-2); margin: .25rem 0 .5rem; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 3px; width: 16px; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { font-family: var(--font); font-size: 11px; fill: var(--mute); }
svg.chart .grid line { stroke: var(--stone-2); }
svg.chart .axis-base { stroke: var(--stone); }
svg.chart .mark { transition: opacity .1s; }
svg.chart .hit { fill: transparent; cursor: default; }
svg.chart .hit:hover + .hl, svg.chart .hit:focus + .hl { opacity: 1; }
svg.chart .hl { fill: var(--ink); opacity: 0; pointer-events: none; }
svg.chart text.lbl { fill: var(--char-2); font-size: 12px; }
svg.chart text.val { fill: var(--ink); font-size: 11.5px; font-weight: 600; }
#tooltip { position: fixed; z-index: 70; pointer-events: none; background: var(--white); border: 1px solid var(--stone); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(31,35,41,.12); padding: .5rem .7rem; font-size: .84rem; min-width: 10rem; }
#tooltip .tt-h { font-weight: 600; color: var(--char-2); margin-bottom: .3rem; }
#tooltip .tt-r { display: flex; align-items: center; gap: .5rem; }
#tooltip .tt-r b { font-variant-numeric: tabular-nums; margin-left: auto; padding-left: 1rem; }
#tooltip .tt-k { width: 12px; height: 3px; border-radius: 2px; }

/* ---------------------------------------------------------------- taulukot */
.table-wrap { background: var(--white); border-radius: var(--radius); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: right; font-size: .78rem; font-weight: 600; color: var(--white); background: var(--char); padding: .6rem .7rem; white-space: nowrap; position: sticky; top: 0; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th.l, table.data td.l { text-align: left; }
table.data td { padding: .55rem .7rem; border-top: 1px solid var(--stone-2); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.name { white-space: normal; min-width: 12rem; font-weight: 500; }
table.data tr.total td { font-weight: 700; background: var(--glacier-3); border-top: 2px solid var(--stone); }
table.data tbody tr:hover td { background: var(--glacier-3); }
table.data td button.cell { all: unset; cursor: pointer; border-radius: 3px; padding: 0 .15rem; }
table.data td button.cell:hover, table.data td button.cell:focus-visible { text-decoration: underline; color: var(--blue); }
table.data th small { font-weight: 400; opacity: .8; }
table.data tr.sub td { background: var(--glacier-3); font-size: .84rem; color: var(--char-2); }
table.data tr.sub td:first-child { padding-left: 2rem; }
table.data .expand { all: unset; cursor: pointer; display: inline-flex; gap: .4rem; align-items: center; }
table.data .expand::before { content: "▸"; color: var(--mute); font-size: .8rem; transition: transform .1s; }
table.data .expand[aria-expanded=true]::before { transform: rotate(90deg); }
.bar-bg { display: inline-block; width: 70px; height: 6px; background: var(--stone-2); border-radius: 3px; vertical-align: middle; margin-left: .45rem; overflow: hidden; }
.bar-bg > span { display: block; height: 100%; background: #2a78d6; border-radius: 3px; }

details.defs { background: var(--white); border-radius: var(--radius); padding: .2rem 1rem; margin-top: 16px; }
details.defs summary { cursor: pointer; padding: .7rem 0; font-weight: 600; color: var(--char); }
details.defs dl { display: grid; grid-template-columns: 11rem 1fr; gap: .4rem 1rem; margin: 0 0 1rem; font-size: .9rem; }
details.defs dt { font-weight: 600; color: var(--char-2); }
details.defs dd { margin: 0; line-height: 1.45; }

.notice { background: var(--amber-bg); border-radius: var(--radius); padding: .7rem 1rem; margin-bottom: 14px; font-size: .9rem; }
.notice.info { background: var(--glacier-2); }
.notice ul { margin: .3rem 0 0; padding-left: 1.2rem; }

/* ---------------------------------------------------------------- erittely */
dialog#drawer { border: 0; padding: 0; margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(980px, 96vw); background: var(--paper); box-shadow: -10px 0 40px rgba(31,35,41,.18); }
dialog#drawer::backdrop { background: rgba(31,35,41,.3); }
#drawer-body { padding: 20px 24px; }
.drawer-head { display: flex; gap: 1rem; align-items: baseline; margin-bottom: .8rem; position: sticky; top: 0; background: var(--paper); padding: .3rem 0 .6rem; }
.drawer-head h2 { margin-right: auto; }

/* ---------------------------------------------------------------- asetukset */
.settings { display: grid; gap: 16px; }
.settings .card h2 { margin-bottom: .5rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.rules td { padding: .3rem .4rem !important; }
.rules select, .rules input { padding: .35rem .45rem; font-size: .88rem; }
.rules td.move { white-space: nowrap; }
pre.json { background: var(--ink); color: #E8EAED; padding: 1rem; border-radius: var(--radius); max-height: 60vh; overflow: auto; font-size: .78rem; line-height: 1.4; }
.split-editor { display: grid; gap: .4rem; margin: .6rem 0; }
.split-editor .r { display: grid; grid-template-columns: 1fr 7rem auto; gap: .4rem; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  main { padding: 16px; }
  .filters { padding: 10px 16px; position: static; }
  .topbar { padding: 0 16px; gap: .75rem; }
  .brand span, .user span { display: none; }
  .topbar nav a { padding: .4rem .5rem; font-size: .88rem; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .val { font-size: 1.3rem; }
  details.defs dl { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
#drawer-body table.data td.l { white-space: normal; }
#drawer-body table.data td.l:first-child { white-space: nowrap; }
.seg { max-width: 100%; overflow-x: auto; }
.seg button { white-space: nowrap; }
/* henkilölaskutus: henkilöt väliotsikoina */
table.data.hl tr.group td { background: var(--glacier-2); font-weight: 600; border-top: 2px solid var(--stone); }
table.data.hl tr.group td.name { font-size: .95rem; }
table.data.hl tr.src td { font-size: .86rem; }
table.data.hl tr.src td.name { padding-left: 1.6rem; font-weight: 400; }
table.data.hl tr.src td.name .cell { font-weight: 600; color: var(--blue); }
#drawer-body .card { margin-bottom: 12px; }
#drawer-body .card h2 { margin-bottom: .5rem; }
.kpi-mini { font-size: 1.5rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
