/* =========================================================================
   SDH design system v2 — vendored (no CDN), CSP-safe.
   App shell: desktop sidebar + mobile bottom nav. Mobile-first, WCAG 2.1 AA,
   light + dark, reduced-motion aware.
   ========================================================================= */

:root {
    --bg:        #eef2f7;
    --surface:   #ffffff;
    --surface-2: #f7f9fc;
    --surface-3: #eef2f7;
    --border:    #e4e9f0;
    --text:      #0f172a;
    --muted:     #5a6b80;
    --brand:     #c01722;
    --brand-700: #9c1119;
    --brand-50:  #fdecec;
    --brand-ink: #ffffff;
    --accent:    #1d4ed8;
    --ok:        #047857;  --ok-bg:#d9f5e8;
    --warn:      #a85a06;  --warn-bg:#fdefcf;
    --err:       #be123c;  --err-bg:#ffe1e6;
    --ring:      #2563eb;
    --r-sm: .5rem; --r: .8rem; --r-lg: 1.1rem;
    --sh-1: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
    --sh-2: 0 4px 12px rgba(16,24,40,.08), 0 2px 4px rgba(16,24,40,.04);
    --sidebar: 15rem;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark;
    --bg:#0a0f1c; --surface:#131a2a; --surface-2:#0f1626; --surface-3:#1b2435; --border:#263044;
    --text:#eef2f7; --muted:#9fb0c6; --brand:#ef4444; --brand-700:#dc2626; --brand-50:#2a1416;
    --accent:#60a5fa; --ok:#34d399; --ok-bg:#09352a; --warn:#fbbf24; --warn-bg:#3a2a08;
    --err:#fb7185; --err-bg:#3a1420; --ring:#60a5fa;
    --sh-1:0 1px 2px rgba(0,0,0,.4); --sh-2:0 6px 18px rgba(0,0,0,.45); } }
:root[data-theme="dark"] { color-scheme: dark;
    --bg:#0a0f1c; --surface:#131a2a; --surface-2:#0f1626; --surface-3:#1b2435; --border:#263044;
    --text:#eef2f7; --muted:#9fb0c6; --brand:#ef4444; --brand-700:#dc2626; --brand-50:#2a1416;
    --accent:#60a5fa; --ok:#34d399; --ok-bg:#09352a; --warn:#fbbf24; --warn-bg:#3a2a08;
    --err:#fb7185; --err-bg:#3a1420; --ring:#60a5fa;
    --sh-1:0 1px 2px rgba(0,0,0,.4); --sh-2:0 6px 18px rgba(0,0,0,.45); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased; }
h1,h2,h3 { line-height: 1.2; letter-spacing: -.01em; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; }   /* never let an image overflow its container */
@media (prefers-reduced-motion: no-preference) { .card, .btn, .navlink { transition: .15s ease; } }

:where(a,button,input,select,textarea,[tabindex]):focus-visible {
    outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: -999px; top: .5rem; z-index: 100;
    background: var(--brand); color: #fff; padding: .6rem 1rem; border-radius: var(--r-sm); }
.skip-link:focus { left: .5rem; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.ico { width: 1.25rem; height: 1.25rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; vertical-align: -.2em; }

/* ---- App shell ---------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100dvh; }
@media (min-width: 1024px) { .shell { grid-template-columns: var(--sidebar) 1fr; } }

.sidebar { display: none; }
@media (min-width: 1024px) {
    .sidebar { display: flex; flex-direction: column; gap: .25rem;
        background: var(--surface); border-right: 1px solid var(--border);
        padding: 1rem .75rem; position: sticky; top: 0; height: 100dvh; }
    .sidebar .brand { padding: .35rem .6rem 1rem; }
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; letter-spacing: -.02em; font-size: 1.05rem; }
.brand .logo { width: 2rem; height: 2rem; display: grid; place-items: center; background: var(--brand); color:#fff; border-radius: .6rem; }

.navlink { display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: var(--r-sm);
    color: var(--text); text-decoration: none; font-weight: 600; font-size: .92rem; }
.navlink:hover { background: var(--surface-3); }
.navlink[aria-current="page"] { background: var(--brand-50); color: var(--brand); }
.sidebar .sb-foot { margin-top: auto; }

/* Topbar (mobile shows brand; desktop shows page actions) */
.topbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1rem; background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.3) blur(8px); border-bottom: 1px solid var(--border); }
.topbar .brand { font-size: 1rem; }
@media (min-width: 1024px) { .topbar .brand.mobile-only { display: none; } }

.content { min-width: 0; display: flex; flex-direction: column; }
main { padding: 1.1rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); max-width: 72rem; width: 100%; margin: 0 auto; }
@media (min-width: 1024px) { main { padding-bottom: 3rem; } }
.stack > * + * { margin-top: 1.75rem; }

/* Page header */
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.4rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.spacer { flex: 1; }

/* ---- Bottom nav (mobile) ------------------------------------------------ */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border); padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom)); }
.bottom-nav::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .bottom-nav { display: none; } }
.bottom-nav a { flex: 1 0 auto; min-width: 4.3rem; display: flex; flex-direction: column; align-items: center; gap: .1rem;
    padding: .4rem .3rem; border-radius: var(--r-sm); color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 600; }
.bottom-nav a[aria-current="page"] { color: var(--brand); }
.bottom-nav a:hover { background: var(--surface-3); }

/* ---- Grid / cards ------------------------------------------------------- */
.grid { display: grid; gap: .9rem; grid-template-columns: 1fr; }
@media (min-width: 560px){ .grid.sm-2{ grid-template-columns: repeat(2,1fr);} }
@media (min-width: 1024px){ .grid.lg-3{ grid-template-columns: repeat(3,1fr);} .grid.lg-4{ grid-template-columns: repeat(4,1fr);} }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--sh-1); padding: 1.1rem; }
a.card:hover, .card.hoverable:hover { box-shadow: var(--sh-2); transform: translateY(-2px); }
.card h3 { margin: 0 0 .3rem; font-size: 1rem; }

/* KPI tiles */
.kpi { display: flex; align-items: center; gap: .9rem; }
.kpi .ic { width: 2.7rem; height: 2.7rem; border-radius: .7rem; display: grid; place-items: center;
    background: var(--brand-50); color: var(--brand); flex: none; }
.kpi .value { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi.is-alert .ic { background: var(--err-bg); color: var(--err); }
.kpi.is-ok .ic { background: var(--ok-bg); color: var(--ok); }

/* ---- Badges / pills ----------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem;
    border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.badge::before { content:""; width:.42rem; height:.42rem; border-radius:50%; background: currentColor; }
.badge-ok{ background:var(--ok-bg); color:var(--ok);} .badge-warn{ background:var(--warn-bg); color:var(--warn);}
.badge-err{ background:var(--err-bg); color:var(--err);} .badge-muted{ background:var(--surface-3); color:var(--muted);}
.badge-info{ background:#e0ecff; color:var(--accent);}

/* ---- Buttons ------------------------------------------------------------ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .55rem .95rem; border-radius: var(--r-sm); border: 1px solid transparent;
    font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--sh-1); }
.btn-primary:hover { background: var(--brand-700); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--err-bg); color: var(--err); }
.btn-sm { min-height: 38px; padding: .4rem .7rem; font-size: .82rem; }
.btn-icon { min-height: 40px; width: 40px; padding: 0; }
.bell-badge { position: absolute; top: 1px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px; background: var(--brand); color: #fff; font-size: .6rem; font-weight: 800;
    display: grid; place-items: center; line-height: 1; }
.btn-block { width: 100%; }

/* ---- Toolbar / search --------------------------------------------------- */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.search { flex: 1; min-width: 12rem; position: relative; }
.search .ico { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 2.3rem; }

/* ---- Tables (desktop) / cards (mobile) ---------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-1); }
table.data { min-width: max-content; }
table.data th, table.data td { white-space: nowrap; }
table.data td:first-child, table.data th:first-child { white-space: normal; } /* let the name column wrap */
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data thead { background: var(--surface-2); }
table.data th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing:.04em; color: var(--muted); padding: .7rem .9rem; }
table.data td { padding: .75rem .9rem; border-top: 1px solid var(--border); }
table.data tbody tr:hover { background: var(--surface-2); }
.only-desktop { display: none; } .only-mobile { display: block; }
@media (min-width: 820px){ .only-desktop{ display: table;} .only-mobile{ display: none;} }
.mobile-list { list-style: none; margin: 0; padding: 0; }
.mobile-list li { padding: .9rem 1rem; border-top: 1px solid var(--border); }
.mobile-list li:first-child { border-top: 0; }

/* ---- Forms -------------------------------------------------------------- */
.field { display: block; margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .9rem; }
.input, select, textarea { width: 100%; padding: .65rem .75rem; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); min-height: 44px; }
.input:focus, select:focus, textarea:focus { border-color: var(--ring); }
textarea { min-height: 5rem; resize: vertical; }
.hint { color: var(--muted); font-size: .8rem; margin-top: .35rem; }

/* ---- Combobox (searchable select) -------------------------------------- */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 25; left: 0; right: 0; top: calc(100% + 3px);
    margin: 0; padding: .25rem; list-style: none; max-height: 16rem; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--sh-2); }
.combo-list li { padding: .55rem .6rem; border-radius: var(--r-sm); cursor: pointer; }
.combo-list li:hover { background: var(--surface-3); }

/* ---- Segmented control (OK / NOK / N/A per step) ----------------------- */
.step-row { padding: .75rem; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); }
.step-row + .step-row { margin-top: .6rem; }
.step-row .instr { font-weight: 600; margin-bottom: .5rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented span { display: block; padding: .5rem .9rem; font-weight: 700; font-size: .85rem; color: var(--muted); border-right: 1px solid var(--border); min-height: 40px; display: grid; place-items: center; }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--brand-50); color: var(--brand); }

/* Dashboard "customize" toggle: a small right-aligned chip; the panel (full
   width) only appears when expanded, so it costs almost no space collapsed. */
.dash-customize { display: flex; flex-direction: column; align-items: flex-end; margin: 0 0 .25rem; }
.dash-customize > summary { list-style: none; cursor: pointer; width: max-content;
    display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; font-weight: 600;
    color: var(--muted); padding: .3rem .55rem; border-radius: var(--r-sm); }
.dash-customize > summary::-webkit-details-marker { display: none; }
.dash-customize > summary:hover { color: var(--brand); background: var(--surface-3); }
.dash-customize > summary svg { width: 1rem; height: 1rem; }
.dash-customize > form { width: 100%; }

/* Warehouse group filter: horizontally scrollable chip row + group headings. */
.wh-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .7rem;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
    color: var(--text); font-size: .82rem; font-weight: 600; text-decoration: none;
    white-space: nowrap; line-height: 1; }
.chip:hover { background: var(--surface-3); }
.chip.is-active { background: var(--brand-50); border-color: var(--brand); color: var(--brand); }
.chip .chip-n { font-size: .7rem; font-weight: 700; padding: .05rem .4rem; border-radius: 999px;
    background: var(--surface-3); color: var(--muted); }
.chip.is-active .chip-n { background: var(--brand); color: #fff; }
.chip-toggle svg { width: .9rem; height: .9rem; }
.wh-group { font-size: 1rem; font-weight: 700; color: var(--muted); margin: 1.4rem 0 .6rem;
    text-transform: uppercase; letter-spacing: .03em; }
.wh-group:first-of-type { margin-top: 0; }

/* Contextual help "?" next to a page heading. */
.help-dot { display: inline-flex; vertical-align: middle; color: var(--muted); margin-left: .4rem; }
.help-dot:hover { color: var(--brand); }
.help-dot svg { width: 1.15rem; height: 1.15rem; }

/* Field flagged by client-side validation. */
.input-error { border-color: var(--err); box-shadow: 0 0 0 3px var(--err-bg); }

/* Voided (storno) finance rows: kept visible but clearly struck. */
.is-voided { opacity: .6; }
.is-voided .link-plain, .is-voided strong.mono { text-decoration: line-through; }

/* Sticky action bar so Save stays reachable one-handed on long mobile forms. */
.sticky-actions { position: sticky; bottom: calc(5rem + env(safe-area-inset-bottom)); z-index: 5;
    background: var(--surface); padding: .6rem; margin: 0 -.2rem; border-radius: var(--r-sm); box-shadow: var(--sh-1); }
@media (min-width: 1024px) { .sticky-actions { position: static; background: none; padding: 0; margin: 0; box-shadow: none; } }
.segmented input[value="ok"]:checked  + span { background: var(--ok-bg);  color: var(--ok); }
.segmented input[value="nok"]:checked + span { background: var(--err-bg); color: var(--err); }
.segmented input[value="na"]:checked  + span { background: var(--surface-3); color: var(--text); }
.segmented input:focus-visible + span { outline: 3px solid var(--ring); outline-offset: -3px; }

/* ---- QR label selection + print grid ----------------------------------- */
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; grid-template-columns: 1fr; }
@media (min-width: 560px){ .pick-list { grid-template-columns: repeat(2,1fr);} }
@media (min-width: 1024px){ .pick-list { grid-template-columns: repeat(3,1fr);} }
.pick-list label { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--border);
    border-radius: var(--r-sm); background: var(--surface); cursor: pointer; }
.pick-list input { width: 1.15rem; height: 1.15rem; }
@media print { .qr-grid { gap: 1.2rem; } }

/* ---- Reservations calendar --------------------------------------------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.cal-head { margin-bottom: .3rem; }
.cal-dow { text-align: center; font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.cal-cell { min-height: 5rem; border: 1px solid var(--border); border-radius: var(--r-sm); padding: .3rem; background: var(--surface); overflow: hidden; }
.cal-out { opacity: .45; }
.cal-today { outline: 2px solid var(--brand); outline-offset: -2px; }
.cal-day { font-size: .75rem; font-weight: 700; color: var(--muted); }
.cal-item { font-size: .66rem; padding: .1rem .3rem; border-radius: 4px; margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-res-item { background: #e0ecff; color: var(--accent); }
.cal-out-item { background: var(--warn-bg); color: var(--warn); }
@media (max-width: 640px) { .cal-cell { min-height: 3.5rem; } .cal-item { font-size: .58rem; } }

/* ---- Alerts / empty state ---------------------------------------------- */
.alert { padding: .8rem 1rem; border-radius: var(--r-sm); border: 1px solid var(--border); margin-bottom: 1rem; }
.alert-err { background: var(--err-bg); color: var(--err); border-color: transparent; }
.alert-ok  { background: var(--ok-bg);  color: var(--ok);  border-color: transparent; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .ico { width: 2.5rem; height: 2.5rem; opacity: .6; margin-bottom: .5rem; }

/* ---- Auth --------------------------------------------------------------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1rem;
    background: radial-gradient(1200px 500px at 50% -10%, var(--brand-50), var(--bg)); }
.auth-card { width: 100%; max-width: 24rem; }

.row { display: flex; gap: .5rem; align-items: center; } .row.wrap { flex-wrap: wrap; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 .7rem; font-weight: 700; }
.text-muted { color: var(--muted); } .text-sm { font-size: .85rem; } .mono { font-family: ui-monospace,"Cascadia Code",Consolas,monospace; }

/* A link that reads as a title/row, not raw blue text. */
.link-plain { color: var(--text); text-decoration: none; }
.link-plain:hover { color: var(--brand); text-decoration: underline; }

/* ---- Lightbox (full-image gallery view) -------------------------------- */
.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center;
    justify-content: center; padding: 1rem; background: rgba(0,0,0,.85); cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; width: auto; height: auto;
    object-fit: contain; border-radius: .4rem; box-shadow: 0 10px 40px rgba(0,0,0,.5); }

/* ---- Print -------------------------------------------------------------- */
@media print { .sidebar,.topbar,.bottom-nav,.btn,.no-print{ display:none !important; }
    body{ background:#fff; } main{ padding:0; max-width:none; } .card,.table-wrap{ box-shadow:none; border-color:#999; } }
