/* Urakkaviikari — app shell. Mobile first (360 px), scaled up with min-width queries.
   One amber primary per view; navy is the frame; state colours only where state is shown. */

:root {
    --bg: #F3F4F0;
    --surface: #FFFFFF;
    --surface-2: #F8F8F5;
    --ink: #15191D;
    --ink-2: #4A525A;
    --ink-3: #6B737A;
    --line: #E1E3DE;
    --line-2: #CDD1CA;
    --brand: #12263F;
    --brand-2: #1C3556;
    --brand-ink: #FFFFFF;
    --brand-muted: #B9C6D8;
    --accent: #E8A303;
    --accent-2: #D19202;
    --accent-ink: #15191D;
    --link: #1D5FD1;
    --ok: #1C6B4A;
    --ok-bg: #E9F5EE;
    --warn: #B45309;
    --warn-bg: #FFF5E1;
    --err: #B42318;
    --err-bg: #FDEDEB;
    --info-bg: #EAF1FC;
    --st-waiting: #8A939B;
    --st-progress: #1D5FD1;
    --st-done: #1C6B4A;
    --st-late: #B42318;
    --st-risk: #D97706;
    --track-1: #0891B2;
    --track-2: #C026D3;
    --track-3: #65A30D;
    --radius: 12px;
    --radius-s: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .05);
    --shadow-up: 0 12px 32px rgba(16, 24, 40, .16);
    --gutter: 16px;
    --tap: 44px;
    --bar: 56px;
    --font: "Archivo Variable", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 16px;
}

* { box-sizing: border-box; }
html { overflow-x: clip; -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }

body {
    font-family: var(--font);
    font-stretch: 100%;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    overflow-wrap: break-word;
}
body.menu-open, body.modal-open { overflow: hidden; }

a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }

h1, h2, h3 { line-height: 1.15; margin: 0 0 .55em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 760; font-stretch: 112%; }
h2 { font-size: 1.2rem; font-weight: 700; font-stretch: 106%; }
h3 { font-size: 1rem; font-weight: 680; }
p { margin: 0 0 .9em; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }
.icon--lg { width: 28px; height: 28px; }

/* --- top bar + navigation ------------------------------------------------ */

.topbar {
    position: sticky; top: 0; z-index: 1100;
    display: flex; align-items: center; gap: 12px;
    min-height: var(--bar); padding: 0 var(--gutter);
    background: var(--brand); color: var(--brand-ink);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; }
.brand img { width: 32px; height: 32px; flex: none; }
.brand span { font-weight: 760; font-stretch: 118%; letter-spacing: .005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand { flex: 1; }
.topbar__company { display: block; font-size: .78rem; font-weight: 500; font-stretch: 100%; color: var(--brand-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__toggle {
    width: var(--tap); height: var(--tap); margin-right: -10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0; color: inherit; cursor: pointer; border-radius: var(--radius-s);
}
.topbar__toggle .icon { width: 26px; height: 26px; }
.topbar__toggle[aria-expanded="true"] .icon-open, .topbar__toggle[aria-expanded="false"] .icon-close { display: none; }

.nav {
    position: fixed; top: var(--bar); right: 0; bottom: 0; width: min(340px, 88vw);
    background: var(--surface); color: var(--ink);
    transform: translateX(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
    overflow-y: auto; overscroll-behavior: contain; padding: 8px 0 32px; box-shadow: var(--shadow-up); z-index: 1120;
    visibility: hidden;
}
.nav.is-open { transform: none; visibility: visible; }
.nav__backdrop { position: fixed; inset: var(--bar) 0 0 0; background: rgba(18, 38, 63, .45); z-index: 1110; }
.nav__user { display: flex; align-items: center; gap: 12px; padding: 12px 20px 14px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.nav__avatar {
    width: 40px; height: 40px; border-radius: 50%; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand); color: var(--brand-ink); font-weight: 700; font-stretch: 110%;
}
.nav__user strong { display: block; line-height: 1.2; }
.nav a, .nav__group > summary {
    display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 20px;
    color: var(--ink); text-decoration: none; font-weight: 560;
}
.nav a .icon, .nav__group > summary .icon { color: var(--ink-3); }
.nav a[aria-current="page"] { background: #EEF2F8; color: var(--brand); box-shadow: inset 3px 0 0 var(--accent); }
.nav a[aria-current="page"] .icon { color: var(--brand); }
.nav__group > summary { cursor: pointer; list-style: none; justify-content: flex-start; }
.nav__group > summary::-webkit-details-marker { display: none; }
.nav__group > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg) translateY(-3px); transition: transform .15s ease; }
.nav__group[open] > summary::after { transform: rotate(225deg) translate(-2px, -1px); }
.nav__group[data-current] > summary { color: var(--brand); }
.nav__items a { padding-left: 52px; font-weight: 450; }
.nav__foot { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 6px; }

@media (min-width: 900px) {
    .topbar { gap: 20px; }
    .topbar .brand { flex: 0 0 auto; }
    .topbar__toggle, .nav__backdrop, .nav__user { display: none !important; }
    .nav {
        position: static; transform: none; visibility: visible; width: auto; box-shadow: none; padding: 0; overflow: visible;
        background: transparent; color: inherit; display: flex; align-items: center; flex: 1; gap: 2px;
    }
    .nav > a, .nav__group > summary { color: #DCE4EF; min-height: var(--bar); padding: 0 12px; gap: 8px; font-weight: 520; }
    .nav > a .icon, .nav__group > summary .icon { display: none; }
    .nav > a:hover, .nav__group > summary:hover { color: #fff; }
    .nav > a[aria-current="page"], .nav__group[data-current] > summary { background: transparent; color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }
    .nav__group > summary::after { width: 6px; height: 6px; border-color: currentColor; margin-left: 2px; }
    .nav__group { position: relative; }
    .nav__items {
        position: absolute; top: calc(100% - 4px); left: 0; min-width: 230px; padding: 6px;
        background: var(--surface); border-radius: var(--radius-s); box-shadow: var(--shadow-up); z-index: 1130;
    }
    .nav__items a { padding: 0 12px; color: var(--ink); border-radius: var(--radius-xs); min-height: 40px; }
    .nav__items a:hover { background: var(--surface-2); }
    .nav__items a[aria-current="page"] { box-shadow: none; background: #EEF2F8; }
    .nav__foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; }
    .nav__foot a { color: #DCE4EF; min-height: var(--bar); }
}

/* --- page frame ---------------------------------------------------------- */

.page { max-width: 1180px; margin: 0 auto; padding: 20px var(--gutter) 64px; }
.page--wide { max-width: none; }
.page__head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 6px 16px; margin-bottom: 20px; }
.page__head h1 { margin: 0; }
.page__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.page__lede { grid-column: 1 / -1; color: var(--ink-2); max-width: 62ch; margin: 0; }
@media (max-width: 559px) { .page__head { grid-template-columns: minmax(0, 1fr); } .page__actions { justify-content: flex-start; } }

.support-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
    margin: -20px calc(var(--gutter) * -1) 20px; padding: 10px var(--gutter);
    background: #2A1F05; color: #FCE7B2; font-size: .92rem;
}
.support-bar strong { color: #fff; }
.support-bar .btn { margin-left: auto; }

.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card--flush { padding: 0; overflow: hidden; }
.card--raised { box-shadow: var(--shadow); border-color: transparent; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card__head h2 { margin: 0; }

.grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid--2 { grid-template-columns: 1fr 1fr; } .grid--3 { grid-template-columns: repeat(3, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi__value { font-size: 1.75rem; font-weight: 760; font-stretch: 110%; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi__label { font-size: .85rem; color: var(--ink-3); }
.kpi--late .kpi__value { color: var(--st-late); }
.kpi--done .kpi__value { color: var(--st-done); }

.stack > * + * { margin-top: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row--end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.row .field.grow { min-width: 200px; }
.spacer { flex: 1; }

/* --- forms --------------------------------------------------------------- */

.field { display: block; }
.field > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.field .hint { display: block; font-weight: 400; color: var(--ink-3); font-size: .85rem; margin-top: 4px; }
input, select, textarea, button { font: inherit; }
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea {
    width: 100%; min-height: var(--tap); padding: 10px 12px;
    font-size: 16px; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line-2); border-radius: var(--radius-s);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18, 38, 63, .16); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: var(--tap); padding: 10px 0; cursor: pointer; }
.check strong { display: block; }
.form-grid { display: grid; gap: 14px; }
@media (min-width: 720px) { .form-grid--2 { grid-template-columns: 1fr 1fr; } }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; margin-bottom: 8px; }
.save-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.save-bar__note { color: var(--warn); font-size: .9rem; }

/* --- buttons ------------------------------------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 0 18px;
    font-weight: 650; font-stretch: 104%; text-decoration: none; white-space: nowrap;
    color: var(--brand); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-s);
    cursor: pointer; transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn--brand { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn--brand:hover { background: var(--brand-2); }
.btn--quiet { background: transparent; border-color: transparent; color: var(--link); padding: 0 10px; }
.btn--quiet:hover { background: var(--surface-2); border-color: transparent; }
.btn--danger { color: var(--err); }
.btn--danger:hover { border-color: var(--err); background: var(--err-bg); }
.btn--small { min-height: 44px; padding: 0 12px; font-size: .9rem; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* --- notices, badges ----------------------------------------------------- */

.notice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 14px; border-radius: var(--radius-s); margin: 0 0 16px; border: 1px solid transparent; }
.notice--ok { background: var(--ok-bg); color: #0E4A31; border-color: #BFE3CE; }
.notice--info { background: var(--info-bg); color: #163E7A; border-color: #C9DAF5; }
.notice--warn { background: var(--warn-bg); color: #7A3A05; border-color: #F5D9A3; }
.notice--error { background: var(--err-bg); color: #7A1810; border-color: #F3C3BD; }
.notice__close { margin-left: auto; background: transparent; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; color: inherit; min-width: 44px; min-height: 44px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 650; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge--plain::before { display: none; }
.badge--waiting { color: var(--st-waiting); }
.badge--progress { color: var(--st-progress); background: #EEF4FD; border-color: #CFDDF6; }
.badge--done { color: var(--st-done); background: var(--ok-bg); border-color: #BFE3CE; }
.badge--late { color: var(--st-late); background: var(--err-bg); border-color: #F3C3BD; }
.badge--risk { color: var(--st-risk); background: var(--warn-bg); border-color: #F5D9A3; }
.badge--off { color: var(--ink-3); }

/* --- tables → cards under 720 px ---------------------------------------- */

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .82rem; font-weight: 650; color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th.right, .table td.right { text-align: right; }
.table a.row-link { font-weight: 650; color: var(--ink); text-decoration: none; }
.table a.row-link:hover { color: var(--link); text-decoration: underline; }
@media (max-width: 719px) {
    .table--cards thead { display: none; }
    .table--cards, .table--cards tbody, .table--cards tr, .table--cards td { display: block; width: 100%; }
    .table--cards tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
    .table--cards tr:last-child { border-bottom: 0; }
    .table--cards td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; }
    .table--cards td[data-label]::before { content: attr(data-label); color: var(--ink-3); font-size: .85rem; }
    .table--cards td.table__main { font-size: 1.05rem; display: block; }
    .table--cards td.table__main::before { display: none; }
    /* Compact cards: the cells after the name share wrapped lines; only `.keep-label` cells keep their label. */
    .table--inline tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
    .table--inline td { width: auto; padding: 0; display: inline-flex; align-items: center; gap: 6px; }
    .table--inline td.table__main { width: 100%; padding-bottom: 4px; }
    .table--inline td[data-label]::before { display: none; }
    .table--inline td.keep-label::before { display: inline; font-size: .8rem; }
    .table--inline td.right { margin-left: auto; }
}

/* Search and filter rows above lists. */
.filters, .search-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-bottom: 14px; }
.search-row { flex-wrap: nowrap; max-width: 520px; }
.search-row .field { flex: 1 1 auto; min-width: 0; }
.filters > .btn, .search-row > .btn { flex: none; }
.filters .field > span:not(.sr-only) { font-size: .85rem; margin-bottom: 4px; }

/* --- tabs, empty states, details folds ---------------------------------- */

.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 8px; vertical-align: -2px; background: var(--line-2); flex: none; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0 0 18px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 14px; color: var(--ink-2); text-decoration: none; font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--accent); }

/* Label / value pairs (run, invoice). */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.facts dt { color: var(--ink-3); font-size: .9rem; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 36px 20px; color: var(--ink-2); }
.empty .icon { width: 44px; height: 44px; color: var(--line-2); margin-bottom: 10px; }
.empty h2 { color: var(--ink); }
.empty p { max-width: 46ch; margin: 0 auto 16px; }

.fold { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }
.fold > summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 16px; cursor: pointer; font-weight: 650; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); }
.fold[open] > summary::after { transform: rotate(225deg); }
.fold__body { padding: 0 16px 16px; }

/* --- setup cards (wizard) ------------------------------------------------ */

.choices { display: grid; gap: 12px; }
@media (min-width: 720px) { .choices { grid-template-columns: repeat(2, 1fr); } }
.choice { position: relative; display: flex; gap: 14px; padding: 16px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.choice:hover { border-color: var(--brand); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
.choice:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.choice__icon { width: 44px; height: 44px; border-radius: var(--radius-s); background: #EEF2F8; color: var(--brand); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.choice strong { display: block; font-stretch: 106%; }
.choice span { color: var(--ink-2); font-size: .92rem; }

/* --- auth pages ---------------------------------------------------------- */

body.bare { min-height: 100vh; background: var(--brand); }
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px var(--gutter); background-image: url("../img/tracks-bg.svg"); background-size: cover; background-position: center; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: var(--radius); padding: 24px 22px 20px; box-shadow: var(--shadow-up); }
.auth-card h1 { font-size: 1.45rem; margin: 18px 0 16px; }
.auth-card__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.auth-card__top .brand { color: var(--brand); }
.auth-card__foot { margin: 16px 0 0; }
.auth-card--wide { max-width: 560px; }
.lang-switch { display: flex; gap: 2px; }
.lang-switch a { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; border-radius: var(--radius-xs); color: var(--ink-3); text-decoration: none; font-weight: 650; font-size: .85rem; }
.lang-switch a[aria-current="true"] { color: var(--brand); background: #EEF2F8; }

/* --- licence lock, maps -------------------------------------------------- */

body.is-locked .page form:not([data-open-when-locked]) { opacity: .55; pointer-events: none; }

.map { position: relative; z-index: 0; isolation: isolate; min-height: 320px; border-radius: var(--radius); overflow: hidden; background: #DDE3DA; }

/* --- reduced motion ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media print {
    .topbar, .nav, .support-bar, .notice__close, .save-bar { display: none !important; }
    body { background: #fff; }
    .card { border-color: #bbb; }
}
.input-days { width: 110px !important; }
.log { overflow-x: auto; white-space: pre; background: var(--surface-2); padding: 12px; border-radius: var(--radius-s); }

/* --- address combo (shared) ---------------------------------------------- */
.combo { position: relative; }
.combo > label > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
.combo__list { position: absolute; left: 0; right: 0; top: 100%; z-index: 1150; margin: 4px 0 0; padding: 4px; list-style: none;
    background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-s); box-shadow: var(--shadow-up); max-height: 300px; overflow-y: auto; }
.combo__list [role=option] { padding: 10px 12px; border-radius: var(--radius-xs); cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }
.combo__list [role=option]:hover, .combo__list [aria-selected=true] { background: var(--surface-2); }
.combo__hint { padding: 10px 12px; color: var(--ink-3); }
