/* ==========================================================================
   Expert Support Desk â€” design system
   Themes: daylight (default), midnight, saffron, lagoon. Switch with <html data-theme="â€¦">.
   ========================================================================== */

:root,
[data-theme="daylight"] {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-3: #eef1f7;
    --line: #e2e6ef;
    --line-strong: #cfd5e2;
    --text: #172033;
    --text-2: #4a5468;
    --muted: #6b7489;
    --primary: #3554d1;
    --primary-2: #2a44ad;
    --primary-soft: #e8edff;
    --on-primary: #ffffff;
    --ok: #14804a;
    --ok-soft: #e3f6ec;
    --warn: #a35c00;
    --warn-soft: #fff3df;
    --bad: #c62f3d;
    --bad-soft: #fde8ea;
    --info: #1f6fb2;
    --info-soft: #e4f1fc;
    --mute-soft: #eef0f4;
    --sidebar: #111a33;
    --sidebar-text: #c9d1e8;
    --sidebar-active: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, .08);
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
    --radius: 12px;
    --radius-sm: 8px;
    --focus: 0 0 0 3px rgba(53, 84, 209, .28);
    color-scheme: light;
}

[data-theme="midnight"] {
    --bg: #0d1220;
    --surface: #151c2e;
    --surface-2: #1a2236;
    --surface-3: #212a40;
    --line: #2a3450;
    --line-strong: #3a4566;
    --text: #e7ebf5;
    --text-2: #b8c0d6;
    --muted: #8a94ad;
    --primary: #7b93ff;
    --primary-2: #9aacff;
    --primary-soft: #232d52;
    --on-primary: #0d1220;
    --ok: #4ad295;
    --ok-soft: #12352a;
    --warn: #ffb547;
    --warn-soft: #3a2b12;
    --bad: #ff6b7a;
    --bad-soft: #3d1a22;
    --info: #5db4ff;
    --info-soft: #14304a;
    --mute-soft: #232b3f;
    --sidebar: #0a0f1b;
    --sidebar-text: #a9b3cc;
    --sidebar-active: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
    --focus: 0 0 0 3px rgba(123, 147, 255, .35);
    color-scheme: dark;
}

[data-theme="saffron"] {
    --bg: #fbf6ef;
    --surface: #ffffff;
    --surface-2: #fdf9f3;
    --surface-3: #f6eee2;
    --line: #eadfce;
    --line-strong: #dccbb2;
    --text: #2b1f12;
    --text-2: #5a4632;
    --muted: #82705c;
    --primary: #d2691e;
    --primary-2: #b05414;
    --primary-soft: #fdebdc;
    --on-primary: #ffffff;
    --sidebar: #3b2412;
    --sidebar-text: #f0dcc6;
    --sidebar-hover: rgba(255, 255, 255, .08);
    --focus: 0 0 0 3px rgba(210, 105, 30, .3);
    color-scheme: light;
}

[data-theme="lagoon"] {
    --bg: #eef7f6;
    --surface: #ffffff;
    --surface-2: #f5fbfa;
    --surface-3: #e2f1ef;
    --line: #d3e7e4;
    --line-strong: #b9d8d3;
    --text: #0f2a2a;
    --text-2: #34504f;
    --muted: #5d7776;
    --primary: #0f8b8d;
    --primary-2: #0a6d6f;
    --primary-soft: #dcf2f1;
    --on-primary: #ffffff;
    --sidebar: #0c3b3c;
    --sidebar-text: #c6e6e4;
    --sidebar-hover: rgba(255, 255, 255, .08);
    --focus: 0 0 0 3px rgba(15, 139, 141, .3);
    color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); }
.h1, h1 { font-size: 22px; font-weight: 650; }
.h2, h2 { font-size: 17px; font-weight: 650; }
.h3, h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 8px; }
code, .mono { font-family: Consolas, "Cascadia Mono", ui-monospace, monospace; }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }
.text-ok { color: var(--ok); }
.text-bad { color: var(--bad); }
.text-warn { color: var(--warn); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.mt-sm { margin-top: 8px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.mb-sm { margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap, .wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.gap-sm { gap: 8px; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.inline { display: inline; margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.side { grid-template-columns: minmax(0, 1fr) 360px; }
.side-l { grid-template-columns: 340px minmax(0, 1fr); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 236px; flex: 0 0 236px; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; padding: 16px 12px; gap: 2px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { margin: 0 6px 16px; }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-sub { color: var(--sidebar-text); opacity: .75; }
.nav-item {
    display: block; padding: 8px 12px; border-radius: 8px; color: var(--sidebar-text);
    font-weight: 500; text-decoration: none !important; transition: background .15s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: var(--sidebar-active); }
[data-theme="midnight"] .nav-item.active { color: var(--on-primary); }
.nav-section { margin: 16px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .6; }
.nav-foot { margin-top: auto; padding-top: 16px; }

.content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.who { font-weight: 600; color: var(--text-2); }
.page { padding: 22px 24px 48px; max-width: 1480px; width: 100%; }
.blank { min-height: 100vh; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none !important; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--on-primary);
    font-weight: 800; letter-spacing: .5px; font-size: 13px; flex: 0 0 auto;
}
.brand-name { font-weight: 700; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--muted); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .h3, .card-head h2, .card-head h3 { margin: 0; }
.card-sub { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 14px 18px 0; }
.card.accent { border-left: 4px solid var(--primary); }
.card.accent-bad { border-left: 4px solid var(--bad); }
.card.accent-ok { border-left: 4px solid var(--ok); }
.card.accent-warn { border-left: 4px solid var(--warn); }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: block; color: inherit; text-decoration: none !important; }
a.stat:hover { border-color: var(--primary); }
.stat-n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-l { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.stat.ok .stat-n { color: var(--ok); }
.stat.bad .stat-n { color: var(--bad); }
.stat.warn .stat-n { color: var(--warn); }
.stat.info .stat-n { color: var(--info); }

.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; font-size: 13px; }
.kv > div { min-width: 0; overflow-wrap: anywhere; }
.kv span { display: block; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.kv.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kv.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text-2); margin-bottom: 4px; }
.loading { padding: 28px; text-align: center; color: var(--muted); }
.loading::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px; border: 2px solid var(--line-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: 8px; border: 1px solid var(--primary);
    background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600;
    cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn-soft { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.btn-soft:hover { background: var(--primary-soft); border-color: var(--primary); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: var(--ok); filter: brightness(.92); border-color: var(--ok); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-wa { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.btn-wa:hover { background: #17834a; border-color: #17834a; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-lg { padding: 11px 18px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; font: inherit; cursor: pointer; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 7px; padding: 4px 8px; cursor: pointer; color: var(--muted); font: inherit; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Forms ---------- */
.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.req::after { content: " *"; color: var(--bad); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.input, select.input, textarea.input {
    width: 100%; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 8px;
    background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input:disabled { background: var(--surface-3); color: var(--muted); }
.input-sm { padding: 5px 8px; font-size: 12.5px; width: auto; }
.input-lg { padding: 11px 13px; font-size: 16px; }
.input.invalid, .invalid .input { border-color: var(--bad); }
.validation-message { color: var(--bad); font-size: 12px; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.f3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.f4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; margin: 0; }
.fieldset legend { padding: 0 6px; font-weight: 650; color: var(--text-2); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; background: var(--surface); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; font: inherit; cursor: pointer; color: var(--text-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary); color: var(--on-primary); font-weight: 600; }

/* Search box */
.search { display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--muted); min-width: 260px; flex: 1 1 280px; max-width: 520px; }
.search:focus-within { border-color: var(--primary); box-shadow: var(--focus); }
.search input { border: 0; outline: none; background: transparent; padding: 8px 0; font: inherit; color: var(--text); width: 100%; }
/* The search bar draws the focus ring (.search:focus-within); the box inside must not draw a second one. */
.search input:focus, .search input:focus-visible { outline: none; box-shadow: none; border-radius: 0; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 150px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.card .table-wrap { border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tr.clickable { cursor: pointer; }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .actions { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); }
.tbl tr.sel td { background: var(--primary-soft); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 9px 14px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none !important; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--primary); border-bottom-color: var(--primary); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--surface-3); color: var(--text-2); font-size: 12px; text-align: center; }
.tab.on .count { background: var(--primary-soft); color: var(--primary); }
.count.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Chips & tags ---------- */
.chip, .tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.6; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag { border-radius: 6px; padding: 1px 7px; font-size: 12px; }
.chip-ok, .tag-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn, .tag-warn { background: var(--warn-soft); color: var(--warn); }
.chip-bad, .tag-bad { background: var(--bad-soft); color: var(--bad); }
.chip-info, .tag-info { background: var(--info-soft); color: var(--info); }
.chip-mute, .tag-mute { background: var(--mute-soft); color: var(--muted); }
.tag-primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert strong { font-weight: 700; }

/* ---------- Pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px 0; flex-wrap: wrap; }
.pager-nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pg { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.pg:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pg.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.pg:disabled { opacity: .45; cursor: not-allowed; }
.pg-gap { padding: 0 4px; color: var(--muted); }

/* ---------- Combobox (client picker) ---------- */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% - 18px); margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 420px; overflow-y: auto; }
.combo-option { padding: 9px 10px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--line); }
.combo-option:last-child { border-bottom: 0; }
.combo-option.active, .combo-option:hover { background: var(--primary-soft); }

/* Client search results (ClientPicker) */
.cp-option { padding: 10px 12px; }
.cp-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cp-name { font-size: 14.5px; }
.cp-name mark { background: var(--warn-soft); color: inherit; padding: 0 1px; border-radius: 3px; }
.cp-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 16px; margin-top: 5px; font-size: 12.5px; }
.cp-meta b, .cp-remarks b { color: var(--muted); font-weight: 500; margin-right: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.cp-addr { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.cp-remarks { margin-top: 3px; font-size: 12.5px; }
.cp-lg .input { font-size: 16px; padding-top: 12px; padding-bottom: 12px; }
.cp-lg .combo-list { max-height: min(560px, 70vh); }

/* Incoming call: full-width finder and caller card */
.find-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; align-items: start; }
.caller-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.caller-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.caller .kv.k4 { margin-top: 12px; }
.caller .kv .big { font-size: 18px; font-weight: 700; }
.caller-lines { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 24px; margin-top: 10px; font-size: 13px; }
/* Tablets: finder stacks, caller details in 2 columns */
@media (max-width: 960px) {
    .find-grid, .caller-lines { grid-template-columns: minmax(0, 1fr); }
    .caller .kv.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Phones: one column, full-width buttons, lists that leave room for the on-screen keyboard */
@media (max-width: 640px) {
    .caller .kv.k4 { grid-template-columns: minmax(0, 1fr); }
    .caller-actions { width: 100%; }
    .caller-actions .btn { flex: 1 1 auto; text-align: center; }
    .cp-lg .combo-list, .combo-list { max-height: 50vh; max-height: 50dvh; }
    .cp-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Touch screens: roomier rows, no keyboard-only hints */
@media (pointer: coarse) {
    .combo-list-select .combo-option { padding: 12px 12px; }
    .cp-option { padding: 12px; }
    .kbd-hint { display: none; }
}

/* Searchable drop-down (Combo) */
.combo-select .combo-input { padding-right: 30px; cursor: pointer; }
.combo-select .combo-input:focus { cursor: text; }
.combo-caret { position: absolute; right: 12px; top: 50%; width: 8px; height: 8px; margin-top: -6px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); pointer-events: none; }
.combo-select.is-disabled .combo-caret { opacity: .4; }
.combo-list-select { top: calc(100% + 4px); max-height: 300px; }
.combo-list-select .combo-option { padding: 7px 10px; border-bottom: 0; }
.combo-option.chosen { font-weight: 600; }
.combo-empty { padding: 8px 10px; color: var(--muted); font-size: .9em; }
.combo-fill .combo-input { width: 100%; }

/* Progress of long jobs (import, sync) */
.job { border: 1px solid var(--line-strong); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; background: var(--surface); }
.bar { position: relative; height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); transition: width .3s ease; }
.bar.indeterminate > span { position: absolute; animation: bar-slide 1.4s ease-in-out infinite; }
@keyframes bar-slide { from { left: -30%; } to { left: 100%; } }
@media (prefers-reduced-motion: reduce) { .bar.indeterminate > span { animation: none; left: 0; width: 100% !important; opacity: .45; } }

/* ---------- Staff picker ---------- */
.pick { display: flex; flex-direction: column; gap: 6px; }
.pick-option { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.pick-option:hover { border-color: var(--primary); }
.pick-option.on { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.pick-option.off { opacity: .55; cursor: not-allowed; background: var(--surface-2); }
.pick-option.off:hover { border-color: var(--line-strong); }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }

/* ---------- Theme switcher ---------- */
.theme-switch { display: flex; gap: 6px; align-items: center; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--primary); }
.swatch-daylight { background: linear-gradient(135deg, #ffffff 50%, #3554d1 50%); }
.swatch-midnight { background: linear-gradient(135deg, #151c2e 50%, #7b93ff 50%); }
.swatch-saffron { background: linear-gradient(135deg, #fbf6ef 50%, #d2691e 50%); }
.swatch-lagoon { background: linear-gradient(135deg, #eef7f6 50%, #0f8b8d 50%); }

/* ---------- Notifications ---------- */
.notif { position: relative; }
.bell { position: relative; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: var(--text-2); border: 1px solid var(--line); background: var(--surface); }
.bell:hover { background: var(--surface-3); text-decoration: none; }
.bell-count { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; gap: 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 10px; box-shadow: var(--shadow-lg); animation: toast-in .25s ease-out; }
.toast-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--info); margin-top: 5px; flex: 0 0 auto; }
.toast-body { flex: 1 1 auto; min-width: 0; }
.toast-warn { border-left-color: var(--warn); } .toast-warn .toast-dot { background: var(--warn); }
.toast-error { border-left-color: var(--bad); } .toast-error .toast-dot { background: var(--bad); }
.toast-ok { border-left-color: var(--ok); } .toast-ok .toast-dot { background: var(--ok); }
.toast-call { border-left-color: var(--ok); background: var(--ok-soft); }
.toast-call .toast-dot { background: var(--ok); animation: ring 1s infinite; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes ring { 50% { transform: scale(1.6); opacity: .5; } }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline li.client::before { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.timeline li.closed::before { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* ---------- Error library ---------- */
.kb { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); }
.kb + .kb { margin-top: 10px; }
.kb-head { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.kb-code { font-family: Consolas, ui-monospace, monospace; font-weight: 700; color: var(--primary); }
.kb-err { font-family: Consolas, ui-monospace, monospace; font-size: 12.5px; background: var(--bad-soft); color: var(--bad); padding: 6px 10px; border-radius: 6px; margin: 8px 0; overflow-wrap: anywhere; }
ol.steps { margin: 8px 0 0; padding-left: 22px; }
ol.steps li { margin-bottom: 4px; }
.shots { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.shot { display: block; width: 180px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.shot img { display: block; width: 100%; height: 110px; object-fit: cover; }
.shot span { display: block; padding: 4px 8px; font-size: 11.5px; color: var(--muted); }
.shot-lg img { height: auto; max-height: 360px; object-fit: contain; }
.upload-box { border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); background: var(--surface-2); }
.suggest { border: 1px solid var(--primary); background: var(--primary-soft); border-radius: var(--radius-sm); padding: 10px 12px; }

/* ---------- Pipeline board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.board-col { background: var(--surface-3); border-radius: var(--radius); padding: 10px; min-height: 160px; }
.board-col h3 { font-size: 13px; display: flex; justify-content: space-between; margin-bottom: 8px; }
.board-card { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); }
.board-card .when { font-size: 12px; }

/* ---------- Chat (assistant) ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 58vh; min-height: 280px; overflow-y: auto; padding: 4px; }
.msg { max-width: 82%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-me { align-self: flex-end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-start; background: var(--surface-3); color: var(--text); border-bottom-left-radius: 4px; }
.msg img { max-width: 220px; border-radius: 8px; display: block; margin-top: 6px; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }

/* ---------- Progress ---------- */
.bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar.ok > span { background: var(--ok); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 30, .45); z-index: 80; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px; }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- Incoming call ---------- */
.caller { border: 2px solid var(--ok); background: linear-gradient(135deg, var(--ok-soft), var(--surface)); }
.caller.unknown { border-color: var(--warn); background: linear-gradient(135deg, var(--warn-soft), var(--surface)); }
.ring { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); animation: ring 1s infinite; margin-right: 6px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
    radial-gradient(1000px 500px at 10% -10%, var(--primary-soft), transparent),
    radial-gradient(800px 400px at 110% 110%, var(--primary-soft), transparent), var(--bg); }
.login-card { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { margin-bottom: 6px; }

/* ---------- Client portal ---------- */
.portal { min-height: 100vh; display: flex; flex-direction: column; }
.portal-top { display: flex; align-items: center; gap: 18px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.portal-nav { display: flex; gap: 4px; flex: 1 1 auto; flex-wrap: wrap; }
.portal-nav a { padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 600; text-decoration: none !important; }
.portal-nav a:hover { background: var(--surface-3); }
.portal-nav a.active { background: var(--primary-soft); color: var(--primary); }
.portal-main { padding: 24px; max-width: 1180px; width: 100%; margin: 0 auto; }
.hero { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--on-primary); border-radius: 16px; padding: 22px 24px; }
.hero h1 { color: inherit; }
.hero .muted { color: inherit; opacity: .85; }
.rating { display: inline-flex; gap: 4px; }
.rating button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 16px; color: var(--muted); }
.rating button.on { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.code-box { font-family: Consolas, ui-monospace, monospace; font-size: 30px; font-weight: 800; letter-spacing: 8px; padding: 10px 16px; background: var(--surface); border: 2px dashed var(--primary); border-radius: 10px; display: inline-block; color: var(--primary); }

/* ---------- WhatsApp template preview ---------- */
.wa-phone { background: #e5ddd5; border-radius: 14px; padding: 16px; }
[data-theme="midnight"] .wa-phone { background: #0b141a; }
.wa-bubble { background: #ffffff; color: #111; border-radius: 10px; padding: 10px 12px; max-width: 360px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); white-space: pre-wrap; font-size: 13.5px; }
[data-theme="midnight"] .wa-bubble { background: #1f2c34; color: #e9edef; }
.wa-head { font-weight: 700; margin-bottom: 4px; }
.wa-foot { color: #667781; font-size: 12px; margin-top: 6px; }
.wa-btn { display: block; text-align: center; color: #027eb5; border-top: 1px solid rgba(0, 0, 0, .08); padding: 7px 0 2px; margin-top: 6px; font-weight: 600; }
pre.json { background: var(--surface-3); border-radius: 8px; padding: 12px; overflow: auto; max-height: 360px; font-size: 12px; margin: 0; }

/* ---------- Blazor error UI ---------- */
#blazor-error-ui { background: var(--warn-soft); color: var(--warn); bottom: 0; box-shadow: 0 -1px 4px rgba(0, 0, 0, .2); display: none; left: 0; padding: 10px 20px; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 8px; }
.blazor-error-boundary { background: var(--bad-soft); color: var(--bad); padding: 12px 16px; border-radius: 8px; }
.blazor-error-boundary::after { content: "Something went wrong on this part of the page. Please reload."; }

/* ---------- Responsive (tablet & phone) ---------- */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.menu-btn, .topbar-brand, .nav-scrim { display: none; }
.menu-btn { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--text); place-items: center; cursor: pointer; }
.table-wrap { -webkit-overflow-scrolling: touch; }
.tbl td, .tbl th { word-break: normal; }

@media (max-width: 1180px) {
    .g5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .side, .side-l { grid-template-columns: minmax(0, 1fr); }
    .form-grid.f4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .page { padding: 18px 18px 40px; }
}

/* Tablet portrait and phones: sidebar becomes a slide-in drawer opened by the â˜° button. */
@media (max-width: 960px) {
    .menu-btn, .topbar-brand { display: grid; }
    .topbar-brand { display: flex; }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; height: 100vh; height: 100dvh; width: 272px; z-index: 90;
        transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
    }
    .nav-toggle:checked ~ .sidebar { transform: none; }
    .nav-toggle:checked ~ .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(10, 15, 30, .45); z-index: 85; }
    .topbar { padding: 10px 16px; }
    .topbar-left { gap: 10px; }
    .g3, .g2 { grid-template-columns: minmax(0, 1fr); }
    .g3.keep-2 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid.f3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .board { grid-auto-columns: minmax(240px, 80vw); }
}

/* Phones */
@media (max-width: 640px) {
    body { font-size: 14.5px; }
    .page { padding: 14px 12px 40px; }
    .page-head { margin-bottom: 14px; }
    .page-head h1, .h1 { font-size: 19px; }
    .page-head .actions { width: 100%; }
    .page-head .actions > * { flex: 1 1 auto; }
    .hide-sm { display: none !important; }
    .topbar { padding: 8px 12px; gap: 8px; }
    .topbar-right { gap: 8px; }
    .topbar-left .small { display: none; }
    .theme-switch { gap: 4px; }
    .swatch { width: 18px; height: 18px; }
    .card { padding: 14px; border-radius: 10px; }
    .stat { padding: 12px; }
    .stat-n { font-size: 21px; }
    .g4, .g5, .form-grid, .form-grid.f3, .form-grid.f4, .kv.k3, .kv.k4 { grid-template-columns: minmax(0, 1fr); }
    .g5.keep-2, .g4.keep-2, .g3.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span2 { grid-column: auto; }
    .search { min-width: 0; max-width: none; flex: 1 1 100%; }
    .toolbar > .input, .toolbar > select { flex: 1 1 140px; min-width: 0; }
    .tabs { margin-left: -12px; margin-right: -12px; padding: 0 12px; }
    .seg { display: flex; width: 100%; }
    .seg button { flex: 1 1 auto; }
    .form-foot { flex-direction: column-reverse; }
    .form-foot > .btn, .form-foot > a.btn { width: 100%; }
    .modal-back { place-items: end center; padding: 0; }
    .modal, .modal.wide { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; padding: 16px; }
    .toasts { right: 10px; left: 10px; bottom: 10px; width: auto; }
    .tbl { font-size: 13px; min-width: 620px; }
    /* Main lists become stacked cards on phones */
    .tbl.cards { min-width: 0; }
    .tbl.cards thead { display: none; }
    .tbl.cards tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
    .tbl.cards tr:last-child { border-bottom: 0; }
    .tbl.cards td { display: block; border: 0; padding: 2px 0; }
    .tbl.cards td:empty { display: none; }
    .tbl.cards td.num, .tbl.cards td.actions { text-align: left; }
    .tbl.cards td.actions { padding-top: 8px; }
    .tbl.cards td[data-label]::before { content: attr(data-label) " Â· "; color: var(--muted); font-size: 12px; }
    .tbl.cards tbody tr:hover td { background: none; }
    .tbl th, .tbl td { padding: 9px 10px; }
    .shot { width: calc(50% - 5px); }
    .chat { max-height: 55vh; }
    .msg { max-width: 92%; }
    .chat-input { flex-wrap: wrap; }
    .chat-input textarea { flex: 1 1 60%; }
    .hero { padding: 18px; border-radius: 14px; }
    .code-box { font-size: 24px; letter-spacing: 6px; }
    .portal-top { padding: 10px 12px; gap: 10px; }
    .portal-nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
    .portal-nav a { white-space: nowrap; }
    .portal-main { padding: 14px 12px; }
    .login-card { padding: 20px; }
    /* 16px inputs stop iPhone Safari from zooming into fields */
    .input, select.input, textarea.input, .search input { font-size: 16px; }
    .input-sm { font-size: 14px; }
}

/* Touch screens: bigger tap targets */
@media (pointer: coarse) {
    .btn-sm { padding: 8px 12px; }
    .pg { min-width: 38px; height: 38px; }
    .icon-btn { padding: 8px 10px; }
    .nav-item { padding: 11px 12px; }
    .check input { width: 20px; height: 20px; }
}

@media print {
    .sidebar, .topbar, .toasts, .menu-btn, .actions, .pager, .form-foot { display: none !important; }
    .page { padding: 0; }
    .card { box-shadow: none; }
}

/* Keyboard hints */
.kbd { display: inline-block; padding: 1px 7px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); font-family: Consolas, ui-monospace, monospace; font-size: 12px; }
.input:focus, select.input:focus, textarea.input:focus { background: var(--surface); }
button:focus-visible, a.btn:focus-visible, .pick-option:focus-visible { box-shadow: var(--focus); outline: none; }
.nav-btn { background: none; border: 0; width: 100%; text-align: left; font: inherit; cursor: pointer; }
.nav-btn .kbd { background: transparent; color: inherit; border-color: rgba(255, 255, 255, .3); margin-left: 6px; }

/* =====================================================================================
   Phones & tablets â€” industry-standard touch sizes and responsive tables
   (44px touch targets per Apple HIG / WCAG 2.5.5, 16px inputs, no sideways scrolling)
   ===================================================================================== */
@media (pointer: coarse), (max-width: 960px) {
    .btn, a.btn { min-height: 44px; }
    .btn-sm, a.btn-sm, .input-sm { min-height: 40px; }
    .input, select.input { min-height: 44px; }
    .seg button { min-height: 44px; padding-left: 14px; padding-right: 14px; }
    .tab { min-height: 44px; display: inline-flex; align-items: center; }
    .pg { min-width: 44px; height: 44px; }
    .icon-btn { min-width: 44px; min-height: 44px; }
    .swatch { width: 28px; height: 28px; }
    .check { min-height: 40px; }
    .check input { width: 22px; height: 22px; }
    .btn-link { min-height: 40px; padding: 8px 4px; }
}

/* Tablets (and phones) */
@media (max-width: 960px) {
    .tiny, .tag, .count, .chip, .kv span { font-size: 12.5px; }
    .btn-sm, a.btn-sm { min-width: 40px; justify-content: center; }
    .toolbar .combo { flex: 1 1 200px; }
    .toolbar .combo .combo-input { width: 100%; min-width: 0; }
}

/* Phones */
@media (max-width: 640px) {
    .toolbar .combo, .toolbar .search { flex: 1 1 100%; }
    .tabs { scroll-snap-type: x proximity; }
    .tab { scroll-snap-align: start; }

    /* Every table becomes a list of labelled cards (labels come from the column headings, see app.js).
       Add class "keep-table" to a table that must stay a grid. */
    .tbl:not(.keep-table) { min-width: 0; }
    .tbl:not(.keep-table) thead { display: none; }
    .tbl:not(.keep-table) tbody tr, .tbl:not(.keep-table) tfoot tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
    .tbl:not(.keep-table) tbody tr:last-child { border-bottom: 0; }
    .tbl:not(.keep-table) td { display: block; border: 0; padding: 3px 0; text-align: left; }
    .tbl:not(.keep-table) td:empty { display: none; }
    .tbl:not(.keep-table) td.num, .tbl:not(.keep-table) td.actions { text-align: left; }
    .tbl:not(.keep-table) td.actions { padding-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
    .tbl:not(.keep-table) td.actions > .btn { flex: 1 1 auto; }
    .tbl:not(.keep-table) td[data-label] { display: grid; grid-template-columns: minmax(92px, 36%) minmax(0, 1fr); gap: 0 10px; align-items: baseline; }
    .tbl:not(.keep-table) td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; grid-row: 1 / span 9; }
    .tbl:not(.keep-table) td[data-label] > * { grid-column: 2; justify-self: start; }
    .tbl:not(.keep-table) td.is-blank { display: none; }
    .tbl:not(.keep-table) td[data-label].actions { display: flex; }
    .tbl:not(.keep-table) td[data-label].actions::before { display: none; }
    .tbl:not(.keep-table) tbody tr:hover td { background: none; }
    .tbl:not(.keep-table) td input[type=checkbox] { width: 22px; height: 22px; }
}

/* Short edit forms (masters): comfortable width on laptops, full width on phones */
.form-card { max-width: 760px; }


/* Long forms in tabs (client edit): the tab bar and the Save bar stay in view while scrolling */
.sticky-tabs { position: sticky; top: var(--topbar-h, 58px); z-index: 19; background: var(--bg); padding-top: 4px; }
.sticky-foot { position: sticky; bottom: 0; z-index: 20; background: var(--bg); padding: 12px 0; margin-top: 12px; border-top: 1px solid var(--line); }
@media (max-width: 640px) { .sticky-tabs { --topbar-h: 52px; } }

/* Import problems list: scrolls inside its own box */
.issue-list { max-height: 360px; overflow-y: auto; }

@media (max-width: 640px) {
    /* Client form on phones: all four tabs visible (two lines), and one slim Save | Cancel bar */
    .sticky-tabs { flex-wrap: wrap; overflow-x: visible; gap: 0 4px; }
    .sticky-tabs .tab { flex: 1 1 auto; justify-content: center; }
    .form-foot.sticky-foot { flex-direction: row; gap: 10px; padding: 10px 0; }
    .form-foot.sticky-foot > .btn, .form-foot.sticky-foot > a.btn { flex: 1 1 0; width: auto; }
}

/* Document icon buttons: PDF / WhatsApp / Email (bills, ledger, outstanding) */
.doc-actions { display: inline-flex; gap: 6px; align-items: center; vertical-align: middle; }
.doc-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border-radius: 9px;
           border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s; }
.doc-btn .doc-ico { width: 20px; height: 20px; }
.doc-btn.pdf { color: #c62f3d; }
.doc-btn.wa { color: #1f9d55; }
.doc-btn.mail { color: var(--primary); }
.doc-btn:hover:not(:disabled):not(.off) { background: var(--surface-2); border-color: currentColor; }
.doc-btn:disabled, .doc-btn.off { color: var(--muted); opacity: .45; cursor: not-allowed; }
.doc-btn:focus-visible { box-shadow: var(--focus); outline: none; }
.tbl td.actions .doc-actions { justify-content: flex-end; }
.hide-sm { }
@media (max-width: 640px) { .hide-sm { display: none; } .tbl:not(.keep-table) td.actions .doc-actions { justify-content: flex-start; } }
@media (pointer: coarse), (max-width: 960px) { .doc-btn { width: 44px; height: 44px; } .doc-btn .doc-ico { width: 22px; height: 22px; } }

/* Send popup */
.send-dialog { max-width: 520px; }
.send-badge { display: inline-flex; width: 40px; height: 40px; border-radius: 12px; align-items: center; justify-content: center; flex: none; }
.send-badge .doc-ico { width: 22px; height: 22px; }
.send-badge.wa { background: #e3f6ec; color: #1f9d55; }
.send-badge.mail { background: var(--surface-2); color: var(--primary); border: 1px solid var(--line); }
.send-summary { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 4px; word-break: break-word; }
.party-to { display: grid; gap: 2px; word-break: break-word; }
.tbl tr.row-sub td { background: var(--surface-2); }
.tbl tr.row-group td { background: var(--surface-2); border-top: 2px solid var(--border); padding-top: 10px; }
.bill-item { min-width: 220px; max-width: 420px; }
.agent-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
    text-decoration: none; border: 1px solid transparent; white-space: nowrap; }
.agent-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.agent-pill.on { color: var(--ok); background: var(--ok-soft); border-color: var(--ok); }
.agent-pill.on .dot { animation: agent-pulse 1.6s ease-in-out infinite; }
.agent-pill.off { color: var(--bad); background: var(--bad-soft); border-color: var(--bad); }
@keyframes agent-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .agent-pill.on .dot { animation: none; } }
.bill-item + .bill-item { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--border); }

/* WhatsApp template editor */
.tp-body { min-height: 150px; font-size: 14px; line-height: 1.5; }
.tp-vars { display: inline-flex; flex-wrap: wrap; gap: 4px 6px; margin: 4px 0; }
.tp-var { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-size: 12px; white-space: nowrap; }
.tp-btn-row { display: grid; grid-template-columns: 140px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; }
.tp-btn-row .combo, .tp-btn-row .combo-input { width: 100%; min-width: 0; }
.tp-samples label { display: grid; gap: 4px; }
@media (max-width: 640px) {
    .tp-btn-row { grid-template-columns: minmax(0, 1fr) auto; }
    .tp-btn-row > .combo { grid-column: 1 / -1; }
    .tp-btn-row > .tiny { display: none; }
}

/* Client alerts: ⭐ privileged (gold), ⚠ caution (amber), 🚨 red alert (red). Staff only. */
.alert-chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; vertical-align: middle; border: 1px solid transparent; }
.alert-chip.vip { background: #fff6d6; color: #8a6100; border-color: #f0d27a; }
.alert-chip.caution { background: #fff0dc; color: #a35c00; border-color: #f5c27a; }
.alert-chip.red { background: #fde8ea; color: #b4232f; border-color: #f3a1a9; }
.client-alert { display: flex; gap: 12px; align-items: flex-start; border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; border: 1px solid; border-left-width: 5px; }
.client-alert.vip { background: #fffaea; border-color: #f0d27a; color: #5c4100; }
.client-alert.caution { background: #fff6ea; border-color: #f5c27a; color: #6b3d00; }
.client-alert.red { background: #fff0f1; border-color: #e5484d; color: #8f1d26; }
.client-alert-icon { font-size: 26px; line-height: 1; }
.client-alert.red .client-alert-icon { animation: siren 1.2s ease-in-out infinite; }
.client-alert-title { font-weight: 700; }
.client-alert-note { margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.client-alert-by { font-size: 12px; opacity: .75; margin-top: 4px; }
[data-theme="midnight"] .client-alert.vip, [data-theme="midnight"] .alert-chip.vip { background: #3a3012; color: #ffd76a; border-color: #6b5718; }
[data-theme="midnight"] .client-alert.caution, [data-theme="midnight"] .alert-chip.caution { background: #3a2b12; color: #ffb547; border-color: #6b4d18; }
[data-theme="midnight"] .client-alert.red, [data-theme="midnight"] .alert-chip.red { background: #3d1a22; color: #ff8a95; border-color: #ff6b7a; }
@keyframes siren { 0%, 100% { transform: scale(1); filter: none; } 50% { transform: scale(1.15); filter: drop-shadow(0 0 6px rgba(229, 72, 77, .8)); } }
@media (prefers-reduced-motion: reduce) { .client-alert.red .client-alert-icon { animation: none; } }
.caller.caller-red { border-color: #e5484d; box-shadow: 0 0 0 3px rgba(229, 72, 77, .18); }
.tbl tr.row-red td:first-child { box-shadow: inset 4px 0 0 #e5484d; }
.cp-option.cp-alert-red { box-shadow: inset 4px 0 0 #e5484d; }
.cp-option.cp-alert-caution { box-shadow: inset 4px 0 0 #f0a020; }
.cp-option.cp-alert-vip { box-shadow: inset 4px 0 0 #e0b100; }
.cp-alert-note { font-size: 12.5px; font-weight: 600; margin-top: 4px; }
.cp-alert-note.red { color: #b4232f; }
.cp-alert-note.caution { color: #a35c00; }
.cp-alert-note.vip { color: #8a6100; }
[data-theme="midnight"] .cp-alert-note.red { color: #ff8a95; }
[data-theme="midnight"] .cp-alert-note.caution { color: #ffb547; }
[data-theme="midnight"] .cp-alert-note.vip { color: #ffd76a; }
.alert-levels { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.alert-level { display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font: inherit; color: inherit; min-height: 44px; }
.alert-level > span:last-child { display: grid; gap: 2px; }
.alert-level-icon { font-size: 20px; line-height: 1.2; }
.alert-level.on { border-width: 2px; padding: 9px 11px; }
.alert-level.on:not(.vip):not(.caution):not(.red) { border-color: var(--primary); }
.alert-level.vip.on { border-color: #e0b100; background: #fffaea; }
.alert-level.caution.on { border-color: #f0a020; background: #fff6ea; }
.alert-level.red.on { border-color: #e5484d; background: #fff0f1; }
[data-theme="midnight"] .alert-level.on { background: var(--surface-2); }
@media (max-width: 640px) { .alert-levels { grid-template-columns: 1fr; } }

/* ---- choice chips (festivals celebrated, company switches) and Expert data screens ---- */
.pick-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer; min-height: 32px; }
.pick:hover { border-color: var(--primary); }
.pick.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.wrap-row { flex-wrap: wrap; }
.code-pill { display: inline-block; font-family: var(--mono, ui-monospace, monospace); font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin: 0 4px 4px 0; white-space: nowrap; }
.code-pill.master { border-color: var(--primary); color: var(--primary); }
.otp-code { font-family: ui-monospace, monospace; font-size: 28px; font-weight: 700; letter-spacing: 4px; padding: 10px 16px; border: 2px dashed var(--primary); border-radius: var(--radius-sm); display: inline-block; }

/* Inactive clients (no longer our client): highlighted when "Don't show inactive clients" is unticked. Theme tokens only. */
.tbl tr.row-inactive td { background: color-mix(in srgb, var(--bad-soft) 70%, transparent); color: var(--muted); }
.tbl tr.row-inactive td:first-child { box-shadow: inset 4px 0 0 var(--bad); }
.tbl tr.row-inactive strong, .tbl tr.row-inactive a { color: var(--text, inherit); text-decoration-color: var(--bad); }
.inactive-tag { vertical-align: middle; cursor: help; text-transform: none; }
.cp-option.cp-inactive { background: color-mix(in srgb, var(--bad-soft) 60%, transparent); box-shadow: inset 4px 0 0 var(--bad); }
.cp-inactive-opt { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; cursor: pointer; }
.active-toggle.is-inactive .inactive-detail { color: var(--bad); }
.client-inactive-panel { border-color: var(--bad); background: var(--bad-soft); }
.sel-col { width: 34px; text-align: center; }

/* ---- Reports */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.report-card { display: block; text-decoration: none; color: inherit; padding: 14px 16px; transition: border-color .15s, box-shadow .15s; }
.report-card:hover { border-color: var(--primary, #3b5bdb); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.report-filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.report-filters .field { display: flex; flex-direction: column; gap: 4px; }
.report-filters .field.end { margin-left: auto; }
.tbl.report-tbl td { white-space: normal; }
.tbl tr.row-bad td { background: var(--bad-soft); }
.tbl tr.row-warn td { background: var(--warn-soft); }
.tbl tr.row-ok td { background: var(--ok-soft); }
.tbl tr.row-mute td { color: var(--muted); }
/* ---- multi-select drop-down (zones, categories) */
.multi-pick { position: relative; display: inline-block; }
.multi-pick > summary { list-style: none; cursor: pointer; min-width: 150px; display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; }
.multi-pick > summary::-webkit-details-marker { display: none; }
.multi-pick > summary::after { content: "▾"; color: var(--muted); }
.multi-pick-panel { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 260px; max-width: 360px; padding: 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.multi-pick-list { max-height: 280px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.multi-pick-list .check { display: flex; gap: 8px; align-items: center; }
.tbl tr.row-group td { font-weight: 600; }
.tbl tr.row-group2 td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); font-weight: 600; }
.tbl.report-tbl td:first-child { white-space: pre-wrap; }