/* Design system (R2 design §5). Tokens: :root = light, [data-theme="dark"], and the system-dark media block
   (identical declarations to [data-theme="dark"]; tests/static/check-contrast.js asserts this and that the colour
   tokens equal Core\Color::THEMES). No web fonts, no CDN, no preprocessor. The brand tokens (--primary*) are
   overridden per site by the inline Core\Color::brandCss() block printed after this file. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #111827;
  --text-muted: #4b5563;
  --text-subtle: #5f6672;
  --success: #166534;
  --success-bg: #dcfce7;
  --warning: #854d0e;
  --warning-bg: #fef3c7;
  --danger: #991b1b;
  --danger-bg: #fee2e2;
  --info: #1e40af;
  --info-bg: #dbeafe;
  --neutral-badge: #374151;
  --neutral-badge-bg: #eef0f3;
  --primary: #15803d;
  --primary-fg: #ffffff;
  --primary-soft: #e3f0e8;
  --primary-text: #147739;
  --focus: 0 0 0 3px rgba(37, 99, 235, .45);
  --overlay: rgba(15, 23, 42, .45);
  --chart-1: #15803d;
  --chart-2: #2563eb;
  --chart-3: #d97706;
  --chart-4: #9333ea;
  --wa-chat: #efeae2;
  --wa-bubble: #ffffff;
  --sh-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --sh-md: 0 4px 12px rgba(16, 24, 40, .08);
  --sh-lg: 0 12px 32px rgba(16, 24, 40, .14);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #1a1e27;
  --border: #262b36;
  --border-strong: #353b48;
  --text: #e6e8ec;
  --text-muted: #a3aab8;
  --text-subtle: #8d95a5;
  --success: #86efac;
  --success-bg: #0f2e1c;
  --warning: #fde68a;
  --warning-bg: #33270a;
  --danger: #fca5a5;
  --danger-bg: #3b1212;
  --info: #93c5fd;
  --info-bg: #13213f;
  --neutral-badge: #d1d5db;
  --neutral-badge-bg: #232834;
  --primary: #15803d;
  --primary-fg: #ffffff;
  --primary-soft: #122220;
  --primary-text: #199a4a;
  --focus: 0 0 0 3px rgba(147, 197, 253, .55);
  --overlay: rgba(0, 0, 0, .6);
  --chart-1: #4ade80;
  --chart-2: #60a5fa;
  --chart-3: #fbbf24;
  --chart-4: #c084fc;
  --wa-chat: #0e1a17;
  --wa-bubble: #1f2c33;
  --sh-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --sh-md: 0 4px 12px rgba(0, 0, 0, .45);
  --sh-lg: 0 12px 32px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0b0d12;
    --surface: #12151c;
    --surface-2: #1a1e27;
    --border: #262b36;
    --border-strong: #353b48;
    --text: #e6e8ec;
    --text-muted: #a3aab8;
    --text-subtle: #8d95a5;
    --success: #86efac;
    --success-bg: #0f2e1c;
    --warning: #fde68a;
    --warning-bg: #33270a;
    --danger: #fca5a5;
    --danger-bg: #3b1212;
    --info: #93c5fd;
    --info-bg: #13213f;
    --neutral-badge: #d1d5db;
    --neutral-badge-bg: #232834;
    --primary: #15803d;
    --primary-fg: #ffffff;
    --primary-soft: #122220;
    --primary-text: #199a4a;
    --focus: 0 0 0 3px rgba(147, 197, 253, .55);
    --overlay: rgba(0, 0, 0, .6);
    --chart-1: #4ade80;
    --chart-2: #60a5fa;
    --chart-3: #fbbf24;
    --chart-4: #c084fc;
    --wa-chat: #0e1a17;
    --wa-bubble: #1f2c33;
    --sh-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --sh-md: 0 4px 12px rgba(0, 0, 0, .45);
    --sh-lg: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* Scales (theme independent) */
:root {
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 20px; --fs-2xl: 24px; --fs-3xl: 30px;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --content-max: 1280px;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs-base); line-height: 1.5;
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--s-2); font-weight: 650; color: var(--text); }
h1 { font-size: var(--fs-2xl); letter-spacing: -.01em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }
p { margin: 0 0 var(--s-3); }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-4) 0; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-2); border-radius: 4px; padding: 1px 5px; }
pre { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3); overflow: auto; font-size: var(--fs-sm); }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
::selection { background: var(--primary-soft); color: var(--text); }
.icon { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.sr-only, .visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: var(--s-2); top: -60px; z-index: 100; background: var(--surface); color: var(--text); padding: var(--s-2) var(--s-3); border-radius: var(--r-md); box-shadow: var(--sh-md); }
.skip-link:focus { top: var(--s-2); }
[hidden], .hidden { display: none !important; }
.js .js-hide { display: none !important; }

/* Utilities */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.w-100 { width: 100%; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.inline { display: inline; }
form.inline, .inline-form { display: inline-flex; gap: var(--s-1); align-items: center; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
td.actions { flex-wrap: nowrap; justify-content: flex-end; }
.stack > * + * { margin-top: var(--s-4); }
.row { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: var(--s-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-5); }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mt-4 { margin-top: var(--s-4); } .mb-4 { margin-bottom: var(--s-4); }
.divider { border-top: 1px solid var(--border); margin: var(--s-4) 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.break { word-break: break-all; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-subtle); }
.dot-success { background: var(--success); } .dot-danger { background: var(--danger); } .dot-warning { background: var(--warning); } .dot-info { background: var(--info); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: 36px; padding: 0 var(--s-4);
  border-radius: var(--r-md); border: 1px solid transparent; font: inherit; font-weight: 550; font-size: var(--fs-base); line-height: 1;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover:not(:disabled) { filter: brightness(.94); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--sh-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { filter: brightness(.96); border-color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-xs { min-height: 24px; padding: 0 var(--s-2); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { min-height: 44px; padding: 0 var(--s-6); font-size: var(--fs-md); }
.btn-icon { padding: 0; width: 36px; }
.btn-icon.btn-sm { width: 30px; }
.btn-group { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.btn-group .btn { border-radius: 0; border: 0; min-height: 34px; background: transparent; color: var(--text-muted); }
.btn-group .btn.active, .btn-group .btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary-text); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600;
  line-height: 1.5; white-space: nowrap; background: var(--neutral-badge-bg); color: var(--neutral-badge);
}
.badge .icon { width: 13px; height: 13px; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-badge-bg); color: var(--neutral-badge); }
.badge-primary { background: var(--primary-soft); color: var(--primary-text); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--sh-sm); margin-bottom: var(--s-5); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }
.card-header .card-title { margin: 0; }
.card-title { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-md); font-weight: 650; margin: 0 0 var(--s-4); color: var(--text); }
.card-title .icon { color: var(--primary-text); }
.card-sub { color: var(--text-muted); font-size: var(--fs-sm); margin: calc(var(--s-3) * -1) 0 var(--s-4); }
.card-soft { background: var(--surface-2); box-shadow: none; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > .card-header { padding: var(--s-4) var(--s-5) 0; }
.card-footer { border-top: 1px solid var(--border); margin: var(--s-4) calc(var(--s-5) * -1) calc(var(--s-5) * -1); padding: var(--s-3) var(--s-5); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s-4); }
.card-grid > .card { margin: 0; display: flex; flex-direction: column; }
.card-grid .card-foot { margin-top: auto; padding-top: var(--s-3); display: flex; gap: var(--s-2); flex-wrap: wrap; }
.section-title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-subtle); font-weight: 650; margin: var(--s-6) 0 var(--s-3); }

/* Page header */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap; }
.page-header h1 { margin: 0; }
.page-header p { margin: var(--s-1) 0 0; color: var(--text-muted); }
.page-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-5); }
.kpi { display: flex; gap: var(--s-3); align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-4) var(--s-5); box-shadow: var(--sh-sm); color: var(--text); }
a.kpi-link:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi-icon { width: 40px; height: 40px; border-radius: var(--r-md); background: var(--primary-soft); color: var(--primary-text); display: grid; place-items: center; flex: none; }
.kpi-icon .icon { width: 20px; height: 20px; }
.kpi-label { color: var(--text-muted); font-size: var(--fs-sm); text-wrap: pretty; }
.kpi-value { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.2; letter-spacing: -.01em; }
.kpi-delta { font-size: var(--fs-xs); font-weight: 600; margin-top: 2px; }
.kpi-up { color: var(--success); } .kpi-down { color: var(--danger); }

/* Forms */
.field, .form-group { margin-bottom: var(--s-4); min-width: 0; }
.field > label, .form-group > label, fieldset.field > legend { display: block; font-weight: 550; font-size: var(--fs-sm); margin-bottom: var(--s-1); color: var(--text); }
fieldset.field { border: 0; padding: 0; margin: 0 0 var(--s-4); }
.req { color: var(--danger); margin-left: 2px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="tel"], input[type="url"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="search"], input:not([type]), select, textarea {
  width: 100%; min-height: 38px; padding: 8px 12px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select[multiple] { background-image: none; padding-right: 12px; min-height: 120px; }
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:focus-visible, select:focus-visible, textarea:focus-visible, input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--focus); outline: none; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
input[type="file"] { width: 100%; font: inherit; color: var(--text-muted); padding: 6px 0; }
input[type="file"]::file-selector-button { font: inherit; margin-right: var(--s-3); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); border-radius: var(--r-sm); padding: 6px 12px; cursor: pointer; }
input[type="color"] { width: 56px; height: 38px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; flex: none; }
.has-error input, .has-error select, .has-error textarea, [aria-invalid="true"] { border-color: var(--danger); }
.form-hint { color: var(--text-muted); font-size: var(--fs-xs); margin: var(--s-1) 0 0; }
.field-error { color: var(--danger); font-size: var(--fs-xs); margin: var(--s-1) 0 0; font-weight: 550; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s-4); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--s-4); }
.form-row-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 var(--s-4); }
.form-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; margin-top: var(--s-2); }
.check, .checkbox { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; font-size: var(--fs-base); font-weight: 450; }
.field-check { margin-bottom: var(--s-3); }
.radio-row { display: flex; gap: var(--s-4); flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch-ui { display: none; }
.switch .switch-ui { display: inline-block; width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background-color .15s; flex: none; }
.switch .switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #ffffff; box-shadow: var(--sh-sm); transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--primary); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { box-shadow: var(--focus); }
.filters, .toolbar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-bottom: var(--s-4); }
.filters input[type="text"], .filters input[type="search"], .toolbar input[type="search"] { width: auto; min-width: 200px; flex: 1 1 220px; }
.filters select, .toolbar select { width: auto; min-width: 140px; }
.filters input[type="date"], .filters input[type="tel"], .filters input[type="file"] { width: auto; }
.filters .field, .toolbar .field { margin: 0; }
.field-inline > label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.input-group { display: flex; gap: var(--s-2); }
.input-group > input { flex: 1; }
.otp-input { letter-spacing: .5em; text-align: center; font-size: var(--fs-xl); font-family: var(--mono); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: var(--fs-xs); font-family: var(--mono); cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary-text); }
.chip.copied { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-text); }
.chip .icon { width: 13px; height: 13px; }

/* Tables */
.table-wrap { position: relative; width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.table-wrap { position: relative; } /* R4-10: .sr-only header text stays inside the scrolling table (wide tables made phone pages scroll sideways) */
.card > .table-wrap { margin: 0 0 var(--s-3); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tr.selected td { background: var(--primary-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.sort-link { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.sort-link:hover { color: var(--text); text-decoration: none; }
.sort-link.active { color: var(--primary-text); }
.sort-icon { width: 13px; height: 13px; }
table .empty-row td { text-align: center; color: var(--text-muted); padding: var(--s-8); }
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--s-2) var(--s-5); margin: 0; }
.kv dt { color: var(--text-muted); font-size: var(--fs-sm); }
.kv dd { margin: 0; font-weight: 500; min-width: 0; word-break: break-word; }

/* Pagination */
.pagination-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-3); }
.pagination-bar p { margin: 0; }
.pagination { display: flex; gap: var(--s-1); align-items: center; }
.page-link { min-width: 32px; height: 32px; padding: 0 var(--s-2); display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: var(--fs-sm); }
.page-link:hover { text-decoration: none; background: var(--surface-2); }
.page-link.current { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); font-weight: 650; }
.page-link.disabled { color: var(--text-subtle); opacity: .6; }
.per-page { display: flex; align-items: center; gap: var(--s-2); margin: 0; }
.per-page select { width: auto; min-height: 32px; padding: 4px 28px 4px 10px; }

/* Tabs */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); margin-bottom: var(--s-5); overflow-x: auto; scrollbar-width: thin; }
.tab { padding: 10px 14px; color: var(--text-muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; }
.tab:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.tab.active { color: var(--primary-text); border-bottom-color: var(--primary); }

/* Empty state */
.empty-state { text-align: center; padding: var(--s-10) var(--s-6); color: var(--text-muted); }
.empty-state h3 { margin: var(--s-3) 0 var(--s-1); }
.empty-state p { max-width: 460px; margin: 0 auto; }
.empty-icon { width: 52px; height: 52px; margin: 0 auto; border-radius: 50%; background: var(--surface-2); color: var(--text-subtle); display: grid; place-items: center; }
.empty-icon .icon { width: 26px; height: 26px; }
.empty-action { margin-top: var(--s-4); display: flex; justify-content: center; gap: var(--s-2); }

/* Meters */
.meter { margin-bottom: var(--s-4); }
.meter-top { display: flex; justify-content: space-between; gap: var(--s-3); font-size: var(--fs-sm); margin-bottom: 6px; }
.meter-top span:last-child { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.meter-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.meter-bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.meter-warn .meter-bar span { background: var(--warning); }
.meter-blocked .meter-bar span { background: var(--danger); }
.meter-blocked .meter-top span:last-child { color: var(--danger); font-weight: 600; }

/* Banners and toasts */
.banner { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); margin-bottom: var(--s-4); border: 1px solid transparent; font-size: var(--fs-sm); }
.banner > .grow { flex: 1 1 240px; }
.banner-info { background: var(--info-bg); color: var(--info); }
.banner-warning { background: var(--warning-bg); color: var(--warning); }
.banner-danger { background: var(--danger-bg); color: var(--danger); }
.banner-success { background: var(--success-bg); color: var(--success); }
.banner .btn-ghost { color: inherit; }
.banner a:not(.btn) { color: inherit; text-decoration: underline; }
.toasts { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 60; display: flex; flex-direction: column; gap: var(--s-2); width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: var(--s-3); align-items: flex-start; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--r-md); padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4); box-shadow: var(--sh-lg); font-size: var(--fs-sm); animation: toast-in .2s ease-out; }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast > .icon { margin-top: 1px; }
.toast-success > .icon { color: var(--success); } .toast-error > .icon { color: var(--danger); } .toast-info > .icon { color: var(--info); } .toast-warning > .icon { color: var(--warning); }
.toast-msg { flex: 1; min-width: 0; word-break: break-word; }
.toast-close { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; padding: 2px; border-radius: var(--r-sm); line-height: 0; }
.toast-close:hover { color: var(--text); background: var(--surface-2); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Dialog */
dialog.dialog { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--sh-lg); width: min(440px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: var(--overlay); }
.dialog-body { padding: var(--s-6) var(--s-6) var(--s-4); display: flex; gap: var(--s-4); }
.dialog-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--danger-bg); color: var(--danger); display: grid; place-items: center; flex: none; }
.dialog-body h2 { font-size: var(--fs-md); margin: 0 0 var(--s-1); }
.dialog-body p { margin: 0; color: var(--text-muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-6) var(--s-5); }

/* Dropdown menus (<details>) */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 40; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-lg); padding: var(--s-1); }
.menu-panel form { margin: 0; }
.menu-item { display: flex; width: 100%; align-items: center; gap: var(--s-2); padding: 8px 10px; border-radius: var(--r-sm); color: var(--text); background: transparent; border: 0; font: inherit; font-size: var(--fs-sm); cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-item[aria-pressed="true"] { color: var(--primary-text); font-weight: 600; }
.menu-item[aria-pressed="true"]::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.menu-head { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: var(--s-1); }
.menu-head strong { display: block; }
.menu-sep { border-top: 1px solid var(--border); margin: var(--s-1) 0; }

/* App shell */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 50;
}
.sidebar-brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4); border-bottom: 1px solid var(--border); color: var(--text); min-height: var(--topbar-h); }
.sidebar-brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: var(--r-md); background: var(--primary); color: var(--primary-fg); display: grid; place-items: center; flex: none; overflow: hidden; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-mark .icon { width: 20px; height: 20px; }
.brand-text { min-width: 0; }
.brand-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-muted); display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--s-2) var(--s-3) var(--s-4); scrollbar-width: thin; }
.nav-group { margin-top: var(--s-4); }
.nav-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-subtle); font-weight: 650; padding: 0 var(--s-3); margin-bottom: var(--s-1); }
.nav-link { display: flex; align-items: center; gap: var(--s-3); padding: 7px var(--s-3); border-radius: var(--r-md); color: var(--text-muted); font-weight: 520; position: relative; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-text); font-weight: 620; }
.nav-link[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav-link .badge { margin-left: auto; }
.sidebar-footer { border-top: 1px solid var(--border); padding: var(--s-3); }
.main { margin-left: var(--sidebar-w); min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-6); background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-title { min-width: 0; flex: 1; }
.topbar-title .crumbs { font-size: var(--fs-xs); color: var(--text-subtle); display: flex; gap: 6px; align-items: center; }
.topbar-title .crumbs a { color: var(--text-subtle); }
.topbar-title strong { display: block; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: var(--s-2); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--success-bg); color: var(--success); }
.status-pill.bad { background: var(--danger-bg); color: var(--danger); }
.status-pill:hover { text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-text); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); flex: none; }
.user-chip { display: flex; align-items: center; gap: var(--s-2); padding: 3px 8px 3px 3px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); }
.user-chip:hover { background: var(--surface-2); }
.user-chip .user-name { font-weight: 550; font-size: var(--fs-sm); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-6); flex: 1; }
.drawer-toggle { display: none; }
.drawer-overlay { display: none; }
/* R1 read-only gate: expired/suspended tenants see disabled submit buttons except on allow-ro forms */
.read-only .content form:not(.allow-ro) button[type=submit] { opacity: .45; pointer-events: none; }

@media (max-width: 1023.98px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--sh-lg); }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .drawer-overlay { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 45; }
  .main { margin-left: 0; }
  .drawer-toggle { display: inline-flex; }
  .topbar { padding: 0 var(--s-4); }
  .content { padding: var(--s-4); }
  .user-chip .user-name { display: none; }
}
@media (max-width: 760px) {
  .grid-2, .grid-3, .form-row, .form-row-3, .form-row-4 { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none !important; }
  .page-header { margin-bottom: var(--s-4); }
  h1 { font-size: var(--fs-xl); }
  .status-pill .label { display: none; }
}

/* Charts */
.chart { margin: 0; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--text-subtle); font-size: 11px; font-family: var(--font); }
.chart-line { stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-s1 { color: var(--chart-1); } .chart-s2 { color: var(--chart-2); } .chart-s3 { color: var(--chart-3); } .chart-s4 { color: var(--chart-4); }
.chart-s1 .chart-line, .chart-s2 .chart-line, .chart-s3 .chart-line, .chart-s4 .chart-line, g .chart-line { stroke: currentColor; }
g[class^="chart-s"] .chart-dot { fill: var(--surface); stroke: currentColor; stroke-width: 2; }
g[class^="chart-s"] .chart-bar { fill: currentColor; }
circle.chart-s1, circle.chart-s2, circle.chart-s3, circle.chart-s4 { stroke: currentColor; }
.chart-track { stroke: var(--surface-2); }
.chart-total { fill: var(--text); font-size: 7px; font-weight: 700; font-family: var(--font); }
.chart-donut-wrap { display: flex; align-items: center; gap: var(--s-5); flex-wrap: wrap; }
.chart-donut { width: 160px; height: 160px; transform: rotate(0deg); }
.chart-legend { list-style: none; padding: 0; margin: var(--s-3) 0 0; display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--fs-sm); color: var(--text-muted); }
.chart-donut-wrap .chart-legend { flex-direction: column; margin: 0; }
.chart-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: currentColor; margin-right: 6px; vertical-align: 0; }

/* WhatsApp preview */
.wa-preview { --wa-text: var(--text); }
.wa-phone { max-width: 320px; margin: 0 auto; border: 8px solid var(--text); border-radius: 28px; overflow: hidden; background: var(--wa-chat); box-shadow: var(--sh-md); }
.wa-head { display: flex; align-items: center; gap: var(--s-2); padding: 10px 12px; background: #075e54; color: #ffffff; font-weight: 600; font-size: var(--fs-sm); }
.wa-chat { padding: var(--s-4) var(--s-3) var(--s-6); min-height: 200px; }
.wa-bubble { position: relative; background: var(--wa-bubble); color: var(--text); border-radius: 0 10px 10px 10px; padding: 6px 9px 18px; max-width: 92%; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); font-size: var(--fs-sm); word-break: break-word; }
.wa-img { display: block; border-radius: 6px; margin-bottom: 6px; max-height: 160px; object-fit: cover; width: 100%; }
.wa-time { position: absolute; right: 8px; bottom: 3px; font-size: 10px; color: var(--text-subtle); }
.wa-text code { background: transparent; padding: 0; }
.wa-mini { background: var(--wa-chat); border-radius: var(--r-md); padding: var(--s-3); }
.wa-mini .wa-bubble { max-width: 100%; max-height: 150px; overflow: hidden; }

/* QR */
.qr-box { display: inline-grid; place-items: center; padding: var(--s-3); background: #ffffff; border: 1px solid var(--border); border-radius: var(--r-md); min-width: 240px; min-height: 240px; }
.qr-box svg { width: 232px; height: 232px; display: block; }
.qr-placeholder { color: #4b5563; font-size: var(--fs-sm); text-align: center; max-width: 200px; }
.card-narrow { max-width: 640px; }
.uppercase input { text-transform: uppercase; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); font-family: var(--mono); background: var(--surface-2); padding: var(--s-3); border-radius: var(--r-md); }

/* Live chat */
.chat-wrap { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); min-height: 520px; }
.chat-list { border-right: 1px solid var(--border); overflow-y: auto; max-height: 70vh; }
.chat-list a { display: block; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); color: var(--text); }
.chat-list a:hover { background: var(--surface-2); text-decoration: none; }
.chat-list a.active, .chat-list a[aria-current="true"] { background: var(--primary-soft); }
.chat-pane { display: flex; flex-direction: column; min-width: 0; }
.chat-msgs { flex: 1; overflow-y: auto; padding: var(--s-4); background: var(--wa-chat); max-height: 60vh; min-height: 360px; display: flex; flex-direction: column; gap: var(--s-2); }
.msg { max-width: 72%; padding: 7px 10px; border-radius: 10px; background: var(--wa-bubble); color: var(--text); box-shadow: 0 1px 1px rgba(0, 0, 0, .1); white-space: pre-wrap; word-break: break-word; font-size: var(--fs-sm); }
.msg.out { align-self: flex-end; background: var(--primary-soft); }
.msg .meta { display: block; font-size: 10px; color: var(--text-subtle); margin-top: 2px; text-align: right; }
.chat-compose { display: flex; gap: var(--s-2); padding: var(--s-3); border-top: 1px solid var(--border); }
.chat-compose input { flex: 1; }
@media (max-width: 760px) { .chat-wrap { grid-template-columns: 1fr; } .chat-list { max-height: 220px; border-right: 0; border-bottom: 1px solid var(--border); } }

/* Logs and misc */
.log-tail { max-height: 420px; overflow: auto; font-family: var(--mono); font-size: var(--fs-xs); white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3); }
.review-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s-4); }
.review-item { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-4); background: var(--surface); }
.thumb { max-height: 90px; border-radius: var(--r-md); border: 1px solid var(--border); }
.step-list { list-style: none; padding: 0; margin: 0; }
.step-list li { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-2); background: var(--surface); }
.step-list .step-list { margin: var(--s-3) 0 0 var(--s-5); }
.prose { max-width: 760px; }
.prose h2 { margin-top: var(--s-8); }
.prose p, .prose li { color: var(--text-muted); }

/* Public site */
.public main { min-height: 60vh; }
.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 var(--s-6); }
.pub-nav { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); }
.pub-nav .wrap { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: 64px; }
.brand { display: flex; align-items: center; gap: var(--s-2); font-weight: 750; font-size: var(--fs-md); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .brand-mark { width: 32px; height: 32px; }
.pub-links { display: flex; align-items: center; gap: var(--s-4); }
.pub-links > a:not(.btn) { color: var(--text-muted); font-weight: 550; }
.pub-links > a:not(.btn):hover { color: var(--text); text-decoration: none; }
.hero { padding: var(--s-12) 0 var(--s-10); background: linear-gradient(180deg, var(--primary-soft), var(--bg)); }
.hero .wrap { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: var(--s-10); align-items: center; }
.hero h1 { font-size: clamp(28px, 4.2vw, 44px); letter-spacing: -.02em; margin-bottom: var(--s-4); }
.hero h1 span { color: var(--primary-text); display: block; }
.lead { font-size: var(--fs-md); color: var(--text-muted); max-width: 620px; }
.cta { display: flex; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-6); }
.hero-points { list-style: none; padding: 0; margin: var(--s-5) 0 0; display: flex; gap: var(--s-4); flex-wrap: wrap; color: var(--text-muted); font-size: var(--fs-sm); }
.hero-points li { display: flex; gap: 6px; align-items: center; }
.hero-points .icon { color: var(--primary-text); }
.section { padding: var(--s-12) 0; }
.section-alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.section-head { text-align: center; max-width: 680px; margin: 0 auto var(--s-8); }
.section-head h2 { font-size: var(--fs-3xl); letter-spacing: -.01em; }
.section-head p { color: var(--text-muted); font-size: var(--fs-md); }
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); }
.feature-icon { width: 40px; height: 40px; border-radius: var(--r-md); background: var(--primary-soft); color: var(--primary-text); display: grid; place-items: center; margin-bottom: var(--s-3); }
.feature h3 { margin-bottom: var(--s-1); }
.feature p { color: var(--text-muted); margin: 0; font-size: var(--fs-sm); }
.steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-5); counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; padding: var(--s-5); border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--bg); }
.steps li::before { content: counter(step); display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: var(--primary-fg); font-weight: 700; margin-bottom: var(--s-3); }
.steps p { color: var(--text-muted); margin: 0; font-size: var(--fs-sm); }
.cycle-toggle { display: flex; justify-content: center; margin-bottom: var(--s-6); }
.price-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--s-4); align-items: stretch; }
.price-card { position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-6); box-shadow: var(--sh-sm); }
.price-card.featured { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary), var(--sh-md); }
.price-card .ribbon { position: absolute; top: -11px; left: 50%; transform: translateX(-50%); }
.price-card h3 { font-size: var(--fs-lg); }
.price-card .desc { color: var(--text-muted); font-size: var(--fs-sm); min-height: 40px; }
.price { font-size: var(--fs-3xl); font-weight: 750; letter-spacing: -.02em; margin: var(--s-3) 0 0; }
.price small { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }
.price-note { color: var(--text-muted); font-size: var(--fs-xs); min-height: 20px; margin: var(--s-1) 0 var(--s-4); }
.price-card ul { list-style: none; padding: 0; margin: 0 0 var(--s-5); display: grid; gap: var(--s-2); font-size: var(--fs-sm); }
.price-card li { display: flex; gap: var(--s-2); align-items: flex-start; }
.price-card li .icon { color: var(--primary-text); width: 16px; height: 16px; margin-top: 2px; }
.price-card li.off { color: var(--text-subtle); }
.price-card li.off .icon { color: var(--text-subtle); }
.price-card .btn { margin-top: auto; }
.matrix th:not(:first-child), .matrix td:not(:first-child) { text-align: center; }
.matrix .icon { color: var(--primary-text); }
.matrix .no { color: var(--text-subtle); }
.faq { max-width: 760px; margin: 0 auto; }
.faq details { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); margin-bottom: var(--s-2); }
.faq summary { cursor: pointer; padding: var(--s-4); font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: var(--s-3); }
.faq summary::-webkit-details-marker { display: none; }
.faq details[open] summary .icon { transform: rotate(180deg); }
.faq details p { padding: 0 var(--s-4) var(--s-4); margin: 0; color: var(--text-muted); }
.final-cta { text-align: center; }
.pub-footer { border-top: 1px solid var(--border); background: var(--surface); padding: var(--s-8) 0; color: var(--text-muted); font-size: var(--fs-sm); }
.pub-footer .wrap { display: flex; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.pub-footer nav { display: flex; gap: var(--s-4); flex-wrap: wrap; }
.pub-footer a { color: var(--text-muted); }
@media (max-width: 900px) {
  .hero .wrap { grid-template-columns: 1fr; }
  .feature-grid, .steps { grid-template-columns: minmax(0, 1fr); }
}

/* Auth */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); }
.auth-brand { display: none; }
.auth-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--s-8) var(--s-4); gap: var(--s-4); }
.auth-top { width: 100%; max-width: 440px; display: flex; justify-content: space-between; align-items: center; }
.auth-box, .auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-8); box-shadow: var(--sh-md); }
.auth-box h1, .auth-card h1 { font-size: var(--fs-xl); }
.auth-box .sub, .auth-card .sub { color: var(--text-muted); margin-bottom: var(--s-6); }
.auth-box .alt, .auth-card .alt { text-align: center; color: var(--text-muted); font-size: var(--fs-sm); margin: var(--s-4) 0 0; }
@media (min-width: 1024px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .auth-brand { display: flex; flex-direction: column; justify-content: space-between; padding: var(--s-12); background: var(--primary); color: var(--primary-fg); }
  .auth-brand .brand, .auth-brand h2 { color: var(--primary-fg); }
  .auth-brand .brand-mark { background: var(--primary-fg); color: var(--primary); }
  .auth-brand h2 { font-size: var(--fs-3xl); letter-spacing: -.02em; max-width: 460px; }
  .auth-brand ul { list-style: none; padding: 0; margin: var(--s-6) 0 0; display: grid; gap: var(--s-3); }
  .auth-brand li { display: flex; gap: var(--s-2); align-items: center; opacity: .95; }
  .auth-brand small { opacity: .85; }
}

/* Manual-UPI review queue */
.card-accent { border-color: var(--warning); box-shadow: 0 0 0 1px var(--warning-bg), var(--sh-sm); }
.review-head { display: flex; gap: var(--s-2); align-items: baseline; }
.review-amount { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.01em; }
.review-actions { display: grid; gap: var(--s-2); margin-top: var(--s-3); }

/* Plan cards (super admin) */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s-4); }
.plan-card { display: flex; flex-direction: column; gap: var(--s-2); margin: 0; }
.plan-card.is-muted { opacity: .7; }
.plan-card-head { display: flex; justify-content: space-between; gap: var(--s-2); align-items: flex-start; }
.plan-name { font-weight: 700; font-size: var(--fs-lg); }
.plan-price { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.02em; }
.plan-limits { list-style: none; margin: var(--s-2) 0; padding: 0; display: grid; gap: var(--s-1); font-size: var(--fs-sm); }
.plan-limits li { display: flex; gap: var(--s-2); align-items: center; }
.plan-card-foot { margin-top: auto; padding-top: var(--s-3); border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.form-section { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: var(--s-5) 0 var(--s-2); }
.switch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s-2) var(--s-4); }

/* Settings page: section nav + body */
.settings-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--s-5); align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-h, 60px) + var(--s-4)); display: grid; gap: 2px; }
.settings-body > form > .card, .settings-body > .card { scroll-margin-top: 80px; }
.sticky-actions { position: sticky; bottom: 0; padding: var(--s-3) 0; background: linear-gradient(transparent, var(--bg) 40%); z-index: 2; }
.copy-row { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; margin-top: var(--s-3); }
@media (max-width: 900px) { .settings-layout { grid-template-columns: 1fr; } .settings-nav { position: static; display: flex; flex-wrap: wrap; } }

/* Tenant detail: action rows and danger zone */
.crumbs { margin-bottom: var(--s-2); color: var(--text-muted); }
.action-list { display: grid; gap: var(--s-3); }
.action-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.action-row input[type="text"] { flex: 1 1 180px; width: auto; }
.action-row select { width: auto; }
.action-row .field { margin: 0; }
.w-xs { width: 90px !important; flex: none; }
.danger-zone { margin-top: var(--s-5); padding: var(--s-4); border: 1px solid var(--danger); border-radius: var(--r-md); background: var(--danger-bg); display: grid; gap: var(--s-3); }
.danger-title { font-weight: 700; color: var(--danger); display: flex; gap: var(--s-2); align-items: center; }

/* Installer */
.install-shell { max-width: 820px; margin: 0 auto; padding: var(--s-6) var(--s-4) var(--s-10); }
.install-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s-5); }
.install-card { padding: var(--s-6); }
.install-foot { text-align: center; margin-top: var(--s-6); }
/* Developer credit (views/partials/dev-credit.php): page footer of the panels, under the auth card, installer footer */
.dev-credit { margin: 0; font-size: var(--fs-xs); color: var(--text-muted); }
.dev-credit a { color: inherit; font-weight: 600; }
.dev-credit a:hover { color: var(--text); }
footer.dev-credit { text-align: center; padding: var(--s-3) var(--s-6) var(--s-5); }
.auth-main > .dev-credit { text-align: center; }
.stepper { list-style: none; margin: 0 0 var(--s-5); padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s-2); counter-reset: step; }
.stepper-item { display: flex; flex-direction: column; align-items: center; gap: var(--s-1); text-align: center; font-size: var(--fs-sm); color: var(--text-muted); position: relative; }
.stepper-item::after { content: ""; position: absolute; top: 15px; left: calc(50% + 20px); right: calc(-50% + 20px); height: 2px; background: var(--border); }
.stepper-item:last-child::after { display: none; }
.stepper-item.is-done::after { background: var(--primary); }
.stepper-dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); border: 2px solid var(--border-strong); color: var(--text-muted); }
.stepper-item.is-current .stepper-dot { border-color: var(--primary); color: var(--primary); background: var(--surface); }
.stepper-item.is-current { color: var(--text); font-weight: 600; }
.stepper-item.is-done .stepper-dot { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.stepper-dot .icon { width: 16px; height: 16px; }
.install-success { display: flex; gap: var(--s-4); align-items: center; margin-bottom: var(--s-4); }
.install-success h1 { margin: 0; font-size: var(--fs-2xl); }
.install-success-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--success-bg); color: var(--success); flex: none; }
.install-success-icon .icon { width: 28px; height: 28px; }
.break { word-break: break-all; white-space: pre-wrap; }
@media (max-width: 640px) { .stepper-label { display: none; } }

/* Team inbox */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr) 280px; gap: var(--s-4); align-items: start; min-height: calc(100vh - 140px); }
.inbox:not(.has-thread) { grid-template-columns: 340px minmax(0, 1fr); }
.inbox > .card { margin: 0; }
.inbox-list { padding: var(--s-3); display: flex; flex-direction: column; max-height: calc(100vh - 120px); overflow: auto; }
.inbox-list .tabs { flex-wrap: wrap; }
.conv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.conv-item { display: flex; gap: var(--s-3); padding: var(--s-3); border-radius: var(--r-md); color: var(--text); }
.conv-item:hover { background: var(--surface-2); text-decoration: none; }
.conv-item.is-active { background: var(--primary-soft, var(--surface-2)); box-shadow: inset 3px 0 0 var(--primary); }
.conv-main { display: grid; gap: 2px; min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: var(--s-2); }
.conv-meta { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-muted); font-weight: 700; flex: none; }
.avatar-lg { width: 48px; height: 48px; font-size: var(--fs-lg); }
.count-pill { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: var(--primary-fg); font-size: var(--fs-xs); font-weight: 700; display: inline-grid; place-items: center; margin-left: auto; }
.inbox-thread { display: flex; flex-direction: column; padding: 0; max-height: calc(100vh - 120px); }
.thread-head { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
.thread-back { display: none; }
.thread-body { flex: 1; overflow: auto; padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); background: var(--surface-2); min-height: 320px; }
.inbox-thread:has(.composer-extras details[open]) .thread-body { min-height: 120px; }
.composer-extras { display: grid; gap: var(--s-1); max-height: 34vh; overflow-y: auto; }
.bubble-row { display: flex; }
.bubble-row.is-out { justify-content: flex-end; }
.bubble { max-width: min(72%, 560px); padding: var(--s-2) var(--s-3); border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--sh-sm); }
.bubble-row.is-out .bubble { background: var(--wa-out, #d9fdd3); color: #111b21; border-color: transparent; }
[data-theme="dark"] .bubble-row.is-out .bubble { background: #005c4b; color: #e9edef; }
.bubble-text { white-space: pre-wrap; word-wrap: break-word; }
.bubble-meta { opacity: .7; text-align: right; margin-top: 2px; }
.note-card { align-self: center; width: min(90%, 620px); background: var(--warning-bg); border: 1px dashed var(--warning); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); display: grid; gap: var(--s-1); }
.composer { border-top: 1px solid var(--border); padding: var(--s-3) var(--s-4); display: grid; gap: var(--s-2); }
.composer textarea { width: 100%; resize: vertical; }
.composer-actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; margin-top: var(--s-2); }
.note-composer textarea { width: 100%; margin: var(--s-2) 0; }
.schedule-composer .field { max-width: 320px; }
.schedule-composer summary .badge { margin-left: var(--s-1); }
.sched-list { list-style: none; margin: var(--s-2) 0; padding: 0; display: grid; gap: var(--s-2); }
.sched-item { display: flex; gap: var(--s-2); align-items: flex-start; background: var(--surface); border: 1px dashed var(--border-strong, var(--border)); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); }
.sched-item.is-failed { border-color: var(--danger); }
.sched-text { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.sched-item .tick-error { text-align: left; }
.inbox-side { display: grid; gap: var(--s-2); max-height: calc(100vh - 120px); overflow: auto; }
.side-head { display: flex; gap: var(--s-3); align-items: center; }
.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.new-msgs { position: sticky; bottom: 0; align-self: center; }
@media (max-width: 1279px) { .inbox, .inbox.has-thread { grid-template-columns: 300px minmax(0, 1fr); } .inbox-side { grid-column: 1 / -1; } }
@media (max-width: 860px) {
  .inbox, .inbox.has-thread { grid-template-columns: 1fr; }
  .inbox.has-thread .inbox-list { display: none; }
  .inbox:not(.has-thread) .inbox-thread { display: none; }
  .thread-back { display: inline-flex; }
}

/* Segment rule builder */
.rule-list { display: grid; gap: var(--s-2); margin: var(--s-3) 0; }
.rule-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: flex-start; border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); margin: 0; background: var(--surface-2); }
.rule-row .field { margin: 0; min-width: 160px; }

/* Notification bell */
.bell-btn { position: relative; }
.bell-count { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.bell-panel { width: 340px; }
.bell-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.bell-list { list-style: none; margin: 0; padding: var(--s-1) 0; max-height: 320px; overflow: auto; }
.bell-list li { display: flex; gap: var(--s-2); align-items: baseline; padding: var(--s-2) var(--s-3); font-size: var(--fs-sm); }
.bell-list li .small { display: block; }
.bell-list li.is-unread { background: var(--surface-2); }
.bell-empty { padding: var(--s-3); margin: 0; }
.bell-all { justify-content: center; border-top: 1px solid var(--border); }
.notif-list li { padding: var(--s-2) 0; border-bottom: 1px solid var(--border); }
.notif-list li.is-unread { font-weight: 560; }

.hours-table input { width: auto; }
.hours-table input[type="time"] { min-width: 110px; }

.question-box { border: 1px dashed var(--border-strong); border-radius: var(--r-md); padding: var(--s-3); margin: var(--s-3) 0; }
.question-box legend { font-weight: 600; padding: 0 var(--s-1); }

/* Getting-started checklist */
.onboard { border-color: var(--primary); }
.onboard-steps { list-style: none; margin: var(--s-3) 0 0; padding: 0; display: grid; gap: var(--s-2); }
.onboard-steps li { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-2) var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); }
.onboard-steps li .small { display: block; }
.onboard-steps li.is-done { opacity: .65; }
.onboard-steps li.is-done strong { text-decoration: line-through; }
.onboard-check { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.onboard-steps li.is-done .onboard-check { background: var(--success-bg); color: var(--success); }

.email-preview { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.email-subject { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); }
.email-preview pre { margin: 0; border: 0; background: transparent; white-space: pre-wrap; }

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-top: 1px solid var(--border); }
.alert-item:first-child { border-top: 0; }

.thumb-sm { width: 32px; height: 32px; object-fit: cover; border-radius: var(--r-sm); vertical-align: middle; }
.input-sm { width: 90px; }
.container.narrow { max-width: 560px; margin: 0 auto; padding: 0 var(--s-4); }

/* Key/value lists and plain lists */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-5); margin: 0; }
.dl dt { color: var(--text-muted); font-size: var(--fs-sm); }
.dl dd { margin: 0; }
.list-plain { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.list-plain li { display: flex; gap: var(--s-2); align-items: baseline; flex-wrap: wrap; }

/* Error page */
.error-page { min-height: 62vh; display: grid; place-items: center; padding: var(--s-12) var(--s-4); text-align: center; }
.error-card { max-width: 520px; }
.error-code { font-size: 64px; font-weight: 800; letter-spacing: -.04em; line-height: 1; color: var(--text-subtle); margin-bottom: var(--s-3); }
.error-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto var(--s-4); display: grid; place-items: center; background: var(--warning-bg); color: var(--warning); }
.error-icon .icon { width: 30px; height: 30px; }
.error-page .request-id { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-subtle); }

/* Print */
.print-body { background: #ffffff; color: #111827; margin: 24px; font-size: 13px; }
.print-body table { font-size: 13px; }
.print-body th, .print-body td { border: 1px solid #cfd4dc; background: transparent; color: #111827; text-transform: none; letter-spacing: 0; font-size: 13px; }
.noprint { margin-bottom: 16px; }

@media print {
  .noprint, .sidebar, .topbar, .toasts, .drawer-overlay, .btn, .dev-credit { display: none !important; }
  .main { margin: 0; }
  body { background: #ffffff; color: #111827; }
}

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

/* Lead pipeline Kanban (G5 #12) */
.kanban { display: flex; gap: var(--s-4); overflow-x: auto; padding-bottom: var(--s-3); align-items: flex-start; }
.kanban-col { flex: 0 0 272px; background: var(--neutral-badge-bg); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-3); min-height: 160px; }
.kanban-col.drop-over { outline: 2px dashed var(--primary); outline-offset: -4px; }
.kanban-won { border-top: 3px solid var(--success); }
.kanban-lost { border-top: 3px solid var(--border-strong); }
.kanban-open { border-top: 3px solid var(--info); }
.kanban-head { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-3); }
.kanban-head h2 { font-size: var(--fs-sm); margin: 0; flex: 1; }
.kanban-cards { display: flex; flex-direction: column; gap: var(--s-2); min-height: 80px; }
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3); box-shadow: var(--sh-sm); cursor: grab; }
.kanban-card.dragging { opacity: .5; }
.kanban-card.saving { opacity: .7; }
.kanban-card-top { display: flex; justify-content: space-between; gap: var(--s-2); }
.kanban-value { font-size: var(--fs-xs); color: var(--success); font-weight: 600; white-space: nowrap; }
.kanban-card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: var(--s-2); }
.kanban-move select { font-size: var(--fs-xs); padding: 2px 4px; max-width: 130px; }

/* Support tickets (G9 #22) */
.support-thread { display: flex; flex-direction: column; gap: var(--s-3); }
.support-msg { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3); max-width: 88%; }
.support-mine { align-self: flex-end; background: var(--primary-soft); }
.support-team { align-self: flex-start; background: var(--surface); }
.support-internal { align-self: flex-end; background: var(--warning-bg); border-style: dashed; }

/* R4-03 broadcast pro: personalisation chips, compose preview, engagement bars, A/B table */
.bp-chips { align-items: center; margin-bottom: var(--s-1); }
.bp-preview { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin-top: var(--s-4); }
.bp-preview[aria-busy="true"] .wa-text { opacity: .6; }
.bp-preview-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-2) var(--s-4); }
.bp-preview-head .section-title { margin: 0 0 var(--s-2); display: inline-flex; align-items: center; gap: var(--s-1); }
.bp-preview-head .field { margin-bottom: var(--s-3); min-width: 220px; max-width: 100%; }
.bp-preview .wa-mini { margin-bottom: var(--s-2); }
.bp-preview .wa-mini .wa-bubble { max-height: 22rem; overflow-y: auto; }
.bp-funnel { list-style: none; margin: 0 0 var(--s-3); padding: 0; display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.bp-funnel-label { display: flex; align-items: center; gap: var(--s-2); color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: var(--s-1); }
.bp-funnel-label .icon { color: var(--primary-text); width: 16px; height: 16px; }
.bp-rate { display: grid; gap: 4px; min-width: 96px; }
.bp-rate-n { font-weight: 650; font-variant-numeric: tabular-nums; }
.bp-funnel .bp-rate-n { font-size: var(--fs-lg); }
.bp-bar { display: block; height: 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bp-bar > span { display: block; height: 100%; background: var(--primary-text); border-radius: 999px; } /* contrast-checked against the track */
.bp-ctr { margin-left: auto; }
.bp-variants tbody th { background: transparent; color: var(--text); text-transform: none; letter-spacing: normal; font-size: var(--fs-sm); }
.bp-variants th[scope="row"] .badge { margin-left: var(--s-1); }
.bp-variants tr.is-current > * { background: var(--primary-soft); }
.bp-url { min-width: 13rem; max-width: 28rem; overflow-wrap: anywhere; } /* phones: the table scrolls instead of breaking every few characters */
.bp-msg { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); overflow-wrap: anywhere; }
.bp-eng .badge { margin: 0 4px 2px 0; }
/* compose switches: keep the toggle and its text apart (.field > label would make the label a block) */
.bp-compose .field-check > .switch { display: inline-flex; }
/* the visually hidden "Actions" header stays inside the scrolling table on phones (no page-wide overflow) */
.bp-table { position: relative; }
/* R4-04 analytics: filters, KPIs (3 + 3), conversion funnel, broadcast stats */
.an-filters { align-items: flex-end; }
.an-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .an-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .an-kpis { grid-template-columns: minmax(0, 1fr); } }
/* a chart's visually hidden data table ignores width: 1px (auto table layout) and widens a phone screen */
.an-chart .chart > table.sr-only { table-layout: fixed; }
.an-lead { margin: calc(-1 * var(--s-2)) 0 var(--s-4); }
.an-foot { margin: var(--s-4) 0 0; }
.funnel { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-4); }
.funnel-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); }
.funnel-name { font-weight: 600; }
.funnel-n { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }
.funnel-bar { display: block; width: 100%; height: 24px; margin: var(--s-1) 0; }
.funnel-track { fill: var(--surface-2); }
.funnel-fill { fill: currentColor; }
.funnel-meta { color: var(--text-muted); font-size: var(--fs-sm); }
.funnel-pct { color: var(--text); font-weight: 600; }
.an-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); margin: 0 0 var(--s-4); }
.an-stats > div { background: var(--surface-2); border-radius: var(--r-md); padding: var(--s-2) var(--s-3); }
.an-stats dt { color: var(--text-muted); font-size: var(--fs-xs); }
.an-stats dd { margin: 0; font-size: var(--fs-lg); font-weight: 650; font-variant-numeric: tabular-nums; }
/* R4-05 inbox routing: presence selector, first-response timers, message search, Routing & SLA page */
.presence-btn { gap: 6px; }
.presence-btn .dot { width: 9px; height: 9px; }
.presence-btn .icon { width: 14px; height: 14px; }
.presence-panel { min-width: 260px; }
.presence-panel .menu-head .small { display: block; margin-top: 2px; }
.presence-note { margin: var(--s-1) 0 0; padding: 0 10px var(--s-1); }
.presence-cell { display: inline-flex; align-items: center; gap: 6px; }
.sla-badge { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* the view tabs (overflow-x: auto) must not collapse to 0 height when a long conversation list overflows */
.inbox-list > .tabs { flex-shrink: 0; }
.inbox-search { flex-wrap: nowrap; }
.inbox-search input[type="search"] { min-width: 0; }
.inbox-search select { min-width: 0; flex: none; }
.search-count { margin: 0 var(--s-1) var(--s-2); }
.hit-snippet { color: var(--text-muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.search-hits mark, .bubble-row mark { background: var(--warning-bg); color: var(--text); border-radius: 3px; padding: 0 2px; box-shadow: inset 0 -1px 0 var(--warning); }
.bubble-row.is-hit .bubble { outline: 2px solid var(--warning); outline-offset: 2px; }
.thread-window { margin: var(--s-2) var(--s-4) 0; }
.mode-options { display: grid; gap: var(--s-2); }
.mode-options > .mode-option { display: flex; gap: var(--s-3); align-items: flex-start; margin: 0; padding: var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); font-weight: 400; cursor: pointer; }
.mode-options > .mode-option > span { display: grid; gap: 2px; }
.mode-options > .mode-option input { margin-top: 3px; }
.mode-options > .mode-option:has(input:checked) { border-color: var(--primary-text); background: var(--primary-soft); }
.mode-options > .mode-option:has(input:disabled) { cursor: not-allowed; opacity: .7; }
.cap-input { width: 130px; }
.routing-form td select { max-width: 340px; }
@media (max-width: 1023.98px) { .presence-btn .presence-text { display: none; } }
@media (max-width: 760px) {
  /* phones: only the status dot, so the page title keeps its room */
  .presence-btn { padding: 0 6px; min-width: 0; }
  .presence-btn .icon { display: none; }
  .presence-panel { position: fixed; left: var(--s-3); right: var(--s-3); top: calc(var(--topbar-h) + 4px); min-width: 0; }
}
/* R4-06 outgoing media: composer attachment, files in inbox bubbles, quick-reply attachment */
.media-attach { display: inline-flex; align-items: center; position: relative; }
.media-file-input { position: absolute; left: 0; top: 0; width: 1px !important; height: 1px; padding: 0; opacity: 0; overflow: hidden; }
.media-file-input:focus-visible + label { box-shadow: var(--focus); }
.composer-actions .media-preview, .composer-actions .media-error { order: -1; flex: 1 1 100%; }
.media-preview, .media-current { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.media-preview { padding: var(--s-2) var(--s-2) var(--s-2) var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.media-field .media-preview { margin-top: var(--s-2); }
.media-current { flex-wrap: wrap; margin-bottom: var(--s-2); }
.media-thumb { width: 44px; height: 44px; flex: none; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; overflow: hidden; color: var(--text-muted); object-fit: cover; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-preview-main { display: grid; min-width: 0; flex: 1; }
.media-preview-main .truncate { max-width: 100%; }
.media-error { color: var(--danger); margin: 0; }
.bubble-media { display: block; max-width: 100%; margin-bottom: var(--s-1); }
/* fixed boxes: the thread keeps its scroll position while files load */
.bubble-image img { display: block; width: 260px; max-width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-md); background: rgba(127, 127, 127, .12); }
.bubble-video { width: 280px; max-width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: var(--r-md); background: #000; }
.bubble-audio { width: 260px; max-width: 100%; height: 40px; }
.bubble-doc { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border-radius: var(--r-md); background: rgba(127, 127, 127, .14); color: inherit; min-width: min(220px, 100%); }
.bubble-doc:hover { text-decoration: none; background: rgba(127, 127, 127, .22); }
.bubble-doc-main { display: grid; min-width: 0; flex: 1; }
.bubble-doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble-doc-meta { font-size: var(--fs-xs); opacity: .75; }
.bubble-row.is-queued .bubble { opacity: .78; }
.canned-clip { width: 14px; height: 14px; margin-left: 4px; color: var(--text-muted); vertical-align: -2px; }
/* R4-07 quick-reply picker ("/" in the composer) and outbound status ticks */
.composer-form { position: relative; }
.canned-picker { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; max-height: min(340px, 60vh); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--sh-lg); }
.canned-picker[hidden] { display: none; }
.canned-picker-head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); }
.canned-picker-head select { max-width: 55%; min-height: 32px; }
.canned-picker-hint { min-width: 0; }
.canned-options { list-style: none; margin: 0; padding: var(--s-1); overflow-y: auto; }
.canned-option { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.canned-option[hidden] { display: none; }
.canned-option:hover, .canned-option.is-active { background: var(--primary-soft); }
.canned-option.is-active { box-shadow: inset 3px 0 0 var(--primary-text); }
.canned-option-top { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.canned-option-top code { flex: none; }
.canned-option-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canned-empty { padding: var(--s-3); margin: 0; }
.bubble-meta.has-tick { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px; }
.tick { display: inline-flex; align-items: center; color: var(--text-subtle); }
.tick .icon { width: 15px; height: 15px; }
.tick-read { color: var(--info); }
.tick-failed { color: var(--danger); }
.tick-error { color: var(--danger); margin: 4px 0 0; text-align: right; }
@media (max-width: 639.98px) {
  .canned-picker-hint { display: none; }
  .canned-picker-head select { max-width: 100%; flex: 1; }
}
/* R4-08 contacts: bulk edit bar, duplicate groups, merge table, contact timeline */
.bulk-bar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; padding: var(--s-2) var(--s-3); margin-bottom: var(--s-4); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.bulk-bar select, .bulk-bar input[type="text"] { width: auto; min-width: 130px; }
.bulk-title { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); margin-right: var(--s-1); }
.bulk-param { display: inline-flex; gap: var(--s-2); flex-wrap: wrap; }
.bulk-history { margin-left: auto; }
.contacts-list { position: relative; } /* keeps the absolutely positioned sr-only header inside the scroll area on phones */
.dup-group .card-header { margin-bottom: var(--s-3); }
.merge-table thead th { text-transform: none; letter-spacing: 0; font-size: var(--fs-sm); color: var(--text); vertical-align: top; min-width: 180px; }
.merge-table tbody th { text-transform: none; letter-spacing: 0; font-size: var(--fs-sm); background: var(--surface); white-space: normal; width: 160px; }
.merge-table thead th:first-child { min-width: 0; }
.merge-table tbody th, .merge-table thead th:first-child { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--border); } /* attribute names stay visible while the contacts scroll */
@media (max-width: 640px) { .merge-table tbody th { width: 112px; min-width: 112px; } .merge-table thead th { min-width: 150px; } }
.merge-table td { vertical-align: top; word-break: break-word; }
.merge-table .is-kept { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.merge-table .check { margin: 0; }
.merge-who { display: grid; gap: 2px; margin-bottom: var(--s-2); }
.merge-who a { color: var(--text); font-weight: 600; }
.merge-info th, .merge-info td { color: var(--text-muted); }
.merge-hint { padding: var(--s-3) var(--s-5) var(--s-4); margin: 0; }
.merge-moves { margin-bottom: var(--s-3); }
.merge-moves li .icon { color: var(--success); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.timeline > li:last-child { border-bottom: 0; }
.tl-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-muted); }
.tl-icon .icon { width: 16px; height: 16px; }
.tl-message .tl-icon, .tl-broadcast .tl-icon { background: var(--info-bg); color: var(--info); }
.tl-order .tl-icon, .tl-payment .tl-icon { background: var(--success-bg); color: var(--success); }
.tl-booking .tl-icon, .tl-csat .tl-icon { background: var(--warning-bg); color: var(--warning); }
.tl-stage .tl-icon, .tl-merge .tl-icon { background: var(--surface); color: var(--primary-text); box-shadow: inset 0 0 0 1.5px var(--primary); }
.tl-conversation .tl-icon { background: var(--neutral-badge-bg); color: var(--neutral-badge); }
.tl-head { display: flex; gap: var(--s-2); align-items: baseline; flex-wrap: wrap; }
.tl-title { font-weight: 560; color: var(--text); }
.tl-time { margin-left: auto; font-size: var(--fs-xs); color: var(--text-subtle); white-space: nowrap; }
.tl-text { margin: 2px 0 0; color: var(--text-muted); font-size: var(--fs-sm); white-space: pre-line; word-break: break-word; }
.tl-meta { margin: 2px 0 0; color: var(--text-subtle); font-size: var(--fs-xs); }
.tl-pager { margin-top: var(--s-4); justify-content: center; }
.bulk-review .lead { color: var(--text); font-weight: 600; }
/* R4-14 number health */
.nh-score { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-2) 0 var(--s-3); }
.nh-score-value { font-size: var(--fs-3xl); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.nh-score-max { color: var(--text-muted); font-size: var(--fs-sm); margin-right: var(--s-2); }
.nh-good .nh-score-value { color: var(--success); }
.nh-warn .nh-score-value { color: var(--warning); }
.nh-bad .nh-score-value { color: var(--danger); }
.nh-tips { margin: var(--s-1) 0 0; padding-left: 1.1em; }
.nh-tips li { margin-bottom: var(--s-1); }
.nh-tip { margin-top: var(--s-1); font-weight: 600; }
/* R4-17 custom roles: permission editor and number checkboxes (label.check is a direct child of .field, which makes it a
   block); role tables keep their visually hidden headers inside the scroll box so phones do not scroll sideways. */
.perm-section .field-check > label.check, [data-access-numbers] .field-check > label.check { display: inline-flex; align-items: flex-start; gap: var(--s-2); font-weight: 450; }
.perm-section .field-check > label.check input, [data-access-numbers] .field-check > label.check input { margin-top: 3px; }
.perm-section .field-check > .form-hint { padding-left: 24px; }
[data-access-numbers] input:disabled ~ span { color: var(--text-muted); }
.r4-roles-table { position: relative; }
.r4-roles-table td.actions { flex-wrap: wrap; }
.r4-access { display: flex; align-items: center; gap: var(--s-1); margin-top: var(--s-1); white-space: nowrap; }
.r4-access .btn-icon { min-height: 26px; }
/* R4-19: a switch inside .field keeps its inline-flex layout (.field > label would make it a block: no gap before the text) */
.field > label.switch { display: inline-flex; }
/* R4-20 tenant health: long headers wrap; the reasons of a workspace sit in a full-width row under it */
.health-table th { white-space: normal; }
.health-table tr.has-reasons > td { border-bottom: 0; }
.health-table tr.health-reasons > td { padding-top: 0; color: var(--text-muted); font-size: var(--fs-xs); }
/* cPanel setup (super admin): one row per hosting setting; data-status (ok|warn|fail|info) picks the icon and colour */
.setup-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.setup-item { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); }
.setup-item[data-status="fail"] { border-color: var(--danger); }
.setup-check { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--text-muted); }
.setup-check .icon { display: none; }
.setup-item[data-status="ok"] .setup-check { background: var(--success-bg); color: var(--success); }
.setup-item[data-status="warn"] .setup-check { background: var(--warning-bg); color: var(--warning); }
.setup-item[data-status="fail"] .setup-check { background: var(--danger-bg); color: var(--danger); }
.setup-item[data-status="ok"] .si-ok, .setup-item[data-status="warn"] .si-warn, .setup-item[data-status="fail"] .si-fail, .setup-item[data-status="info"] .si-info { display: block; }
.setup-body { flex: 1; min-width: 0; }
.setup-head { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; justify-content: space-between; }
.setup-detail { margin-top: var(--s-1); word-break: break-word; }
.setup-guide { margin-top: var(--s-2); }
.setup-guide summary { cursor: pointer; color: var(--primary-text); }
.setup-steps { margin: var(--s-2) 0; padding-left: 1.4em; display: grid; gap: var(--s-1); }
.setup-steps code, .setup-copy code, .setup-quick code { word-break: break-all; }
.setup-copy { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-top: var(--s-2); }
.setup-copy .small { min-width: 90px; }
/* Cron setup: Run now buttons and the last output of a job; Node.js setup: numbered steps, the next one marked */
.setup-actions { margin-top: var(--s-2); }
.setup-out-title { margin-top: var(--s-3); }
.setup-out { max-height: 220px; margin-top: var(--s-1); }
.setup-num .setup-n { font-weight: 700; font-size: var(--fs-sm); line-height: 1; }
.setup-item[data-status="ok"] .setup-num .setup-n { display: none; }
.setup-item[data-current] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
/* Node.js setup complete: the green screen */
.setup-done { display: flex; gap: var(--s-5); align-items: center; background: var(--success-bg); border-color: var(--success); padding: var(--s-6); }
.setup-done-icon { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--success); color: var(--success-bg); }
.setup-done-icon .icon { width: 40px; height: 40px; }
.setup-done h2 { margin: 0 0 var(--s-1); font-size: var(--fs-2xl); color: var(--success); }
.setup-done p { margin: 0 0 var(--s-2); }
.setup-done-detail { font-family: var(--mono); word-break: break-word; }
@media (max-width: 639.98px) {
  .setup-quick { grid-template-columns: 1fr; }
  .setup-quick dd { margin-bottom: var(--s-2); }
  .setup-done { flex-direction: column; text-align: center; }
  .setup-done .action-row { justify-content: center; }
}
/* Guide (app/guide.php, superadmin/guide.php): search, category chips, getting started and one <details> per feature */
.guide-tools { display: grid; gap: var(--s-3); }
.guide-search { display: flex; align-items: center; gap: var(--s-2); }
.guide-search .icon { color: var(--text-muted); flex: none; }
.guide-search input { flex: 1; min-width: 0; }
.guide-cats .chip { font-family: inherit; font-size: var(--fs-sm); padding: 4px 12px; text-decoration: none; }
.guide-cats .chip .icon { width: 15px; height: 15px; }
.guide-start, .guide-cat, .guide-item { scroll-margin-top: calc(var(--topbar-h) + var(--s-4)); }
.guide-start-steps .action-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; justify-content: flex-end; }
.guide-n { font-weight: 700; font-size: var(--fs-sm); line-height: 1; }
.guide-cat-title { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); font-size: var(--fs-lg); margin: 0 0 var(--s-3); }
.guide-cat-title .small { font-weight: 400; }
.guide-cat { margin-bottom: var(--s-6); }
.guide-list { display: grid; gap: var(--s-2); }
.guide-ui { font-weight: 650; }
.guide-item { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.guide-item[open] { border-color: var(--primary); box-shadow: var(--sh-sm); }
.guide-item > summary { list-style: none; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); cursor: pointer; border-radius: var(--r-md); }
.guide-item > summary::-webkit-details-marker { display: none; }
.guide-item > summary:hover { background: var(--surface-2); }
.guide-item > summary:focus-visible { outline: none; box-shadow: var(--focus); }
.guide-icon { width: 36px; height: 36px; border-radius: var(--r-md); display: grid; place-items: center; flex: none; background: var(--primary-soft); color: var(--primary-text); }
.guide-head { flex: 1; min-width: 0; }
.guide-head .small { display: block; margin-top: 2px; }
.guide-chev { flex: none; color: var(--text-muted); transition: transform .15s ease; }
.guide-item[open] .guide-chev { transform: rotate(180deg); }
.guide-body { padding: 0 var(--s-4) var(--s-4) calc(36px + var(--s-3) + var(--s-4)); }
.guide-h { display: flex; align-items: center; gap: 6px; margin: 0 0 var(--s-2); font-size: var(--fs-sm); font-weight: 650; }
.guide-steps { font-size: var(--fs-sm); margin-top: 0; }
.guide-steps code, .guide-example code, .guide-tip code { word-break: break-word; }
.guide-example { margin-top: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--info-bg); font-size: var(--fs-sm); }
.guide-example .guide-h { color: var(--info); }
.guide-tip { display: flex; align-items: flex-start; gap: 6px; margin: var(--s-3) 0 0; }
.guide-tip .icon { flex: none; margin-top: 1px; color: var(--text-muted); }
.guide-plan { margin: var(--s-3) 0 0; }
.guide-actions { margin-top: var(--s-3); }
.guide-item.is-target { animation: guide-target 1.8s ease; }
@keyframes guide-target { from { box-shadow: 0 0 0 4px var(--primary-soft); } to { box-shadow: var(--sh-sm); } }
@media (max-width: 760px) {
  .guide-body { padding-left: var(--s-4); }
  .topbar-guide .label { display: none; }
}
/* small phones: the top bar keeps every control (with the guide's "How it works" icon) without scrolling sideways */
@media (max-width: 420px) {
  .topbar { gap: var(--s-2); padding: 0 var(--s-3); }
  .topbar-right { gap: 2px; }
  .user-chip { padding-right: 3px; }
  .user-chip > .icon { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .guide-chev { transition: none; }
  .guide-item.is-target { animation: none; }
}
/* Updates (one-click update): the steps, the output and the release notes */
.update-steps { list-style: none; margin: 0 0 var(--s-3); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--fs-sm); }
.update-steps li { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.update-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); flex: none; }
.update-steps li[data-state="done"] { color: var(--success); }
.update-steps li[data-state="done"] .update-dot { background: var(--success); }
.update-steps li[data-state="current"] { color: var(--primary-text); font-weight: 650; }
.update-steps li[data-state="current"] .update-dot { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.update-steps li[data-state="failed"] { color: var(--danger); font-weight: 650; }
.update-steps li[data-state="failed"] .update-dot { background: var(--danger); }
.update-log { max-height: 260px; }
.update-title { font-size: var(--fs-md); margin: 0 0 var(--s-1); }
.release-notes { white-space: pre-wrap; max-height: 320px; overflow: auto; font-size: var(--fs-sm); }

/* R5 #9 festival calendar (app/occasions.php) and the broadcast page's upcoming occasions */
.occ-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s-4); align-items: start; }
.occ-remind { position: sticky; top: var(--s-4); }
.occ-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.occ-item { display: flex; gap: var(--s-3); align-items: flex-start; padding-top: var(--s-3); border-top: 1px solid var(--border); }
.occ-item:first-child { border-top: 0; padding-top: 0; }
.occ-date { display: grid; justify-items: center; min-width: 48px; padding: var(--s-1); border-radius: var(--r-md); background: var(--surface-2); }
.occ-day { font-size: var(--fs-lg, 1.25rem); font-weight: 700; line-height: 1.1; }
.occ-name { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-2); align-items: center; }
.occ-soon .card-title a { margin-left: auto; font-weight: 500; }
.occ-soon-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s-2) var(--s-4); }
.occ-soon-list li { display: flex; gap: var(--s-2); align-items: center; padding: var(--s-2) var(--s-3); border: 1px solid var(--border); border-radius: var(--r-md); }
.occ-prefill { flex-wrap: nowrap; }
@media (max-width: 960px) { .occ-layout { grid-template-columns: 1fr; } .occ-remind { position: static; } }
