:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #5f6b65;
  --line: #dfe3df;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --sent: #1f6f5c;
  --read: #b9d8cf;
  --danger: #b3261e;
  --ok: #1f6f5c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1b201d;
    --ink: #e7ece9;
    --muted: #9aa69f;
    --line: #2e3531;
    --accent: #5fbfa4;
    --accent-ink: #0d1411;
    --sent: #5fbfa4;
    --read: #2f4a42;
    --danger: #ff8a80;
    --ok: #5fbfa4;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.top { border-bottom: 1px solid var(--line); background: var(--card); padding: 20px 0 16px; }
h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); }
main.wrap { padding-top: 20px; padding-bottom: 48px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }
h2 { margin: 0 0 12px; font-size: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 0; }
.stats dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 2px 0 0; font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hint, .note { color: var(--muted); margin: 0 0 14px; }
.note { margin: 12px 0 0; }
code { font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 4px; max-width: 360px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); }
input[type=password], input[type=search], input[type=email] {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%;
}
.drop {
  display: block; border: 1.5px dashed var(--line); border-radius: 10px; padding: 26px 16px;
  text-align: center; cursor: pointer; color: var(--muted); transition: border-color .15s, background .15s;
}
.drop.over, .drop:hover { border-color: var(--accent); }
.drop.has-file { color: var(--ink); border-style: solid; }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
button {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 9px 16px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.progress { margin-top: 16px; }
.bar { position: relative; height: 10px; border-radius: 5px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.bar > div { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .2s; }
.bar .read { background: var(--read); }
.bar .sent { background: var(--sent); }
#progress-text { margin: 6px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.message { margin: 12px 0 0; min-height: 1.5em; }
.message.err { color: var(--danger); }
.message.ok { color: var(--ok); font-weight: 600; }
.search { display: flex; gap: 8px; margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- navigation */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- home tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile {
  display: flex; flex-direction: column; gap: 6px; padding: 22px 22px 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s;
}
.tile:hover, .tile:focus-visible { border-color: var(--accent); transform: translateY(-1px); }
.tile-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tile-title { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.tile-text { color: var(--muted); flex: 1; }
.tile-go { color: var(--accent); font-weight: 600; margin-top: 6px; }

/* ---------------------------------------------------------------- search */
.search input { flex: 1; }
.results-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.results-head h2 { margin: 0; }
.company-list { list-style: none; margin: 0; padding: 0; }
.company-list li + li { border-top: 1px solid var(--line); }
.company-list a {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 10px 8px; margin: 0 -8px;
  border-radius: 8px; color: var(--ink); text-decoration: none;
}
.company-list a:hover, .company-list a:focus-visible { background: var(--bg); }
.co-name { font-weight: 600; }
.co-meta { color: var(--muted); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.co-field { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
@media (max-width: 560px) { .company-list a { grid-template-columns: 1fr; } .co-meta { text-align: left; } }

/* ---------------------------------------------------------------- company card */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 34px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-value.missing { font-size: 20px; color: var(--muted); font-weight: 500; }
.kpi-delta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi-delta .up { color: var(--ink); }
.kpi-delta .down { color: var(--ink); }
.company-page .kpis + .note { margin: 10px 0 16px; }
.company-page .kpis { margin-bottom: 16px; }
.chart { width: 100%; }
.chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .value-label { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .nodata { fill: var(--muted); font-size: 12px; }
.chart .bar { fill: var(--accent); opacity: .55; }
.chart .bar.current { opacity: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.tooltip {
  position: fixed; z-index: 10; pointer-events: none; padding: 7px 10px; border-radius: 8px;
  background: var(--ink); color: var(--card); font-size: 13px; line-height: 1.4;
  font-variant-numeric: tabular-nums; box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 10px; }

/* ---------------------------------------------------------------- Äriregister */
h3 { margin: 20px 0 8px; font-size: 14px; }
.ar-state { color: var(--muted); }
.ar-state:empty { display: none; }
.ar-state.err { color: var(--danger); }
#owners-table td, #reps-table td, #ubo-table td { white-space: normal; }
#reps-special { margin: 12px 0 0; }
.tag {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 18px; white-space: nowrap;
}
.ar-source { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin: -6px 0 16px; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.link-button:disabled { color: var(--muted); cursor: default; }
.share-bar { display: inline-block; vertical-align: middle; width: 48px; height: 6px; margin-left: 8px; border-radius: 3px; background: var(--line); overflow: hidden; }
.share-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------------------------------------------------------------- tabs (upload page) */
.tabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  padding: 8px 14px; white-space: nowrap; color: var(--muted); text-decoration: none; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.stats.result { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- tax debt on company card */
.debt-card.has-debt { border-color: var(--danger); }
.debt-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.debt-amount { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--danger); }
.debt-badge {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  color: var(--danger); border: 1px solid var(--danger);
}
.debt-stats dd { font-size: 15px; }
#debt-history h3 { margin-top: 16px; }
.debt-card.has-debt #debt-history h3 { margin-top: 20px; }

/* ---------------------------------------------------------------- revenue by EMTAK */
.rev-root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4;
  --series-other: #a3a29c;
}
@media (prefers-color-scheme: dark) {
  .rev-root { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-other: #6b6a65; }
}
.rev-bars { display: grid; grid-template-columns: auto 1fr auto; gap: 10px 12px; align-items: center; margin-bottom: 12px; }
.rev-year { font-weight: 600; font-variant-numeric: tabular-nums; }
.rev-total { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rev-stack { display: flex; height: 22px; gap: 2px; border-radius: 4px; overflow: hidden; background: var(--bg); }
.rev-stack > span { display: block; height: 100%; min-width: 2px; cursor: crosshair; }
.rev-stack.empty { align-items: center; padding: 0 8px; color: var(--muted); font-size: 12px; }
.legend { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }
#rev-table td:first-child { white-space: normal; min-width: 220px; }
#rev-table .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }
#rev-table tfoot td { font-weight: 600; border-bottom: 0; }
.pct { color: var(--muted); font-size: 12px; margin-left: 4px; }

/* ---------------------------------------------------------------- company facts + address */
.info-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 720px) { .info-grid { grid-template-columns: 1fr; } }
.info-grid .card { margin-bottom: 16px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 2px 0 0; font-size: 15px; overflow-wrap: anywhere; }
.facts dd.muted { color: var(--muted); }
.facts dd.status-warn { color: var(--danger); font-weight: 600; }
.address { margin: 0 0 8px; font-size: 15px; }
.address-links { margin: 0; }
.address-links a { color: var(--accent); }

/* ---------------------------------------------------------------- segments */
.segment-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.segment-tag {
  font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.segment-tag.auto { background: transparent; border-style: dashed; }

/* ---------------------------------------------------------------- segments pages */
.segment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.segment-card {
  display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.segment-card:hover, .segment-card:focus-visible { border-color: var(--accent); transform: translateY(-1px); }
.segment-name { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
.segment-count { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1.2; }
.segment-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.segment-mini dt { font-size: 11px; color: var(--muted); }
.segment-mini dd { margin: 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.section-title { margin: 0 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpis-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpis-4 .kpi-value { font-size: 26px; }
.table-filter { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 240px; }
.sort-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.sort-btn:hover { color: var(--ink); }
.sort-btn[data-dir="desc"]::after { content: " ↓"; color: var(--ink); }
.sort-btn[data-dir="asc"]::after { content: " ↑"; color: var(--ink); }
#companies td.co-cell { white-space: normal; min-width: 220px; }
#companies td.co-cell a { color: var(--ink); font-weight: 600; text-decoration: none; display: block; }
#companies td.co-cell a:hover { color: var(--accent); text-decoration: underline; }
.co-code { color: var(--muted); font-size: 12px; }
td.delta.pos { color: var(--ok); }
td.delta.neg { color: var(--danger); }
td.delta.zero { color: var(--muted); }
.wide .wrap { max-width: 1240px; }
#companies { font-size: 12.5px; }
#companies th, #companies td { padding: 6px 6px; }
.tag.tag-warn { color: var(--danger); border-color: var(--danger); }

/* ---------------------------------------------------------------- owners / control */
.form-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.form-row .field { margin-bottom: 0; }
select, .form-row input[type=number] {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
#ow-errors { margin: 8px 0 0; padding-left: 18px; font-size: 12px; }
.control-badge { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); }
.control-badge.foreign { border-color: #eb6834; }
.control-badge.est { border-color: var(--accent); }
.ctl { font-size: 12px; white-space: nowrap; }
.ctl.foreign { color: #c2501e; font-weight: 600; }
@media (prefers-color-scheme: dark) { .ctl.foreign { color: #f08a5d; } }

/* ---------------------------------------------------------------- export */
a.button {
  display: inline-block; font-weight: 600; border-radius: 8px; padding: 9px 16px;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
}
a.button.disabled { opacity: .45; pointer-events: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; padding-bottom: 8px; }

/* ---------------------------------------------------------------- annual report figures */
.fin-kpis { margin: 0 0 14px; }
.fin-kpis .kpi { box-shadow: none; border: 1px solid var(--line); }
#fin-table td:first-child { white-space: normal; min-width: 240px; }
#fin-table tr.fin-group td {
  padding-top: 14px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line);
}
#fin-table td.fin-sub { padding-left: 22px; color: var(--muted); }
#fin-table td.fin-neg { color: var(--danger); }
.seg-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-toggle button {
  background: transparent; color: var(--muted); border: 0; border-radius: 0; padding: 6px 12px;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg-toggle button + button { border-left: 1px solid var(--line); }
.seg-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- growth class */
.kk-badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 14px;
  border: 1px solid var(--line); color: var(--ink); background: var(--bg);
}
.kk-badge.kk-1, .kk-badge.kk-2 { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.kk-badge.kk-3 { border-color: #c98500; color: #8a5a00; }
.kk-badge.kk-6 { border-color: var(--danger); color: var(--danger); }
.kk-badge.kk-na { color: var(--muted); }
@media (prefers-color-scheme: dark) { .kk-badge.kk-3 { color: #f0b545; border-color: #c98500; } }
.kk-summary { margin: 4px 0 8px; }
.kk-reasons { margin: 0 0 8px; padding-left: 20px; font-variant-numeric: tabular-nums; }
.kk-reasons li { margin: 2px 0; }
.kk-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------------------------------------------------------------- accounts / permissions */
.no-access { display: none !important; }
body[data-leht]:not(.auth-ready) main { visibility: hidden; }
header.top .wrap { position: relative; }
.userbar {
  float: right; display: flex; gap: 14px; align-items: center; font-size: 13px; margin-top: 2px;
}
.userbar a { color: var(--muted); text-decoration: none; }
.userbar a:hover { color: var(--accent); text-decoration: underline; }
.userbar .link-button { font-size: 13px; }
a.button { display: inline-block; text-decoration: none; }
.auth-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.auth-grid .field input { width: 100%; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 24px; }
.perm-grid h3 { grid-column: 1 / -1; margin: 12px 0 2px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.users-table tr { cursor: pointer; }
.users-table tr[aria-selected="true"] td { background: var(--bg); }
.users-table td.special { font-style: italic; }
.badge-small { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; }
.badge-small.warn { color: var(--danger); border-color: var(--danger); }
.badge-small.ok { color: var(--accent); border-color: var(--accent); }
.seg-list { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
