/* ==========================================================================
   Sorted. - panel stylesheet
   One design system for the company panel, the platform's sign-in pages and
   the owner dashboard. Tokens first; every component reads from them.

   Identity: deep ink + warm paper + one accent, jade - the full stop in
   "Sorted." that reads as "done". Ink is for action, jade is for done /
   good / the AI. Display type is Fraunces (soft), UI type is Inter.
   ========================================================================== */

/* ---------- Fonts (self-hosted) ---------- */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/sorted/inter-latin-wght-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/sorted/inter-latin-ext-wght-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Fraunces";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/sorted/fraunces-latin-full-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Fraunces";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/sorted/fraunces-latin-ext-full-normal.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Fraunces";
    font-style: italic;
    font-weight: 100 900;
    font-display: swap;
    src: url("/fonts/sorted/fraunces-latin-full-italic.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Design tokens ---------- */

:root {
    /* Ink: text and dark surfaces - a green-black, like fountain-pen ink */
    --ink-950: #0b1310;
    --ink-900: #13201b;
    --ink-800: #1f2e28;
    --ink-700: #33423b;
    --ink-600: #4a5852;
    --ink-500: #5f6b65;
    --ink-400: #8b948f;
    --ink-300: #b8beb9;

    /* Paper: warm neutrals */
    --paper-0: #ffffff;
    --paper-50: #fbfaf7;
    --paper-100: #f6f4ef;
    --paper-150: #f0ede6;
    --paper-200: #e9e5dc;
    --paper-300: #e1dcd1;
    --paper-400: #cdc6b8;

    /* Jade: the accent - the full stop */
    --jade-50: #eaf6f1;
    --jade-100: #d3eee3;
    --jade-200: #a6dcc7;
    --jade-300: #6cc7a6;
    --jade-400: #34c08f;   /* on dark surfaces */
    --jade-500: #12a179;   /* the dot itself (graphics, 3:1+) */
    --jade-600: #0b8463;   /* fills with white text - 4.7:1 */
    --jade-700: #08694f;   /* text and links on light - 6.7:1 */
    --jade-800: #0a5240;

    /* Signals */
    --amber-600: #9a5b00;
    --amber-200: #eed8a6;
    --amber-50: #fcf2de;
    --red-700: #912018;
    --red-600: #b42318;
    --red-200: #f2c5bf;
    --red-50: #fdeeec;
    --blue-600: #1f5fbf;
    --blue-200: #c7daf4;
    --blue-50: #ebf2fc;

    /* Semantic roles */
    --bg: var(--paper-100);
    --surface: var(--paper-0);
    --surface-2: var(--paper-50);
    --sunken: var(--paper-150);
    --card: var(--surface);
    --border: #e4dfd5;
    --border-strong: var(--paper-400);
    --text: var(--ink-900);
    --text-dim: var(--ink-600);
    --text-faint: var(--ink-500);
    --text-ghost: var(--ink-400);
    --accent: var(--jade-600);
    --accent-strong: var(--jade-700);
    --accent-soft: var(--jade-50);
    --accent-dot: var(--jade-500);
    --hover: rgba(19, 32, 27, 0.05);

    /* Legacy names - every existing view keeps working */
    --green: var(--jade-600);
    --green-strong: var(--jade-700);
    --green-soft: var(--jade-50);
    --amber: var(--amber-600);
    --amber-soft: var(--amber-50);
    --red: var(--red-600);
    --red-strong: var(--red-700);
    --red-soft: var(--red-50);
    --blue: var(--blue-600);
    --blue-soft: var(--blue-50);
    --brand-grad: linear-gradient(135deg, var(--jade-500), var(--jade-700));

    /* Type */
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    --text-xs: 12px;
    --text-sm: 13px;
    --text-base: 14px;
    --text-md: 16px;
    --text-lg: 18px;
    --text-xl: 22px;
    --text-2xl: 28px;
    --text-3xl: 36px;

    /* Space: an 8px grid, with 4px half-steps */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;
    --sp-12: 48px;
    --sp-16: 64px;

    /* Radii */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-pill: 999px;

    /* Elevation - warm, low and soft */
    --shadow-xs: 0 1px 1px rgba(19, 32, 27, 0.04);
    --shadow: 0 1px 2px rgba(19, 32, 27, 0.05), 0 1px 3px rgba(19, 32, 27, 0.03);
    --shadow-md: 0 8px 20px -8px rgba(19, 32, 27, 0.14), 0 2px 4px -2px rgba(19, 32, 27, 0.06);
    --shadow-lg: 0 20px 48px -14px rgba(19, 32, 27, 0.24), 0 4px 12px -4px rgba(19, 32, 27, 0.08);

    /* Focus */
    --ring: 0 0 0 3px rgba(18, 161, 121, 0.26);
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --spring: cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: 1.55;
    font-feature-settings: "cv11";
    min-height: 100vh;
    /* Safety net: if any element ever escapes its width, clip it rather than
       let the page grow wider than the screen (which makes the PWA zoom right
       out). overflow-x:clip - unlike hidden - doesn't break sticky headers. */
    overflow-x: clip;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { letter-spacing: -0.012em; line-height: 1.25; }
img { max-width: 100%; }
code, kbd, pre { font-family: var(--mono); }
code { font-size: 0.92em; background: var(--sunken); border-radius: 5px; padding: 1px 5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }

::selection { background: var(--jade-100); color: var(--ink-900); }

/* Thin, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--paper-400) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--paper-400); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--ink-300); }
*::-webkit-scrollbar-track { background: transparent; }

/* Keyboard focus: visible, calm, on-brand */
:focus-visible { outline: 2px solid var(--accent-dot); outline-offset: 2px; border-radius: 6px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }

/* The wordmark - "Sorted" with a jade full stop.
   <span class="wordmark">Sorted<i>.</i></span> */
.wordmark {
    font-family: var(--font-display);
    font-weight: 620;
    font-variation-settings: "SOFT" 100, "WONK" 0;
    font-style: normal;
    letter-spacing: -0.02em;
    color: var(--ink-900);
    line-height: 1;
    white-space: nowrap;
}
.wordmark i { font-style: normal; color: var(--accent-dot); }

.display {
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 50, "WONK" 0;
    font-weight: 560;
    letter-spacing: -0.02em;
}

/* ---------- Shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 252px;
    flex-shrink: 0;
    background: var(--paper-150);
    border-right: 1px solid var(--border);
    padding: var(--sp-4) var(--sp-3) var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: 1px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}

/* The nav scrolls between a fixed brand block and a fixed foot, so the
   signed-in user and sign-out are always in reach. */
.sidebar > nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 0 calc(-1 * var(--sp-3));
    padding: 0 var(--sp-3) var(--sp-2);
    display: flex;
    flex-direction: column;
    gap: 1px;
    scrollbar-width: none;
}
.sidebar > nav::-webkit-scrollbar { display: none; }
.sidebar > nav:hover { scrollbar-width: thin; }

/* Brand block: the company, front and centre */
.brand {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 14px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    min-width: 0;
}
.brand.has-logo { flex-direction: column; align-items: stretch; gap: 8px; }

.brand-badge {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 10px;
    background: var(--ink-900);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 650;
    font-size: 13px;
    letter-spacing: 0.02em;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), var(--shadow);
}

.brand-logo {
    display: flex;
    align-items: center;
    height: 44px;
    padding: 6px 10px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
}
.brand-logo img { display: block; max-height: 30px; max-width: 100%; width: auto; object-fit: contain; object-position: left center; }

.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-name { font-weight: 650; font-size: 14px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub, .brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--text-faint); }
.brand.has-logo .brand-text { padding: 0 2px; }

/* Legacy brand dot (older markup): a small ink tile with a jade full stop */
.brand .dot {
    width: 30px; height: 30px; flex-shrink: 0;
    border-radius: 9px;
    background: var(--ink-900);
    position: relative;
}
.brand .dot::after {
    content: "";
    position: absolute; right: 7px; bottom: 7px;
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--jade-400);
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    padding: 14px 10px 5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    color: var(--ink-700);
    font-weight: 500;
    font-size: 13.5px;
    line-height: 20px;
    position: relative;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--ink-500); transition: color 0.15s; }
.nav-item:hover { background: rgba(19, 32, 27, 0.055); color: var(--text); }
.nav-item:hover svg { color: var(--ink-700); }
.nav-item.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow), 0 0 0 1px rgba(19, 32, 27, 0.06);
}
.nav-item.active svg { color: var(--accent); }

.nav-item .count {
    margin-left: auto;
    min-width: 20px;
    text-align: center;
    background: rgba(19, 32, 27, 0.07);
    color: var(--ink-700);
    font-size: 11px;
    font-weight: 650;
    line-height: 18px;
    border-radius: var(--radius-pill);
    padding: 0 7px;
    font-variant-numeric: tabular-nums;
}
.nav-item.active .count { background: var(--accent-soft); color: var(--accent-strong); }
.nav-item.is-urgent, .nav-item.is-urgent svg { color: var(--red); }
.nav-item.is-urgent .count { background: var(--red-soft); color: var(--red); }

.sidebar .spacer { flex: 0 0 auto; }

/* Sidebar foot: who's signed in, sign out, and the quiet Sorted. signature */
.sidebar-foot { flex: none; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; display: flex; flex-direction: column; gap: 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 2px 2px 2px 6px; }
.me-avatar {
    width: 30px; height: 30px; flex: none; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--paper-300); color: var(--ink-800);
    font-size: 11.5px; font-weight: 650;
}
.me-text { min-width: 0; flex: 1; line-height: 1.25; }
.me-text b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { display: block; font-size: 11.5px; color: var(--text-faint); }
.me form { margin: 0; }
.me-out {
    width: 32px; height: 32px; display: grid; place-items: center;
    border: 0; background: transparent; color: var(--ink-500);
    border-radius: var(--radius-sm); cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.me-out svg { width: 18px; height: 18px; }
.me-out:hover { background: var(--hover); color: var(--text); }

.sorted-sig {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 0 8px 2px;
    font-size: 11px;
    color: var(--text-faint);
    font-weight: 500;
    align-self: flex-start;
}
.sorted-sig .wordmark { font-size: 15px; color: var(--ink-700); }
.sorted-sig:hover .wordmark { color: var(--ink-900); }

.main { flex: 1; min-width: 0; padding: var(--sp-8) var(--sp-10) 80px; max-width: 1280px; }

/* ---------- Page headers ---------- */

.page-head { display: flex; align-items: flex-end; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.page-head h1 {
    margin: 0;
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 50, "WONK" 0;
    font-size: 28px;
    font-weight: 560;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--ink-900);
}
.page-head p { margin: 6px 0 0; color: var(--text-dim); font-size: 14px; max-width: 760px; }
.page-head .actions { margin-left: auto; display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

.kicker { font-size: 11.5px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-strong); }
.lead { font-size: 15px; color: var(--text-dim); line-height: 1.6; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* script/template tags between cards must not eat the gap - inline scripts
   after a card kept breaking simple adjacency. */
.card + .card,
script + .card,
.card + script + .card { margin-top: var(--sp-4); }

.card-title {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 650;
    font-size: 13.5px;
    letter-spacing: -0.005em;
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--text);
}
.card-title .hint { color: var(--text-faint); font-weight: 500; margin-left: auto; font-size: 12px; }
.card-body { padding: 20px; }

/* Generic callout: a soft panel inside a card or page */
.callout { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); }
.callout.accent { background: var(--accent-soft); border-color: var(--jade-200); }

/* ---------- Stats ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: var(--sp-6); }

.stat {
    display: block;
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
}
a.stat:hover { border-color: var(--border-strong); }
.stat .label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); padding-right: 16px; }
.stat .value {
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 50, "WONK" 0;
    font-size: 32px;
    font-weight: 560;
    letter-spacing: -0.02em;
    line-height: 1.15;
    margin-top: 6px;
    font-variant-numeric: tabular-nums lining-nums;
    color: var(--ink-900);
}
.stat .sub { color: var(--text-faint); font-size: 12.5px; margin-top: 4px; }
.stat.good .value { color: var(--accent-strong); }
.stat.warn .value { color: var(--amber); }
.stat.good::after, .stat.warn::after {
    content: "";
    position: absolute;
    top: 20px; right: 18px;
    width: 8px; height: 8px; border-radius: 50%;
}
.stat.good::after { background: var(--accent-dot); box-shadow: 0 0 0 4px var(--accent-soft); }
.stat.warn::after { background: #d68a00; box-shadow: 0 0 0 4px var(--amber-soft); }

/* ---------- Tables ---------- */

table.list { width: 100%; border-collapse: collapse; }

table.list th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-faint);
    font-weight: 600;
    padding: 12px 20px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}

table.list td { padding: 13px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr { transition: background 0.12s; }
table.list tbody tr:hover { background: var(--paper-50); }

.row-link { font-weight: 600; color: var(--text); }
.row-link:hover { color: var(--accent-strong); }
.row-sub { color: var(--text-faint); font-size: 12.5px; }

/* ---------- Pills & badges ---------- */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 18px;
    border-radius: var(--radius-pill);
    padding: 1px 9px;
    white-space: nowrap;
    border: 1px solid transparent;
}

.pill.green, .pill.success { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--jade-100); }
.pill.amber { background: var(--amber-soft); color: var(--amber); border-color: #f5e3bb; }
.pill.red { background: var(--red-soft); color: var(--red); border-color: #f8d8d3; }
.pill.blue { background: var(--blue-soft); color: var(--blue); border-color: #d9e6f8; }
.pill.grey { background: var(--paper-150); color: var(--text-dim); border-color: var(--paper-200); }
.pill.ink { background: var(--ink-900); color: #fff; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    line-height: 20px;
    padding: 7px 14px;
    border-radius: 9px;
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s, transform 0.1s;
}

.btn svg { width: 15px; height: 15px; }
.btn:hover { background: var(--paper-50); border-color: var(--ink-300); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn.primary {
    background: var(--ink-900);
    border-color: var(--ink-900);
    color: #fff;
    box-shadow: 0 1px 2px rgba(19, 32, 27, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.btn.primary:hover { background: var(--ink-800); border-color: var(--ink-800); }

.btn.accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 1px 2px rgba(8, 105, 79, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn.accent:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn.danger { color: var(--red); border-color: var(--red-200); background: var(--surface); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn.subtle { border-color: transparent; box-shadow: none; background: transparent; color: var(--text-dim); }
.btn.subtle:hover { background: var(--hover); color: var(--text); }
.btn.small { padding: 4px 10px; font-size: 12.5px; line-height: 18px; border-radius: 8px; }
.btn.large { padding: 11px 20px; font-size: 14.5px; border-radius: 11px; }
.btn.block { width: 100%; }

/* ---------- Forms ---------- */

label.field { display: block; margin-bottom: var(--sp-4); }
label.field > span, .field-label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-700);
    margin-bottom: 6px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="datetime-local"], input[type="date"], input[type="time"],
input[type="search"], input[type="tel"], textarea, select {
    width: 100%;
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 12px;
    font: inherit;
    line-height: 20px;
    outline: none;
    box-shadow: inset 0 1px 1px rgba(19, 32, 27, 0.03);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder, textarea::placeholder { color: var(--text-ghost); }

input:hover:not(:focus):not([type="checkbox"]):not([type="radio"]):not([type="file"]), textarea:hover:not(:focus), select:hover:not(:focus) { border-color: var(--ink-300); }

input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}

select:not([multiple]) {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 32px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%235f6b65' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 16px 16px;
    cursor: pointer;
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

textarea { resize: vertical; line-height: 1.6; }
.help { color: var(--text-faint); font-size: 12px; margin-top: 5px; line-height: 1.5; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--sp-4); }
.form-grid .full { grid-column: 1 / -1; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 600; font-size: 13px; }
.switch input { display: none; }
.switch .track { width: 36px; height: 21px; border-radius: 99px; background: var(--paper-400); position: relative; transition: background 0.18s var(--ease); flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: transform 0.2s var(--spring); box-shadow: 0 1px 2px rgba(19, 32, 27, 0.25); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(15px); }

/* ---------- Conversation ---------- */

.thread { display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; gap: 12px; align-items: flex-start; }

.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-weight: 650;
    font-size: 12.5px;
    color: var(--ink-800);
    background: var(--paper-300);
}

.msg.outbound .avatar { background: var(--ink-900); color: #fff; }

.msg-card {
    flex: 1;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.msg.outbound .msg-card { background: #f4faf7; border-color: var(--jade-100); }

.msg-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
}

.msg.outbound .msg-head { border-color: var(--jade-100); }
.msg-head .who { font-weight: 650; }
.msg-head .when { color: var(--text-faint); margin-left: auto; }
/* overflow-wrap:anywhere + word-break:break-word force even an unbreakable
   token (tracking-link blobs, raw headers) to wrap instead of stretching the
   bubble past the screen and zooming the whole PWA out. */
.msg-body { padding: 14px 16px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; font-size: 14px; line-height: 1.6; }
.msg-body a { overflow-wrap: anywhere; word-break: break-word; color: var(--accent-strong); text-decoration: underline; text-decoration-color: var(--jade-200); text-underline-offset: 2px; }

/* ---------- Composer ---------- */

.composer { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.composer textarea { border: none; box-shadow: none; border-radius: var(--radius) var(--radius) 0 0; padding: 14px 16px; font-size: 14px; }
.composer textarea:focus { box-shadow: none; }
.composer .bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
    flex-wrap: wrap;
}
.composer .bar .right { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Misc ---------- */

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

.issues { margin: 0; padding-left: 18px; color: var(--text-dim); font-size: 13px; }
.issues li { margin-bottom: 6px; }

.score-ring { font-family: var(--font-display); font-variation-settings: "SOFT" 50, "WONK" 0; font-weight: 600; font-size: 28px; letter-spacing: -0.02em; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ink-900);
    color: #fff;
    border-radius: 12px;
    padding: 12px 18px 12px 14px;
    font-weight: 550;
    font-size: 13.5px;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s var(--spring), toast-out 0.4s ease 4.6s forwards;
    z-index: 200;
    max-width: min(520px, calc(100vw - 32px));
}
.toast::before {
    content: "";
    width: 8px; height: 8px; flex: none;
    border-radius: 50%;
    background: var(--jade-400);
    box-shadow: 0 0 0 4px rgba(52, 192, 143, 0.18);
}

@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); visibility: hidden; } }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--sp-4); align-items: center; }

.chip {
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 18px;
    box-shadow: var(--shadow-xs);
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { background: var(--ink-900); border-color: var(--ink-900); color: #fff; box-shadow: 0 1px 2px rgba(19, 32, 27, 0.2); }

.search { margin-left: auto; width: 260px; }
.search input {
    border-radius: var(--radius-pill);
    padding: 7px 14px 7px 34px;
    border-color: var(--border);
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b948f' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='m20 20-4.2-4.2'/%3E%3C/svg%3E") no-repeat 12px center / 15px 15px;
    box-shadow: var(--shadow-xs);
}

.pagination { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 20px; align-items: center; color: var(--text-faint); font-size: 12.5px; }

/* Empty states: a quiet full stop - nothing to do here */
.empty { text-align: center; padding: 56px 24px; color: var(--text-faint); font-size: 13.5px; }
.empty .big { font-size: 30px; margin-bottom: 10px; line-height: 1; }
.empty .big:empty::before {
    content: "";
    display: inline-block;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--accent-dot);
    box-shadow: 0 0 0 8px var(--accent-soft);
    margin-bottom: 8px;
}
.empty > strong, .empty > h3 { display: block; color: var(--text); font-family: var(--font-display); font-variation-settings: "SOFT" 50, "WONK" 0; font-weight: 560; font-size: 18px; margin: 0 0 4px; }

.sparkle { color: var(--accent); }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-4); align-items: start; }
.two-col.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
/* Grid gaps space these; the stacked-card margin would knock them out of line. */
.two-col > .card + .card, .two-col > script + .card, .settings-wrap > .card + .card { margin-top: 0; }

.alert {
    position: relative;
    border-radius: var(--radius-md);
    padding: 12px 16px 12px 38px;
    font-weight: 500;
    font-size: 13.5px;
    line-height: 1.5;
    margin-bottom: var(--sp-4);
    border: 1px solid;
}
.alert::before {
    content: "";
    position: absolute;
    left: 16px; top: 18px;
    width: 8px; height: 8px; border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
}
.alert.warn { background: var(--amber-soft); border-color: var(--amber-200); color: #6f4100; }
.alert.error { background: var(--red-soft); border-color: var(--red-200); color: var(--red-700); }
.alert.info { background: var(--blue-soft); border-color: var(--blue-200); color: #1a4f9e; }
.alert.success { background: var(--accent-soft); border-color: var(--jade-200); color: var(--jade-800); }
.alert code { background: rgba(255, 255, 255, 0.65); }
.alert a { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Ticket detail (classic layout) ---------- */

.ticket-head { margin-bottom: 14px; }
.crumb { font-size: 12.5px; font-weight: 600; color: var(--text-faint); display: flex; gap: 7px; align-items: center; margin-bottom: 6px; }
.crumb a { color: var(--text-faint); }
.crumb a:hover { color: var(--text-dim); }
.crumb .sep { color: var(--border-strong); }
.ticket-title { margin: 0; font-family: var(--font-display); font-variation-settings: "SOFT" 50, "WONK" 0; font-size: 26px; font-weight: 560; letter-spacing: -0.02em; line-height: 1.25; }

.ticket-meta { margin-bottom: 14px; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px 22px; padding: 16px 18px; }
.meta-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: 6px; }
.meta-value { font-size: 13.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 7px; flex-wrap: wrap; row-gap: 5px; }
.meta-value .pill { white-space: nowrap; }
.meta-avatar {
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--paper-200); color: var(--text-dim);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 650; flex: none;
}

/* z-index lifts the toolbar's paint layer above later siblings - the page
   entrance animations give every section its own stacking context, which
   would otherwise draw the alert banner over the Escalate-to popover. */
.ticket-toolbar {
    display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-start;
    position: relative; z-index: 20;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px;
}
.ticket-toolbar form { display: contents; }
.ticket-toolbar .btn { border: none; background: transparent; box-shadow: none; border-radius: 8px; font-weight: 600; }
.ticket-toolbar .btn:hover { background: var(--hover); }
.ticket-toolbar > form:last-of-type { margin-left: auto; }
.ticket-toolbar > form:last-of-type .btn { color: var(--red); }
.ticket-toolbar > form:last-of-type .btn:hover { background: var(--red-soft); }
.ticket-toolbar summary.btn { border: none; background: transparent; box-shadow: none; border-radius: 8px; }
.ticket-toolbar summary.btn:hover { background: var(--hover); }

/* The Escalate-to dropdown: a real floating panel, exempt from the
   display:contents rule that flattens button-wrapper forms above. */
.assign-drop { position: relative; }
.assign-drop summary { list-style: none; cursor: pointer; }
.assign-drop summary::-webkit-details-marker { display: none; }
.assign-drop[open] summary { background: var(--paper-50); }
.ticket-toolbar .assign-drop form.assign-pop,
form.assign-pop {
    display: block;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 30;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 14px;
    width: 280px;
}

/* ---------- Attachments, lightbox ---------- */

.msg-attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.msg-attachments img {
    max-height: 130px; max-width: 200px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    object-fit: cover; display: block;
    background: var(--paper-50);
}
.msg-attachments a:hover img { border-color: var(--accent); }

.lb-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(11, 19, 16, 0.8);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    display: grid; place-items: center;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
    cursor: zoom-out; padding: 24px;
}
.lb-overlay.open { opacity: 1; pointer-events: auto; }
.lb-img {
    max-width: min(92vw, 1100px); max-height: 82vh;
    border-radius: var(--radius); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
    transform: scale(0.92); transition: transform 0.25s var(--spring);
    background: #fff;
}
.lb-overlay.open .lb-img { transform: scale(1); }
.lb-cap { color: var(--paper-200); font-size: 13px; font-weight: 550; margin-top: 12px; text-align: center; }

/* ---------- Outstanding orders: product cards + drill-in modal ---------- */

.op-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.op-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 16px 14px 14px; text-align: center; cursor: pointer; font: inherit; color: var(--text);
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.op-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.op-card img { width: 84px; height: 84px; object-fit: cover; border-radius: var(--radius); background: var(--paper-50); }
.op-noimg { width: 84px; height: 84px; border-radius: var(--radius); background: var(--paper-150); display: grid; place-items: center; color: var(--text-ghost); }
.op-noimg svg { width: 32px; height: 32px; }
.op-name { font-weight: 650; font-size: 13px; line-height: 1.35; }
.op-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.op-overlay {
    position: fixed; inset: 0; z-index: 95;
    background: rgba(11, 19, 16, 0.5);
    -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
    display: grid; place-items: center; padding: 20px;
    opacity: 0; pointer-events: none; transition: opacity 0.18s;
}
.op-overlay.open { opacity: 1; pointer-events: auto; }
.op-modal {
    background: var(--surface); border-radius: var(--radius-xl); width: min(680px, 94vw); max-height: 84vh;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 28px 80px rgba(11, 19, 16, 0.35);
    transform: scale(0.94) translateY(10px); transition: transform 0.24s var(--spring);
}
.op-overlay.open .op-modal { transform: none; }
.op-modal-head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.op-modal-head img { width: 52px; height: 52px; object-fit: cover; border-radius: var(--radius-md); background: var(--paper-50); }
.op-close {
    margin-left: auto; width: 32px; height: 32px; border-radius: 50%;
    border: none; background: var(--paper-150); color: var(--text-dim);
    font-size: 18px; cursor: pointer; transition: background 0.15s;
}
.op-close:hover { background: var(--paper-200); }
.op-modal-body { overflow-y: auto; padding: 14px 22px 20px; }
.op-section { margin-bottom: 16px; }
.op-section-title { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: 8px; }
.op-section-chased .op-section-title { color: var(--red); }
.op-section-chased .op-row { background: #fffaf9; border-color: var(--red-200); }
.op-row { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 8px; }
.op-order { font-weight: 700; color: var(--accent-strong); }
.op-ticket { display: block; margin-top: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.op-ticket:hover { color: var(--accent-strong); }
.op-ticket small { color: var(--text-faint); font-weight: 500; }

/* Download-format modal */
.dl-overlay {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(11, 19, 16, 0.45);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    display: grid; place-items: center;
    opacity: 0; pointer-events: none; transition: opacity 0.18s;
    padding: 20px;
}
.dl-overlay.open { opacity: 1; pointer-events: auto; }
.dl-modal {
    background: var(--surface); border-radius: var(--radius-lg); padding: 22px 24px;
    box-shadow: 0 24px 70px rgba(11, 19, 16, 0.3);
    width: min(420px, 92vw);
    transform: scale(0.94) translateY(8px); transition: transform 0.22s var(--spring);
}
.dl-overlay.open .dl-modal { transform: none; }
.dl-choice {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px;
    border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 12px;
    text-align: center; transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.dl-choice:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-2px); }
.dl-choice svg { width: 26px; height: 26px; color: var(--accent-strong); }
.dl-choice span { font-weight: 700; font-size: 14px; }
.dl-choice small { color: var(--text-faint); font-size: 11px; line-height: 1.35; }

/* Customer photos sidebar card */
.cp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cp-item { display: flex; flex-direction: column; gap: 2px; position: relative; }
.cp-item .attach-del { position: absolute; top: -6px; right: -6px; opacity: 0; transition: opacity 0.15s; z-index: 2; }
.cp-item:hover .attach-del { opacity: 1; }
.cp-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--paper-50); display: block; transition: border-color 0.15s, transform 0.15s; }
.cp-item a:hover img { border-color: var(--accent); transform: scale(1.03); }
.cp-item.cp-deleted img { opacity: 0.4; filter: grayscale(0.8); }
.cp-cap { font-size: 10.5px; color: var(--text-faint); font-weight: 600; display: flex; gap: 6px; align-items: center; }

.msg-attach { position: relative; display: inline-block; }
.msg-attach .attach-del { position: absolute; top: -6px; right: -6px; opacity: 0; transition: opacity 0.15s; }
.msg-attach:hover .attach-del { opacity: 1; }
.attach-del button {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--red); color: #fff; border: 2px solid #fff;
    font-size: 12px; line-height: 1; cursor: pointer; padding: 0;
    box-shadow: var(--shadow);
}

/* ---------- Internal notes ---------- */

.notes-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.note {
    background: #fffbf0;
    border: 1px solid #f0e2bd;
    border-radius: var(--radius-md);
    padding: 12px 14px;
}

.note.pinned { border-color: #e2c983; box-shadow: 0 1px 3px rgba(154, 91, 0, 0.08); }

.note-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 6px; }
.note-author { font-weight: 650; font-size: 13px; color: #7a4800; }
.note-when { font-size: 12px; color: #8a6420; }
.note-actions { margin-left: auto; display: flex; gap: 2px; }
.note-actions .btn.subtle { color: #7a4800; padding: 2px 8px; }
.note-actions .btn.subtle:hover { background: #f6ead0; color: #5c3600; }
.note-body { font-size: 13.5px; color: #4f3c14; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; line-height: 1.55; }

.pin-tag {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
    color: #7a4800; background: #f6ead0;
    padding: 2px 8px; border-radius: var(--radius-pill);
}
.pin-tag svg { width: 11px; height: 11px; }

/* @mentions */
.mention {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 650;
    border-radius: 6px;
    padding: 0 4px;
}
.mention-menu {
    /* Overlays the textarea below its first line (the card clips anything
       outside itself, so the menu must open inward, Slack-style). */
    position: absolute;
    left: 10px;
    top: 40px;
    z-index: 40;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    min-width: 220px;
    max-height: 200px;
    overflow-y: auto;
}
.mention-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 10px;
    border-radius: 7px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}
.mention-item:hover, .mention-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.mention-dot {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--ink-900);
    color: #fff; display: grid; place-items: center;
    font-size: 11px; font-weight: 700; flex: none;
}

/* ---------- Follow-ups ---------- */

.fu-list { display: flex; flex-direction: column; }
.fu-row {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    transition: background 0.15s;
}
.fu-row:first-child { border-top: none; }
.fu-row:hover { background: var(--paper-50); }
.fu-row.overdue { background: #fffaf9; }
.fu-main { flex: 1; min-width: 0; }
.fu-desc { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.fu-meta { font-size: 12.5px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fu-meta a { color: var(--text-dim); font-weight: 600; }
.fu-meta a:hover { color: var(--accent-strong); }
.fu-meta .dot { color: var(--border-strong); }
.fu-due { text-align: right; flex: none; }
.fu-label { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; font-style: italic; }
.fu-actions { display: flex; gap: 6px; flex: none; }

@media (max-width: 700px) {
    .fu-row { flex-wrap: wrap; }
    .fu-due { text-align: left; }
}

/* ---------- AI console ---------- */

details.ai-call { border-bottom: 1px solid var(--border); }
details.ai-call:last-of-type { border-bottom: none; }
details.ai-call summary {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 20px; cursor: pointer; list-style: none;
    transition: background 0.15s;
}
details.ai-call summary::-webkit-details-marker { display: none; }
details.ai-call summary:hover { background: var(--paper-50); }
details.ai-call .ai-purpose { font-weight: 650; font-size: 13px; font-family: var(--mono); }
details.ai-call .ai-meta { margin-left: auto; color: var(--text-faint); font-size: 12px; white-space: nowrap; }
details.ai-call .ai-io { padding: 4px 20px 16px; }
details.ai-call .ai-io pre {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 12px; font-family: var(--mono); font-size: 11.5px;
    white-space: pre-wrap; word-break: break-word; color: var(--text-dim);
    max-height: 420px; overflow: auto; margin: 4px 0 12px;
}

/* ---------- Setup checks ---------- */

.check { display: flex; gap: 13px; align-items: flex-start; }
.check .icon { font-size: 17px; line-height: 1.4; }
.check h3 { margin: 0 0 2px; font-size: 14px; font-weight: 650; }
.check p { margin: 0; color: var(--text-dim); font-size: 13px; }
.check .hint-text { color: var(--text-faint); font-size: 12.5px; margin-top: 4px; }

details.steps { margin-top: 10px; }
details.steps summary { cursor: pointer; color: var(--accent-strong); font-weight: 600; font-size: 12.5px; }
details.steps ol { margin: 8px 0 0; padding-left: 20px; color: var(--text-dim); font-size: 13px; }
details.steps li { margin-bottom: 6px; }

details.context-block summary { cursor: pointer; color: var(--text-dim); font-weight: 600; font-size: 12.5px; }
details.context-block pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    font-family: var(--mono);
    font-size: 11.5px;
    white-space: pre-wrap;
    color: var(--text-dim);
    max-height: 360px;
    overflow: auto;
}

/* Generic step list - numbered circles; a jade tick when done.
   <ol class="steplist"><li class="done"><b>Title</b><span>detail</span></li></ol> */
.steplist { list-style: none; margin: 0; padding: 0; counter-reset: step; display: flex; flex-direction: column; gap: 2px; }
.steplist > li {
    counter-increment: step;
    position: relative;
    padding: 12px 14px 12px 52px;
    border-radius: var(--radius);
}
.steplist > li::before {
    content: counter(step);
    position: absolute; left: 14px; top: 12px;
    width: 26px; height: 26px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 650;
    background: var(--paper-150); color: var(--ink-700);
    border: 1px solid var(--border);
}
.steplist > li.done::before {
    content: "";
    background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5 10 17l9-10'/%3E%3C/svg%3E") no-repeat center / 14px;
    border-color: var(--accent);
}
.steplist > li.current { background: var(--surface); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.steplist > li.current::before { background: var(--ink-900); color: #fff; border-color: var(--ink-900); }
.steplist > li b { display: block; font-weight: 650; font-size: 14px; }
.steplist > li span { display: block; color: var(--text-dim); font-size: 13px; margin-top: 2px; }

/* Progress bar: <div class="progress"><span style="width:40%"></span></div> */
.progress { height: 6px; border-radius: 99px; background: var(--paper-200); overflow: hidden; }
.progress > span, .progress > i { display: block; height: 100%; border-radius: 99px; background: var(--accent-dot); transition: width 0.4s var(--ease); }

/* ---------- Auth pages (sign in, two-factor, invites) ---------- */

.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(400px, 5fr) 7fr;
    background: var(--bg);
}

.auth-aside {
    position: relative;
    overflow: hidden;
    background: var(--ink-900);
    color: var(--paper-100);
    padding: 40px 48px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
    isolation: isolate;
}
.auth-aside::before {
    content: "";
    position: absolute;
    right: -160px; bottom: -200px;
    width: 560px; height: 560px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(52, 192, 143, 0.2), rgba(52, 192, 143, 0) 65%);
    z-index: -1;
}
.auth-aside::after {
    /* faint ruled lines, like good writing paper */
    content: "";
    position: absolute; inset: 0;
    background-image: linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 100% 32px;
    -webkit-mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
    mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
    z-index: -1;
}
.auth-aside .wordmark { color: var(--paper-100); font-size: 26px; }
.auth-aside .wordmark i { color: var(--jade-400); }
.auth-quote {
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 100, "WONK" 0;
    font-weight: 460;
    font-size: clamp(32px, 3.3vw, 44px);
    line-height: 1.1;
    letter-spacing: -0.025em;
    margin: 0;
    max-width: 12ch;
}
.auth-quote em { font-style: italic; color: var(--jade-300); }
.auth-quote .dot { color: var(--jade-400); }
.auth-points { list-style: none; margin: 24px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; color: rgba(246, 244, 239, 0.78); font-size: 14px; }
.auth-points li { display: flex; gap: 10px; align-items: baseline; }
.auth-points li::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--jade-400); transform: translateY(-2px); }

/* A small, quiet product glimpse on the dark side */
.auth-glimpse {
    background: rgba(255, 255, 255, 0.055);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    max-width: 400px;
    font-size: 13px;
    color: rgba(246, 244, 239, 0.86);
}
.auth-glimpse .g-head { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: rgba(246, 244, 239, 0.6); margin-bottom: 8px; }
.auth-glimpse .g-head b { color: var(--paper-100); font-weight: 600; }
.auth-glimpse .g-state { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: var(--jade-300); font-weight: 600; }
.auth-glimpse .g-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--jade-400); }
.auth-glimpse p { margin: 0; line-height: 1.55; }
.auth-foot { font-size: 12px; color: rgba(246, 244, 239, 0.5); display: flex; gap: 16px; flex-wrap: wrap; }
.auth-foot a:hover { color: var(--paper-100); }

.auth-main { display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-company { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; min-width: 0; }
.auth-company img { max-height: 36px; max-width: 180px; object-fit: contain; }
.auth-company .brand-name { font-size: 15px; }
.auth-card h1 {
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 50, "WONK" 0;
    font-weight: 560;
    font-size: 32px;
    letter-spacing: -0.02em;
    line-height: 1.12;
    margin: 0 0 8px;
}
.auth-lead { color: var(--text-dim); font-size: 14.5px; margin: 0 0 28px; }
:is(.auth-card, .auth-solo-card) :is(input[type="text"], input[type="email"], input[type="password"]) { padding: 11px 14px; font-size: 15px; border-radius: 10px; }
:is(.auth-card, .auth-solo-card) .btn.primary { width: 100%; padding: 11px 16px; font-size: 14.5px; border-radius: 10px; margin-top: 4px; }
.auth-alt { margin-top: 24px; text-align: center; color: var(--text-faint); font-size: 13px; }
.auth-alt a, .auth-alt button { color: var(--accent-strong); font-weight: 600; }
.auth-alt button { background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
.auth-alt a:hover, .auth-alt button:hover { text-decoration: underline; text-underline-offset: 2px; }
.auth-error { display: flex; gap: 10px; align-items: flex-start; background: var(--red-soft); border: 1px solid var(--red-200); color: var(--red-700); border-radius: var(--radius-md); padding: 10px 14px; font-size: 13.5px; margin-bottom: 18px; }
.code-input { font-size: 24px !important; letter-spacing: 0.4em; text-align: center; font-family: var(--mono) !important; padding: 12px 14px !important; }
.auth-mobile-brand { display: none; }

@media (max-width: 900px) {
    .auth { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .auth-main { align-items: flex-start; padding: 28px 20px 48px; }
    .auth-mobile-brand { display: flex; justify-content: center; margin: 8px 0 36px; }
    .auth-mobile-brand .wordmark { font-size: 26px; }
}

.auth-note { margin: 18px 0 0; font-size: 13px; color: var(--text-faint); text-align: center; }
.auth-note + .auth-alt { margin-top: 8px; }

/* ----- Company-branded sign-in (company's own address) ----- */
/* The company's colour drives the button, links and focus; Sorted. only
   appears as a small "Powered by" at the foot. */
.auth-co .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-on); box-shadow: 0 1px 2px rgba(19, 32, 27, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.14); }
.auth-co .btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.auth-co h1 { font-family: var(--font); font-variation-settings: normal; font-weight: 700; font-size: 28px; letter-spacing: -0.025em; line-height: 1.2; margin: 0 0 8px; }
.auth-co .auth-lead { margin-bottom: 26px; }
.auth-message { white-space: pre-line; }
.auth-co .auth-alt a, .auth-co .auth-alt button { color: var(--brand-text); }

.auth-co-mark { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; min-width: 0; }
.co-logo { display: block; max-height: 48px; max-width: 220px; width: auto; object-fit: contain; object-position: left center; }
.co-badge-lg {
    width: 44px; height: 44px; flex: none; border-radius: 12px;
    display: grid; place-items: center;
    background: var(--brand); color: var(--brand-on);
    font-weight: 700; font-size: 15px; letter-spacing: 0.02em;
    box-shadow: 0 6px 16px -6px rgba(var(--brand-rgb), 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.co-name { font-weight: 650; font-size: 17px; letter-spacing: -0.01em; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.co-name.light { color: #fff; text-shadow: 0 1px 12px rgba(0, 0, 0, 0.35); }

.auth-powered { margin-top: 32px; display: flex; justify-content: center; }
.powered-by { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--text-faint); padding: 6px 10px; border-radius: 99px; transition: background 0.15s, color 0.15s; }
.powered-by img { height: 14px; width: auto; display: block; }
.powered-by:hover { background: rgba(19, 32, 27, 0.05); color: var(--text-dim); }

/* No photo: a centred card on a soft wash of the company's colour. */
.auth-solo {
    min-height: 100vh;
    display: flex;
    background:
        radial-gradient(900px 420px at 50% -120px, rgba(var(--brand-rgb), 0.16), transparent 70%),
        radial-gradient(600px 300px at 100% 100%, rgba(var(--brand-rgb), 0.06), transparent 70%),
        var(--bg);
    border-top: 4px solid var(--brand);
}
.auth-solo-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 20px 32px; }
.auth-solo-card {
    width: 100%; max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 40px 36px;
    box-shadow: var(--shadow-lg);
}
.auth-solo-card .auth-co-mark { justify-content: center; flex-direction: column; text-align: center; gap: 12px; }
.auth-solo-card .co-logo { object-position: center; max-width: 240px; }
.auth-solo-card h1, .auth-solo-card .auth-lead { text-align: center; }
@media (max-width: 520px) {
    .auth-solo-main { justify-content: flex-start; padding-top: 28px; }
    .auth-solo-card { padding: 28px 22px 26px; border-radius: 16px; }
}

/* With a photo: the company's picture fills one side. */
.auth.has-photo { grid-template-columns: 7fr minmax(420px, 5fr); }
.auth-photo {
    position: relative;
    background-color: var(--brand-dark);
    background-size: cover;
    background-position: center;
    min-height: 100vh;
    isolation: isolate;
}
.auth-photo::after {
    content: "";
    position: absolute; inset: 0; z-index: -1;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.32) 0%, rgba(0, 0, 0, 0) 28%, rgba(0, 0, 0, 0) 62%, rgba(var(--brand-rgb), 0.45) 100%);
    pointer-events: none;
}
.auth-photo-brand { position: absolute; top: 32px; left: 36px; display: flex; align-items: center; gap: 12px; z-index: 1; }
.co-logo-chip { display: inline-flex; align-items: center; background: rgba(255, 255, 255, 0.94); border-radius: 14px; padding: 10px 14px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.35); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.co-logo-chip img { display: block; max-height: 34px; max-width: 200px; object-fit: contain; }
.auth.has-photo .auth-main { background: var(--surface); border-top: 4px solid var(--brand); }
.auth.has-photo .auth-card .auth-powered { justify-content: flex-start; margin-left: -10px; }
.mobile-only { display: none; }
@media (max-width: 900px) {
    .auth.has-photo { grid-template-columns: 1fr; grid-template-rows: 200px auto; }
    .auth-photo { display: block; min-height: 200px; }
    .auth-photo-brand { display: none; }
    .auth.has-photo .auth-main { border-top: 0; padding-top: 28px; }
    .mobile-only { display: flex; }
}

/* Older single-card markup still works */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-card { width: 400px; max-width: 100%; }
.login-card.card { border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.login-card .card-body { padding: 32px; }
.login-card h1 { font-family: var(--font-display); font-variation-settings: "SOFT" 50, "WONK" 0; font-weight: 560; font-size: 24px; letter-spacing: -0.02em; margin: 16px 0 20px; }

/* ---------- Mobile app nav ---------- */

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255, 255, 255, 0.94);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 40;
    justify-content: space-around;
    box-shadow: 0 -2px 16px rgba(19, 32, 27, 0.06);
}

.mobile-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 9.5px;
    font-weight: 600;
    color: var(--text-faint);
    padding: 5px 4px;
    border-radius: 10px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
}

.mobile-nav a svg { width: 20px; height: 20px; }
.mobile-nav a.active { color: var(--text); }

/* ---------- Mobile app (PWA) ---------- */

.mobile-topbar { display: none; }
.ticket-cards { display: none; }

/* ---------- Motion ---------- */

/* Cross-page transitions: pages crossfade into each other instead of
   flashing white (modern browsers; older ones just navigate normally). */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation-duration: 0.1s; }
::view-transition-new(root) { animation-duration: 0.18s; }

html { scroll-behavior: smooth; }

@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: no-preference) {
    /* Content rises in with a gentle stagger on every page */
    .main > * { animation: rise-in 0.34s var(--ease) both; }
    .main > *:nth-child(2) { animation-delay: 0.04s; }
    .main > *:nth-child(3) { animation-delay: 0.08s; }
    .main > *:nth-child(4) { animation-delay: 0.12s; }
    .main > *:nth-child(5) { animation-delay: 0.16s; }
    .main > *:nth-child(6) { animation-delay: 0.2s; }
    .main > *:nth-child(n+7) { animation-delay: 0.24s; }

    /* Conversation bubbles cascade in */
    .thread .msg { animation: rise-in 0.3s ease both; }
    .thread .msg:nth-child(2) { animation-delay: 0.05s; }
    .thread .msg:nth-child(3) { animation-delay: 0.1s; }
    .thread .msg:nth-child(4) { animation-delay: 0.15s; }
    .thread .msg:nth-child(n+5) { animation-delay: 0.2s; }

    /* Interactive stat cards lift */
    a.stat { transition: transform 0.18s var(--ease), box-shadow 0.18s, border-color 0.18s; }
    a.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

    /* The active nav item gets a jade marker that draws in */
    @keyframes bar-in { from { transform: translateY(-50%) scaleY(0); } }
    .nav-item.active::before {
        content: "";
        position: absolute;
        left: -12px;
        top: 50%;
        transform: translateY(-50%);
        width: 3px;
        height: 18px;
        border-radius: 0 99px 99px 0;
        background: var(--accent-dot);
        animation: bar-in 0.28s var(--spring);
    }

    /* Buttons: primary lifts, everything presses down */
    .btn.primary:hover, .btn.accent:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
    .btn:active { transform: translateY(1px) scale(0.99); }

    /* Count badges pop when a page lands */
    @keyframes pop-in { from { transform: scale(0.5); opacity: 0; } }
    .nav-item .count, .page-head .pill { animation: pop-in 0.3s var(--spring) 0.15s both; }

    /* Floating menus spring open */
    @keyframes menu-in { from { opacity: 0; transform: scale(0.94) translateY(-6px); } }
    form.assign-pop { animation: menu-in 0.22s var(--spring); transform-origin: top left; }
    .mention-menu { animation: menu-in 0.18s var(--spring); transform-origin: top left; }
    .tk-menu-pop { animation: menu-in 0.2s var(--spring); transform-origin: top right; }

    .chip:active { transform: scale(0.96); }

    /* Notes settle in */
    .notes-list .note { animation: rise-in 0.3s ease both; }

    /* Pinned-note pin wiggles once on load */
    @keyframes pin-wiggle { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-14deg); } 60% { transform: rotate(10deg); } }
    .pin-tag svg { animation: pin-wiggle 0.5s ease 0.4s; }

    /* The full stop in empty states breathes, gently */
    @keyframes dot-breathe { 0%, 100% { box-shadow: 0 0 0 8px var(--accent-soft); } 50% { box-shadow: 0 0 0 12px var(--accent-soft); } }
    .empty .big:empty::before { animation: dot-breathe 3.2s ease-in-out infinite; }

    .sendbar { animation: rise-in 0.3s var(--ease); }
}

@media (max-width: 1000px) {
    html { -webkit-text-size-adjust: 100%; }
    body { -webkit-tap-highlight-color: transparent; }
    a, button, input, select, textarea, label { touch-action: manipulation; }

    .sidebar { display: none; }
    .mobile-nav { display: flex; }
    .two-col, .two-col.even, .two-col[style] { grid-template-columns: minmax(0, 1fr) !important; }

    /* App bar: sticky, blurred, safe-area aware */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 35;
        background: rgba(246, 244, 239, 0.88);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        border-bottom: 1px solid var(--border);
        padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    }
    .mobile-topbar .brand-badge { width: 28px; height: 28px; border-radius: 8px; font-size: 11px; }
    .mobile-topbar .topbar-logo { height: 24px; max-width: 120px; object-fit: contain; }
    .mobile-topbar .dot { width: 24px; height: 24px; border-radius: 7px; flex: none; background: var(--ink-900); }
    .mobile-topbar .title {
        font-weight: 650; font-size: 15.5px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }

    .main { padding: 18px 16px calc(90px + env(safe-area-inset-bottom)); }

    /* The app bar already shows the title; the page head shrinks to
       description + actions */
    .page-head { margin-bottom: 16px; align-items: flex-start; }
    .page-head h1 { font-size: 24px; }
    .page-head .actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
    .page-head .actions .btn, .page-head .actions form { flex: 1; }
    .page-head .actions form .btn { width: 100%; }

    /* Finger-sized controls; 16px inputs stop iOS zooming the page on focus */
    .btn { min-height: 42px; padding: 9px 15px; font-size: 14px; justify-content: center; }
    .btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
    input, select, textarea { font-size: 16px !important; }
    input:not([type="checkbox"]):not([type="radio"]), select { min-height: 42px; }

    .card { border-radius: 14px; }

    /* Filter chips: one scrolling row, like app segments */
    .filters { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 0 -16px 12px; padding: 2px 16px; }
    .filters::-webkit-scrollbar { display: none; }
    .chip { flex: none; padding: 8px 14px; font-size: 13px; }
    .search { margin-left: 0; flex: none; width: 200px; }
    .search input { min-height: 38px; }

    /* Tickets list: tap cards, not a table */
    .ticket-list-card table.list { display: none; }
    .ticket-cards { display: block; }
    #bulk-bar { display: none !important; }

    /* Any other wide table scrolls inside its card instead of breaking the page */
    .card:has(> table.list) { overflow-x: auto; }
    table.list th, table.list td { padding: 11px 12px; }
    table.list td { white-space: nowrap; }

    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat .value { font-size: 26px; }

    .form-grid, .card .form-grid { grid-template-columns: 1fr !important; gap: 10px !important; }

    /* Ticket detail */
    .ticket-title { font-size: 21px; }
    .meta-grid { grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 14px 16px; }
    .ticket-toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: transparent; border: none; padding: 0; }
    .ticket-toolbar .btn { width: 100%; padding: 9px 6px; font-size: 12.5px; background: var(--surface); border: 1px solid var(--border); }
    .ticket-toolbar > form:last-of-type { margin-left: 0; }
    form.assign-pop { left: 50%; transform: translateX(-50%); width: min(280px, calc(100vw - 36px)); }
    .msg .avatar { width: 26px; height: 26px; font-size: 11px; }
    .composer textarea { font-size: 16px; }
    .composer .bar { flex-wrap: wrap; gap: 8px; }
    .composer .bar .right { width: 100%; }
    .composer .bar .right .btn { flex: 1; }
    .msg-attachments img { max-height: 100px; max-width: 140px; }

    /* Follow-ups rows stack cleanly with full-width actions */
    .fu-row { flex-wrap: wrap; gap: 8px 14px; }
    .fu-due { text-align: left; }
    .fu-actions { width: 100%; }
    .fu-actions form { flex: 1; }
    .fu-actions .btn { width: 100%; }

    .pagination { justify-content: space-between; }

    /* Toast sits above the tab bar */
    .toast { left: 16px; right: 16px; transform: none; max-width: none; bottom: calc(88px + env(safe-area-inset-bottom)); animation: toast-in-m 0.3s var(--spring), toast-out-m 0.4s ease 4.6s forwards; }
    @keyframes toast-in-m { from { opacity: 0; transform: translateY(10px); } }
    @keyframes toast-out-m { to { opacity: 0; transform: translateY(8px); visibility: hidden; } }

    /* Bottom tab bar: bigger targets */
    .mobile-nav { padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); }
    .mobile-nav a { gap: 4px; padding: 6px 2px; border-radius: 12px; }
    .mobile-nav a svg { width: 22px; height: 22px; }
    .mobile-nav a.active, .mn-tile.active { font-weight: 700; }
    .mobile-nav a:active { transform: scale(0.94); transition: transform 0.08s; }

    .op-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .op-modal { width: 100%; max-height: 88dvh; }
}

/* Ticket cards (mobile list) */
.tcard { display: block; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.tcard:last-child { border-bottom: none; }
.tcard:active { background: var(--paper-150); }
.tcard .t-top { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.tcard .t-subject { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.tcard .t-time { color: var(--text-faint); font-size: 12px; flex: none; margin-top: 2px; }
.tcard .t-sub { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; }
.tcard .t-meta { display: flex; gap: 7px; margin-top: 9px; align-items: center; flex-wrap: wrap; }

/* ---------- Pick list (mobile warehouse mode) ---------- */

.pick-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 10px 2px; background: var(--bg); }
.pick-back { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); color: var(--text); flex: none; }
.pick-back svg { width: 20px; height: 20px; }
.pick-bar-mid { display: flex; flex-direction: column; min-width: 0; }
.pick-bar-mid strong { font-size: 16px; }
.pick-bar-mid span { color: var(--text-dim); font-size: 12.5px; }
.pick-count { margin-left: auto; font-size: 12.5px; font-weight: 650; color: var(--accent-strong); white-space: nowrap; }
.pick-progress { height: 6px; border-radius: 99px; background: var(--paper-200); overflow: hidden; margin: 0 2px 14px; }
.pick-progress-fill { height: 100%; border-radius: 99px; background: var(--accent-dot); width: 0; transition: width 0.35s var(--ease); }
.pick-list { display: flex; flex-direction: column; gap: 12px; padding-bottom: 96px; }
.pick-order { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.pick-order.is-chased { border-color: var(--red-200); }
.pick-order.is-done { opacity: 0.55; }
.pick-order-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.pick-order-head strong { font-size: 14.5px; }
.pick-cust { display: block; color: var(--text-dim); font-size: 12.5px; margin-top: 1px; }
.pick-order-pills { display: flex; gap: 6px; flex: none; }
.pick-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text); text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 0.15s; font: inherit; }
.pick-item:last-child { border-bottom: 0; }
.pick-item:active { background: var(--paper-150); }
.pick-item img, .pick-noimg { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; background: var(--paper-150); flex: none; }
.pick-noimg { display: grid; place-items: center; color: var(--text-ghost); }
.pick-noimg svg { width: 22px; height: 22px; }
.pick-item-mid { min-width: 0; flex: 1; }
.pick-item-name { display: block; font-size: 13.5px; font-weight: 550; line-height: 1.3; }
.pick-item-sku { display: block; color: var(--text-faint); font-size: 11.5px; margin-top: 2px; font-family: var(--mono); }
.pick-tick { display: grid; place-items: center; min-width: 46px; height: 46px; border-radius: 12px; border: 2px solid var(--border); font-weight: 700; font-size: 13px; color: var(--text-dim); flex: none; padding: 0 6px; transition: all 0.2s; }
.pick-item.is-picked .pick-tick { background: var(--accent); border-color: var(--accent); color: #fff; }
.pick-item.is-picked .pick-tick svg { width: 22px; height: 22px; }
.pick-item.is-picked .pick-item-name { text-decoration: line-through; opacity: 0.6; }
.pick-fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 40; display: flex; align-items: center; gap: 9px; padding: 15px 22px; border: 0; border-radius: 99px; background: var(--ink-900); color: #fff; font-size: 15px; font-weight: 650; box-shadow: 0 10px 28px rgba(19, 32, 27, 0.35); cursor: pointer; transition: transform 0.15s; font-family: inherit; }
.pick-fab:active { transform: scale(0.94); }
.pick-fab svg { width: 21px; height: 21px; }
.scan-overlay { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; }
.scan-lock { overflow: hidden; }
#scan-video { position: absolute; inset: 0; }
#scan-video video { width: 100%; height: 100%; object-fit: cover; }
.scan-top { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(14px + env(safe-area-inset-top)) 16px 14px; color: #fff; font-weight: 650; background: linear-gradient(rgba(0, 0, 0, 0.55), transparent); }
.scan-close, .scan-torch { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; border: 0; background: rgba(255, 255, 255, 0.16); color: #fff; backdrop-filter: blur(6px); cursor: pointer; }
.scan-close svg, .scan-torch svg { width: 21px; height: 21px; }
.scan-torch.is-on { background: var(--accent); }
.scan-frame { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(85vw, 420px); height: min(40vh, 220px); border: 2.5px solid rgba(255, 255, 255, 0.9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35); pointer-events: none; z-index: 1; }
.scan-toast { position: absolute; left: 16px; right: 16px; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 3; padding: 15px 18px; border-radius: 15px; font-weight: 650; font-size: 14.5px; color: #fff; text-align: center; animation: rise-in 0.25s var(--ease); }
.scan-toast.is-ok { background: var(--accent); }
.scan-toast.is-bad { background: var(--red); }
.scan-hint { position: absolute; left: 50%; transform: translateX(-50%); top: calc(50% + min(20vh, 110px) + 16px); z-index: 2; padding: 7px 14px; border-radius: 99px; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 12.5px; font-weight: 600; white-space: nowrap; backdrop-filter: blur(4px); }
@media (min-width: 800px) { .pick-list { max-width: 560px; } }
@media (max-width: 1000px) {
    /* Sit below the sticky app bar; clear the bottom tab bar. */
    .pick-bar { top: calc(49px + env(safe-area-inset-top)); }
    .pick-fab { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ---------- Mobile nav: 5 roomy tabs + More sheet ---------- */

.mobile-nav a, .mobile-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1; padding: 6px 2px 4px; border: 0; background: none; color: var(--text-faint); font-size: 10.5px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; font-family: inherit; }
.mobile-nav a.active, .mobile-nav button.active { color: var(--text); }
.mobile-nav a.active .mn-icon::after, .mobile-nav button.active .mn-icon::after {
    content: "";
    position: absolute; bottom: -6px; left: 50%;
    width: 4px; height: 4px; margin-left: -2px; border-radius: 50%;
    background: var(--accent-dot);
}
.mn-icon { position: relative; display: grid; place-items: center; width: 26px; height: 24px; }
.mn-icon svg { width: 22px; height: 22px; }
.mn-badge { position: absolute; top: -4px; right: -7px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.mn-sheet-backdrop { position: fixed; inset: 0; z-index: 45; background: rgba(11, 19, 16, 0.4); animation: fade-in 0.2s ease; }
.mn-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 46; background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 14px calc(76px + env(safe-area-inset-bottom)); box-shadow: 0 -12px 40px rgba(19, 32, 27, 0.18); animation: sheet-up 0.28s var(--ease); max-height: 84vh; overflow-y: auto; }
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.mn-sheet-grab { width: 40px; height: 4px; border-radius: 99px; background: var(--paper-300); margin: 2px auto 12px; }
.mn-sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.mn-tile-form { display: contents; }
.mn-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px 10px; border: 0; border-radius: 14px; background: none; color: var(--text-dim); font-size: 11px; font-weight: 600; text-align: center; cursor: pointer; -webkit-tap-highlight-color: transparent; width: 100%; font-family: inherit; }
.mn-tile:active { background: var(--paper-150); }
.mn-tile.active { color: var(--accent-strong); background: var(--accent-soft); }
.mn-tile.is-urgent { color: var(--red); }
.mn-tile-icon { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; background: var(--paper-150); }
.mn-tile.active .mn-tile-icon { background: var(--jade-100); }
.mn-tile-icon svg { width: 22px; height: 22px; }
.mn-sheet-open { overflow: hidden; }
.mn-sheet-foot { display: flex; justify-content: center; padding: 18px 0 0; }
.mn-sheet-foot .wordmark { font-size: 15px; color: var(--ink-500); }

/* The hidden attribute loses to any display rule above - make it absolute. */
.scan-overlay[hidden], .scan-torch[hidden], .scan-toast[hidden], .scan-hint[hidden],
.mn-sheet[hidden], .mn-sheet-backdrop[hidden] { display: none !important; }

/* ---------- Send delay: countdown + undo ---------- */

.sendbar {
    display: flex; align-items: center; gap: 14px;
    margin-top: 18px; padding: 14px 16px;
    background: linear-gradient(135deg, var(--accent-soft), var(--surface));
    border: 1px solid var(--jade-200); border-left: 3px solid var(--accent-dot);
    border-radius: var(--radius-lg);
}
.sendbar-ring { width: 42px; height: 42px; flex: none; transform: rotate(-90deg); }
.sendbar-ring .ring-bg { fill: none; stroke: var(--jade-100); stroke-width: 3.5; }
.sendbar-ring .ring-fg { fill: none; stroke: var(--accent-dot); stroke-width: 3.5; stroke-linecap: round; }
.sendbar-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sendbar-text strong { font-size: 14px; }
.sendbar-text span { font-size: 12.5px; color: var(--text-dim); }
.sendbar-text b { font-variant-numeric: tabular-nums; color: var(--accent-strong); }
.sendbar form { flex: none; }
.sendbar.is-going { border-color: var(--border); border-left-color: var(--text-ghost); background: var(--card); }
.sendbar.is-going .ring-fg { stroke: var(--text-ghost); }
.sendbar.is-going form { display: none; }
/* Composer is read-only while a send is counting down. */
.composer.is-locked { opacity: 0.45; pointer-events: none; filter: grayscale(0.3); }
@media (max-width: 700px) {
    .sendbar { gap: 11px; padding: 12px 13px; }
    .sendbar-ring { width: 36px; height: 36px; }
}

/* ---------- Quick answers (dashboard) ---------- */

.qa-row { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.qa-row:last-child { border-bottom: 0; }
.qa-top { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.qa-form { display: flex; gap: 8px; }
.qa-form input { flex: 1; font-size: 13px; padding: 8px 12px; }
.qa-form .btn { flex: none; white-space: nowrap; }
@media (max-width: 700px) {
    .qa-form { flex-direction: column; }
    .qa-form .btn { width: 100%; }
}

/* ---------- Email-style composer header (To / Cc / Bcc) ---------- */

.mailhead { border-bottom: 1px solid var(--border); padding: 4px 14px; }
.mh-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--paper-150); }
.mh-row:last-child { border-bottom: 0; }
.mh-label { flex: none; width: 30px; font-size: 12px; font-weight: 600; color: var(--text-faint); }
.mh-to { font-size: 13px; color: var(--text); }
.mh-row input { flex: 1; border: 0; outline: none; font: inherit; font-size: 13px; padding: 2px 0; background: transparent; box-shadow: none; min-height: 0; }
.mh-row input:focus { box-shadow: none; }
.mh-row input::placeholder { color: var(--text-ghost); }
.mh-toggle { margin-left: auto; border: 0; background: none; color: var(--text-faint); font-size: 12px; font-weight: 600; cursor: pointer; padding: 2px 6px; font-family: inherit; }
.mh-toggle:hover { color: var(--text); }

/* Non-image attachments in the thread */
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); font-size: 12.5px; font-weight: 600; }
.file-chip svg { width: 15px; height: 15px; color: var(--text-faint); }
.file-chip:hover { border-color: var(--accent); color: var(--accent-strong); }

/* ---------- Ticket page ---------- */

/* Header: back arrow, title + fact chips, action cluster. */
.tk-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 20px;
    /* Must stack above the thread: message cards animate in, which gives
       them their own stacking contexts that were painting over the
       overflow/escalate popovers. */
    position: relative;
    z-index: 60;
}

.tk-back {
    flex: none;
    width: 34px; height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-dim);
    box-shadow: var(--shadow-xs);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    margin-top: 2px;
}
.tk-back svg { width: 16px; height: 16px; }
.tk-back:hover { background: var(--paper-50); color: var(--text); border-color: var(--border-strong); }

.tk-heading { flex: 1; min-width: 0; }

.tk-ref {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.tk-ref-sep { color: var(--border-strong); }
.tk-order-link { color: var(--accent-strong); }
.tk-order-link:hover { text-decoration: underline; }

.tk-title {
    margin: 4px 0 12px;
    font-family: var(--font-display);
    font-variation-settings: "SOFT" 50, "WONK" 0;
    font-size: 22px;
    font-weight: 560;
    letter-spacing: -0.015em;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.tk-facts { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tk-fact {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 3px 11px 3px 4px;
    max-width: 100%;
    min-width: 0;
}
.tk-fact.faint { padding: 3px 11px; font-weight: 500; color: var(--text-faint); }

.tk-fact-avatar {
    flex: none;
    width: 20px; height: 20px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 10.5px;
    font-weight: 700;
    color: #fff;
    background: var(--ink-800);
}
.tk-fact-avatar.alt { background: var(--accent); }

.tk-actions { flex: none; display: flex; align-items: center; gap: 8px; margin-top: 2px; }

.tk-icon-btn { padding: 7px 9px; }
.tk-icon-btn svg { width: 17px; height: 17px; }

/* Overflow menu: secondary + destructive actions live behind the dots. */
.tk-menu { position: relative; }
.tk-menu > summary { list-style: none; }
.tk-menu > summary::-webkit-details-marker { display: none; }
.tk-menu[open] > summary { background: var(--paper-50); }

.tk-menu-pop {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 40;
    width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}
.tk-menu-pop form { margin: 0; }

.tk-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 0;
    background: none;
    font: inherit;
    font-size: 13px;
    font-weight: 550;
    color: var(--text);
    text-align: left;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s;
}
.tk-menu-item svg { width: 15px; height: 15px; flex: none; color: var(--text-dim); }
.tk-menu-item:hover { background: var(--paper-150); }
.tk-menu-item.danger { color: var(--red); }
.tk-menu-item.danger svg { color: var(--red); }
.tk-menu-item.danger:hover { background: var(--red-soft); }

.tk-menu-sep { height: 1px; background: var(--border); margin: 5px 8px; }

/* The escalate popover opens from the right edge up here. */
.tk-actions .assign-drop form.assign-pop { left: auto; right: 0; }

/* Body: conversation + sidebar. */
.two-col.tk-body { grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; }

/* Conversation bubbles, softened. */
.tk-body .thread { gap: 16px; }
.tk-body .avatar { width: 32px; height: 32px; font-size: 12px; box-shadow: var(--shadow-xs); }
.tk-body .msg.outbound .avatar { background: var(--ink-900); color: #fff; }
.tk-body .msg-card { border-radius: var(--radius-lg); }
.tk-body .msg.inbound .msg-card { border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg); }
.tk-body .msg.outbound .msg-card { border-radius: var(--radius-lg) 4px var(--radius-lg) var(--radius-lg); background: #f4faf7; }
.tk-body .msg-head { border-bottom: 0; padding: 12px 16px 0; }
.tk-body .msg-body { padding: 8px 16px 14px; }
.tk-body .msg-attachments { padding: 0 16px 14px; margin-top: 0; }
.tk-body .msg-card > form { padding: 0 16px 12px; margin-top: 0 !important; }

/* Composer: one card with its own header. */
.tk-reply { margin-top: 20px; }
.tk-body .composer { border-radius: var(--radius-lg); }
.tk-body .composer:focus-within { border-color: var(--border-strong); box-shadow: var(--shadow-md); }

.composer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.composer-head .ch-title { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 650; }
.composer-head .ch-title svg { width: 15px; height: 15px; color: var(--accent); }

.conf-chip {
    margin-left: auto;
    font-size: 11.5px;
    font-weight: 650;
    border-radius: var(--radius-pill);
    padding: 2px 10px;
}
.conf-chip.good { background: var(--accent-soft); color: var(--accent-strong); }
.conf-chip.mid { background: var(--amber-soft); color: var(--amber); }
.conf-chip.low { background: var(--red-soft); color: var(--red); }

.tk-body .mailhead { padding: 4px 16px; background: var(--surface); }
.tk-body .composer textarea { border-radius: 0; min-height: 170px; }

/* Sidebar: consistent rounded cards, collapsible secondary ones. */
.side-col .card, .ticket-side .card { margin-bottom: 14px; }
.tk-body > div:last-child .card { border-radius: var(--radius-lg); }
.tk-body > div:last-child .card + .card,
.tk-body > div:last-child script + .card,
.tk-body > div:last-child .card + script + .card { margin-top: 14px; }

details.tk-fold > summary.card-title { cursor: pointer; list-style: none; user-select: none; }
details.tk-fold > summary.card-title::-webkit-details-marker { display: none; }
details.tk-fold > summary.card-title::after {
    content: "";
    width: 7px; height: 7px;
    border-right: 1.8px solid var(--text-faint);
    border-bottom: 1.8px solid var(--text-faint);
    transform: rotate(45deg);
    transition: transform 0.15s;
    flex: none;
    margin-left: 2px;
    align-self: center;
}
details.tk-fold[open] > summary.card-title::after { transform: rotate(225deg); margin-top: 4px; }
details.tk-fold:not([open]) > summary.card-title { border-bottom: 0; }
details.tk-fold > summary.card-title:hover { background: var(--paper-50); }

.tk-body > div:first-child .card { border-radius: var(--radius-lg); }
.tk-body .sendbar { border-radius: var(--radius-lg); }

/* Long confidence-issue lists scroll instead of swallowing the sidebar. */
.tk-body .issues { max-height: 240px; overflow-y: auto; }

/* Composer toolbar labels stay on one line when the bar wraps. */
.tk-body .composer .bar > label { white-space: nowrap; }

@media (max-width: 1100px) {
    .two-col.tk-body { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 1000px) {
    .two-col.tk-body { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .tk-header { flex-wrap: wrap; padding: 14px; }
    .tk-heading { flex-basis: calc(100% - 48px); }
    .tk-actions { margin-left: 48px; margin-top: 6px; flex-wrap: wrap; }
    .tk-actions .assign-drop form.assign-pop { right: auto; left: 0; }
    .tk-title { font-size: 19px; }
}

/* ---------- Settings area (left sub-nav, one section at a time) ---------- */

.settings-wrap { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 28px; align-items: start; }

.set-nav { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 1px; }
.set-group {
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--text-faint); padding: 14px 10px 5px;
}
.set-group:first-child { padding-top: 2px; }
.set-item {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 500; color: var(--ink-700);
    transition: background 0.13s, color 0.13s;
}
.set-item svg { width: 17px; height: 17px; flex: none; color: var(--ink-500); }
.set-item:hover { background: rgba(19, 32, 27, 0.055); color: var(--text); }
.set-item.active {
    background: var(--surface);
    color: var(--text); font-weight: 600;
    box-shadow: var(--shadow), 0 0 0 1px rgba(19, 32, 27, 0.06);
}
.set-item.active svg { color: var(--accent); }

.set-content { min-width: 0; }
.set-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
.set-head h2 { margin: 0; font-family: var(--font-display); font-variation-settings: "SOFT" 50, "WONK" 0; font-size: 20px; font-weight: 560; letter-spacing: -0.015em; }
.set-head p { margin: 4px 0 0; color: var(--text-dim); font-size: 13.5px; max-width: 640px; }
.set-head .btn, .set-head a.btn { margin-left: auto; flex: none; }

@media (max-width: 1000px) {
    .settings-wrap { display: block; }
    .set-nav {
        position: static; flex-direction: row; overflow-x: auto; gap: 6px;
        margin: 0 -16px 16px; padding: 2px 16px 8px;
        -webkit-overflow-scrolling: touch; scrollbar-width: none;
    }
    .set-nav::-webkit-scrollbar { display: none; }
    .set-group { display: none; }
    .set-item { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 7px 14px; box-shadow: var(--shadow-xs); }
    .set-item.active { background: var(--ink-900); color: #fff; border-color: var(--ink-900); }
    .set-item.active svg { color: var(--jade-400); }
}

/* ---------- Wrong wires: one card per customer with their photos ---------- */

.ww-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.ww-grid .card + .card { margin-top: 0; }
.ww-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.ww-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ww-name { font-weight: 650; font-size: 14.5px; }
.ww-name:hover { color: var(--accent-strong); }
.ww-facts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-dim); }
.ww-label { color: var(--text-faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; margin-right: 2px; }
.ww-kit { font-size: 12.5px; font-weight: 600; color: var(--text); }
.ww-connector { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--blue); background: var(--blue-soft); border-radius: 8px; padding: 6px 10px; }
.ww-connector svg { width: 14px; height: 14px; flex: none; }
.ww-photos { grid-template-columns: repeat(4, 1fr); }
.ww-nophoto { font-size: 12.5px; color: var(--amber); background: var(--amber-soft); border-radius: 8px; padding: 10px 12px; }
.ww-address { font-size: 12.5px; color: var(--text-dim); }
.ww-address summary { cursor: pointer; font-weight: 600; color: var(--text-faint); }
.ww-address div { margin-top: 6px; line-height: 1.5; }
.ww-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 10px; border-top: 1px solid var(--border); }
@media (max-width: 700px) {
    .ww-grid { grid-template-columns: 1fr; }
    .ww-photos { grid-template-columns: repeat(3, 1fr); }
}
.ww-send { padding-top: 10px; border-top: 1px solid var(--border); }
.ww-send + .ww-actions { border-top: 0; padding-top: 0; }
.ww-ai { font-size: 12.5px; color: var(--text-dim); background: var(--paper-50); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; line-height: 1.45; }
.ww-ai strong { color: var(--text); font-weight: 650; }
.ww-ai.is-dead { background: var(--amber-soft); border-color: var(--amber-200); color: var(--amber); }
.ww-ai.is-dead strong { color: var(--amber); }
.ww-ai-when { color: var(--text-faint); font-size: 11.5px; margin-left: 4px; white-space: nowrap; }

/* ---------- Ask AI: the panel's chat assistant ---------- */

.ai-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.ai-wrap:not(:has(.ai-chats)) { grid-template-columns: 1fr; }
.ai-chats { display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 210px); overflow-y: auto; }
.ai-chats-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); padding: 0 10px 6px; }
.ai-chat-link { display: block; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.35; }
.ai-chat-link span { display: block; font-size: 11.5px; font-weight: 500; color: var(--text-faint); margin-top: 2px; }
.ai-chat-link:hover { background: rgba(19, 32, 27, 0.055); }
.ai-chat-link.active { background: var(--surface); box-shadow: var(--shadow), 0 0 0 1px rgba(19, 32, 27, 0.06); }
.ai-panel { display: flex; flex-direction: column; height: calc(100vh - 200px); min-height: 460px; }
.ai-thread { flex: 1; overflow-y: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.ai-empty { margin: auto; text-align: center; max-width: 560px; }
.ai-empty-title { font-family: var(--font-display); font-variation-settings: "SOFT" 50, "WONK" 0; font-size: 22px; font-weight: 560; letter-spacing: -0.015em; margin-bottom: 16px; }
.ai-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ai-suggestion { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; color: var(--text); cursor: pointer; box-shadow: var(--shadow-xs); transition: border-color 0.15s, background 0.15s; }
.ai-suggestion:hover { border-color: var(--jade-200); background: var(--accent-soft); }
#ai-messages { display: flex; flex-direction: column; gap: 14px; }
.ai-msg { display: flex; }
.ai-user { justify-content: flex-end; }
.ai-bubble { max-width: min(760px, 88%); padding: 11px 15px; border-radius: 16px; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.ai-user .ai-bubble { background: var(--ink-900); color: #fff; border-bottom-right-radius: 4px; }
.ai-assistant .ai-bubble { background: var(--paper-100); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.ai-assistant .ai-bubble p { margin: 0 0 8px; }
.ai-assistant .ai-bubble p:last-child, .ai-assistant .ai-bubble ul:last-child, .ai-assistant .ai-bubble ol:last-child { margin-bottom: 0; }
.ai-assistant .ai-bubble ul, .ai-assistant .ai-bubble ol { margin: 0 0 8px; padding-left: 20px; }
.ai-assistant .ai-bubble li { margin-bottom: 4px; }
.ai-assistant .ai-bubble a { color: var(--accent-strong); font-weight: 600; text-decoration: underline; text-decoration-color: var(--jade-200); text-underline-offset: 2px; }
.ai-assistant .ai-bubble code { font-family: var(--mono); font-size: 12.5px; background: var(--paper-200); padding: 1px 5px; border-radius: 4px; }
.ai-progress { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-dim); padding: 4px 2px; }
/* display:flex above would otherwise override the hidden attribute */
.ai-progress[hidden], .ai-empty[hidden] { display: none !important; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-dot); animation: ai-bounce 1.2s infinite ease-in-out; }
.ai-dots i:nth-child(2) { animation-delay: 0.15s; }
.ai-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.ai-composer { display: flex; gap: 8px; align-items: flex-end; padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.ai-composer textarea { flex: 1; resize: none; font-size: 14px; line-height: 1.5; padding: 10px 12px; max-height: 180px; }
.ai-composer .btn { flex: none; }
@media (max-width: 800px) {
    .ai-wrap { grid-template-columns: 1fr; }
    .ai-chats { flex-direction: row; overflow-x: auto; max-height: none; gap: 6px; }
    .ai-chats-title { display: none; }
    .ai-chat-link { flex: none; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid var(--border); background: var(--surface); }
    .ai-panel { height: calc(100vh - 230px); }
    .ai-thread { padding: 14px; }
}

/* ---------- Owner dashboard (the platform owner, above all companies) ---------- */

.owner-top {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 28px;
    padding: 14px 32px;
    background: var(--ink-900);
    color: var(--paper-100);
}
.owner-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--paper-100); }
.owner-brand .wordmark { font-size: 22px; color: var(--paper-100); }
.owner-brand .wordmark i { color: var(--jade-400); }
.owner-brand .tag {
    font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--jade-300); border: 1px solid rgba(108, 199, 166, 0.35); border-radius: 6px; padding: 1px 7px;
}
.owner-nav { display: flex; gap: 4px; }
.owner-nav a { padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 550; color: rgba(246, 244, 239, 0.7); }
.owner-nav a:hover { color: var(--paper-100); background: rgba(255, 255, 255, 0.06); }
.owner-nav a.active { color: var(--paper-100); background: rgba(255, 255, 255, 0.1); }
.owner-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: rgba(246, 244, 239, 0.6); }
.owner-right form { margin: 0; }
.owner-top .btn.subtle { color: rgba(246, 244, 239, 0.85); }
.owner-top .btn.subtle:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.owner-main { margin: 0 auto; max-width: 1240px; padding: 36px 32px 80px; }
.co-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.co-badge { width: 34px; height: 34px; flex: none; border-radius: 10px; background: var(--ink-900); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 650; overflow: hidden; }
.co-badge.has-logo { background: #fff; border: 1px solid var(--border); padding: 3px; }
.co-badge img { width: 100%; height: 100%; object-fit: contain; }
.num, table.list th.num, table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 800px) {
    .owner-top { padding: 12px 16px; gap: 12px; flex-wrap: wrap; }
    .owner-main { padding: 22px 16px 60px; }
    .owner-nav { order: 3; width: 100%; }
}

/* Owner "you're in X's panel" banner */
.owner-banner {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    padding: 8px 16px;
    background: var(--ink-900); color: var(--paper-100);
    font-size: 13px; font-weight: 550;
    position: sticky; top: 0; z-index: 60;
    flex-wrap: wrap;
    text-align: center;
}
.owner-banner::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--jade-400); box-shadow: 0 0 0 3px rgba(52, 192, 143, 0.2); }
.owner-banner form { margin: 0; }
.owner-banner button { background: var(--paper-100); color: var(--ink-900); border: 0; border-radius: 7px; padding: 4px 12px; font: inherit; font-size: 12.5px; font-weight: 650; cursor: pointer; }
.owner-banner button:hover { background: #fff; }

/* ---------- Small utilities ---------- */

.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Flow: nothing sits flush against its neighbour ---------- */
/* Default vertical rhythm on the 8px grid. Stacked blocks get --sp-4
   between them; small trailing controls (a Save button under a card, a
   button after a note or a disclosure) get --sp-3. Every rule here is
   wrapped in :where(), so it has zero specificity: it only fills gaps, and
   any component's own spacing (or an inline style) still wins. Vertical
   margins between blocks collapse, so larger explicit margins hold. */

/* A card's next neighbour - a Save button, a second form, a note, a grid. */
:where(.card) + :where(:not(.card, script, template, style, input[type="hidden"])) { margin-top: var(--sp-4); }
/* Blocks that end without a bottom margin, followed by a card. */
:where(.alert, .plan-grid, form, p, ul, ol, .welcome-steps, .filters, .stats, .callout, .row, table, details) + :where(.card) { margin-top: var(--sp-4); }

/* Inside a card body: stacked forms, and buttons after the thing above. */
:where(.card-body) > :where(form, .btn) + :where(form, .btn, p),
:where(.card-body) > :where(.form-grid, p) + :where(form) { margin-top: var(--sp-3); }
:where(form) > :where(.btn:only-child) { margin-top: 0; }

/* Things that end flush (no bottom margin) followed by a control. */
:where(details, .help, .kv, .callout, .cp-grid, .progress, .steplist, .msg-attachments, .row-sub, table.list, .form-grid, pre, .issues)
    + :where(.btn, button, form, .actions, .row, .full) { margin-top: var(--sp-3); }
:where(details[open] > summary) { margin-bottom: var(--sp-2); }

/* Page-level stacks: forms and button rows in the content column. */
:where(.main, .set-content, .owner-main) > :where(form, .btn) + :where(form, .btn) { margin-top: var(--sp-3); }
:where(.main, .set-content, .owner-main) > :where(.stats, .filters, .two-col, .settings-wrap, .ww-grid, .op-grid, table) + :where(:not(script, style)) { margin-top: var(--sp-4); }

/* Buttons sitting side by side in normal (non-flex) flow. */
:where(.card-body, form, .set-content, .owner-main, .main, td, .help, p, .full) > :where(.btn) + :where(.btn) { margin-left: var(--sp-2); }

/* Form grids: fields without the .field class still get row spacing. */
:where(.form-grid) > :where(label:not(.field)) { display: block; margin-bottom: var(--sp-4); }
/* ...and a full-width button row gets a little air above it. */
:where(.form-grid) > :where(.full:has(> :is(.btn, button):first-child)) { margin-top: var(--sp-2); }

/* Resets: grids and flex rows space their children with gap. */
:where(.two-col, .stats, .op-grid, .ww-grid, .settings-wrap, .plan-grid, .mn-sheet-grid, .row, .stack, .actions, .tk-actions, .bar, .qa-form, .fu-actions, .ww-actions, .filters, .tk-facts,
       [style*="display:flex"], [style*="display: flex"], [style*="display:grid"], [style*="display: grid"]) > * { margin-top: 0; }
:where(.row, .stack, .actions, .tk-actions, .bar, .qa-form, .fu-actions, .ww-actions, .filters,
       [style*="display:flex"], [style*="display: flex"], [style*="display:grid"], [style*="display: grid"]) > :where(.btn) + :where(.btn) { margin-left: 0; }

/* Small checkbox labels under a field ("Remove saved key"). */
label.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: var(--sp-2);
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
}
label.check input { width: auto; margin: 0; }
label.field > label.check { display: flex; }

/* A pill used as a stat's value keeps the UI face. */
.stat .value .pill { font-family: var(--font); font-variation-settings: normal; font-size: 12.5px; letter-spacing: 0; line-height: 20px; vertical-align: middle; }
