/* ==========================================================================
   Kiwa Estonia — application styles
   Brand palette (from slogan.png / kiwa.com 2024):
                   Kiwa blue #2253be · mint #c8fbde · white #ffffff
                   support: navy #0f2f6b · slate #2a3f54
   Slogan lockup:  "creating trust" (white) / "driving progress" (mint italic)
   Theming is driven by CSS custom properties switched on [data-theme].
   ========================================================================== */

@font-face {
    font-family: "Azo Sans";
    src: url("/fonts/azo-sans-light.woff2") format("woff2");
    font-weight: 300;
    font-display: swap;
}

/* ---- Design tokens ------------------------------------------------------- */
:root {
    --kiwa-blue:  #2253be;   /* brand blue, sampled from slogan.png */
    --kiwa-blue-d:#1a4198;   /* darker blue for hover/press states */
    --kiwa-navy:  #0f2f6b;   /* deep blue for footer / contrast */
    --kiwa-slate: #2a3f54;
    --kiwa-cyan:  #3b6fd6;
    --kiwa-aqua:  #6f9bec;
    --kiwa-mint:  #c8fbde;   /* mint accent, sampled from slogan.png */
    --kiwa-green: #1d774d;
    --kiwa-red:   #d1111c;
    /* Red used as TEXT (errors, delete/ban icons, expired dates). Lightened
       in the dark theme; red backgrounds and borders keep --kiwa-red. */
    --danger-text: var(--kiwa-red);

    --radius: 6px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(7, 38, 67, 0.12);
    --shadow-md: 0 4px 16px rgba(7, 38, 67, 0.14);
    --shadow-lg: 0 12px 40px rgba(7, 38, 67, 0.22);
    /* Signed-out (public) pages: a centred column. Signed-in pages override
       this to the full screen width (body.has-sidebar below). */
    --container: 1140px;
    /* Reading width for public form/text pages. */
    --container-narrow: 1100px;
    /* One height for every interactive control — inputs, selects and buttons
       all use these, so anything sitting on the same row lines up exactly.
       -sm is the compact variant for table rows and dense grids. */
    --control-h: 46px;
    --control-h-sm: 36px;
    --header-h: 72px;
    --transition: 0.25s ease;
    --font: "Aptos", "Azo Sans", "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Light theme (default) */
:root, :root[data-theme="light"] {
    --bg:        #f4f6f9;
    --bg-elev:   #ffffff;
    --bg-alt:    #eef2f6;
    --text:      #1a2733;
    --text-mut:  #5b6b7a;
    --border:    #d7dee6;
    --primary:   var(--kiwa-blue);
    --primary-ct:#ffffff;
    --accent:    var(--kiwa-blue);
    --header-bg: #ffffff;
    --footer-bg: var(--kiwa-navy);
    --footer-ct: #dfeaff;
}

/* Dark theme */
:root[data-theme="dark"] {
    /* Native parts (scrollbars, date pickers, select lists, checkboxes,
       range tracks, autofill) follow the theme instead of staying light. */
    color-scheme: dark;
    --danger-text: #ff6b6b;
    --bg:        #0e1a26;
    --bg-elev:   #142534;
    --bg-alt:    #18303f;
    --text:      #e7eef5;
    --text-mut:  #9db0c2;
    --border:    #274054;
    --primary:   #4f83e8;
    --primary-ct:#ffffff;
    --accent:    var(--kiwa-mint);
    --header-bg: #0d1926;
    --footer-bg: #0a1c42;
    --footer-ct: #c4d2df;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ---- Base ---------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; color: var(--text); }
img { max-width: 100%; }

.container { max-width: var(--container); margin: 0 auto; padding: 0 20px; }
.container.narrow { max-width: var(--container-narrow); }
/* Signed in: every page, forms included, spans the full screen width.
   Signed out: the capped column above. */
body.has-sidebar .container { max-width: 100%; }

/* One size for every text-like control across the site: inputs, selects,
   date pickers — same height, padding and border everywhere. */
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="tel"], input[type="number"], input[type="date"], select {
    height: var(--control-h);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    box-sizing: border-box;
}
textarea {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text); font: inherit; resize: vertical;
}

/* Visible focus on every control, site-wide. */
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(34, 83, 190, .18);
}
.btn:focus-visible, .icon-btn:focus-visible, a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Main content always fills the viewport (minus the sticky header), so the
   footer sits below the fold on every page — even short ones. */
main.page {
    min-height: calc(100vh - var(--header-h));
    min-height: calc(100dvh - var(--header-h));
}

/* ---- Buttons ------------------------------------------------------------- */
/* Buttons are sized like inputs, not by their text box: inline-flex with a
   fixed height means an <a class="btn"> and a <button class="btn"> come out
   identical (they inherit different line-heights otherwise) and both line up
   with the inputs and selects beside them. */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--control-h);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0 24px;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-alt);
    color: var(--text);
    box-sizing: border-box;
}
.btn:hover { text-decoration: none; }
.btn[hidden] { display: none; }   /* inline-block would otherwise defeat [hidden] */
.btn-primary { background: var(--primary); color: var(--primary-ct); }
.btn-primary:hover { background: var(--kiwa-navy); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { min-height: 54px; padding: 0 32px; font-size: 1.05rem; }

/* ---- Header -------------------------------------------------------------- */
.site-header {
    position: sticky; top: 0; z-index: 50;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.header-inner {
    display: flex; align-items: center; gap: 20px;
    height: var(--header-h);
}
.brand { display: flex; align-items: center; flex-shrink: 0; }
.brand img { width: 115px; max-width: none; height: auto; }   /* height follows width: the logo keeps its 1350:469 ratio */
/* Blue wordmark reads poorly on the dark header — render it white. */
:root[data-theme="dark"] .brand img { filter: brightness(0) invert(1); }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* Classic top navigation — shown to guests on desktop. */
.main-nav { display: flex; gap: 8px; margin-left: 12px; }
.main-nav a {
    color: var(--text); font-weight: 600; padding: 8px 12px;
    border-radius: var(--radius); transition: all var(--transition);
}
.main-nav a:hover { background: var(--bg-alt); text-decoration: none; color: var(--primary); }

/* ---- Left sidebar navigation ---------------------------------------------- */
.sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: var(--sidebar-w, 240px);
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    padding: 18px 12px;
    overflow-y: auto;
    z-index: 45;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar a {
    display: block; padding: 11px 14px; border-radius: var(--radius);
    color: var(--text); font-weight: 600; transition: all var(--transition);
}
.sidebar a:hover { background: var(--bg-alt); color: var(--primary); text-decoration: none; }
.sidebar a.active { background: var(--primary); color: var(--primary-ct); }
.sidebar-sep { border-top: 1px solid var(--border); margin: 12px 4px; }
.sidebar-heading {
    font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
    color: var(--text-mut); padding: 4px 14px 6px;
}
/* A heading that folds its group away (Superadmin). */
.sidebar-toggle {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    background: none; border: 0; border-radius: var(--radius); cursor: pointer;
    font-family: inherit; text-align: left; padding: 8px 14px;
}
.sidebar-toggle:hover { color: var(--primary); background: var(--bg-alt); }
.sidebar-toggle svg { transition: transform var(--transition); }
.sidebar-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.sidebar-group[hidden] { display: none; }

/* Superadmin pages */
.admin-form { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.admin-form input, .admin-form select {
    flex: 1; min-width: 170px; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit;
}
.admin-form .btn { flex: 0 0 auto; }
.admin-error { color: var(--danger-text); margin-bottom: 14px; }
.admin-ok { color: var(--kiwa-green); margin-bottom: 14px; }
/* Superadmin file-transfer management (/admin/transfers). */
.status-chip.transfer-active { background: var(--kiwa-green); color: #fff; }
.status-chip.transfer-expired { background: var(--kiwa-red); color: #fff; }
.status-chip.transfer-cleared { background: var(--bg-alt); color: var(--text-mut); border: 1px solid var(--border); }
.transfer-meta { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-bottom: 22px; font-size: .9rem; color: var(--text); }
.transfer-meta-label { color: var(--text-mut); margin-right: 4px; }
.transfer-meta-link { flex-basis: 100%; word-break: break-all; }
.transfer-admin-actions { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; margin-bottom: 30px; }
.transfer-admin-actions form { display: inline-flex; align-items: center; gap: 12px; }
.form-hint { display: block; color: var(--text-mut); font-size: .82rem; margin-top: 4px; }
.client-actions a.btn { vertical-align: middle; }
.transfer-new-code code { font-size: 1.15rem; font-weight: 700; letter-spacing: 1px; background: var(--bg-alt); padding: 2px 8px; border-radius: 4px; }
.dash-table code { font-weight: 600; letter-spacing: .5px; }
.menu-slug { color: var(--text-mut); font-size: .78rem; margin-left: 6px; }
.menu-state.on { color: var(--kiwa-green); font-weight: 700; }
.menu-state.off { color: var(--danger-text); font-weight: 700; }
.menu-group td {
    background: var(--bg-alt); font-weight: 700; font-size: .74rem;
    text-transform: uppercase; letter-spacing: .04em; color: var(--text-mut);
    padding: 7px 12px;
}
.inline-form { display: inline; }
.btn-sm { min-height: var(--control-h-sm); padding: 0 12px; font-size: .9rem; }

.admin-edit-form .form-row { margin-bottom: 16px; }
.admin-edit-form label { display: block; font-size: .85rem; color: var(--text-mut); margin-bottom: 4px; }
.admin-edit-form input, .admin-edit-form select, .admin-edit-form textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit;
}
.menu-group-label {
    font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-mut); margin: 14px 0 8px;
}
.menu-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.menu-check {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; cursor: pointer; font-weight: 600;
}
.menu-check input { width: 18px; height: 18px; accent-color: var(--primary); }
.menu-check-disabled { opacity: .55; }
.ban-check { max-width: 320px; }
.ban-check input { accent-color: var(--kiwa-red); }

.status-chip {
    display: inline-block; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap;
    padding: 3px 10px; background: var(--bg-alt); border: 1px solid var(--border);
}
.client-actions { white-space: nowrap; }
.cell-role { white-space: nowrap; }
.cell-role .role-select { height: var(--control-h-sm); padding: 4px 8px; width: auto; margin-right: 6px; }

/* Inline member editing inside a client card */
.member-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 14px; margin-bottom: 8px;
}
.member-row input[type=email] { flex: 2; min-width: 220px; }
.member-avatar {
    width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg-alt); border: 1px solid var(--border);
}
.member-avatar-ph { font-size: .8rem; font-weight: 700; color: var(--text-mut); }
.member-id { flex: 2; min-width: 180px; display: flex; flex-direction: column; gap: 1px; }
.member-row .member-email { font-weight: 600; word-break: break-all; }
.member-sub { font-size: .8rem; color: var(--text-mut); }
.member-row select { flex: 0 0 130px; }
.member-actions { display: flex; gap: 6px; margin-left: auto; }
.member-actions .act-accept { color: var(--kiwa-green); }
.member-actions .act-ban { color: var(--danger-text); }
.member-actions .act-delete { color: var(--danger-text); }
.client-actions .act-accept { color: var(--kiwa-green); }
.client-actions .act-ban { color: var(--danger-text); }
.status-chip.banned { background: var(--kiwa-red); color: #fff; }
.status-chip.invited { background: var(--bg-alt); color: var(--text-mut); border: 1px solid var(--border); }
.admin-ok { color: var(--kiwa-green); font-weight: 600; margin-bottom: 14px; }
.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(7, 38, 67, .5); z-index: 125;
}

/* Desktop: signed-in users get the fixed sidebar column; guests keep the
   classic top navigation with full-width content. */
@media (min-width: 861px) {
    body.has-sidebar main.page, body.has-sidebar .site-footer { margin-left: var(--sidebar-w, 240px); }
    body:not(.has-sidebar) .sidebar { display: none; }
}

/* Mobile: sidebar becomes a slide-in overlay driven by the burger button. */
@media (max-width: 860px) {
    .sidebar {
        top: 0; height: 100%; width: 270px;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 130;
        box-shadow: none;
    }
    .sidebar.open { transform: none; box-shadow: 12px 0 40px rgba(0, 0, 0, .3); }
}

.icon-btn {
    background: transparent; border: 1px solid transparent; color: var(--text);
    font: inherit; font-size: .95rem; cursor: pointer;
    padding: 8px 12px; border-radius: var(--radius); transition: all var(--transition);
    display: inline-flex; align-items: center; gap: 6px;
    white-space: nowrap;          /* controls never wrap internally */
}
.icon-btn:hover { background: var(--bg-alt); }
#userBtn .user-email {
    max-width: 180px; overflow: hidden; text-overflow: ellipsis; display: inline-block;
    vertical-align: bottom;
}
.menu-user-email { display: none; }
@media (max-width: 640px) {
    /* Compact account button on phones: icon only; email lives in the menu. */
    #userBtn .user-email { display: none; }
    .icon-btn { padding: 8px 8px; }
    .header-inner { gap: 8px; }
    .menu-user-email {
        display: block; padding: 8px 12px 10px; color: var(--text-mut);
        font-size: .82rem; border-bottom: 1px solid var(--border); margin-bottom: 4px;
        max-width: 220px; overflow: hidden; text-overflow: ellipsis;
    }
}

.theme-toggle .theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-toggle .theme-icon-dark { display: inline; }

/* Dropdowns */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    list-style: none; margin: 0; padding: 6px; min-width: 150px;
    display: none; z-index: 60;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button {
    display: block; width: 100%; text-align: left;
    background: transparent; border: 0; color: var(--text);
    font: inherit; padding: 9px 12px; border-radius: var(--radius); cursor: pointer;
}
.dropdown-menu button:hover { background: var(--bg-alt); }
.dropdown-menu button.active { color: var(--primary); font-weight: 700; }

/* Language flags */
.flag { display: inline-block; width: 1.35em; text-align: center; line-height: 1; }
/* Drawn flags, not emoji (Windows has no flag glyphs). The hairline ring keeps
   the white-heavy flags — Poland, Finland — from dissolving into the menu. */
.flag svg {
    width: 1.15em; height: auto; display: inline-block; vertical-align: -.15em;
    border-radius: 1.5px; box-shadow: 0 0 0 .5px rgba(0, 0, 0, .22);
}
:root[data-theme="dark"] .flag svg { box-shadow: 0 0 0 .5px rgba(255, 255, 255, .35); }
#langMenu .lang-option { display: flex; align-items: center; gap: 4px; }
.menu-divider hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; }

/* On small screens the language menu becomes a bottom sheet:
   full-width, two columns, large touch targets. */
@media (max-width: 640px) {
    .lang-switch .dropdown-menu {
        position: fixed;
        top: auto; left: 0; right: 0; bottom: 0;
        border-radius: 16px 16px 0 0;
        border: none;
        box-shadow: 0 -8px 48px rgba(0, 0, 0, .4);
        max-height: 70vh;
        overflow-y: auto;
        padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
        grid-template-columns: 1fr 1fr;
        gap: 4px 10px;
        z-index: 120;
    }
    .lang-switch .dropdown-menu.open { display: grid; }
    .lang-switch .menu-divider { grid-column: 1 / -1; }
    .lang-switch .lang-option { padding: 14px 12px; font-size: 1.05rem; }
}

/* Nav toggle (mobile) */
.nav-toggle { display: none; flex-direction: column; gap: 5px; background: none; border: 0; cursor: pointer; padding: 8px; }
.nav-toggle span { width: 24px; height: 2px; background: var(--text); border-radius: 2px; }

/* ---- Auth panel ---------------------------------------------------------- */
.auth-panel {
    position: absolute; right: 20px; top: var(--header-h);
    width: 320px; background: var(--bg-elev);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 22px; display: none; z-index: 70;
}
.auth-panel.open { display: block; }

/* On phones the panel stops being a dropdown hanging off the header — at that
   width it would sit against the edge and run off the bottom. It becomes a
   centred dialog over a dimmed page instead. */
@media (max-width: 640px) {
    .auth-panel {
        position: fixed;
        top: 50%; left: 50%; right: auto;
        transform: translate(-50%, -50%);
        width: min(92vw, 380px);
        max-height: 85dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Dim the page behind the dialog. The backdrop lives on <body>, not on the
       panel: a pseudo-element inside .auth-panel is confined to that panel's
       stacking context and never covers the page. The header is lifted above
       the backdrop (and above the cookie banner at z-index 95). */
    body:has(.auth-panel.open)::after {
        content: "";
        position: fixed; inset: 0;
        background: rgba(7, 38, 67, .55);
        z-index: 110;
    }
    body:has(.auth-panel.open) .site-header { z-index: 120; }
}
.auth-form label { display: block; font-size: .85rem; color: var(--text-mut); margin: 12px 0 4px; }
.auth-form input, .contact-form input, .contact-form textarea, .filters input, .filters select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit;
}
.auth-form input:focus, .contact-form input:focus, .contact-form textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 79, 159, .15);
}
.contact-form textarea { resize: vertical; }   /* height only — keep the layout width fixed */
.auth-form input.is-invalid { border-color: var(--kiwa-red); }
.auth-form .btn { width: 100%; margin-top: 16px; }
/* ---- One-time-code boxes -------------------------------------------------- */
/* Six separate boxes read as "six digits" at a glance and make a typo easy to
   spot and fix. The real value lives in a hidden field, so the submit handlers
   still read one value. */
.otp { display: flex; gap: 8px; margin-top: 4px; }
.otp-box {
    width: 100%; min-width: 0; height: 48px;
    padding: 0;                       /* centring beats the shared input padding */
    text-align: center;
    font-size: 1.25rem; font-weight: 600;
    font-variant-numeric: tabular-nums;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text);
    caret-color: var(--primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.otp-box:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(34, 83, 190, .18);
}
.otp-box.is-filled { border-color: var(--primary); }
.otp.is-invalid .otp-box { border-color: var(--kiwa-red); }
/* While the code is being checked, the boxes are read-only rather than jumpy. */
.otp.is-busy { opacity: .6; pointer-events: none; }

@media (max-width: 380px) {
    .otp { gap: 5px; }
    .otp-box { height: 42px; font-size: 1.05rem; }
}

.auth-links { text-align: right; margin-top: 10px; font-size: .85rem; }
.auth-switch { font-size: .85rem; color: var(--text-mut); }
.form-errors { color: var(--danger-text); font-size: .85rem; margin: 10px 0 0; padding-left: 18px; }
.auth-panel hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---- Hero + brand slogan lockup ------------------------------------------ */
.hero {
    background: var(--kiwa-blue);            /* flat brand blue, per slogan.png */
    color: #fff; padding: 96px 0; text-align: left;
}
.hero h1 { color: #fff; font-size: 2.6rem; }

/* "creating trust / driving progress" — recreated from slogan.png */
.slogan {
    line-height: 1.02;
    margin: 0 0 24px;
    letter-spacing: -0.01em;
}
.slogan span { display: block; font-size: clamp(2.6rem, 8vw, 4.6rem); }
.slogan .line-1 { color: #ffffff; font-weight: 400; }
.slogan .line-2 { color: var(--kiwa-mint); font-weight: 800; font-style: italic; }

/* Footer-scale variant of the same lockup */
.slogan-footer { margin: 14px 0 0; text-align: left; }
.slogan-footer span { font-size: 1.5rem; }
.slogan-footer span + span { margin-top: 10px; }

.hero-sub { font-size: 1.2rem; opacity: .92; max-width: 620px; margin: 0 0 28px; }
.hero-actions { display: flex; gap: 14px; justify-content: flex-start; flex-wrap: wrap; }
.hero .btn-primary { background: var(--kiwa-mint); color: #0f2f6b; }
.hero .btn-primary:hover { background: #ffffff; color: var(--kiwa-blue); }
.hero .btn-ghost { border-color: rgba(255,255,255,.5); color: #fff; }
.hero .btn-ghost:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ---- Sections ------------------------------------------------------------ */
.section { padding: 64px 0; }
/* Inside the portal the generous marketing rhythm just pushes every working
   screen below the fold. Signed-in pages start right under the header. */
body.has-sidebar .section { padding-top: 20px; padding-bottom: 32px; }
body.has-sidebar .page-title { margin-bottom: 16px; }
.section-alt { background: var(--bg-alt); }
.section-title { font-size: 1.9rem; text-align: center; margin-bottom: 36px; }
.page-title { font-size: 2rem; margin-bottom: 24px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }

.service-card {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 28px 22px; text-align: center;
    color: var(--text); transition: all var(--transition);
}
.service-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); text-decoration: none; border-color: var(--primary); }
.service-icon { color: var(--accent); font-size: 1.6rem; }
.service-card h3 { font-size: 1.1rem; margin-top: 12px; }

.training-card {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 22px; color: var(--text);
    transition: all var(--transition); border-top: 3px solid var(--primary);
}
.training-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); text-decoration: none; }
.training-sector {
    display: inline-block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--accent); font-weight: 700; margin-bottom: 8px;
}
.training-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; color: var(--text-mut); font-size: .9rem; }
.training-price { color: var(--primary); font-weight: 700; }

/* ---- Training list ------------------------------------------------------- */
.filters { display: flex; gap: 12px; margin-bottom: 28px; flex-wrap: wrap; }
.filters select, .filters input { flex: 1; min-width: 160px; }
.filters .btn { flex: 0 0 auto; }

.training-list { display: flex; flex-direction: column; gap: 12px; }
.training-row {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-left: 4px solid var(--primary); border-radius: var(--radius);
    padding: 18px 22px; color: var(--text); transition: all var(--transition);
}
.training-row:hover { box-shadow: var(--shadow-md); text-decoration: none; transform: translateX(3px); }
.training-row h3 { font-size: 1.15rem; margin: 4px 0 0; }
.training-row-meta { display: flex; gap: 18px; align-items: center; color: var(--text-mut); font-size: .9rem; white-space: nowrap; }

.empty-state { text-align: center; color: var(--text-mut); padding: 40px; }

/* ---- Training detail ----------------------------------------------------- */
.back-link { display: inline-block; margin-bottom: 16px; color: var(--text-mut); }
.training-detail-meta {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; margin: 20px 0;
}
.training-detail-meta .meta-label { display: block; font-size: .75rem; text-transform: uppercase; color: var(--text-mut); margin-bottom: 4px; }
.training-body { margin: 24px 0; font-size: 1.05rem; }
.training-cta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 24px; }

/* ---- Contact ------------------------------------------------------------- */
.contact-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 32px; }
.contact-info a { font-size: 1.1rem; }
.contact-form .form-row { margin-bottom: 14px; }
.contact-form label { display: block; font-size: .85rem; color: var(--text-mut); margin-bottom: 4px; }

/* ---- File transfer (/files) ----------------------------------------------- */
.transfer-rule { color: var(--text-mut); margin-bottom: 24px; }
/* Rows bring their own 16px bottom margin, so no row gap — a gap doubled the
   spacing inside the grid compared with the rows around it. */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
#transferForm .form-row { margin-bottom: 16px; }
#transferForm label { display: block; font-size: .85rem; color: var(--text-mut); margin-bottom: 4px; }
#transferForm input, #transferForm textarea, #transferForm select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit;
}
#transferForm textarea { resize: vertical; }
#transferForm input.is-invalid { border-color: var(--kiwa-red); }
.expiry-row { display: flex; gap: 10px; }
.expiry-row select { flex: 1; }
.expiry-row #tr_date_field { flex: 1; display: flex; }
.expiry-row #tr_date_field[hidden] { display: none; }
.expiry-row .date-field { width: 100%; }

.dropzone {
    border: 2px dashed var(--border); border-radius: var(--radius-lg);
    padding: 28px; text-align: center; transition: all var(--transition);
    background: var(--bg-elev);
}
.dropzone.drag { border-color: var(--primary); background: var(--bg-alt); }
.dropzone { cursor: pointer; }
.dropzone p { font-size: 2rem; margin: 0 0 10px; }
.dropzone-hint { color: var(--text-mut); margin-bottom: 14px; }
.dropzone-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.file-list { list-style: none; margin: 12px 0 0; padding: 0; }
.file-list li {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 14px; margin-bottom: 6px; word-break: break-all;
}
.file-list li > :first-child { flex: 1; }
.file-list a { flex: 1; color: var(--text); }
.file-list a:hover { color: var(--primary); text-decoration: none; }

/* Folder-tree presentation: rows indent by nesting depth (--depth). */
.file-list .tree-name { flex: 1; padding-left: calc(var(--depth, 0) * 22px); }
.file-list li.tree-dir {
    background: var(--bg-alt);
    font-weight: 600;
    padding-top: 7px; padding-bottom: 7px;
    cursor: pointer;
    user-select: none;
}
.file-list li.tree-file { border-left: 3px solid var(--border); }

/* Collapse/expand: caret shows state; hidden rows collapse away. */
.tree-dir .tree-name::before {
    content: '▾';
    display: inline-block;
    width: 1.1em;
    color: var(--text-mut);
    transition: transform var(--transition);
}
.tree-dir.collapsed .tree-name::before { content: '▸'; }
/* Folder chosen as the upload target. */
.tree-dir.selected { background: var(--bg-alt); border-radius: var(--radius); }
.tree-dir.selected .tree-name { color: var(--primary); font-weight: 700; }
.file-list li.tree-hidden { display: none; }
.file-size { color: var(--text-mut); font-size: .85rem; white-space: nowrap; }
.file-remove {
    background: none; border: 0; color: var(--danger-text); font-size: 1.2rem;
    cursor: pointer; padding: 0 4px; line-height: 1;
}
.picked-total { margin-top: 8px; font-weight: 700; color: var(--text-mut); }
.picked-total.over-limit { color: var(--danger-text); }

.otp-row { display: flex; gap: 10px; }
.otp-row input { max-width: 160px; text-align: center; font-size: 1.2rem; letter-spacing: .3em; }

.progress { height: 10px; background: var(--bg-alt); border-radius: 5px; overflow: hidden; margin: 8px 0 16px; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .2s ease; }

.transfer-cta { margin-top: 12px; }
.transfer-result {
    background: var(--bg-elev); border: 1px solid var(--border); border-left: 4px solid var(--kiwa-green);
    border-radius: var(--radius-lg); padding: 24px; margin-top: 20px;
}
.link-row { display: flex; gap: 10px; }
.link-row input {
    flex: 1; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit;
}
.result-expiry { color: var(--text-mut); margin: 10px 0 0; }

.transfer-meta {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; margin-bottom: 18px;
}
.transfer-meta .meta-label { display: block; font-size: .75rem; text-transform: uppercase; color: var(--text-mut); margin-bottom: 4px; }
.transfer-message {
    border-left: 4px solid var(--primary); background: var(--bg-elev);
    margin: 0 0 18px; padding: 14px 18px; border-radius: 0 var(--radius) var(--radius) 0;
}

@media (max-width: 640px) {
    .form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Dashboard -------------------------------------------------------------- */
.dash-role { display: block; font-size: .9rem; font-weight: 400; color: var(--text-mut); margin-top: 4px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 30px; }
.stat-card {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-top: 3px solid var(--primary); border-radius: var(--radius-lg);
    padding: 20px 22px;
}
/* Clickable cards keep the same look, plus a lift on hover. */
a.stat-card { display: block; position: relative; color: inherit; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
a.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(34, 83, 190, .12); }
/* Affordance: clickable cards carry a subtle arrow that lifts on hover. */
a.stat-card::after {
    content: '\2192'; position: absolute; top: 16px; right: 18px;
    color: var(--text-mut); opacity: .35; transition: opacity .15s ease, transform .15s ease, color .15s ease;
}
a.stat-card:hover::after { opacity: 1; color: var(--primary); transform: translateX(3px); }
.stat-num { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1.2; word-break: break-word; }
.stat-num .stat-sub { font-size: 1rem; font-weight: 400; color: var(--text-mut); margin-left: 6px; }
.stat-card.client-card .stat-num { font-size: 1.25rem; }
.stat-label { color: var(--text-mut); font-size: .85rem; margin-top: 6px; }
.stat-label a { color: var(--primary); }

.dash-h2 { font-size: 1.15rem; margin: 26px 0 12px; }
.role-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.role-chip {
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: 999px;
    padding: 6px 14px; font-size: .85rem; color: var(--text-mut);
}
.role-chip strong { color: var(--primary); margin-right: 4px; }
a.role-chip { text-decoration: none; transition: border-color .15s ease, color .15s ease; }
a.role-chip:hover { border-color: var(--primary); color: var(--text); }

.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.table-wrap { overflow-x: auto; }
.dash-table { width: 100%; border-collapse: collapse; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); }
.dash-table th {
    text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--primary-ct); background: var(--primary); padding: 9px 12px;
}
.dash-table td { padding: 9px 12px; border-top: 1px solid var(--border); font-size: .88rem; word-break: break-word; }
.dash-expired { color: var(--danger-text); }

/* ---- Table columns: resize + reorder (app.js "Table columns") ------------- */
/* Headers drag sideways to reorder; the strip on each header's right edge
   drags to resize (double-click: auto-fit). Right-click opens .tl-menu. */
.tl-th { position: relative; cursor: grab; user-select: none; -webkit-user-select: none; }
.tl-grip {
    position: absolute; top: 0; right: 0; width: 9px; height: 100%;
    cursor: col-resize; touch-action: none; z-index: 1;
}
.tl-grip::after {
    content: ""; position: absolute; top: 22%; bottom: 22%; right: 3px; width: 2px;
    border-radius: 1px; background: transparent; transition: background var(--transition);
}
.tl-th:hover .tl-grip::after { background: rgba(255, 255, 255, .45); }
.tl-grip:hover::after, .tl-grip.active::after { background: var(--primary-ct); }
/* Once any width is set the columns keep those widths (the last one fills the
   rest, so the table stays full width; app.js sets the table's width); overlong
   cell text ends in an ellipsis instead of stretching the column. */
.dash-table.tl-sized { table-layout: fixed; max-width: none; }
.tl-sized th, .tl-sized td { overflow: hidden; text-overflow: ellipsis; }
.tl-dragging { opacity: .45; }
body.tl-moving, body.tl-moving * { cursor: grabbing !important; }
body.tl-resizing, body.tl-resizing * { cursor: col-resize !important; user-select: none !important; }
.tl-drop {
    position: fixed; width: 3px; border-radius: 2px; background: var(--primary);
    box-shadow: 0 0 0 1px var(--bg-elev); z-index: 150; pointer-events: none;
}
.tl-menu {
    position: fixed; z-index: 150; list-style: none; margin: 0; padding: 6px; min-width: 220px; max-width: 320px;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.tl-menu button {
    display: block; width: 100%; text-align: left;
    background: transparent; border: 0; color: var(--text);
    font: inherit; font-size: .9rem; padding: 8px 12px; border-radius: var(--radius); cursor: pointer;
}
.tl-menu button:hover { background: var(--bg-alt); }
.tl-menu-hint {
    padding: 6px 12px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border);
    font-size: .78rem; color: var(--text-mut); line-height: 1.4;
}

/* NDT plan welds: one cell per field, each holding an input. Cells are
   classed by field (.weld-c-<field>), never by position — the columns can be
   moved. */
.weld-table th { vertical-align: middle; }
.weld-table td { vertical-align: middle; }
.weld-table input, .weld-table select { width: 100%; min-width: 64px; height: var(--control-h-sm); padding: 4px 8px; font-size: .85rem; }
.weld-table .weld-res { min-width: 76px; }
.weld-table .weld-res.is-nok { border-color: var(--kiwa-red); color: var(--kiwa-red); font-weight: 600; }
.weld-table .weld-f:not(.weld-pct) { min-width: 90px; }
.weld-table .weld-c-welding_process input { min-width: 110px; }
.weld-table .weld-c-comments input { min-width: 180px; }
.weld-table .weld-pct { min-width: 60px; }
.weld-table .date-field { width: 100%; min-width: 132px; }
.weld-table .date-field > input[type="text"] { height: var(--control-h-sm); padding: 4px 34px 4px 8px; font-size: .85rem; }
/* Brief highlight while a row is being written back. */
.weld-item.weld-saving td { background: var(--bg-alt); }
/* Drag to reorder: the handle sits before the weld number. */
.weld-table td.weld-c-weld_no { display: flex; align-items: center; gap: 8px; }
.weld-drag {
    cursor: grab; color: var(--text-mut); font-size: .9rem; line-height: 1;
    letter-spacing: -2px; user-select: none; flex: 0 0 auto;
}
.weld-drag:active { cursor: grabbing; }
.weld-item.dragging { opacity: .5; outline: 2px dashed var(--primary); }

/* Plan toolbar: filters on the left, exports/compare on the right. */
.plan-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.plan-filters { margin-bottom: 0; flex: 1 1 320px; align-items: center; }
/* Roomy screens: sized to their content. Narrow ones: fill the row, like
   every other filter bar on the site. */
.plan-filters select, .plan-filters input { flex: 1 1 190px; min-width: 130px; }
/* The "n shown" counter is empty until a filter is set; empty, its flex gap
   still squeezed the search box beside it on phones. */
#weldShown:empty { display: none; }
.plan-exports { display: flex; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }

/* Revision comparison. Status colours reuse the palette already in play. */
#weldDiff { margin-bottom: 18px; }
.diff-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.diff-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.status-chip.diff-added   { background: var(--kiwa-mint); color: var(--kiwa-navy); }
.status-chip.diff-removed { background: var(--kiwa-red); color: #fff; }
.status-chip.diff-changed { background: var(--primary); color: var(--primary-ct); }
.status-chip.diff-same    { background: var(--bg-alt); color: var(--text-mut); border: 1px solid var(--border); }
.diff-row.diff-same td { color: var(--text-mut); }
.diff-changes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.diff-changes li { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: .85rem; }
.diff-from { text-decoration: line-through; color: var(--text-mut); }
.diff-to { font-weight: 600; }

/* Print: the plan table only, no chrome. */
@media print {
    .plan-toolbar, #weldDiff { display: none; }
    .weld-print-table { font-size: .8rem; }
    .weld-print-table th, .weld-print-table td { padding: 4px 6px; }
}

/* Responsive: turn `.dash-table--cards` rows into stacked cards whenever the
   table's own container is too narrow for its columns — a container query, so
   it works regardless of the sidebar taking up width. */
.table-cq { container-type: inline-size; }

@container (max-width: 820px) {
    .dash-table--cards { border: 0; background: transparent; }
    .dash-table--cards thead,
    .dash-table--cards tr:has(th) { display: none; }   /* header row (thead or inline) */
    .dash-table--cards tr {
        /* A column flexbox (not block) so the actions row can be ordered last. */
        display: flex; flex-direction: column; background: var(--bg-elev); border: 1px solid var(--border);
        border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 10px; padding: 4px 14px;
    }
    .dash-table--cards td {
        display: flex; align-items: center; justify-content: space-between; gap: 14px;
        padding: 9px 0; border-top: 0; border-bottom: 1px solid var(--border);
        font-size: .95rem; text-align: right; word-break: normal;
    }
    .dash-table--cards td:last-child { border-bottom: 0; }
    .dash-table--cards td:empty { display: none; }              /* hide blank cells */
    .dash-table--cards td::before {
        content: attr(data-label); flex: 0 0 auto; text-align: left;
        font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
        color: var(--text-mut);
    }
    /* Actions row: no label, buttons grouped to the right. */
    .dash-table--cards td.row-actions,
    .dash-table--cards td.dash-table-actions { justify-content: flex-end; gap: 6px; }
    .dash-table--cards td.row-actions::before,
    .dash-table--cards td.dash-table-actions::before { content: none; }
    /* Buttons close the card wherever the column sits on a wide screen. */
    .dash-table--cards td.row-actions,
    .dash-table--cards td.dash-table-actions { order: 99; border-bottom: 0; }
    /* Group header: a plain section label between cards, not a card itself. */
    .dash-table--cards .menu-group {
        background: transparent; border: 0; box-shadow: none;
        margin: 14px 0 6px; padding: 0;
    }
    .dash-table--cards .menu-group td { border: 0; padding: 4px 2px; justify-content: flex-start; }
    .dash-table--cards .menu-group td::before { content: none; }
}
.dropdown-menu .menu-link { display: block; padding: 9px 12px; border-radius: var(--radius); color: var(--text); }
.dropdown-menu .menu-link:hover { background: var(--bg-alt); text-decoration: none; }

@media (max-width: 860px) {
    .dash-cols { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Error pages (403 / 404 / 410) ----------------------------------------- */
.error-page { text-align: center; padding: 40px 0 20px; }
.error-code {
    font-size: clamp(6rem, 18vw, 9rem); font-weight: 800; line-height: 1;
    color: var(--primary); letter-spacing: -0.03em;
}
.error-title { font-size: 1.6rem; margin: 10px 0 6px; }
/* Brand lockup, light-background variant (dark line + blue italic line). */
.slogan-error { text-align: left; width: fit-content; margin: 44px auto 48px; }
.slogan-error span { font-size: 1.15rem; }
.slogan-error .line-1 { color: var(--text); font-weight: 700; }
.slogan-error .line-2 { color: var(--primary); }
.error-page .transfer-cta { justify-content: center; display: flex; gap: 14px; flex-wrap: wrap; }

/* ---- Application detail ----------------------------------------------------- */
/* Header bar: date / status on the left, action buttons grouped on the right. */
.app-header {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; margin-bottom: 18px;
}
.app-header-info { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 28px; }
.app-header-info .meta-label { display: block; font-size: .75rem; text-transform: uppercase; color: var(--text-mut); margin-bottom: 4px; }
.app-header-flags { align-self: center; }
.app-header-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.app-details {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px 24px; margin: 18px 0 6px;
}
.app-details .meta-label { display: block; font-size: .75rem; text-transform: uppercase; color: var(--text-mut); margin-bottom: 4px; }
/* Grouped detail summary (pressure): one card per form section. */
.app-group {
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--bg-elev); padding: 4px 18px 18px; margin: 0 0 16px;
}
.app-group-title { font-size: .9rem; font-weight: 600; color: var(--primary); margin: 14px 0 2px; }
.app-group .app-details { margin: 10px 0 0; }
/* Involved users box (message/file notification recipients). */
.involved-box { margin: 26px 0 6px; }
.involved-box .block-title { margin-top: 0; }
.involved-add { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.involved-add select { flex: 1; min-width: 220px; }
.inv-flag { width: 18px; height: 18px; cursor: pointer; }
.inv-flag[disabled] { cursor: default; }
.app-group-text { margin: 10px 0 0; white-space: pre-line; }
/* "Download all" spaced like the other action buttons (upload etc.). */
.app-zip-cta { margin: 12px 0 30px; }
#appDocs { margin-top: 30px; }
/* Row action buttons (⬇ download, 🗑 delete) — one uniform size.
   The extra .file-list scope beats the generic `.file-list a { flex: 1 }`. */
.tree-act,
.file-list .tree-act, .file-list a.tree-act {
    flex: 0 0 30px; margin-left: 8px; padding: 0; width: 30px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .9rem; line-height: 1;
}
/* Flex with a gap, so buttons that wrap onto a second line on a phone line up
   on the left instead of keeping a stray left margin. */
.transfer-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
/* Page title with its main action on the same row (NDT, lifts, pressure). */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .page-title { margin: 0; min-width: 0; }
.page-head .transfer-cta { margin: 0; flex: 0 0 auto; }
.page-head .transfer-cta[hidden] { display: none; }
.btn-new { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.upload-target { max-width: 420px; }
.upload-target label { display: block; font-size: .85rem; color: var(--text-mut); margin-bottom: 4px; }
.upload-target select { width: 100%; }

/* Inspection report (sections of clauses/checkpoints). */
.report-section { margin-bottom: 6px; }
/* Sticky toolbar: overall progress + expand / collapse all. */
.report-toolbar {
    /* Below the sticky site header, not under it. */
    position: sticky; top: var(--header-h); z-index: 30;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    background: var(--bg); padding: 12px 0; margin-bottom: 12px; border-bottom: 1px solid var(--border);
}
.report-progress { flex: 1; min-width: 220px; display: flex; align-items: center; gap: 12px; }
.report-progress-bar { flex: 1; height: 8px; border-radius: 999px; background: var(--bg-alt); overflow: hidden; }
.report-progress-bar span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .25s ease; }
.report-progress.complete .report-progress-bar span { background: #1a9c53; }
.report-progress-label { font-size: .8rem; color: var(--text-mut); white-space: nowrap; }
.report-toolbar-actions { display: flex; gap: 8px; }
.report-intro { background: var(--bg-elev); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.report-confirmed { background: #e6f7ec; border: 1px solid #1a9c53; color: #157a42; font-weight: 700; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.row-locked { opacity: .75; }
.row-locked .value-input, .row-locked input { background: var(--bg-alt); cursor: not-allowed; }
/* Whole-section N/A (Annex A). */
.section-na { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 6px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.section-na input { accent-color: var(--primary); }
.section-disabled .report-row, .section-disabled .report-group { opacity: .5; }
/* Report confirmation: summary + declaration modal. */
.report-summary { list-style: none; margin: 0 0 16px; padding: 0; }
.report-summary li { padding: 5px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.decl-check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; cursor: pointer; }
.decl-check input { margin-top: 3px; accent-color: var(--primary); flex-shrink: 0; }
/* Accordion: collapsible section with a status-bearing header. */
.report-acc { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.report-acc-head {
    display: flex; align-items: center; gap: 10px; width: 100%;
    background: var(--bg-elev); border: none; cursor: pointer;
    padding: 14px 16px; font: inherit; text-align: left; color: var(--text);
    border-left: 3px solid transparent;
}
.report-acc-head:hover { background: var(--bg-alt); }
.report-acc-head.head-nok { border-left-color: var(--kiwa-red, #d33); }
.report-acc-head.head-unanswered { border-left-color: #e08700; }
.report-acc-head.head-done { border-left-color: #1a9c53; }
.acc-caret { color: var(--text-mut); transition: transform .15s ease; flex-shrink: 0; }
.report-acc-head:not(.collapsed) .acc-caret { transform: rotate(90deg); }
.acc-title { flex: 1; font-weight: 700; overflow-wrap: anywhere; }
.acc-flags { display: flex; gap: 6px; flex-shrink: 0; }
.acc-flag {
    display: inline-flex; align-items: center; border-radius: 999px;
    font-size: .75rem; font-weight: 700; padding: 3px 10px;
}
.acc-flag[hidden] { display: none; }   /* the flex display would otherwise defeat [hidden] */
.acc-flag.flag-nok { background: #fdecec; color: #b02525; }
.acc-flag.flag-unanswered { background: #fff4e2; color: #b56b00; }
.acc-flag.flag-done { background: #e6f7ec; color: #157a42; }
/* The count badges jump to their clauses on click. */
.acc-flag.flag-nok, .acc-flag.flag-unanswered { cursor: pointer; }
.acc-flag.flag-nok:hover { background: #f9d9d9; }
.acc-flag.flag-unanswered:hover { background: #ffe8c2; }
/* Brief highlight when a clause is jumped to. */
@keyframes rowFlash { from { background: var(--bg-alt); } to { background: transparent; } }
.report-row.row-flash { animation: rowFlash 1.2s ease; border-radius: var(--radius); }
.report-acc-body { padding: 4px 16px 8px; }
.report-page { max-width: 100%; }
.report-row {
    /* One consistent style: clause on top, answer controls stacked below. */
    /* minmax(0, …): a plain 1fr never shrinks below its content, so the
       360px answer fields pushed the row past the card edge on phones. */
    display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px;
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.report-clause { overflow-wrap: anywhere; }
.report-row-answers, .report-row-wide { grid-template-columns: minmax(0, 1fr); }
/* Lead-in header rows (a sub-heading the PDF lists above dashed sub-checks). */
.report-row-header { border-bottom: none; padding-bottom: 0; }
.report-row-header .clause-primary { font-weight: 700; }
.report-cid { color: var(--text-mut); font-size: .8rem; }
/* Clause number on the left, its standard reference right-aligned. */
.clause-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 2px; }
.clause-std { color: var(--text-mut); font-size: .78rem; text-align: right; }
.report-answers { display: flex; gap: 6px; white-space: nowrap; justify-content: flex-start; }
.report-opt {
    display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
    border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: .85rem;
}
.report-opt input { accent-color: var(--primary); margin: 0; }
.report-opt:has(input:checked).opt-ok  { background: #e6f7ec; border-color: #1a9c53; color: #157a42; }
.report-opt:has(input:checked).opt-nok { background: #fdecec; border-color: var(--kiwa-red, #d33); color: #b02525; }
.report-opt:has(input:checked).opt-na  { background: var(--bg-alt); border-color: var(--text-mut); }
input.report-note { grid-column: 1 / -1; height: var(--control-h-sm); }
/* Subsection header inside a section body. */
.report-group {
    margin: 16px 0 8px; font-size: .9rem; font-weight: 700; color: var(--primary);
    padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.report-group:first-child { margin-top: 4px; }
/* Report remarks textarea spans the full width, like the accordion sections. */
#reportNotes { width: 100%; resize: vertical; }
/* Bilingual clause label. */
.clause-primary { display: block; }
.clause-secondary { display: block; font-size: .8rem; color: var(--text-mut); margin-top: 2px; }
/* Value / cert answer fields (right column). */
.report-fields { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-start; }
.report-fields input[type="text"] { width: 190px; height: var(--control-h-sm); }
/* Single value fields are wider than the paired cert fields. */
.report-fields input.value-input,
.report-fields select.value-input { width: 360px; max-width: 100%; height: var(--control-h-sm); }
.field-na { display: inline-flex; align-items: center; gap: 5px; font-size: .82rem; color: var(--text-mut); white-space: nowrap; }
.field-na input { accent-color: var(--primary); }
/* Deviations chosen for a non-compliant clause (full-width row under it). */
.report-dev { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dev-chip {
    background: #fdecec; color: #b02525; border: 1px solid #f2c4c4;
    border-radius: 999px; font-size: .78rem; padding: 3px 10px;
}
@media (max-width: 860px) {
    .report-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}
/* Deviation picker modal. */
.dev-search { width: 100%; margin-bottom: 10px; }
.dev-choices { display: flex; flex-direction: column; gap: 2px; max-height: 46vh; overflow-y: auto; margin-bottom: 14px; }
.dev-choice { display: flex; gap: 8px; align-items: flex-start; padding: 7px 8px; border-radius: var(--radius); cursor: pointer; }
.dev-choice:hover { background: var(--bg-alt); }
.dev-choice input { margin-top: 3px; accent-color: var(--primary); flex-shrink: 0; }
.dev-add { display: flex; gap: 8px; margin-bottom: 8px; }
.dev-add input { flex: 1; }
/* Report-wide numbered findings list. */
.findings-list { margin: 0 0 8px; }
.findings-head {
    font-size: .95rem; font-weight: 700; color: var(--text);
    margin: 14px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.findings-group { margin: 0; padding-left: 26px; }
.findings-group li { padding: 5px 0; display: flex; align-items: center; gap: 4px; }
.finding-cp { color: var(--text-mut); font-size: .8rem; margin-right: 4px; }
.finding-text { flex: 1; }
.finding-fix {
    display: inline-flex; align-items: center; gap: 5px; margin-left: auto;
    font-size: .8rem; color: var(--text-mut); cursor: pointer; white-space: nowrap;
}
.finding-fix input { accent-color: #1a9c53; margin: 0; }
.finding-repaired .finding-text { text-decoration: line-through; color: var(--text-mut); }
.finding-repaired .finding-fix { color: #157a42; font-weight: 700; }
.finding-del {
    margin-left: auto; background: none; border: none; cursor: pointer;
    color: var(--text-mut); font-size: 1.1rem; line-height: 1; padding: 0 6px;
}
.finding-del:hover { color: var(--danger-text); }

/* Print-friendly report (→ PDF). */
.print-actions { display: flex; justify-content: space-between; margin-bottom: 18px; }
.print-head { margin-bottom: 18px; }
.print-head h1 { font-size: 1.6rem; margin: 0 0 8px; }
.print-meta { font-size: .9rem; color: var(--text-mut); }
.print-confirmed { color: #157a42; font-weight: 700; margin-top: 4px; }
.print-section { font-size: 1.15rem; margin: 22px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--primary); }
.print-na { font-size: .8rem; color: var(--text-mut); font-weight: 400; }
.print-group { font-size: .95rem; font-weight: 700; color: var(--primary); margin: 14px 0 4px; }
.print-table { width: 100%; border-collapse: collapse; }
.print-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; vertical-align: top; font-size: .85rem; }
.print-clause { width: 72%; }
.print-cid { color: var(--text-mut); font-size: .78rem; margin-right: 4px; }
.print-answer { font-weight: 600; white-space: nowrap; }
.print-note { font-weight: 400; color: var(--text-mut); }
.print-row-header td { font-weight: 700; background: var(--bg-alt); }
.print-finding { font-size: .85rem; padding: 3px 0; }
.print-notes { font-size: .85rem; white-space: pre-wrap; }
@media print {
    .site-header, .sidebar, .site-footer, .print-actions, .scroll-top, .cookie-banner { display: none !important; }
    .page, .main, main.page { margin: 0 !important; }
    .container { max-width: 100% !important; }
    /* Each report section starts on its own page. The first one stays with the
       title block so there is no blank leading page. */
    .print-section { break-after: avoid; break-before: page; }
    .print-section:first-of-type { break-before: auto; }
    .print-table, .print-finding, .print-group { break-inside: avoid; }
    body { background: #fff !important; }
    /* The scroll-triggered "lazy reveal" never fires for off-screen content
       when printing, leaving those elements at opacity:0 — i.e. blank pages.
       Force every revealed/animated element fully visible for print. */
    .reveal { opacity: 1 !important; transform: none !important; transition: none !important; }
    .hero .container { transform: none !important; }
}

/* Tabs on the application page (Messages / Documents). */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: 26px 0 18px; }
.tab-btn {
    background: none; border: none; cursor: pointer; font: inherit;
    color: var(--text-mut); padding: 10px 16px; margin-bottom: -2px;
    border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); font-weight: 700; border-bottom-color: var(--primary); }
.tab-count { font-weight: 400; font-size: .85em; }

/* Activity flags: data changed / files added / new messages. */
.app-flag {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    font-size: .65rem; color: #fff; margin-left: 3px; vertical-align: middle;
    cursor: default; position: relative;
}
.app-flag.flag-data { background: #e08700; }
.app-flag.flag-file { background: var(--primary); }
.app-flag.flag-msg  { background: #1a9c53; }
/* Instant tooltip on hover (native title needs a long hover). */
.app-flag:hover::after {
    content: attr(data-tip);
    position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%);
    background: var(--text); color: var(--bg-elev);
    padding: 4px 10px; border-radius: 6px; font-size: .75rem; font-weight: 400;
    white-space: nowrap; z-index: 60; pointer-events: none;
    box-shadow: var(--shadow-md);
}
.app-flag:hover::before {
    content: ''; position: absolute; bottom: calc(100% + 2px); left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent; border-top-color: var(--text);
    z-index: 60; pointer-events: none;
}

/* Application message thread. */
/* Long threads scroll inside the list; the newest message stays in view. */
.msg-list { list-style: none; margin: 0 0 16px; padding: 0 4px 0 0; max-height: 420px; overflow-y: auto; }
.msg-item {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-left: 3px solid var(--primary); border-radius: var(--radius);
    padding: 12px 16px; margin-bottom: 10px;
}
.msg-meta { display: flex; align-items: center; gap: 12px; font-size: .8rem; color: var(--text-mut); margin-bottom: 6px; }
.msg-meta .msg-delete { margin-left: auto; }
.msg-body { overflow-wrap: anywhere; }
/* Composer spans the same width as the message cards above it. */
.msg-compose textarea { width: 100%; resize: vertical; }

/* In-page file preview (modal iframe). */
.modal-box.modal-wide { max-width: 960px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.preview-head strong { overflow-wrap: anywhere; }
.preview-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

/* ---- Domain workspaces (lift applications etc.) ---------------------------- */
.block-title { font-size: 1.25rem; margin: 30px 0 14px; }
/* Select + "+" (add new value) pairs on the application form. */
/* Select + "+"/"–" (previous-value memory) pairs on the lift form. */
.combo-row { display: flex; gap: 8px; }
.combo-row select { flex: 1; min-width: 0; }
.lift-add { width: 46px; flex-shrink: 0; padding: 0; font-size: 1.2rem; line-height: 1; }

/* ---- Application forms: full-width, grouped, responsive (shared style) ----- */
/* `.app-form` is the house style for every domain form (lift, pressure, …). */
.app-form { margin-bottom: 10px; }
.app-form .form-row { margin: 0; min-width: 0; }
.app-form label { display: block; font-size: .8rem; color: var(--text-mut); margin-bottom: 5px; }
.app-form input, .app-form select, .app-form textarea { width: 100%; }
.ps-group {
    min-width: 0; margin: 0 0 18px;
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--bg-elev); padding: 8px 18px 20px;
}
.ps-group > legend {
    font-weight: 600; font-size: .9rem; color: var(--primary);
    padding: 2px 10px; border: 1px solid var(--border); border-radius: 999px;
    background: var(--bg);
}
/* Fields flow into as many columns as the width allows. */
.ps-grid {
    display: grid; gap: 14px 18px;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.ps-grid .ps-span { grid-column: 1 / -1; }
/* Standard (a memory select with long values) takes two field widths. */
.ps-grid .ps-wide { grid-column: span 2; }
/* The two chambers sit side by side, then stack on narrower screens. */
.ps-chambers { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
.ps-chamber { margin-bottom: 18px; }
/* Five columns so the eight parameters land on two rows; the medium/fluid
   field is three blocks wide (PS/TS/V on row 1, DN, PT, Fluid on row 2). */
.ps-grid--chamber { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.ps-grid--chamber .ps-fluid { grid-column: span 3; }
.ps-actions { margin-top: 4px; }
@media (max-width: 1200px) {
    .ps-chambers { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
    .ps-group { padding: 6px 13px 15px; }
    .ps-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .ps-grid .ps-wide { grid-column: auto; }
    .ps-grid--chamber { grid-template-columns: 1fr 1fr; gap: 10px 12px; }
    .ps-grid--chamber .ps-fluid { grid-column: 1 / -1; }
}

/* Onsite works: banner above the form saying whether Save creates a new
   record (green) or overwrites the one being edited (amber). */
.ow-form-mode {
    display: flex; align-items: center; gap: 8px;
    margin: 0 0 14px; padding: 9px 12px;
    border-radius: var(--radius); border-left: 4px solid var(--kiwa-green);
    background: rgba(29, 119, 77, .10);
    font-weight: 600; font-size: .85rem; color: var(--kiwa-green);
}
.ow-form-mode[data-mode="edit"] {
    border-left-color: #b5810a; background: rgba(181, 129, 10, .12); color: #8a6100;
}
:root[data-theme="dark"] .ow-form-mode {
    background: rgba(200, 251, 222, .08); color: var(--kiwa-mint); border-left-color: var(--kiwa-mint);
}
:root[data-theme="dark"] .ow-form-mode[data-mode="edit"] {
    background: rgba(240, 200, 74, .12); color: #f0c84a; border-left-color: #f0c84a;
}

/* ---- Certificates registry ------------------------------------------------ */
.cert-total { color: var(--text-mut); font-size: 1.2rem; font-weight: 400; }
.cert-count {
    display: inline-block; min-width: 1.6em; text-align: center;
    background: var(--primary); color: var(--primary-ct);
    border-radius: 999px; font-size: .75rem; padding: 2px 7px; margin-left: 8px;
    vertical-align: 2px;
}
.cert-address { display: block; color: var(--text-mut); font-weight: 400; font-size: .82rem; margin-top: 2px; }
.cert-item .tree-name { display: block; }
.cert-head { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.cert-head strong { color: var(--primary); }
.cert-standard { color: var(--text); }
.cert-dates { margin-left: auto; color: var(--text-mut); font-size: .88rem; white-space: nowrap; }
.cert-dates.cert-expired { color: var(--danger-text); }
.cert-scope { margin-top: 6px; font-size: .92rem; }
.cert-meta { margin-top: 6px; display: flex; gap: 18px; flex-wrap: wrap; color: var(--text-mut); font-size: .82rem; }

/* ---- Footer -------------------------------------------------------------- */
.site-footer { background: var(--footer-bg); color: var(--footer-ct); margin-top: auto; }
.footer-inner { display: flex; justify-content: space-between; gap: 40px; padding: 48px 20px; flex-wrap: wrap; }
.footer-brand img { filter: brightness(0) invert(1); opacity: .9; }
.footer-brand p { color: var(--footer-ct); opacity: .8; margin-top: 10px; }
.footer-contact h4 { color: #fff; }
.footer-contact a { color: var(--footer-ct); }
.footer-bottom { border-top: 1px solid rgba(255,255,255,.1); padding: 16px 0; font-size: .85rem; text-align: center; opacity: .7; }
.footer-bottom a { color: var(--footer-ct); text-decoration: underline; }
.footer-sep { margin: 0 6px; }
.footer-legal { margin-top: 6px; display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 0; }

/* ---- Modal --------------------------------------------------------------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(7, 38, 67, .55);
    display: none; align-items: flex-start; justify-content: center;
    padding: 60px 20px; z-index: 100; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--bg-elev); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); padding: 30px; width: 100%; max-width: 520px;
}
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }

/* ---- Localised calendar popup --------------------------------------------- */
/* Replaces the native date popup, which always renders in the browser's locale
   ("Mo Tu We") regardless of the page language. */
.cal-pop {
    position: absolute; z-index: 70; top: calc(100% + 6px); right: 0;
    width: 268px; padding: 10px;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-weight: 600; font-size: .95rem; }
.cal-nav {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: var(--radius);
    background: transparent; color: var(--text); cursor: pointer; font-size: 1rem; line-height: 1;
}
.cal-nav:hover { border-color: var(--primary); color: var(--primary); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow {
    text-align: center; font-size: .72rem; color: var(--text-mut);
    padding: 4px 0 6px; text-transform: uppercase;
}
.cal-day {
    height: 32px; border: 1px solid transparent; border-radius: var(--radius);
    background: transparent; color: var(--text); cursor: pointer;
    font: inherit; font-size: .9rem; font-variant-numeric: tabular-nums;
}
.cal-day:hover { background: var(--bg-alt); }
.cal-day.today { border-color: var(--border); font-weight: 600; }
.cal-day.selected { background: var(--primary); color: var(--primary-ct); border-color: var(--primary); }
/* The field is the positioning context for the popup. */
.date-field { position: relative; }

/* ---- Profile menu: relocated theme + language (mobile) -------------------- */
.menu-tools[hidden] { display: none; }
.menu-tools {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px; border-bottom: 1px solid var(--border);
}
/* The language list can't hang off the profile menu as a nested absolute
   dropdown — it lands off-screen and gets clipped. On phones it becomes a
   centred sheet instead, which also suits a 14-item list far better. */
.menu-tools .lang-switch .dropdown-menu.open {
    position: fixed;
    top: 50%; left: 50%;
    right: auto; bottom: auto;
    transform: translate(-50%, -50%);
    width: min(88vw, 320px);
    max-height: 70dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 130;                      /* above the profile menu and its backdrop */
}
.menu-tools .lang-switch .dropdown-menu.open .lang-option { padding: 10px 12px; }
/* Dim the page behind the language sheet so it reads as a modal choice.
   The header owns a stacking context (z-index 50), so the sheet's z-index is
   confined to it — the header itself must be lifted above the backdrop, or the
   backdrop paints over the sheet and swallows every tap. */
body:has(.menu-tools .lang-switch .dropdown-menu.open)::before {
    content: "";
    position: fixed; inset: 0;
    background: rgba(7, 38, 67, .55);
    z-index: 125;
}
body:has(.menu-tools .lang-switch .dropdown-menu.open) .site-header { z-index: 130; }

/* ---- Searchable combobox -------------------------------------------------- */
/* Replaces the old "select + [+]" pair: type to filter, or type something new
   and it is kept as-is. The original <select> stays in the DOM as the value
   carrier, so anything already reading it keeps working. */
.combo { position: relative; }
.combo-input {
    width: 100%;
    /* Room for the caret on the right. */
    padding-right: 34px !important;
}
.combo-caret {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    pointer-events: none; color: var(--text-mut); font-size: .8rem; line-height: 1;
}
.combo-menu {
    position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 4px);
    margin: 0; padding: 4px; list-style: none;
    max-height: 260px; overflow-y: auto;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    display: none;
}
.combo-menu.open { display: block; }
/* Open calendars and combobox lists are moved to <body> by app.js
   (floatOpen) and placed against their field, so they always draw on top:
   above the sidebar, the sticky header, panels and modals — only toasts and
   the view-as bar (z-index 200) stay above them. */
.float-layer { position: fixed; right: auto; bottom: auto; z-index: 150; overflow-y: auto; }
.combo-opt {
    padding: 8px 10px; border-radius: var(--radius); cursor: pointer;
    font-size: .95rem; color: var(--text);
    overflow-wrap: anywhere;
}
.combo-opt:hover, .combo-opt.active { background: var(--bg-alt); }
.combo-opt.selected { color: var(--primary); font-weight: 600; }
/* The "use what I typed" row, shown when the text matches no existing option. */
.combo-opt.combo-new { color: var(--text-mut); font-style: italic; }
.combo-opt.combo-new strong { color: var(--text); font-style: normal; }
.combo-empty { padding: 8px 10px; color: var(--text-mut); font-size: .9rem; }
/* Memory fields: each remembered suggestion carries a remove button. */
.combo-opt.has-forget { display: flex; align-items: center; gap: 8px; padding-right: 4px; }
.combo-opt.has-forget .combo-label { flex: 1; min-width: 0; }
.combo-forget {
    flex: 0 0 auto; width: 30px; height: 30px; border: 0; border-radius: var(--radius);
    background: none; color: var(--text-mut); font-size: 1.15rem; line-height: 1; cursor: pointer;
}
.combo-forget:hover { color: var(--kiwa-red); background: var(--bg); }
@media (hover: hover) {
    .combo-opt.has-forget .combo-forget { opacity: 0; }
    .combo-opt.has-forget:hover .combo-forget, .combo-opt.has-forget.active .combo-forget { opacity: 1; }
}

/* ---- Portal: never slide sideways ---------------------------------------- */
/* Scoped to the content column rather than <body>, so the sticky header and
   the fixed dialogs keep working. Long unbroken values — equipment serials,
   gauge numbers, emails — are the usual reason a row pushes past the edge on a
   phone, so they are allowed to break mid-string. */
/* NB: no overflow-x on main.page — any overflow value other than `visible`
   makes it a scroll container, which silently kills `position: sticky` for
   everything inside it (the work-hours total bar). Clip at the root instead;
   the sticky elements are positioned against the viewport, not this box. */
html { overflow-x: clip; }
.ow-item, .ow-item *,
.tree-name, .cert-item, .msg-item {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ---- Onsite works: form beside the list ----------------------------------- */
/* Desktop splits the screen 5/12 for the entry form and 7/12 for the saved
   list, so a visit can be logged without losing sight of the day's entries.
   Below the breakpoint they become one pane at a time, switched by .ow-switch. */
.ow-split { display: block; }
.ow-switch { display: flex; gap: 6px; margin: 0 0 16px; }
.ow-switch-btn {
    /* Sized by content (then sharing the rest), so the longer "saved entries
       + count" label never wraps onto two lines on a phone. */
    flex: 1 1 auto; min-height: var(--control-h-sm); padding: 0 10px; white-space: nowrap;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text-mut);
    font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.ow-switch-btn.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ct); }
.ow-switch-btn .ow-count {
    background: rgba(255,255,255,.25); border-radius: 999px;
    padding: 1px 7px; font-size: .78rem;
}
.ow-switch-btn:not(.active) .ow-count { background: var(--bg-alt); color: var(--text-mut); }
.ow-pane[hidden] { display: none; }

@media (min-width: 1000px) {
    /* 12-column proportions without a grid framework. */
    .ow-split {
        display: grid;
        grid-template-columns: 5fr 7fr;
        gap: 24px;
        align-items: start;
    }
    /* Both panes are always visible here, whatever the mobile toggle last did. */
    .ow-pane { display: block !important; }
    .ow-switch { display: none; }
    /* The form stays in view while the list scrolls past it. */
    .ow-pane-form { position: sticky; top: calc(var(--header-h) + 12px); }
    /* One column is narrow now — let the field grid reflow rather than squeeze. */
    .ow-pane-form .ps-grid { grid-template-columns: 1fr 1fr; }
    .ow-pane-form .ps-grid .ps-span { grid-column: 1 / -1; }
}

/* ---- QR / barcode scanner ------------------------------------------------- */
.qr-overlay .modal-box { max-width: 420px; }
.qr-stage {
    position: relative; width: 100%; aspect-ratio: 1 / 1;
    background: #000; border-radius: var(--radius-lg); overflow: hidden;
}
.qr-stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Corner brackets marking where to hold the code. */
.qr-reticle {
    position: absolute; inset: 16%;
    border: 2px solid rgba(255, 255, 255, .9);
    border-radius: 12px;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
.qr-scan svg { display: block; }

/* ---- Toasts -------------------------------------------------------------- */
.toast-wrap { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--bg-elev); color: var(--text); border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-md); border-radius: var(--radius); padding: 14px 20px;
    min-width: 260px; animation: toastIn .3s ease;
}
.toast.success { border-left-color: var(--kiwa-green); }
.toast.error { border-left-color: var(--kiwa-red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }

/* ---- Motion: lazy reveal + parallax --------------------------------------- */
/* Elements tagged .reveal fade/slide in when scrolled into view (app.js). */
.reveal {
    opacity: 0;
    transform: translateY(26px);
    transition: opacity .65s ease, transform .65s ease;
    transition-delay: var(--reveal-delay, 0s);
}
.reveal.visible { opacity: 1; transform: none; }
/* Sticky boxes must never carry the reveal transform: a transform on a sticky
   element shifts it out of its pinned position for the length of the fade, so
   the work-hours total bar visibly drifts under the header. Opt them out. */
.wh-topbar.reveal, .wh-cal-add.reveal,
.wh-card.reveal { opacity: 1; transform: none; transition: none; }  /* holds the sticky save bar */

/* The hero content drifts slower than the page scroll (app.js sets --plx). */
.hero .container {
    transform: translateY(var(--plx, 0));
    will-change: transform;
}

/* Accessibility: no motion for users who asked for none. */
@media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1; transform: none; transition: none; }
    .hero .container { transform: none; }
}

/* ---- Cookie banner --------------------------------------------------------- */
/* display:flex would defeat the [hidden] attribute — keep it authoritative. */
.cookie-banner[hidden] { display: none; }
.cookie-banner {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
    display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap;
    background: var(--bg-elev); color: var(--text);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 30px rgba(7, 38, 67, .18);
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    font-size: .92rem;
}
.cookie-banner .cookie-text { max-width: 760px; }
.cookie-banner a { text-decoration: underline; }
.cookie-banner .btn { padding: 0 22px; }

/* ---- Scroll-top ---------------------------------------------------------- */
.scroll-top {
    position: fixed; bottom: 22px; right: 22px; width: 46px; height: 46px;
    background: var(--primary); color: #fff; border-radius: var(--radius);
    display: none; align-items: center; justify-content: center; cursor: pointer;
    box-shadow: var(--shadow-md); font-size: 1.4rem; z-index: 40; opacity: .85;
}
.scroll-top:hover { opacity: 1; }
.scroll-top.show { display: flex; }
/* The cookie banner owns the bottom edge until it's dismissed. */
body.cookie-open .scroll-top { display: none; }
/* Work hours is a single short form with its own sticky total bar — a
   scroll-to-top button there only covers the controls. Keyed off .wh-topbar so
   no per-page plumbing is needed. */
body:has(.wh-topbar) .scroll-top { display: none; }

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 860px) {
    .nav-toggle { display: flex; order: -1; }
    /* Centre the wordmark between the burger and the profile button. Absolute
       rather than flex centring, so it stays optically centred regardless of
       how wide the two sides are. */
    .header-inner { position: relative; justify-content: space-between; gap: 8px; }
    .brand {
        position: absolute; left: 50%; top: 50%;
        transform: translate(-50%, -50%);
        pointer-events: auto;
    }
    .header-actions { margin-left: auto; }
    .main-nav { display: none; }   /* guests use the burger + slide-in menu */
}

/* Phones: there is no room to centre the wordmark over the gap between the
   burger and the actions — it ran into the theme / language buttons. Put it
   back in the row, smaller, right after the burger. */
@media (max-width: 640px) {
    .brand { position: static; transform: none; }
    .brand img { width: 84px; }
    .header-actions { gap: 2px; }
    .section { padding: 32px 0 40px; }
    .page-title { font-size: 1.6rem; }
    .scroll-top { width: 40px; height: 40px; right: 14px; bottom: 14px; font-size: 1.2rem; }
}
@media (max-width: 400px) {
    .lang-switch .lang-code { display: none; }   /* the flag says it */
    .contact-grid { grid-template-columns: minmax(0, 1fr); }
    .training-row { flex-direction: column; align-items: flex-start; }
    .hero h1 { font-size: 2rem; }
}

/* --- Settings (superadmin) ------------------------------------------------- */
.settings-grid { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 22px; align-items: start; }
.settings-card {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 22px 22px 24px;
}
.settings-h2 { font-size: 1.15rem; margin: 0 0 4px; }
.settings-hint { display: block; color: var(--text-mut); font-size: .82rem; margin: 4px 0 14px; }
.form-row .settings-hint { margin: 6px 0 0; }
/* Settings → System: PHP cache facts and the stale-file warning. */
.cache-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; margin: 6px 0 18px; font-size: .92rem; }
.cache-facts dt { color: var(--text-mut); }
.cache-facts dd { margin: 0; overflow-wrap: anywhere; }
.settings-hint-inline { color: var(--text-mut); font-size: .82rem; }
.cache-stale {
    border: 1px solid var(--kiwa-red); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px;
    background: color-mix(in srgb, var(--kiwa-red) 7%, transparent);
}
.cache-stale ul { margin: 6px 0 0; padding-left: 18px; font-size: .88rem; }
.cache-stale code { overflow-wrap: anywhere; }
@media (max-width: 480px) {
    .cache-facts { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .cache-facts dd { margin-bottom: 8px; }
}
.form-actions { margin-top: 8px; }

/* Email template preview gallery */
.tpl-preview { display: grid; grid-template-columns: 190px 1fr; gap: 16px; align-items: start; }
.tpl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tpl-item {
    width: 100%; text-align: left; background: none; border: 1px solid transparent;
    border-radius: var(--radius); cursor: pointer; font: inherit; color: var(--text-mut);
    padding: 8px 12px;
}
.tpl-item:hover { color: var(--text); background: var(--bg-alt); }
.tpl-item.active { color: var(--primary); font-weight: 700; background: var(--bg-alt); border-color: var(--border); }
.tpl-frame-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #edf0f5; }
.tpl-frame-bar { display: flex; justify-content: flex-end; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
#tplPreview { display: block; width: 100%; height: 640px; border: 0; background: #edf0f5; }

@media (max-width: 900px) {
    .settings-grid { grid-template-columns: minmax(0, 1fr); }
    .tpl-preview { grid-template-columns: minmax(0, 1fr); }
    #tplPreview { height: 520px; }
}

/* SMTP settings block inside the email tab */
.smtp-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 16px 4px; margin: 4px 0 14px; }
.smtp-block[hidden] { display: none; }
.smtp-block legend { font-size: .82rem; font-weight: 700; color: var(--text-mut); padding: 0 6px; }

/* --- Adjustable dashboard cards ------------------------------------------- */
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; align-items: start; }
.dash-card {
    grid-column: span var(--span, 12);
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); display: flex; flex-direction: column; min-width: 0;
}
.dash-card[hidden] { display: none; }   /* overrides the flex display above */
/* Anchor jumps (#card-…) land below the sticky header, not under it. */
.dash-card { scroll-margin-top: calc(var(--header-h) + 16px); }
.dash-card.dragging { opacity: .5; outline: 2px dashed var(--primary); }
.dash-card-head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.dash-card-title { font-size: 1rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-drag { cursor: grab; color: var(--text-mut); font-size: 1.05rem; line-height: 1; user-select: none; }
.dash-drag:active { cursor: grabbing; }
.dash-card-tools { display: flex; gap: 3px; }
.dash-w {
    width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    border-radius: var(--radius); cursor: pointer; font: inherit; font-size: 1.1rem; line-height: 1;
}
.dash-w:hover { border-color: var(--primary); color: var(--primary); }
.dash-hide {
    width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; background: none; color: var(--text-mut);
    border-radius: var(--radius); cursor: pointer; font: inherit; font-size: 1.15rem; line-height: 1;
}
.dash-hide:hover { border-color: var(--kiwa-red); color: var(--danger-text); }
.dash-collapse {
    width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; background: none; color: var(--text-mut);
    border-radius: var(--radius); cursor: pointer;
}
.dash-collapse:hover { border-color: var(--primary); color: var(--primary); }
.dash-collapse svg { transition: transform .2s; }
.dash-card.is-collapsed .dash-collapse svg { transform: rotate(-90deg); }
.dash-card.is-collapsed .dash-card-body { display: none; }

/* Header actions: Add card (dropdown) + Reset layout */
.dash-actions { display: flex; align-items: center; gap: 8px; position: relative; }
.dash-add { position: relative; }
.dash-add-menu {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 40; margin: 0; padding: 6px;
    list-style: none; min-width: 200px; max-height: 320px; overflow-y: auto;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.dash-add-menu[hidden] { display: none; }
.dash-add-menu li { margin: 0; }
.dash-add-menu button {
    display: block; width: 100%; text-align: left; background: none; border: 0;
    padding: 8px 12px; border-radius: var(--radius); cursor: pointer; font: inherit; color: var(--text);
}
.dash-add-menu button:hover { background: var(--bg-alt); color: var(--primary); }
.dash-card-body { padding: 14px; overflow-x: auto; }
.dash-card-body .stat-grid { margin-bottom: 0; }

@media (max-width: 860px) {
    .dash-grid { grid-template-columns: minmax(0, 1fr); }
    .dash-card { grid-column: 1 / -1 !important; }
    /* Width steppers are pointless full-width, but keep the collapse + hide
       tools reachable on mobile. */
    .dash-card-tools .dash-w { display: none; }
}

/* --- Profile avatar + round editor ---------------------------------------- */
/* ---- Profile form -------------------------------------------------------- */
/* Inputs are sized to the value they hold. A phone number stretched across the
   full column reads as an error; capping the width makes the form scannable
   and signals the expected length. The cap is a max, so narrow screens still
   collapse to full width. */
.profile-form .field-sm input { max-width: 240px; }
.profile-form .field-md input { max-width: 420px; }

/* Admin-managed values: separated from the editable fields and styled so they
   are visibly not inputs, instead of repeating a "locked" hint under each. */
.profile-locked {
    margin-top: 28px; padding-top: 18px;
    border-top: 1px solid var(--border);
}
.profile-locked-title {
    margin: 0 0 12px; font-size: .82rem; color: var(--text-mut);
}
.profile-form input:disabled {
    background: var(--bg-alt);
    color: var(--text-mut);
    cursor: default;
}
/* The notifications block is a separate concern from the profile form. */
.push-actions { display: flex; gap: 10px; flex-wrap: wrap; }

@media (max-width: 560px) {
    .profile-form .field-sm input,
    .profile-form .field-md input { max-width: 100%; }
}

.avatar-block { display: flex; align-items: center; gap: 20px; margin: 6px 0 26px; }
.avatar-view {
    width: 96px; height: 96px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
    background: var(--bg-alt); border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-placeholder { font-size: 2rem; font-weight: 700; color: var(--text-mut); }
.avatar-side { display: flex; flex-direction: column; gap: 6px; }
.avatar-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* Header mini avatar */
.avatar-mini { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; vertical-align: middle; }

/* display:flex would defeat the [hidden] attribute — the editor must stay shut
   until "Change photo" is pressed. */
.avatar-editor[hidden] { display: none; }
.avatar-editor {
    display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px; margin: 0 0 26px;
    /* The whole editor is a drop target; the dashed border only appears while
       a file is actually over it, so the resting state stays calm. */
    border: 1px dashed var(--border);
    transition: border-color var(--transition), background var(--transition);
}
.avatar-editor.is-dropping {
    border-color: var(--primary);
    background: var(--bg-alt);
}
/* Pointer events on children would fight the counter that tracks enter/leave. */
.avatar-editor.is-dropping .avatar-controls,
.avatar-editor.is-dropping .avatar-stage { pointer-events: none; }
.avatar-stage { position: relative; width: 280px; height: 280px; flex: 0 0 auto; }
#avatarCanvas {
    width: 280px; height: 280px; border-radius: 50%; cursor: grab; touch-action: none;
    background:
        repeating-conic-gradient(var(--bg-alt) 0% 25%, transparent 0% 50%) 50% / 20px 20px;
    box-shadow: 0 0 0 2px var(--border), inset 0 0 0 1px rgba(0,0,0,.04);
}
#avatarCanvas:active { cursor: grabbing; }
.avatar-empty {
    position: absolute; inset: 0; margin: 0; display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 0 32px; color: var(--text-mut); pointer-events: none; font-size: .9rem;
}
.avatar-controls { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 14px; }
.avatar-range { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px; font-size: .88rem; color: var(--text-mut); }
.avatar-range input[type="range"] { width: 100%; height: auto; padding: 0; border: 0; background: transparent; accent-color: var(--primary); }
.avatar-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar-actions { display: flex; gap: 8px; margin-top: 4px; }

@media (max-width: 560px) {
    .avatar-editor { flex-direction: column; align-items: center; }
    .avatar-controls { width: 100%; }
}

/* Auth confirm-email hint text */
.auth-hint { margin: 0 0 12px; font-size: .86rem; color: var(--text-mut); }

/* Valdkond filter inside the dashboard applications card */
.dash-filter { margin-bottom: 12px; }
.dash-filter select { flex: 0 0 auto; min-width: 200px; max-width: 280px; }


/* ==========================================================================
   Working-hours entry (/kiwa/work-hours) — today only, mobile-first.
   Progress ring toward the daily norm + ± steppers for fast thumb entry.
   ========================================================================== */
.wh-card {
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); padding: 0 16px 4px;
    /* clip, not hidden: hidden makes the card a scroll container, which would
       pin the sticky save bar to the card instead of the viewport. */
    overflow: clip;
}

/* --- Sticky total bar (replaces the hero) ----------------------------- */
/* Sits just below the sticky site header and stays put while the field
   list scrolls, so the running total is always in view on mobile. */
.wh-topbar {
    position: sticky; top: var(--header-h); z-index: 20;
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 12px;
}
/* Day switcher: two pills (yesterday / today) at the top of the sticky bar.
   Links, not JS tabs — each day is its own URL, so reload and back both work. */
.wh-day-switch {
    display: flex; gap: 6px;
    padding: 8px 15px 0;
}
.wh-day-btn {
    flex: 0 0 auto; padding: 4px 14px; border-radius: 999px;
    font-size: .84rem; font-weight: 600; text-decoration: none;
    color: var(--text-mut); background: var(--bg-alt);
    border: 1px solid var(--border);
    transition: background .15s, color .15s, border-color .15s;
}
.wh-day-btn:hover { color: var(--text); border-color: var(--text-mut); }
.wh-day-btn.active {
    color: #fff; background: var(--primary); border-color: var(--primary);
    pointer-events: none;
}
.wh-topbar-main {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 15px;
}
.wh-topbar-when { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.wh-topbar-dayline { display: flex; align-items: center; gap: 8px; }
.wh-topbar-day { font-size: 1.05rem; font-weight: 700; line-height: 1.2; }
.wh-topbar-date { font-size: .82rem; color: var(--text-mut); }
.wh-badge {
    padding: 2px 8px; border-radius: 999px;
    font-size: .64rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
    background: color-mix(in srgb, var(--kiwa-cyan) 18%, transparent); color: var(--kiwa-blue);
}
:root[data-theme="dark"] .wh-badge { color: var(--kiwa-aqua); }
/* Holiday / shortened-day marker — distinct from the "edited" badge. */
.wh-badge-day { background: color-mix(in srgb, #e0a800 22%, transparent); color: #8a6300; }
:root[data-theme="dark"] .wh-badge-day { color: #f0c84a; }
.wh-topbar-total { display: flex; align-items: baseline; gap: 4px; flex: 0 0 auto; }
.wh-total-num { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.wh-topbar-unit { font-size: .82rem; color: var(--text-mut); }
.wh-topbar-track { height: 4px; background: var(--bg-alt); }
.wh-topbar-fill {
    display: block; height: 100%; width: 0; background: var(--primary);
    transition: width .4s cubic-bezier(.4, 0, .2, 1), background .3s;
}

/* Status vs the daily norm: under = red, met = green, over = amber/yellow. */
.wh-topbar-total.is-under .wh-total-num { color: var(--danger-text); }
.wh-topbar-total.is-met   .wh-total-num { color: var(--kiwa-green); }
.wh-topbar-total.is-over  .wh-total-num { color: #b5810a; }
.wh-topbar-fill.is-under { background: var(--kiwa-red); }
.wh-topbar-fill.is-met   { background: var(--kiwa-green); }
.wh-topbar-fill.is-over  { background: #e0a800; }
:root[data-theme="dark"] .wh-topbar-total.is-under .wh-total-num { color: #ff6b6b; }
:root[data-theme="dark"] .wh-topbar-total.is-met   .wh-total-num { color: var(--kiwa-mint); }
:root[data-theme="dark"] .wh-topbar-total.is-over  .wh-total-num { color: #f0c84a; }
:root[data-theme="dark"] .wh-topbar-fill.is-met  { background: var(--kiwa-mint); }
:root[data-theme="dark"] .wh-topbar-fill.is-over { background: #f0c84a; }

/* --- Section headings -------------------------------------------------- */
.wh-section-label {
    display: block; font-size: .72rem; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: var(--text-mut); margin: 20px 0 6px;
}

/* --- Field rows: icon + label + stepper ------------------------------- */
.wh-rows { display: flex; flex-direction: column; }
.wh-row {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 0; border-bottom: 1px solid var(--border);
}
.wh-rows .wh-row:last-child { border-bottom: 0; }
.wh-row-ic {
    flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--bg-alt); color: var(--text-mut); transition: background .2s, color .2s;
}
.wh-row.is-filled .wh-row-ic {
    background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary);
}
:root[data-theme="dark"] .wh-row.is-filled .wh-row-ic { color: var(--kiwa-aqua); }
.wh-row-label { flex: 1 1 auto; min-width: 0; font-size: 1rem; }

/* On a phone the icon + stepper leave the label under 90px, and languages with
   long compound words ("Сверхурочные", "Keskiviikkona") were being clipped
   mid-word rather than wrapped. Reclaim width from the stepper, and let a word
   break as a last resort so nothing is ever cut off. */
@media (max-width: 560px) {
    .wh-row { gap: 8px; }
    .wh-row-ic { width: 32px; height: 32px; }
    .wh-row-label { font-size: .95rem; overflow-wrap: anywhere; }
    .wh-stepper { gap: 4px; }
    .wh-step { width: 34px; height: 34px; }
    .wh-stepper input { width: 52px !important; }
}

/* Stepper control */
.wh-stepper { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.wh-step {
    width: 38px; height: 38px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 50%; background: var(--bg-elev);
    color: var(--text); cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: background .15s, border-color .15s, transform .05s;
}
.wh-step:hover { background: var(--bg-alt); border-color: var(--text-mut); }
.wh-step:active { transform: scale(.9); }
.wh-stepper input {
    width: 62px; text-align: center; padding: 9px 4px; font-size: 1.1rem; font-weight: 600;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg);
    color: var(--text); font-variant-numeric: tabular-nums;
}
.wh-row.is-filled .wh-stepper input { border-color: var(--primary); color: var(--primary); }
:root[data-theme="dark"] .wh-row.is-filled .wh-stepper input { color: var(--text); }
.wh-stepper input:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(34, 83, 190, .18);
}

/* Overtime block reads as secondary */
.wh-rows-ot .wh-row-ic { border-radius: 10px; }
.wh-rows-ot .wh-row-label { color: var(--text-mut); }

/* --- Note ------------------------------------------------------------- */
.wh-note textarea {
    width: 100%; padding: 11px 12px; font-size: 1.02rem; font-family: inherit; line-height: 1.4;
    resize: vertical; min-height: 82px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text);
}
.wh-note textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(34, 83, 190, .18);
}

/* --- Save bar: fixed to the bottom of the screen, so Salvesta/Lähtesta are
   always reachable. Capped at the narrow container width and centred over the
   content area (offset past the sidebar on desktop); the section below adds
   matching bottom padding so the note field can scroll clear of the bar. --- */
.wh-save-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    /* Full width of the content column, inset by the container's 20px gutter. */
    max-width: none;
    margin: 0 20px;
    display: flex; align-items: center; justify-content: flex-end; gap: 14px;
    /* Extra bottom padding only where a phone home-indicator overlays the
       page (PWA standalone); env() is 0 everywhere else. */
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-elev);
    border: 1px solid var(--border); border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -6px 24px rgba(7, 38, 67, .10);
}
/* Desktop: centre over the content column, not the sidebar underneath. */
@media (min-width: 861px) {
    body.has-sidebar .wh-save-bar { left: var(--sidebar-w, 240px); }
}
/* Room for the bar (tallest state: message row + buttons on a phone). */
/* Outranks body.has-sidebar .section, which sets its own padding-bottom. */
.section.wh-today,
body.has-sidebar .section.wh-today { padding-bottom: calc(108px + env(safe-area-inset-bottom, 0px)); }
.wh-save-bar .btn { min-width: 132px; }
.wh-save-bar .btn:disabled { opacity: .45; cursor: default; }
.wh-save-msg { margin-right: auto; font-size: .9rem; font-weight: 600; color: var(--text-mut); }

/* On a phone two 132px buttons plus the gaps are wider than the bar, and
   nothing may shrink — so the status text was pushed to a negative offset and
   its first characters were clipped off the left edge. Give the message its own
   row above the buttons, and let the buttons share the width instead. */
@media (max-width: 560px) {
    .wh-save-bar { flex-wrap: wrap; gap: 10px; justify-content: stretch; }
    .wh-save-msg {
        order: -1;                 /* above the buttons, not squeezed beside them */
        flex: 1 0 100%;
        margin-right: 0;
        min-width: 0;
        overflow-wrap: anywhere;   /* long compound words still can't overflow */
    }
    .wh-save-msg:empty { display: none; }   /* no blank row before the first edit */
    .wh-save-bar .btn { flex: 1 1 0; min-width: 0; }
}
.wh-save-msg.is-dirty { color: var(--kiwa-blue); }
.wh-save-msg.is-saved { color: var(--kiwa-green); }
.wh-save-msg.is-error { color: var(--danger-text); }
:root[data-theme="dark"] .wh-save-msg.is-dirty { color: var(--kiwa-aqua); }
:root[data-theme="dark"] .wh-save-msg.is-saved { color: var(--kiwa-mint); }

/* Settings → Calendar: inline add-form panel + table action cell */
.wh-cal-add {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; margin-bottom: 22px;
    padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-alt);
}
.wh-cal-add .form-row { margin: 0; flex: 0 0 auto; }
.wh-cal-add .form-row label { font-size: .82rem; font-weight: 600; color: var(--text-mut); }
.wh-cal-add .wh-cal-name { flex: 1 1 200px; }
.wh-cal-add .form-actions { margin: 0; }
.dash-table-actions { white-space: nowrap; }
.dash-table-actions form { margin: 0; display: inline-block; }

/* Date field: dd.mm.YYYY text input + a calendar button that opens the
   native date picker (the transparent date input overlays the icon). */
.date-field { position: relative; display: flex; width: 172px; max-width: 100%; }
.date-field > input[type="text"] { flex: 1 1 auto; min-width: 0; padding-right: 42px; }
/* Inside app-forms the date field is a grid cell like any other input, so it
   fills the column instead of keeping its standalone 172px width. */
.app-form .date-field { width: 100%; }
.date-field-pick {
    position: absolute; right: 1px; top: 1px; bottom: 1px; width: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-mut); cursor: pointer; border-radius: 0 var(--radius) var(--radius) 0;
}
.date-field-pick:hover { color: var(--primary); }
.date-field input.is-invalid { border-color: var(--kiwa-red); }
.date-field > input[type="text"]:disabled + .date-field-pick { cursor: default; opacity: .5; }
.cal-day:disabled { opacity: .3; cursor: default; background: none; }
.date-field-pick svg { pointer-events: none; }
.date-field-pick input[type="date"] {
    position: absolute; inset: 0; width: 100%; height: 100%;
    opacity: 0; border: 0; padding: 0; margin: 0; cursor: pointer;
}

/* Keep the add/edit panel in view while scrolling the list (desktop/tablet;
   on mobile the panel is tall when stacked, so it stays static). */
@media (min-width: 641px) {
    .wh-cal-add { position: sticky; top: var(--header-h); z-index: 10; box-shadow: var(--shadow-sm); }
}

/* Mobile: the add form stacks, every control goes full-width. */
@media (max-width: 640px) {
    .wh-cal-add { display: block; }
    .wh-cal-add .form-row { margin-bottom: 12px; }
    .wh-cal-add .form-row:last-of-type { margin-bottom: 0; }
    .wh-cal-add .form-row input:not([type="date"]),
    .wh-cal-add .form-row select,
    .wh-cal-add .date-field { width: 100%; }
    .wh-cal-add .form-actions .btn { width: 100%; }
}

/* ---- Onsite works (/kiwa/onsite-works) ------------------------------------- */
.ow-list { list-style: none; margin: 0; padding: 0; }
.ow-item {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-left: 3px solid var(--primary); border-radius: var(--radius);
    padding: 12px 16px; margin-bottom: 10px;
}
.ow-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ow-equip { font-weight: 600; }
.ow-mf { color: var(--text-mut); }
.ow-meta { font-size: .8rem; color: var(--text-mut); }
.ow-actions { margin-left: auto; white-space: nowrap; }
.ow-comments { margin-top: 6px; overflow-wrap: anywhere; }
/* Photo strip: thumbnails plus the two add tiles (picker / camera). */
.ow-photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ow-photo { position: relative; }
.ow-photo img {
    width: 72px; height: 72px; object-fit: cover; display: block;
    border: 1px solid var(--border); border-radius: var(--radius);
}
/* .oo-photo-del is the Muu tab's twin (its own class for its own handler);
   it had no styling and fell under the thumbnail as a tiny grey box. */
.ow-photo-del, .oo-photo-del {
    position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0;
    border-radius: 50%; border: 1px solid var(--border); background: var(--bg-elev);
    color: var(--text-mut); font-size: .8rem; line-height: 1; cursor: pointer;
}
.ow-photo-del:hover, .oo-photo-del:hover { color: var(--danger-text); }
/* Fingers need a bigger target than a 20px dot. */
@media (pointer: coarse) {
    .ow-photo-del, .oo-photo-del { width: 28px; height: 28px; top: -9px; right: -9px; font-size: 1rem; }
}
.ow-photo-add {
    width: 72px; height: 72px; display: flex; align-items: center; justify-content: center;
    border: 1px dashed var(--border); border-radius: var(--radius);
    color: var(--text-mut); font-size: 1.3rem; cursor: pointer;
}
.ow-photo-add:hover { border-color: var(--primary); color: var(--primary); }
/* The camera tile only makes sense where a camera is likely — small screens. */
@media (min-width: 768px) { .ow-photo-cam { display: none; } }
.ow-form-photos { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* Previews of photos picked but not yet uploaded; empty until something is chosen. */
.ow-new-photos:empty { display: none; }
.ow-new-photos { margin-top: 10px; }

/* ---- NDT orders ---------------------------------------------------------- */
/* Method codes as inline checkboxes, wrapping like a chip row. */
.ndt-types { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 6px; }
.ndt-type { display: inline-flex; align-items: center; gap: 5px; margin: 0; cursor: pointer; }
.app-form .ndt-type { font-size: .95rem; color: var(--text); }
.app-form .ndt-type input { width: auto; margin: 0; }
/* Order table: every cell on one line (emails, company names, dates); the
   .table-wrap scrolls sideways instead. Only in the table layout — the
   stacked cards on narrow containers keep wrapping. */
@container (min-width: 821px) {
    .ndt-table th, .ndt-table td { white-space: nowrap; word-break: normal; }
}
#owPickedCount { font-size: .85rem; color: var(--text-mut); }
.ow-preview-img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: var(--radius); }
/* Lightbox slider: arrows overlay the photo, counter sits in the head. */
.ow-slider { position: relative; min-height: 120px; }
.ow-nav {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 1;
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
    font-size: 1.1rem; line-height: 1; cursor: pointer; opacity: .85;
    transition: all var(--transition);
}
.ow-nav:hover { opacity: 1; border-color: var(--primary); color: var(--primary); }
.ow-prev { left: 10px; }
.ow-next { right: 10px; }
.ow-count { color: var(--text-mut); font-size: .85rem; white-space: nowrap; }

/* ---- Google sign-in button ------------------------------------------------ */
.btn-google { width: 100%; margin-top: 4px; }
.btn-google .google-g {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; color: #4285f4; font-weight: 700; font-size: .9rem;
    border: 1px solid var(--border);
}

/* ==========================================================================
   Public training landing page (/taotlus/?taotlus=koolitus&id=…)
   Rendered in the bare `embed` layout: Kiwa bar, one white card, no portal
   chrome. Self-contained on purpose — nothing here depends on the portal's
   sidebar/header rules, so the page is safe to link to from kiwa.com.
   ========================================================================== */
.embed-body { background: #eef1f5; margin: 0; color: var(--text); font-family: var(--font); }
.embed-header { background: #fff; border-top: 5px solid var(--kiwa-blue); box-shadow: var(--shadow-sm); }
.embed-header-inner {
    max-width: 1160px; margin: 0 auto; padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.embed-logo img { display: block; height: 38px; width: auto; max-width: none; }
.embed-langs { display: flex; gap: 4px; }
.embed-lang {
    padding: 5px 10px; border-radius: var(--radius); font-size: .82rem; font-weight: 700;
    color: var(--text-mut); text-decoration: none; letter-spacing: .04em;
}
.embed-lang:hover { background: var(--bg-alt); color: var(--kiwa-blue); }
.embed-lang.active { background: var(--kiwa-blue); color: #fff; }
.embed-main { max-width: 1160px; margin: 0 auto; padding: 24px; }

.kool-card { background: #fff; padding: 34px 40px 40px; box-shadow: var(--shadow-sm); }
.kool-title {
    margin: 0 0 26px; font-size: 1.85rem; line-height: 1.25; font-weight: 700; color: #16202e;
}
/* "New course" marker (uus_koolitus). Sits on the title's first line and keeps
   its own size, so a long title still wraps normally around it. */
.kool-new {
    display: inline-block; vertical-align: middle; margin: -4px 6px 0 0;
    background: var(--kiwa-red); color: #fff; border-radius: 4px;
    padding: 4px 10px; font-size: .72rem; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase;
}

/* ---- Session blocks ------------------------------------------------------- */
.kool-block {
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
    background: var(--kiwa-blue); color: #fff; text-decoration: none;
    padding: 16px 22px; margin-bottom: 14px; transition: background var(--transition);
}
a.kool-block:hover { background: var(--kiwa-blue-d); color: #fff; }
.kool-block.is-closed { background: #7c8b9c; cursor: default; }
.kool-block-date { display: flex; align-items: center; gap: 14px; }
.kool-block em, .kool-block-seats em {
    display: block; font-style: normal; font-size: .82rem; opacity: .85; margin-bottom: 2px;
}
.kool-block b { font-size: 1.05rem; font-weight: 700; }
.kool-block-seats { text-align: right; }
.kool-ic-cal { display: flex; }

.kool-back { margin-top: 10px; }
.kool-image { display: block; width: 100%; height: auto; margin-top: 22px; }
.kool-note { color: var(--text-mut); line-height: 1.6; }
.kool-ok {
    background: #e8f7ef; border-left: 4px solid var(--kiwa-green); color: #14532d;
    padding: 14px 18px; margin: 0 0 22px; line-height: 1.6;
}
.kool-error {
    background: #fdecec; border-left: 4px solid var(--kiwa-red); color: #7f1d1d;
    padding: 14px 18px; margin: 0 0 22px;
}

/* ---- Registration form ---------------------------------------------------- */
.kool-selected { display: flex; align-items: center; gap: 8px; margin: -14px 0 26px; font-size: 1rem; }
.kool-check {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 3px; background: var(--kiwa-green);
    color: #fff; font-size: .8rem;
}
.kool-legend { margin: 0 0 14px; color: var(--text-mut); }
.kool-legend-sm { margin: 22px 0 10px; text-transform: uppercase; font-size: .82rem; letter-spacing: .04em; }
.kool-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 14px; }
.kool-form .form-row { margin: 0; min-width: 0; }
.kool-form label { display: block; font-size: .9rem; font-weight: 700; color: #16202e; margin-bottom: 6px; }
.kool-form input[type="text"], .kool-form input[type="email"] {
    width: 100%; height: var(--control-h); padding: 0 12px; font: inherit;
    border: 1px solid #b9c3ce; border-radius: 2px; background: #fff; color: var(--text);
}
.kool-form input[type="text"]:focus, .kool-form input[type="email"]:focus {
    outline: none; border-color: var(--kiwa-blue); box-shadow: 0 0 0 3px rgba(34, 83, 190, .15);
}
.kool-participant { padding-bottom: 6px; }
/* Each further participant starts below a divider — stacked on a phone they
   otherwise ran together, and "remove" looked like it belonged to the next one. */
.kool-participant + .kool-participant { border-top: 1px dashed var(--border); margin-top: 10px; padding-top: 18px; }
.kool-remove-cell { display: flex; align-items: flex-end; justify-content: flex-end; }
.kool-remove {
    display: inline-flex; align-items: center; gap: 8px; background: none; border: 0;
    color: var(--danger-text); font: inherit; cursor: pointer; padding: 0 0 12px;
}
/* inline-flex would otherwise defeat [hidden] on the single-participant row */
.kool-remove[hidden] { display: none; }
.kool-ic-minus, .kool-ic-plus {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 1.1rem; line-height: 1;
}
.kool-ic-minus { background: var(--kiwa-red); }
.kool-ic-plus { background: var(--kiwa-green); }
.kool-add-wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 6px 0 0; }
.kool-add {
    display: inline-flex; align-items: center; gap: 10px; background: none; border: 0;
    color: var(--kiwa-green); font: inherit; cursor: pointer; padding: 0;
}
.kool-add[disabled] { opacity: .45; cursor: not-allowed; }
.kool-seats-left { color: var(--text-mut); font-size: .88rem; }
.kool-hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.kool-radios { display: flex; flex-wrap: wrap; gap: 16px 48px; margin-bottom: 18px; }
.kool-radio { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.kool-radio input { width: 18px; height: 18px; accent-color: var(--kiwa-blue); }
.kool-radio span { font-weight: 600; }
.kool-consent { display: flex; align-items: flex-start; gap: 12px; margin: 16px 0; cursor: pointer; }
.kool-consent input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--kiwa-blue); flex: 0 0 auto; }
.kool-consent span { font-size: .9rem; font-weight: 700; line-height: 1.55; color: #16202e; }
.kool-consent a { color: var(--kiwa-blue); }
.kool-cancel { font-size: .9rem; color: var(--kiwa-blue); margin: 18px 0 0; }
.kool-cancel a { color: var(--kiwa-blue); text-decoration: underline; }
.kool-actions { display: flex; justify-content: center; margin: 26px 0 6px; }
.kool-send { min-width: 180px; }
.kool-footbar { background: #eef1f5; margin: 26px -40px -40px; padding: 16px 40px; }
.kool-footbar .kool-back { margin: 0; }

@media (max-width: 780px) {
    .embed-main { padding: 14px; }
    .kool-card { padding: 22px 18px 26px; }
    .kool-title { font-size: 1.4rem; }
    .kool-grid-3 { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .kool-block { flex-direction: column; align-items: flex-start; gap: 10px; }
    .kool-block-seats { text-align: left; }
    .kool-footbar { margin: 22px -18px -26px; padding: 14px 18px; }
    /* Finger-sized targets: the language switch and "add participant" were
       31px and 26px tall. */
    .embed-lang { padding: 10px 12px; }
    .kool-add { min-height: 44px; white-space: nowrap; }
    /* "Add participant" keeps one line; the seat count drops below it. */
    .kool-add-wrap { flex-wrap: wrap; gap: 4px 16px; }
}
/* The payer field stands alone above the contact grid; without this it sat
   flush against the next label while every other field has a gap. */
#koolPayerFields > .form-row { margin-bottom: 18px; }
@media (max-width: 780px) {
    #koolPayerFields > .form-row { margin-bottom: 12px; }
}

/* Editable email copy in Seaded → Koolitused: one block per text, one row per
   language. The placeholder shows the shipped default, so an empty field reads
   as "unchanged" rather than "missing". */
.kool-text-block {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 18px 4px; margin: 0 0 18px;
}
.kool-text-block legend { padding: 0 6px; font-size: .9rem; font-weight: 600; color: var(--text); }
.kool-text-block .form-row { margin-bottom: 12px; }
.kool-text-block label { font-size: .78rem; font-weight: 700; color: var(--text-mut); letter-spacing: .06em; }
.kool-text-block textarea, .kool-text-block input[type="text"] {
    width: 100%; padding: 10px 12px; font: inherit; line-height: 1.5;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text); resize: vertical;
}
.kool-text-block code { background: var(--bg-alt); padding: 1px 6px; border-radius: 3px; font-size: .85em; }

/* ---- Onsite works → "Muu": equipment-number chips -------------------------- */
.tagbox {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    min-height: var(--control-h); padding: 6px 10px; cursor: text;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text);
}
.tagbox:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34, 83, 190, .15); }
.tagbox-tags { display: contents; }
.tagbox-tag {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--primary); color: var(--primary-ct);
    padding: 3px 6px 3px 10px; border-radius: 999px; font-size: .86rem; line-height: 1.4;
}
.tagbox-del {
    border: 0; background: rgba(255, 255, 255, .25); color: inherit; cursor: pointer;
    width: 18px; height: 18px; border-radius: 50%; line-height: 1; padding: 0; font-size: .9rem;
}
.tagbox-del:hover { background: rgba(255, 255, 255, .45); }
/* The text field takes the rest of the row and carries no chrome of its own —
   the box around it already reads as the input. */
.tagbox-input {
    flex: 1 1 120px; min-width: 120px; border: 0; outline: none; padding: 4px 0;
    background: transparent; color: inherit; font: inherit;
}
.oo-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.oo-tag {
    background: var(--bg-alt); border: 1px solid var(--border); border-radius: 999px;
    padding: 2px 10px; font-size: .82rem; color: var(--text-mut);
}
.oo-private { margin: 0 0 10px; }

/* The transfer limits line: the general rule for everyone, the live server
   numbers appended for superadmins. */
.transfer-limits { margin: -12px 0 20px; }
.transfer-limits-admin { display: block; opacity: .75; }

/* ---- Feedback ----------------------------------------------------------- */
.fb-form { margin-bottom: 24px; }
.fb-form .ps-group { display: grid; gap: 14px; }
.fb-back { margin: -10px 0 12px; font-size: .9rem; }
.fb-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--text-mut); font-size: .9rem; margin: -12px 0 18px; }
.fb-meta strong { color: var(--text); }
.fb-h2 { font-size: 1.15rem; margin: 28px 0 12px; }
.fb-body { padding: 18px 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-alt); }
.fb-comments { max-height: none; }
.fb-comment--kiwa { border-left: 3px solid var(--kiwa-blue, #0054c5); }
.fb-client { color: var(--text-mut); }
.fb-status-open   { background: var(--kiwa-mint); color: var(--kiwa-navy); }
.fb-status-closed { background: var(--bg-alt); color: var(--text-mut); border: 1px solid var(--border); }
.fb-editor-row.is-invalid .note-editor, .fb-editor-row.is-invalid textarea { border-color: var(--kiwa-red); }
/* Sanitised rich text (feedback bodies and comments). */
.rich-text { overflow-wrap: anywhere; line-height: 1.55; }
.rich-text p { margin: 0 0 .7em; }
.rich-text p:last-child { margin-bottom: 0; }
.rich-text img { max-width: 100%; height: auto; border-radius: 6px; }
.rich-text table { border-collapse: collapse; max-width: 100%; margin: .5em 0; }
.rich-text td, .rich-text th { border: 1px solid var(--border); padding: 4px 8px; }
.rich-text blockquote { margin: .5em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-mut); }
.rich-text pre { white-space: pre-wrap; background: var(--bg-alt); padding: 8px 10px; border-radius: 6px; }
/* Summernote lite in the house theme. */
.note-editor.note-frame { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.note-editor.note-frame .note-toolbar { background: var(--bg-alt); border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.note-editor.note-frame .note-editing-area .note-editable { background: var(--bg); color: var(--text); }
.note-editor.note-frame .note-statusbar { background: var(--bg-alt); border-top: 1px solid var(--border); }
.note-editor .note-btn { background: var(--bg); color: var(--text); border-color: var(--border); }
.note-editor .note-btn:hover { background: var(--bg-alt); }
:root[data-theme="dark"] .note-editor .note-dropdown-menu,
:root[data-theme="dark"] .note-editor .note-modal-content { background: var(--bg-alt); color: var(--text); border-color: var(--border); }

/* ==========================================================================
   Messenger (/messages): contacts on the left, the open thread on the right.
   ========================================================================== */
.sidebar a { display: flex; align-items: center; gap: 8px; }
.nav-badge {
    margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px;
    border-radius: 11px; background: var(--kiwa-red, #e4002b); color: #fff;
    font-size: .74rem; font-weight: 700; line-height: 22px; text-align: center;
}
/* Header icon: the badge sits on the bubble's corner. */
.msg-btn { position: relative; padding: 8px 10px; }
.msg-btn .msg-icon { display: block; }
.msg-btn .nav-badge {
    /* Anchored from the button's centre, so it overlaps only the bubble's
       top-right corner; from the right edge it covered the whole icon. */
    position: absolute; top: 0; left: calc(50% + 3px); right: auto; margin: 0;
    min-width: 14px; height: 16px; line-height: 16px; padding: 0 4px; font-size: .66rem;
    border: 2px solid var(--bg-elev); box-sizing: content-box;
}

.chat-section { padding: 28px 0; }
.chat {
    display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 0;
    height: calc(100vh - var(--header-h) - 56px); min-height: 480px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden;
}
.chat-list { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.chat-list-head { padding: 16px 14px 10px; border-bottom: 1px solid var(--border); }
.chat-title { font-size: 1.3rem; margin: 0 0 10px; }
.chat-filter { width: 100%; }
.chat-groups { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }
.chat-group-head {
    padding: 12px 8px 4px; font-size: .74rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--text-mut);
}
.chat-contact {
    display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: var(--radius);
    color: var(--text); transition: background var(--transition);
}
.chat-contact:hover { background: var(--bg-alt); text-decoration: none; }
.chat-contact.active { background: var(--primary); color: var(--primary-ct); }
.chat-contact.active .chat-contact-sub { color: var(--primary-ct); opacity: .8; }
.chat-contact-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-contact-sub { font-size: .76rem; color: var(--text-mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-role { font-size: .68rem; padding: 1px 6px; }
.chat-contact.active .chat-role { background: #fff; color: var(--primary); }
.chat-unread {
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--kiwa-red, #e4002b); color: #fff; font-size: .72rem; font-weight: 700;
    line-height: 20px; text-align: center; flex: 0 0 auto;
}
.chat-avatar {
    width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
}
.chat-avatar--initial { background: var(--bg-alt); color: var(--text-mut); font-weight: 700; border: 1px solid var(--border); }
.chat-contact.active .chat-avatar--initial { background: rgba(255,255,255,.2); color: #fff; border-color: transparent; }
.chat-nomatch { padding: 24px; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-placeholder {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-mut); gap: 8px; padding: 40px;
}
.chat-placeholder-icon { font-size: 3rem; opacity: .5; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-head-text { display: flex; flex-direction: column; min-width: 0; }
.chat-head-sub { font-size: .8rem; color: var(--text-mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-back { display: none; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; background: var(--bg-alt); }
.chat-thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { display: flex; }
.chat-msg--own { justify-content: flex-end; }
.chat-bubble {
    max-width: min(78%, 640px); padding: 8px 12px 6px; border-radius: 14px;
    background: var(--bg-elev); border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.chat-msg--own .chat-bubble {
    background: var(--primary); color: var(--primary-ct); border-color: var(--primary);
    border-bottom-left-radius: 14px; border-bottom-right-radius: 4px;
}
.chat-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-time { font-size: .7rem; color: var(--text-mut); margin-top: 3px; text-align: right; }
.chat-msg--own .chat-time { color: var(--primary-ct); opacity: .75; }
/* Read receipt: an eye after the time of the newest own message the other side has read. */
.chat-seen { display: inline-flex; vertical-align: -2px; margin-left: 6px; }
.chat-seen[hidden] { display: none; }   /* the class rule would otherwise beat the attribute */
.chat-seen svg { display: block; }
.chat-msg--own .chat-time { display: flex; justify-content: flex-end; align-items: center; }
.chat-empty { padding: 60px 20px; }
.chat-compose { display: flex; gap: 10px; padding: 12px 16px 6px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-compose textarea { flex: 1; resize: none; min-height: 42px; max-height: 160px; line-height: 1.4; }
.chat-send { flex: 0 0 auto; }
.chat-hint { margin: 0; padding: 0 16px 10px; font-size: .72rem; color: var(--text-mut); }

@media (max-width: 860px) {
    .chat { grid-template-columns: minmax(0, 1fr); height: calc(100vh - var(--header-h) - 32px); }
    .chat-section { padding: 16px 0; }
    .chat-list { border-right: 0; }
    .chat--open .chat-list { display: none; }
    .chat:not(.chat--open) .chat-pane { display: none; }
    .chat-back { display: inline-flex; }
    .chat-hint { display: none; }
    .chat-bubble { max-width: 88%; }
}


/* ==========================================================================
   PED category calculator (/ped)
   A risk ramp, not the brand palette: the five outcomes read as an escalation
   at a glance, and the Kiwa blue stays free for the marker and the chrome.
   ========================================================================== */
:root {
    --ped-c0: #8593a3;   /* sound engineering practice — no category */
    --ped-c1: #2f9e5f;
    --ped-c2: #c99109;
    --ped-c3: #dd6f16;
    --ped-c4: #c02430;
    --ped-f0: rgba(133, 147, 163, .13);
    --ped-f1: rgba(47, 158, 95, .15);
    --ped-f2: rgba(201, 145, 9, .16);
    --ped-f3: rgba(221, 111, 22, .17);
    --ped-f4: rgba(192, 36, 48, .17);
    --ped-grid: rgba(90, 107, 122, .22);
}
:root[data-theme="dark"] {
    --ped-c0: #94a3b4;
    --ped-c1: #46bd79;
    --ped-c2: #e0aa22;
    --ped-c3: #f08a33;
    --ped-c4: #e24a56;
    --ped-f0: rgba(148, 163, 180, .16);
    --ped-f1: rgba(70, 189, 121, .18);
    --ped-f2: rgba(224, 170, 34, .18);
    --ped-f3: rgba(240, 138, 51, .19);
    --ped-f4: rgba(226, 74, 86, .19);
    --ped-grid: rgba(160, 178, 194, .2);
}

.ped-lead { color: var(--text-mut); max-width: 62ch; margin: -6px 0 26px; }

/* Form left; on the right the verdict line, the diagram, then the working.
   The verdict line is a fixed height and the diagram's height follows only
   its width, so the diagram never moves while a slider is dragged — the part
   that grows and shrinks with the result (note, facts, modules) sits below
   it. One column, with verdict and working in one pinned card, once the
   screen narrows. */
.ped-app {
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    grid-template-areas: "form output" "form chart";
    grid-template-rows: auto 1fr;
    gap: 22px 26px;
    align-items: start;
}
.ped-form   { grid-area: form; }
.ped-output { grid-area: output; }
.ped-chart-wrap { grid-area: chart; margin: 0; min-width: 0; }

.ped-form {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px;
    position: sticky; top: calc(var(--header-h) + 16px);
}
.ped-field { margin-bottom: 18px; }
.ped-field:last-of-type { margin-bottom: 14px; }
.ped-label, .ped-field > label {
    display: block; font-size: .85rem; font-weight: 600;
    color: var(--text-mut); margin-bottom: 6px;
}
.ped-field select { width: 100%; }

/* Segmented control — two mutually exclusive choices, sized like an input. */
.ped-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ped-seg label { position: relative; display: block; }
.ped-seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.ped-seg span {
    display: flex; align-items: center; justify-content: center;
    height: var(--control-h); padding: 0 10px; text-align: center;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text); font-weight: 600; font-size: .92rem;
    cursor: pointer; transition: all var(--transition);
}
.ped-seg label:hover span { border-color: var(--primary); color: var(--primary); }
.ped-seg input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-ct); }
.ped-seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.ped-num { display: flex; align-items: center; gap: 8px; }
.ped-num input { flex: 1; min-width: 0; }
.ped-unit { color: var(--text-mut); font-size: .9rem; font-weight: 600; flex: 0 0 auto; }
.ped-range { width: 100%; margin: 10px 0 0; accent-color: var(--primary); }
.ped-reset { width: 100%; }

/* Verdict card. The badge carries the category colour; everything else stays calm. */
.ped-output {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px 20px;
}
.ped-verdict { display: flex; align-items: center; gap: 16px; }
.ped-badge {
    flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
    min-width: 68px; height: 68px; padding: 0 10px;
    border-radius: var(--radius-lg); background: var(--ped-c0); color: #fff;
    font-size: 1.7rem; font-weight: 800; letter-spacing: .5px; line-height: 1;
}
.ped-badge.is-sep { font-size: 1.05rem; }
.ped-badge.cat-1 { background: var(--ped-c1); }
.ped-badge.cat-2 { background: var(--ped-c2); }
.ped-badge.cat-3 { background: var(--ped-c3); }
.ped-badge.cat-4 { background: var(--ped-c4); }
.ped-verdict-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ped-verdict-text strong { font-size: 1.25rem; line-height: 1.25; }
.ped-verdict-text span { color: var(--text-mut); font-size: .86rem; }
.ped-note { margin: 14px 0 0; color: var(--text-mut); font-size: .88rem; line-height: 1.55; }

.ped-facts { display: flex; flex-wrap: wrap; gap: 6px 26px; margin: 14px 0 0; }
.ped-facts dt { color: var(--text-mut); font-size: .8rem; }
.ped-facts dd { margin: 0 0 0 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ped-facts > div { display: flex; align-items: baseline; }

.ped-sub { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
           color: var(--text-mut); margin: 0 0 10px; }
.ped-modules { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.ped-modules ul { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.ped-modules li {
    border: 1px solid var(--border); border-radius: 999px; padding: 5px 13px;
    font-size: .85rem; font-weight: 600; background: var(--bg-alt);
}

/* Diagram. app.js draws the SVG at the container's real pixel size, so the
   labels stay the same size on a phone as on a desktop. */
.ped-chart-wrap {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px 20px 16px;
}
.ped-chart svg { display: block; width: 100%; height: auto; }
.ped-chart text { fill: var(--text-mut); font-family: var(--font); }
.ped-chart .ped-axis-title { fill: var(--text); font-weight: 700; }
.ped-chart .ped-region-label { font-weight: 800; }
.ped-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 8px; }
.ped-legend span { display: inline-flex; align-items: center; gap: 7px; font-size: .8rem; color: var(--text-mut); }
.ped-legend i { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.ped-disclaimer {
    margin: 26px 0 0; padding-top: 16px; border-top: 1px solid var(--border);
    color: var(--text-mut); font-size: .82rem; line-height: 1.6; max-width: 80ch;
}

/* Wide screens show the working in full: no disclosure, nothing to open.
   A closed <details> hides its content through ::details-content, which a
   display rule on the child cannot undo — app.js sets the open state to match
   the viewport, and this only takes the summary out of the way. */
.ped-more > summary { display: none; }

@media (min-width: 981px) {
    .ped-app {
        grid-template-areas: "form verdict" "form chart" "form more";
        grid-template-rows: auto auto 1fr;
    }
    /* The verdict card splits in two around the diagram: its line and its
       working become grid items of their own, each drawn as a card. */
    .ped-output { display: contents; }
    .ped-verdict, .ped-more {
        background: var(--bg-elev); border: 1px solid var(--border);
        border-radius: var(--radius-lg); padding: 18px 20px;
    }
    .ped-verdict { grid-area: verdict; }
    .ped-more    { grid-area: more; }
    .ped-more-body { display: flex; flex-direction: column; gap: 14px; }
    .ped-more-body > * { margin: 0; }
    .ped-more-body > .ped-modules { margin-top: 4px; }
    /* Facts are cleared only when an input is empty — then there is no working. */
    .ped-more:has(.ped-facts:empty) { display: none; }
}

@media (max-width: 980px) {
    /* The answer moves above the inputs and stays pinned under the header, so
       dragging a slider at the bottom of the form still shows the category. */
    .ped-app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "output" "form" "chart"; grid-template-rows: none; }
    .ped-form { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
    .ped-field { margin-bottom: 14px; }
    .ped-reset { grid-column: 1 / -1; }
    .ped-output {
        position: sticky; top: var(--header-h); z-index: 20;
        box-shadow: var(--shadow-md); padding: 14px 16px;
        /* Hard ceiling: pinned, this card sits on top of the form, so it must
           never grow far enough to cover the fields being edited. Opening the
           details scrolls inside the card instead of pushing it down. */
        max-height: 52vh; overflow-y: auto; overscroll-behavior: contain;
    }
    .ped-more > summary {
        display: block; cursor: pointer; margin-top: 12px; padding-top: 10px;
        border-top: 1px solid var(--border);
        font-size: .8rem; font-weight: 700; text-transform: uppercase;
        letter-spacing: .06em; color: var(--text-mut);
    }
    .ped-more[open] > summary { margin-bottom: 4px; }
}
@media (max-width: 560px) {
    .ped-form { grid-template-columns: minmax(0, 1fr); }
    .ped-badge { min-width: 54px; height: 54px; font-size: 1.35rem; }
    .ped-verdict-text strong { font-size: 1.05rem; }
    .ped-chart-wrap { padding: 16px 12px 12px; }
}

/* ==========================================================================
   Superadmin "view as" — read-only bar across the top of every page.
   ========================================================================== */
.viewas-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: var(--viewas-h, 44px); padding: 0 16px;
    display: flex; align-items: center; gap: 12px;
    background: #f5b301; color: #1b1b1b; font-size: .88rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.viewas-icon { font-size: 1.2rem; }
.viewas-text { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; overflow: hidden; white-space: nowrap; }
.viewas-text > * { overflow: hidden; text-overflow: ellipsis; }
.viewas-who, .viewas-note { opacity: .8; }
.viewas-form { margin: 0; flex: 0 0 auto; }
.viewas-stop { background: #1b1b1b; color: #fff; border-color: #1b1b1b; }
.viewas-stop:hover { background: #000; color: #fff; }
/* Everything fixed below the bar moves down by its height. */
body.is-viewing-as { padding-top: var(--viewas-h, 44px); }
body.is-viewing-as .site-header { top: var(--viewas-h, 44px); }
body.is-viewing-as .sidebar { top: calc(var(--header-h) + var(--viewas-h, 44px)); }
.client-actions .act-viewas { font-size: 1rem; }
@media (max-width: 860px) {
    .viewas-note { display: none; }
}
@media (max-width: 640px) {
    .viewas-who { display: none; }
}

/* ---- Passkeys + active sessions (profile, admin user edit) ---------------- */
.btn-passkey { width: 100%; margin-top: 10px; justify-content: center; gap: 8px; }
.passkey-list { list-style: none; margin: 0 0 14px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.passkey-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.passkey-item + .passkey-item { border-top: 1px solid var(--border); }
.passkey-icon { font-size: 1.3rem; }
.passkey-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.passkey-name { overflow-wrap: anywhere; }
.passkey-meta { color: var(--text-mut); font-size: .82rem; }
.passkey-actions { display: flex; gap: 6px; flex-shrink: 0; }
.session-table td { vertical-align: middle; }
.session-table .status-chip { margin-left: 6px; }
.session-actions { text-align: right; white-space: nowrap; }
.security-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 8px; }
/* .btn sets display, which would otherwise beat the hidden attribute. */
.btn[hidden] { display: none; }
@media (max-width: 560px) {
    .passkey-item { flex-wrap: wrap; }
    .passkey-actions { width: 100%; justify-content: flex-end; }
}

/* ---- Phones: tab bars scroll sideways instead of running off the page ---- */
@media (max-width: 640px) {
    .tabs {
        overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        /* The 2px rule as an inset shadow: a real border plus the buttons'
           -2px margin would be clipped by the scroll container. */
        border-bottom: none; box-shadow: inset 0 -2px 0 var(--border);
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab-btn { flex: 0 0 auto; white-space: nowrap; margin-bottom: 0; padding: 10px 12px; }
}
@media (max-width: 640px) {
    /* Dashboard number tiles: two per row instead of one tall card each. */
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat-card { padding: 14px 14px 12px; }
    .stat-num { font-size: 1.6rem; }
    a.stat-card::after { top: 10px; right: 12px; }
}

/* NDT weld plan: the grid scrolls sideways on narrow screens; keep the weld
   number column pinned so every row stays identifiable while scrolling. */
.weld-table thead tr:first-child th:first-child,
.weld-table tbody td:first-child {
    position: sticky; left: 0; z-index: 2;
}
.weld-table tbody td:first-child { background: var(--bg-elev); box-shadow: 1px 0 0 var(--border); }

/* Card-mode tables: long unbroken values (e-mail addresses, file names) wrap
   inside the card instead of pushing it wider than the screen. */
@container (max-width: 820px) {
    .dash-table--cards td { overflow-wrap: anywhere; }
}
/* A form row whose only field is hidden (e.g. company for staff roles) hides
   its label too, instead of leaving it orphaned. */
.form-row:has(> select[hidden]:only-of-type) { display: none; }

/* Header account icon (no avatar): sized like the messenger bubble. */
#userBtn .user-icon { display: block; }
/* Card-mode tables: an actions cell with no buttons (e.g. your own row) is
   whitespace only, so :empty misses it — drop it by content instead. */
@container (max-width: 820px) {
    .dash-table--cards td.row-actions:not(:has(*)) { display: none; }
}

/* PED categories, dark theme: the brighter category colours need dark
   numerals — white on the yellow badge was only 2.1:1 (grey 2.6:1). */
:root[data-theme="dark"] .ped-badge { color: #0e1a26; }

/* ---- Onsite works: several actions per equipment ------------------------- */
#owForm input.is-invalid { border-color: var(--kiwa-red); box-shadow: 0 0 0 3px rgba(209, 17, 28, .15); }
/* "This equipment already has a record — saving adds to it." */
.ow-merge-hint {
    border-left: 4px solid var(--kiwa-aqua, #00a0c6); background: var(--bg-alt);
    border-radius: 0 var(--radius) var(--radius) 0; padding: 10px 14px; font-size: .9rem;
}
.ow-acts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ow-acts:empty { display: none; }
.ow-act {
    border: 1px solid var(--border); border-left: 3px solid var(--primary);
    border-radius: var(--radius); background: var(--bg-elev); padding: 8px 10px;
}
.ow-act.is-visual { border-left-color: var(--kiwa-green, #2f9e5f); }
.ow-act-top { display: flex; align-items: center; gap: 8px; }
.ow-act-no { font-weight: 700; color: var(--text-mut); min-width: 1.4em; }
.ow-act-top select, .ow-act-top input[data-f="type"] { flex: 1 1 auto; min-width: 0; }
.ow-act-date { font-size: .8rem; color: var(--text-mut); white-space: nowrap; }
.ow-act-date:empty { display: none; }
.ow-act-del { flex: 0 0 auto; color: var(--danger-text); font-size: 1.1rem; line-height: 1; }
.ow-act-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 8px; }
.ow-act-fields[hidden] { display: none; }
.ow-act-field { display: grid; gap: 3px; margin: 0; }
.ow-act-field span { font-size: .78rem; color: var(--text-mut); }
/* 16px text: iOS zooms the page into any field with smaller type. */
.ow-act-field input, .ow-act-top select, .ow-act-top input[data-f="type"] { width: 100%; font-size: 1rem; }
.ow-acts-add { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ow-acts:not(:empty) + .ow-acts-add { margin-top: 10px; }
/* Card: the actions done to this equipment. */
.ow-steps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.ow-step {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
    font-size: .88rem; padding: 5px 0; border-top: 1px dashed var(--border);
}
.ow-step:first-child { border-top: 0; }
.ow-step-date { color: var(--text-mut); font-size: .82rem; min-width: 76px; }
.ow-type {
    display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; font-weight: 600;
    background: var(--bg-alt); color: var(--text); border: 1px solid var(--border);
}
.ow-type-pressure { border-color: var(--primary); color: var(--primary); }
.ow-type-visual { border-color: var(--kiwa-green, #2f9e5f); color: var(--kiwa-green, #2f9e5f); }
:root[data-theme="dark"] .ow-type-visual { color: var(--kiwa-mint, #7ee2b8); border-color: var(--kiwa-mint, #7ee2b8); }
.ow-step-gauge, .ow-step-user { color: var(--text-mut); font-size: .82rem; }
.ow-step-pressure { white-space: nowrap; }
.ow-item.row-flash { animation: rowFlash 1.2s ease; }
@media (max-width: 340px) {
    .ow-act-fields { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Onsite works: records on an equipment card --------------------------- */
.ow-visits { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.ow-visit {
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); padding: 8px 10px;
}
.ow-visit-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.ow-visit-date { font-size: .92rem; }
.ow-visit-meta { color: var(--text-mut); font-size: .8rem; }
.ow-visit-actions { margin-left: auto; display: flex; gap: 4px; }
.ow-visit-actions .btn { padding: 2px 8px; min-height: 0; height: 30px; }
.ow-visit .ow-steps { margin-top: 6px; }
.ow-visit .ow-step { border-top: 0; padding: 2px 0; }
.ow-visit .ow-comments { margin-top: 6px; font-size: .9rem; }
#ooList .ow-visit .ow-steps { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---- Audit log (/admin/log) ---- */
.log-filters { align-items: flex-end; }
.log-filters .log-date { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; min-width: 130px; max-width: 220px; font-size: .8rem; color: var(--text-mut); }
.log-filters .log-date .date-field { width: 100%; }
/* Delete toolbar: select-all, delete ticked, delete everything found. */
.log-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: -12px 0 14px; }
.log-pick-all { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; cursor: pointer; margin-right: auto; }
.log-del-form { margin: 0; }
.log-del-btn { color: var(--kiwa-red); }
.log-del-btn:disabled { opacity: .45; cursor: default; }
.log-pick { margin: 0 8px 0 0; vertical-align: -2px; cursor: pointer; }
.log-row:has(.log-pick:checked) td { background: color-mix(in srgb, var(--kiwa-red) 7%, transparent); }
.log-active { display: flex; gap: 8px; flex-wrap: wrap; margin: -16px 0 18px; }
.log-active .oo-tag a { margin-left: 4px; text-decoration: none; font-weight: 700; }
.log-table td { vertical-align: top; }
.log-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-sec { color: var(--text-mut); }
.log-muted { display: block; color: var(--text-mut); font-size: .8rem; }
.log-action code { font-size: .85rem; overflow-wrap: anywhere; }
.log-target { margin-left: 6px; color: var(--text-mut); font-size: .85rem; }
.log-method {
    display: inline-block; min-width: 44px; margin-right: 6px; padding: 1px 6px; border-radius: 4px;
    font-size: .7rem; font-weight: 700; text-align: center; letter-spacing: .03em;
    background: var(--bg-alt); color: var(--text-mut); border: 1px solid var(--border);
}
.log-method-post { background: var(--primary); color: var(--primary-ct); border-color: transparent; }
.log-details { margin-top: 6px; font-size: .85rem; }
.log-details summary { cursor: pointer; color: var(--primary); }
.log-details pre {
    margin: 6px 0; padding: 8px 10px; max-height: 320px; overflow: auto;
    background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .78rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.status-chip.log-chip-ok { background: var(--kiwa-green); color: #fff; }
.status-chip.log-chip-error { background: var(--kiwa-red); color: #fff; }
.status-chip.log-chip-denied { background: var(--kiwa-navy); color: #fff; }
.log-message { margin-top: 4px; font-size: .8rem; color: var(--text-mut); overflow-wrap: anywhere; max-width: 340px; }
.log-row.log-error .log-message { color: var(--danger-text); }
.log-pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.log-pager .log-muted { display: inline; }
:root[data-theme="dark"] .status-chip.log-chip-denied { background: var(--kiwa-slate); }
.log-cell { min-width: 0; }
@container (max-width: 820px) {
    .log-table td { align-items: flex-start; }
    .log-table .log-cell { text-align: right; }
    .log-table .log-message { max-width: none; }
    /* The action and its details read left to right under their label. */
    .log-table td.log-action { display: block; text-align: left; }
    .log-table td.log-action::before { display: block; margin-bottom: 4px; }
    .log-table td.log-action .log-cell { text-align: left; }
}

/* ---- Order pages (applications, NDT orders) on phones --------------------- */
@media (max-width: 640px) {
    /* Tab bars wrap as pills: every tab stays visible instead of hiding the
       last ones behind a sideways scroll with no scrollbar. */
    .tabs {
        overflow: visible; flex-wrap: wrap; gap: 6px;
        border-bottom: 0; box-shadow: none; margin: 22px 0 16px;
    }
    .tab-btn {
        flex: 0 1 auto; padding: 7px 12px; font-size: .9rem;
        border: 1px solid var(--border); border-radius: 999px; background: var(--bg-elev);
    }
    .tab-btn.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ct); }
    /* Order details: two short label/value pairs per row, not one. */
    .app-details { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
    .app-details > div { min-width: 0; overflow-wrap: anywhere; }
    /* Report toolbar: progress on its own line, smaller buttons below. */
    .report-toolbar { padding: 8px 0; gap: 8px; }
    .report-progress { flex-basis: 100%; min-width: 0; }
    .report-toolbar-actions { flex-wrap: wrap; gap: 6px; }
    .report-toolbar-actions .btn { padding: 6px 10px; font-size: .82rem; }
    /* NDT weld plan: the method filter and the search each on their own line. */
    .plan-filters select { flex: 1 1 100%; min-width: 0; }
    .plan-filters input { flex: 1 1 100%; }
}
/* Linked users: notification ticks big enough to hit with a finger. */
@media (pointer: coarse) {
    .inv-flag { width: 24px; height: 24px; }
}

/* ---- Domain lists (lifts, pressure, NDT) on narrow screens ---------------- */
/* Compact cards: the linked name/number as the card title, the other fields
   two per row with the label above the value, actions along the bottom. */
@container (max-width: 820px) {
    .dash-table--compact tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 16px; padding: 12px 14px 4px;
    }
    .dash-table--compact td {
        display: block; min-width: 0; padding: 0 0 10px; border-bottom: 0;
        text-align: left; font-size: .92rem; overflow-wrap: anywhere;
    }
    .dash-table--compact td::before { display: block; margin-bottom: 2px; }
    .dash-table--compact td.cell-main {
        grid-column: 1 / -1; order: -1; font-size: 1rem; font-weight: 600;
        padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--border);
    }
    .dash-table--compact td.cell-main::before { content: none; }
    .dash-table--compact td.row-actions,
    .dash-table--compact td.dash-table-actions {
        grid-column: 1 / -1; display: flex; padding: 8px 0;
        border-top: 1px solid var(--border);
    }
}
/* Filter bars on phones: search on its own line, the dropdowns and the
   search button two per row instead of the button alone on a line. */
@media (max-width: 640px) {
    .filters > input[type="search"] { flex: 1 1 100%; }
    .filters > select { flex: 1 1 calc(50% - 6px); min-width: 0; }
    .filters > .btn { flex: 1 1 calc(50% - 6px); }
    .filters > .settings-hint { flex: 1 1 100%; }
    .filters > .settings-hint:empty { display: none; }
}

