/* SMAP Central Ticketing System — prototype styles
   Light SaaS helpdesk theme. Tokens first, then base, components, layouts, pages. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-ring: rgba(37, 99, 235, .25);

  --navy: #0b1530;
  --navy-2: #121f42;
  --navy-text: #c7d2fe;
  --navy-muted: #8b98c2;

  --success: #16a34a; --success-soft: #dcfce7; --success-text: #15803d;
  --warning: #d97706; --warning-soft: #fef3c7; --warning-text: #b45309;
  --indigo: #4f46e5;
  --danger: #dc2626;  --danger-soft: #fee2e2; --danger-text: #b91c1c;
  --violet: #7c3aed;  --violet-soft: #ede9fe; --violet-text: #6d28d9;
  --slate-soft: #e2e8f0;

  --note-bg: #fffbeb;
  --note-border: #fcd34d;
  --note-text: #92400e;

  /* Ticket thread cards (ui/conversation.js). Customer = blue, support reply = green. */
  --msg-customer-bg: #eff6ff;
  --msg-customer-border: #bfdbfe;
  --msg-reply-bg: #f0fdf4;
  --msg-reply-border: #bbf7d0;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .16);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 56px;
  --banner-h: 0px;
  color-scheme: light;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--bg);
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
.icon { flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 550; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--faint); }
.btn-outline { background: var(--surface); border-color: var(--primary); color: var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-soft); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-note { background: #b45309; color: #fff; }
.btn-note:hover:not(:disabled) { background: #92400e; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14.5px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--muted); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }
.link-btn:hover { text-decoration: underline; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.req { color: var(--danger); }
.input, .field input:not([type]), .field input[type="text"], .field input[type="email"], .field input[type="search"], .field input[type="tel"], .field input[type="url"], .field input[type="password"], .field input[type="number"], .field input[type="date"], .field input[type="datetime-local"], .field input[type="time"], .field input[type="month"], .field input[type="week"], .field textarea, .select-wrap select {
  width: 100%; height: 38px; min-height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
  color-scheme: light;
}
.field textarea, textarea.input { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.field input[type="date"], .field input[type="datetime-local"], .field input[type="time"], .field input[type="month"], .field input[type="week"] { line-height: 1.5; }
.field input[type="number"] { font-variant-numeric: tabular-nums; }
.field input[type="date"]::-webkit-calendar-picker-indicator,
.field input[type="datetime-local"]::-webkit-calendar-picker-indicator,
.field input[type="time"]::-webkit-calendar-picker-indicator,
.field input[type="month"]::-webkit-calendar-picker-indicator,
.field input[type="week"]::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }
.field input[type="date"]::-webkit-calendar-picker-indicator:hover,
.field input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
.field input[type="time"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.input::placeholder, input::placeholder, textarea::placeholder { color: var(--faint); }
.input:focus, .field input:focus, .field textarea:focus, .select-wrap select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring);
}
.input:disabled, .field input:disabled, .field textarea:disabled { background: var(--surface-3); color: var(--muted); cursor: not-allowed; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--danger); }
.field.has-error input:focus, .field.has-error textarea:focus, .field.has-error select:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .18); }
.hint { font-size: 12px; color: var(--muted); }
.error-text { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--danger-text); }
.select-wrap { position: relative; }
.select-wrap select { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer; }
.select-wrap select:disabled { background: var(--surface-3); cursor: not-allowed; color: var(--muted); }
.select-caret { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--muted); }
.select-wrap.sm select { height: 34px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-error-summary {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger-text); font-size: 13px;
}
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.search-input { position: relative; display: flex; align-items: center; }
.search-input .icon { position: absolute; left: 11px; color: var(--faint); pointer-events: none; }
.search-input input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.search-input input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }

/* dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px; text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragging, .dropzone:focus-within { border-color: var(--primary); background: var(--primary-soft); }
.dropzone strong { color: var(--text-2); font-weight: 600; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* files */
.file-list { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px; max-width: 260px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.file-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: var(--surface-3); color: var(--muted); }
.file-icon.is-image { background: var(--primary-soft); color: var(--primary); }
.file-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.file-name { font-size: 12.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 11.5px; color: var(--muted); }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-open { background: var(--primary-soft); color: #1d4ed8; }
.status-in_progress { background: var(--violet-soft); color: var(--violet-text); }
.status-pending_customer { background: var(--warning-soft); color: var(--warning-text); }
.status-resolved { background: var(--success-soft); color: var(--success-text); }
.status-closed { background: var(--slate-soft); color: #475569; }
.priority-low { background: var(--surface-3); color: #475569; }
.priority-medium { background: var(--warning-soft); color: var(--warning-text); }
.priority-high { background: #ffedd5; color: #c2410c; }
.priority-critical { background: var(--danger-soft); color: var(--danger-text); }
.priority-critical::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.role-badge { background: var(--surface-3); color: var(--text-2); }
.role-admin { background: var(--primary-soft); color: #1d4ed8; }
.role-technical { background: var(--violet-soft); color: var(--violet-text); }
.role-cs { background: #ccfbf1; color: #0f766e; }
.active-badge { background: var(--success-soft); color: var(--success-text); }
.inactive-badge { background: var(--surface-3); color: var(--muted); }
.note-badge { background: var(--note-bg); color: var(--note-text); border: 1px solid var(--note-border); }

.sla { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.sla-on_track { color: var(--success-text); }
.sla-at_risk { color: var(--warning-text); }
.sla-overdue, .sla-breached { color: var(--danger-text); }
.sla-paused, .sla-met { color: var(--muted); }

.product-tag { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.product-swatch { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: #6366f1; color: #fff; font-size: 12.5px; font-weight: 700; flex-shrink: 0; letter-spacing: .02em;
}
.avatar.team { background: var(--primary); }
.avatar.note { background: #b45309; outline: 2px solid #b45309; outline-offset: 1px; } /* the user's colour comes inline; the ring marks a note */
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }

/* Avatar colour picker: radio swatches, the checked one gets a ring */
.avatar-picker { border: 0; margin: 0; padding: 0; min-width: 0; }
.avatar-picker legend { font-size: 13px; font-weight: 600; margin-bottom: 8px; padding: 0; }
.swatch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; }
.swatch { position: relative; display: inline-grid; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.swatch-dot { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; font-size: 12px; font-weight: 700; border: 1px solid rgba(0, 0, 0, .08); }
.swatch input:checked + .swatch-dot { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatch input:focus-visible + .swatch-dot { outline: 2px solid var(--primary); outline-offset: 3px; }

/* ------------------------------------------------------------------ cards / misc */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; }
.card-body { padding: 16px 18px; }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 36px 16px; }
.empty-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-3); color: var(--muted); margin-bottom: 4px; }
.empty-title { font-weight: 650; color: var(--text); }
.empty-state .btn { margin-top: 8px; }

.proto-note {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px dashed var(--border-strong); color: var(--muted); font-size: 12.5px;
}
.proto-note .icon { margin-top: 2px; color: var(--primary); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 13px; }
.alert-error { background: var(--danger-soft); color: var(--danger-text); }
.alert-info { background: var(--primary-soft); color: #1e40af; }
.alert-warn { background: var(--warning-soft); color: var(--warning-text); }
.alert .icon { margin-top: 2px; }

dl.meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 20px; margin: 0; }
dl.meta dt { font-size: 12px; color: var(--muted); }
dl.meta dd { margin: 2px 0 0; font-weight: 600; font-size: 13px; }
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; color: var(--text); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* prototype banner */
.proto-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  min-height: var(--banner-h); padding: 4px 16px; background: #1e293b; color: #e2e8f0; font-size: 12px; text-align: center;
}
.proto-banner strong { color: #fff; }
.proto-banner a { color: #93c5fd; font-weight: 600; }
/* only mock mode renders the prototype banner; api mode keeps --banner-h at 0 */
:root:has(.proto-banner) { --banner-h: 30px; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2);
  padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.table .cell-sub { display: block; font-size: 12px; color: var(--muted); }
.table .ticket-link { font-weight: 600; color: var(--primary); white-space: nowrap; }
.table .subject { font-weight: 550; color: var(--text); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.table .clip { display: block; max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table td.nowrap { white-space: nowrap; }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.page-btn {
  min-width: 30px; height: 30px; padding: 0 8px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; display: grid; place-items: center; font-size: 13px; color: var(--text-2);
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .45; cursor: not-allowed; }
.page-gap { padding: 0 4px; color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 10px 12px; border: 0; background: none; cursor: pointer; font-weight: 550; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count { font-size: 11.5px; background: var(--surface-3); color: var(--muted); padding: 0 6px; border-radius: 999px; }
.tab[aria-selected="true"] .count { background: var(--primary-soft); color: var(--primary); }

/* ------------------------------------------------------------------ conversation */
.thread { display: flex; flex-direction: column; }
.msg { display: flex; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.msg-author { font-weight: 650; font-size: 13.5px; }
.msg-time { font-size: 12px; color: var(--muted); }
.msg-text { color: var(--text-2); overflow-wrap: anywhere; }
.msg .file-list { margin-top: 10px; }
.msg.is-note {
  background: var(--note-bg); border: 1px solid var(--note-border); border-radius: var(--radius);
  padding: 12px 14px; margin: 10px 0;
}
.msg.is-note .msg-text { color: var(--note-text); }
.msg-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }

/* composer */
.composer { border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.composer:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.composer textarea { width: 100%; border: 0; min-height: 96px; padding: 12px 14px; resize: vertical; outline: none; background: transparent; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.composer-files { padding: 0 12px 10px; }
.composer.mode-note { border-color: var(--note-border); background: var(--note-bg); }
.composer.mode-note:focus-within { box-shadow: 0 0 0 3px rgba(217, 119, 6, .2); border-color: #d97706; }
.composer.mode-note .composer-foot { background: #fef3c7; border-top-color: var(--note-border); }
.composer-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.composer-tab {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted);
}
.composer-tab[aria-selected="true"].reply { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.composer-tab[aria-selected="true"].note { background: var(--note-bg); border-color: #d97706; color: var(--note-text); }
.composer-hint { font-size: 12px; display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.composer-hint.reply { color: var(--muted); }
.composer-hint.note { color: var(--note-text); }
.attach-btn input { display: none; }

/* timeline (history) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { display: block; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ toasts */
.toasts { position: fixed; right: 16px; top: calc(var(--banner-h) + var(--topbar-h) + 12px); display: flex; flex-direction: column; gap: 8px; z-index: 1000; max-width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: none; /* clicks pass through to the page; only Dismiss is clickable */
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-radius: var(--radius);
  background: #0f172a; color: #f8fafc; box-shadow: var(--shadow-lg); font-size: 13px; animation: toast-in .2s ease-out;
}
.toast .icon-btn { color: #94a3b8; margin-left: auto; pointer-events: auto; }
.toast .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.toast-success > .icon { color: #4ade80; }
.toast-error > .icon { color: #f87171; }
.toast-info > .icon { color: #93c5fd; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ modal */
dialog.modal {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); color: var(--text); background: var(--surface); display: flex; flex-direction: column;
}
dialog.modal:not([open]) { display: none; }
dialog.modal.sm { width: min(420px, calc(100vw - 32px)); }
dialog.modal.lg { width: min(720px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ------------------------------------------------------------------ menus / popovers */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 60; padding: 6px;
}
.menu-label { padding: 6px 10px 4px; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px;
  cursor: pointer; text-align: left; font-size: 13px; color: var(--text-2); text-decoration: none !important;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); color: var(--text); }
.menu-item.is-current { background: var(--primary-soft); color: var(--primary); }
.menu-item .grow { flex: 1; min-width: 0; }
.notif-item { align-items: flex-start; }
.notif-item .icon { margin-top: 2px; color: var(--primary); }

/* =================================================================== PORTAL */
.portal { min-height: 100vh; display: flex; flex-direction: column; }
.portal-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.portal-header-inner { max-width: 1080px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; color: var(--text); text-decoration: none !important; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 2px; }
.portal-nav { display: flex; gap: 4px; margin-left: auto; }
.portal-nav a {
  padding: 7px 12px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 550; font-size: 13.5px; text-decoration: none;
}
.portal-nav a:hover { background: var(--surface-3); }
.portal-nav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.portal-menu-btn { display: none; margin-left: auto; }
.portal-main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 16px 48px; }
.portal-main.narrow { max-width: 640px; }
.portal-main.medium { max-width: 1080px; }
.portal-footer { border-top: 1px solid var(--border); background: var(--surface); }
.portal-footer-inner { max-width: 1080px; margin: 0 auto; padding: 14px 16px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }

.hero {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 24px; padding: 24px 28px; margin-bottom: 20px;
  background: linear-gradient(120deg, #eff6ff 0%, #f5f3ff 100%); border: 1px solid #dbeafe; border-radius: var(--radius-lg);
}
.hero h1 { font-size: 26px; letter-spacing: -.02em; }
.hero p { color: var(--text-2); margin-top: 6px; max-width: 520px; }
.hero-art { display: grid; place-items: center; width: 92px; height: 92px; border-radius: 24px; background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.hero-products { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.hero-products .product-tag { background: #fff; border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; }

.success-mark { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%; background: var(--success); color: #fff; margin: 0 auto 14px; box-shadow: 0 0 0 8px var(--success-soft); }
.summary-table { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); border-collapse: separate; border-spacing: 0; overflow: hidden; font-size: 13.5px; }
.summary-table th, .summary-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.summary-table tr:last-child th, .summary-table tr:last-child td { border-bottom: 0; }
.summary-table th { width: 38%; background: var(--surface-2); color: var(--muted); font-weight: 550; }
.ticket-id-big { color: var(--primary); font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.step { text-align: center; padding: 14px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 12.5px; color: var(--text-2); }
.step-num { display: grid; place-items: center; width: 26px; height: 26px; margin: 0 auto 8px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 12.5px; }
.info-box { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--radius); background: var(--primary-soft); border: 1px solid #dbeafe; }
.info-box .info-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #6366f1; color: #fff; flex-shrink: 0; }
.info-box p { font-size: 13px; color: var(--text-2); }

.ticket-card-list { display: flex; flex-direction: column; }
.ticket-card {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 14px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); color: inherit; text-decoration: none !important; border-left: 3px solid transparent;
}
.ticket-card:hover { background: var(--surface-2); border-left-color: var(--primary); }
.ticket-card:last-child { border-bottom: 0; }
.ticket-card .tc-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); }
.ticket-card .tc-id { font-weight: 700; font-size: 13.5px; color: var(--text); }
.ticket-card .tc-sub { color: var(--text-2); font-size: 13px; }
.ticket-card .tc-meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.ticket-card > .icon { color: var(--faint); }

.demo-box { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border-strong); font-size: 12.5px; color: var(--muted); }
.demo-box ul { margin: 6px 0 0; padding-left: 18px; }
.demo-box button { font-size: 12.5px; }

/* =================================================================== TEAM */
.team-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: calc(100vh - var(--banner-h)); transition: grid-template-columns .2s; }
.team-shell.collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
.sidebar-col { background: var(--navy); min-width: 0; }
.sidebar {
  background: var(--navy); color: var(--navy-text); display: flex; flex-direction: column; position: sticky; top: 0; height: calc(100vh - var(--banner-h)); overflow: hidden;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: var(--topbar-h); padding: 0 12px 0 16px; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.sidebar .brand { color: #fff; font-size: 17px; }
.sidebar-toggle { color: var(--navy-muted); }
.sidebar-toggle:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--navy-text);
  font-weight: 500; font-size: 13.5px; text-decoration: none !important; white-space: nowrap;
}
.nav-item:hover { background: var(--navy-2); color: #fff; }
.nav-item[aria-current="page"] { background: var(--primary); color: #fff; }
.nav-item .nav-count { margin-left: auto; font-size: 11px; font-weight: 700; background: rgba(255, 255, 255, .14); padding: 0 7px; border-radius: 999px; }
.nav-parent .nav-caret { margin-left: auto; transition: transform .15s; opacity: .7; }
.nav-parent.is-open { color: #fff; }
.nav-parent.is-open .nav-caret { transform: rotate(180deg); }
.nav-sub { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 4px; }
.nav-sub[hidden] { display: none; }
.nav-child { padding: 7px 10px 7px 39px; font-size: 13px; }
.settings-tabs { display: none; gap: 4px; flex-wrap: wrap; }
.settings-tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 550; text-decoration: none; }
.settings-tabs a[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: #fff; }
/* Roles matrix: fixed layout so every role column is exactly as wide as the others; the capability column keeps a fixed share.
   Narrow screens scroll the table inside .table-wrap instead of squeezing the columns. */
.roles-matrix { table-layout: fixed; min-width: 600px; }
.roles-matrix col.roles-cap { width: 34%; }
.roles-matrix th, .roles-matrix td { overflow-wrap: anywhere; position: relative; } /* relative: keeps the .sr-only texts inside the scrolling wrapper */
.table.roles-matrix th.roles-role, .table.roles-matrix td.roles-check { text-align: center; padding-inline: 8px; }
.roles-matrix th.roles-role { white-space: normal; }
.roles-matrix .roles-role-name, .roles-matrix .roles-role a, .roles-matrix .roles-role .btn { display: block; margin-inline: auto; }
.roles-matrix .roles-role a { margin-top: 2px; font-weight: 500; }
.roles-matrix .roles-role .btn { margin-top: 8px; width: fit-content; }
.perm-list { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.perm-row .hint { margin: 2px 0 0 24px; }
.th-sort { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; font: inherit; font-weight: 600; color: inherit; cursor: pointer; }
.th-sort:hover, .th-sort.is-active { color: var(--text); }
.th-sort .th-sort-icon { opacity: .35; transition: transform .15s; }
.th-sort.is-active .th-sort-icon { opacity: 1; }
.th-sort.is-asc .th-sort-icon { transform: rotate(180deg); }
.is-loading { opacity: .6; transition: opacity .15s; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .06); font-size: 11.5px; color: var(--navy-muted); }
.sidebar-foot a { color: #93c5fd; }
.team-shell.collapsed .nav-label, .team-shell.collapsed .nav-count, .team-shell.collapsed .brand-text, .team-shell.collapsed .sidebar-foot { display: none; }
.team-shell.collapsed .sidebar-head { justify-content: center; padding: 0; }
.team-shell.collapsed .sidebar-head .brand { display: none; }
.team-shell.collapsed .nav-item { justify-content: center; padding: 10px 0; }
.team-shell.collapsed .nav-sub, .team-shell.collapsed .nav-caret { display: none; }

.team-main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40;
}
.topbar .search-input { width: min(420px, 100%); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.notif-dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.profile-btn { display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px; border: 0; background: none; border-radius: var(--radius); cursor: pointer; text-align: left; }
.profile-btn:hover { background: var(--surface-3); }
.profile-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.profile-role { font-size: 11.5px; color: var(--muted); }

.page { padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 3px; }
[data-body] { display: flex; flex-direction: column; gap: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 550; margin-bottom: 6px; }
.back-link:hover { color: var(--primary); text-decoration: none; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.filters .search-input { flex: 1 1 240px; max-width: 340px; }
.filters .select-wrap { flex: 0 1 150px; }
.filters .select-wrap select { height: 36px; font-size: 13px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 14px 16px; border-left: 3px solid var(--border); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.kpi-value { font-size: 26px; font-weight: 750; margin-top: 2px; letter-spacing: -.02em; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi.total { border-left-color: var(--text); }
.kpi.open { border-left-color: var(--primary); }
.kpi.in_progress { border-left-color: var(--violet); }
.kpi.pending_customer { border-left-color: var(--warning); }
.kpi.resolved { border-left-color: var(--success); }
a.kpi { color: inherit; text-decoration: none; }
a.kpi:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; }
.dash-grid-3 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 28px; padding: 18px 20px; flex-wrap: wrap; }
.donut { position: relative; width: 168px; height: 168px; flex-shrink: 0; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .seg { cursor: pointer; transition: opacity .15s; }
.donut:hover .seg { opacity: .55; }
.donut .seg:hover, .donut .seg:focus { opacity: 1; outline: none; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center strong { font-size: 26px; font-weight: 750; line-height: 1; }
.donut-center span { font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 180px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .val { margin-left: auto; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.legend .pct { width: 42px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-tip { position: fixed; pointer-events: none; background: #0f172a; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; z-index: 100; box-shadow: var(--shadow-lg); }

/* bars */
.bars { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { display: block; height: 10px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 0 4px 4px 0; }
.bar-row .val { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li a { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.mini-list li:last-child a { border-bottom: 0; }
.mini-list li a:hover { background: var(--surface-2); }
.mini-list .mini-id { font-weight: 650; font-size: 13px; }
.mini-list .mini-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.focus-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.focus-tile { display: flex; flex-direction: column; padding: 10px 14px; border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none; }
.focus-tile:hover { box-shadow: var(--shadow); }
.focus-tile.late.has { border-left-color: var(--danger); background: var(--danger-soft); }
.focus-tile.late.has .kpi-value { color: var(--danger-text); }
.focus-tile.risk.has { border-left-color: var(--warning); background: var(--warning-soft); }
.focus-tile.risk.has .kpi-value { color: var(--warning-text); }
.focus-tile.urgent.has { border-left-color: var(--primary); }
.focus-tile.owner.has { border-left-color: var(--violet); }
.focus-list .focus-row a { grid-template-columns: minmax(0, 1fr) auto 84px; }
.focus-row .mini-id { color: var(--indigo); }
.focus-badges { display: flex; align-items: center; gap: 10px; }
.focus-owner { font-size: 12px; color: var(--text-2); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focus-owner.none { color: var(--danger-text); font-weight: 600; }
.mini-list .mini-time { font-size: 12px; color: var(--muted); width: 58px; text-align: right; }

/* portal ticket view */
.td-subject { color: var(--text-2); margin-top: 4px; font-size: 14px; }

/* ticket queue (list + detail pane) */
.page.page-queue { padding: 0; gap: 0; }
.queue { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); height: calc(100vh - var(--topbar-h) - var(--banner-h)); }
.q-list { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--surface); }
.q-head { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 0; border-bottom: 1px solid var(--border); }
.q-title { font-size: 18px; }
.q-title span { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.q-focus { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; }
.q-focus[hidden] { display: none; }
.q-focus-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.q-focus-toggle { display: inline-flex; align-items: center; gap: 5px; margin-right: auto; padding: 2px 0; border: 0; background: none; color: var(--danger-text); font-size: 13px; font-weight: 700; cursor: pointer; }
.q-focus-toggle[aria-expanded="true"] .q-focus-caret { transform: rotate(180deg); }
.q-focus-chip { padding: 2px 9px; border-radius: 999px; border: 1px solid transparent; font-size: 12px; font-weight: 650; cursor: pointer; }
.q-focus-chip.late { background: var(--danger-soft); color: var(--danger-text); }
.q-focus-chip.risk { background: var(--warning-soft); color: var(--warning-text); }
.q-focus-chip[aria-pressed="true"] { border-color: currentColor; }
.q-focus-list { list-style: none; margin: 6px 0 0; padding: 0; }
.q-focus-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 5px 2px; border-top: 1px solid var(--border); color: inherit; text-decoration: none !important; font-size: 12.5px; }
.q-focus-item:hover .q-focus-sub { text-decoration: underline; }
.q-focus-id { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--indigo); }
.q-focus-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.q-search { display: flex; gap: 6px; }
.q-search .search-input { flex: 1; min-width: 0; }
.q-search .search-input input { height: 34px; }
.q-filter-btn { height: 34px; flex-shrink: 0; }
.q-filter-btn[aria-expanded="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.q-filter-btn .count:not(:empty) { font-size: 11px; font-weight: 700; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--primary); color: #fff; text-align: center; }
.q-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.q-filters[hidden] { display: none; }
.q-filters .select-wrap select { height: 32px; font-size: 12.5px; }
.q-filters .btn { justify-self: start; }
.q-views { display: flex; margin: 0 -14px; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
.q-view {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 7px 8px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--muted); font-size: 13px; font-weight: 550; white-space: nowrap; cursor: pointer;
}
.q-view:hover { color: var(--text); }
.q-view .count { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--faint); }
.q-view[aria-pressed="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.q-view[aria-pressed="true"] .count { color: var(--primary); }
.q-items { flex: 1; min-height: 0; overflow-y: auto; }
.q-card {
  display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent; color: inherit; text-decoration: none !important;
}
.q-card:hover { background: var(--surface-2); }
.q-card.is-late { background: #fef6f6; }
.q-card.is-selected { background: var(--primary-soft); border-left-color: var(--primary); }
.q-card:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.q-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.q-id { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-sla { font-weight: 600; white-space: nowrap; }
.q-subject { font-weight: 650; color: var(--text); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-cust { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-foot { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.q-owner { margin-left: auto; font-size: 12px; color: var(--text-2); }
.q-owner.none { color: var(--danger-text); font-weight: 600; }

.q-detail { min-width: 0; min-height: 0; background: var(--surface); display: flex; flex-direction: column; }
.q-detail > .empty-state { margin: auto; }
.qd { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.qd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px 10px; }
.qd-headline { min-width: 0; flex: 1 1 280px; }
.qd-back { display: none; }
.qd-meta { font-size: 12px; color: var(--muted); }
.qd-num { display: inline-block; margin-right: 10px; padding: 0 9px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary); font-weight: 750; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.qd-title { font-size: 19px; margin-top: 2px; text-wrap: balance; overflow-wrap: anywhere; }
.qd-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.qd-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 0 20px 12px; border-bottom: 1px solid var(--border); }
.qd-controls .control-row { margin: 0; gap: 4px; }
.qd-controls label { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.qd-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 20px 8px; background: var(--surface-2); }
.qd-cards { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 12px; margin-bottom: 12px; }
.qd-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.qd-label, .qd-info dt { display: block; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.qd-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin: 0; }
.qd-info dd { margin: 2px 0 0; font-size: 13px; overflow-wrap: anywhere; }
.qd-sla { font-weight: 650; margin: 4px 0 8px; }
.sla-meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-bottom: 8px; }
.sla-meter span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.sla-meter.sla-at_risk span { background: var(--warning); }
.sla-meter.sla-overdue span, .sla-meter.sla-breached span { background: var(--danger); }
.sla-meter.sla-met span { background: var(--success); }
.sla-meter.sla-paused span { background: var(--faint); }
.qd-scroll .tabs { background: transparent; }
.qd-composer { padding: 10px 20px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.qd-composer .composer-tabs { align-items: center; flex-wrap: wrap; }
.qd-composer .composer-hint { margin: 0 0 0 auto; }
.qd-composer .composer textarea { min-height: 64px; }

/* ------------------------------------------------------------------ thread cards (RunCloud / Freshdesk style)
   One card per message: avatar left, author + time header, thin divider, body, attachment cards below.
   customer = blue card, reply (support) = green card with the SMAP mark as avatar, note = yellow dashed (unchanged).
   The app is light-only (color-scheme: light), so no dark variants here. */
.thread-cards { gap: 12px; padding: 14px 0; }
.thread-cards .msg { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); margin: 0; }
.thread-cards .msg:last-child { border: 1px solid var(--border); }
.thread-cards .msg-customer,
.thread-cards .msg-customer:last-child { background: var(--msg-customer-bg); border-color: var(--msg-customer-border); }
.thread-cards .msg-reply,
.thread-cards .msg-reply:last-child { background: var(--msg-reply-bg); border-color: var(--msg-reply-border); }
.thread-cards .msg.is-note, .thread-cards .msg.is-note:last-child { background: var(--note-bg); border: 1px dashed #d97706; }
.thread-cards .msg-head { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.thread-cards .msg-sub { font-size: 12px; font-weight: 550; color: var(--muted); }
.thread-cards .msg-sub::before { content: "\00b7\00a0"; }
.thread-cards .avatar.avatar-logo { background: #fff; border: 1px solid var(--msg-reply-border); }
.thread-cards .avatar.avatar-logo img { width: 20px; height: 20px; margin: auto; }

/* attachment cards under the message body: compact, fit the content, name links to the file in a new tab */
.thread-cards .msg { scroll-margin-bottom: 16px; }
.thread-cards .msg .file-list { flex-direction: row; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thread-cards .msg .file-chip {
  display: inline-flex; align-items: center; gap: 8px; width: auto; max-width: 360px; min-width: 0;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.thread-cards .msg-customer .file-chip { border-color: #c7d2fe; }
.thread-cards .msg .file-chip:hover { border-color: var(--primary); }
.thread-cards .msg .file-chip:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.thread-cards .msg .file-icon { width: 28px; height: 28px; flex: 0 0 auto; }
.thread-cards .msg .file-meta { min-width: 0; flex: 1 1 auto; gap: 2px; }
.thread-cards .msg .file-name { display: block; max-width: 100%; color: var(--primary); font-weight: 600; text-decoration: none; }
.thread-cards .msg .file-name:hover { text-decoration: underline; }
.thread-cards .msg .file-name:focus-visible { outline: none; }
.thread-cards .msg .file-size { font-size: 12px; }
.side-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.side-section:last-child { border-bottom: 0; }
.side-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }
.control-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.control-row:last-child { margin-bottom: 0; }
.control-row label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.perm-hint { font-size: 11.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; }

/* AI intake */
.intake-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.sample-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 12px; cursor: pointer; color: var(--text-2); display: inline-flex; align-items: center; gap: 5px; }
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.draft-dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; margin: 0; font-size: 13.5px; }
.draft-dl dt { color: var(--muted); }
.draft-dl dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.confidence { font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.skeleton { height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3), #e9eef5, var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.1s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* customer profile */
.profile-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.status-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.status-summary .ss { padding: 10px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); text-align: center; }
.status-summary .ss strong { display: block; font-size: 20px; }
.status-summary .ss span { font-size: 11.5px; color: var(--muted); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .qd-cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1024px) {
  .dash-grid, .dash-grid-3, .intake-grid, .profile-grid { grid-template-columns: minmax(0, 1fr); }
  .queue { grid-template-columns: minmax(280px, 320px) minmax(0, 1fr); }
  .qd-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .focus-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .focus-list .focus-row a { grid-template-columns: minmax(0, 1fr) auto; }
  .focus-owner { display: none; }
  .team-shell, .team-shell.collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  .team-shell .nav-label, .team-shell .nav-count, .team-shell .brand-text, .team-shell .sidebar-foot, .team-shell .sidebar-head .brand { display: none; }
  .team-shell .nav-item { justify-content: center; padding: 10px 0; }
  .team-shell .nav-sub, .team-shell .nav-caret { display: none; }
  .settings-tabs { display: flex; }
  .team-shell .sidebar-head { justify-content: center; padding: 0; }
  .sidebar-toggle { display: none; }
  .profile-text { display: none; }
  .page { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .queue { display: block; height: auto; }
  .queue.has-selection .q-list, .queue:not(.has-selection) .q-detail { display: none; }
  .q-list { border-right: 0; }
  .q-items { overflow: visible; }
  .qd { height: auto; }
  .qd-back { display: inline-flex; }
  .qd-head, .qd-scroll, .qd-composer { padding-left: 16px; padding-right: 16px; }
  .qd-controls { padding: 0 16px 12px; }
  .qd-scroll { overflow: visible; }
  .qd-info { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .portal-nav { display: none; position: absolute; top: 60px; left: 0; right: 0; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px 12px; z-index: 30; box-shadow: var(--shadow); }
  .portal-nav.open { display: flex; }
  .portal-header-inner { position: relative; }
  .portal-menu-btn { display: inline-grid; }
  .portal-main { padding: 18px 16px 36px; }
  .hero { grid-template-columns: 1fr; padding: 18px; }
  .hero-art { display: none; }
  .hero h1 { font-size: 21px; }
  .form-grid { grid-template-columns: 1fr; }
  dl.meta { grid-template-columns: 1fr 1fr; }
  .steps { grid-template-columns: 1fr; }
  .ticket-card { grid-template-columns: auto 1fr auto; }
  .ticket-card > .icon { display: none; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .card-pad { padding: 16px; }
  .brand small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.table th:first-child, .table td:first-child { padding-left: 14px; }
.table th:last-child, .table td:last-child { padding-right: 12px; }

/* ------------------------------------------------------------------ table conventions
   Class list on data tables: "table table-striped table-mobile-md".
   - table-striped: even rows get a light tint (works with the hover tint of clickable rows).
   - table-mobile-md: below 768px the header is hidden and every row becomes a stacked card whose cells
     show their label (td[data-label]) above the value. Left-aligned, rows separated by a bottom border. */
.table-striped tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-3) 70%, var(--surface)); }
.table-striped tbody tr.clickable:hover td { background: var(--surface-3); }
.table .col-num { width: 1%; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.table th.col-num { color: var(--muted); }

@media (max-width: 767.98px) {
  .table-mobile-md { display: block; }
  .table-mobile-md thead { display: none; }
  .table-mobile-md tbody { display: flex; flex-direction: column; }
  .table-mobile-md tbody tr { display: flex; flex-direction: column; border-bottom: 1px solid var(--border-strong); padding: 6px 0; }
  .table-mobile-md tbody tr:last-child { border-bottom: 0; }
  .table-mobile-md tbody td,
  .table-mobile-md tbody tr:last-child td {
    display: block; width: auto; max-width: none; padding: 5px 14px; border-bottom: 0; text-align: left; white-space: normal;
  }
  .table-mobile-md td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 1px; font-size: .625rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  }
  .table-mobile-md td.col-num { width: auto; }
  .table-mobile-md .subject, .table-mobile-md .clip { max-width: none; white-space: normal; }
  .table-mobile-md .actions { justify-content: flex-start; flex-wrap: wrap; }
}

/* datatable footers and the lazy customer picker */
.dt-error { padding: 4px 0; }
.picker-search { margin-bottom: 6px; }
.picker-search input { height: 34px; }
.picker-status { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

/* ticket queue: load-more footer under the cards */
.q-sentinel { height: 1px; }
.q-more { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.q-more .btn { flex-shrink: 0; }
.q-hint { color: var(--muted); font-size: 11.5px; }
@media (max-width: 860px) { .q-hint { display: none; } }
.q-loading { padding: 12px 14px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.table th.th-right { text-align: right; }
@media (max-width: 767.98px) { .table-mobile-md th.th-right { text-align: left; } }
.field .picker-search input[type="search"] { padding-left: 34px; }

/* ------------------------------------------------------------------ AIRA Review */
.lane-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 14px 16px 0; }
.lane-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; text-align: left; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 13.5px;
}
.lane-btn small { display: block; font-weight: 450; font-size: 12px; color: var(--muted); }
.lane-btn .lane-count { font-size: 18px; font-weight: 750; }
.lane-btn[aria-selected="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.lane-btn[data-lane="errors"][aria-selected="true"] { border-color: var(--danger); background: var(--danger-soft); }
.review-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; padding: 12px 16px; }
.review-stats .kpi { padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius); }
.review-stats .kpi-value { font-size: 20px; }
.review-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.review-card { margin-bottom: 12px; }
.review-card.is-highlight { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.review-card .variants { margin: 0 0 8px; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.review-card .answer { margin: 0 0 10px; color: var(--muted); }
.review-card .owner { width: 170px; }
.badge-stale { background: var(--warning-soft); color: var(--warning-text); }
.badge-error { background: var(--danger-soft); color: var(--danger-text); }
.badge-auto { background: var(--violet-soft); color: var(--violet-text); }
/* Knowledge base writing */
.review-note:not(:empty) { padding: 0 16px 12px; }
.review-stats .kpi.kpi-warn { background: var(--warning-soft); border-left: 3px solid var(--warning); }
.review-stats .kpi .link-btn { margin-top: 2px; font-size: 12px; }
.badge-kbfail { background: var(--warning); color: #fff; font-weight: 700; gap: 5px; }
.kb-warning { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--warning); background: var(--warning-soft); color: var(--warning-text); font-size: 13px; font-weight: 550; }
.kb-entry { margin: 0 0 10px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--success); background: var(--success-soft); color: var(--success-text); }
.kb-entry .icon { vertical-align: -1px; }
.kb-entry .muted { color: var(--success-text); opacity: .85; }
.kb-entry-title { margin: 6px 0 2px; font-weight: 650; color: var(--text); }
.kb-entry-text { margin: 0 0 6px; font-size: 13px; color: var(--text-2); }
.kb-offer { align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.kb-offer-text { flex: 1 1 260px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kb-offer-actions { display: flex; gap: 6px; flex-shrink: 0; }
.kb-ticket-line { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.kb-counter { margin: -6px 0 0; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kb-counter.is-near { color: var(--warning-text); font-weight: 600; }
.kb-pii { align-items: flex-start; }
.kb-pii .checkbox { color: var(--warning-text); font-weight: 600; }
.kb-preview { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.kb-preview h3 { margin: 0 0 6px; font-size: 13px; color: var(--text-2); }
.kb-preview p { margin: 0; }
.kb-hits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.kb-hits li { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; font-size: 13px; }
.kb-hits li .small { flex-basis: 100%; }
.kb-score { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kb-exact { margin: 0; display: grid; gap: 4px; }
.kb-exact dt { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 8px; }
.kb-exact dd { margin: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow-y: auto; }
@media (max-width: 1100px) { .review-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .lane-switch, .review-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-card .owner { width: 100%; }
}

/* ------------------------------------------------------------------
 * Staff check-in control (topbar). Shown only in api mode.
 * ------------------------------------------------------------------ */
.presence { display: flex; align-items: center; gap: 8px; margin-right: 8px; white-space: nowrap; }
.presence-pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--success-soft); color: var(--success-text); border: 1px solid var(--success); }
@media (max-width: 720px) {
  .presence-pill { display: none; }
}

/* ---- Portal: reopen ticket (button + side panel) ---- */
.portal-reopen-btn { margin-left: auto; }
.reopen-panel { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-2); }
.reopen-panel p { margin: 0; font-size: 14px; }
.reopen-panel svg { flex: none; margin-top: 2px; }

/* ------------------------------------------------------------------
 * Ticket tags
 * ------------------------------------------------------------------ */
.tag-chip { display: inline-flex; align-items: center; max-width: 100%; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid rgba(0, 0, 0, .06); }
.tag-chip.tag-more { background: var(--surface-3); color: var(--muted); }
.tag-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.tag-row .tag-chip { font-size: 12px; }
.tag-add { gap: 4px; color: var(--muted); }
.tag-filter-btn { justify-self: start; gap: 4px; }
.tag-select { position: relative; }
dialog.modal.tag-select-modal, .tag-select-modal .modal-body { overflow: visible; }
.tag-select-box { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px 32px 6px 8px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); }
.tag-select-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.tag-select-chips { display: contents; }
.tag-select-chip { gap: 4px; padding-right: 4px; }
.tag-select-chip.is-new { border-style: dashed; border-color: currentColor; }
.tag-select-chip button { display: inline-grid; place-items: center; width: 16px; height: 16px; padding: 0; border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer; }
.tag-select-chip button:hover { background: rgba(0, 0, 0, .12); }
.tag-select-box .tag-select-input { flex: 1 1 120px; min-width: 0; padding: 4px; border: 0; box-shadow: none; background: transparent; outline: none; }
.tag-select-caret { position: absolute; right: 10px; top: 14px; color: var(--muted); pointer-events: none; transition: transform .15s; }
.tag-select.is-open .tag-select-caret { transform: rotate(180deg); }
.tag-select-list[hidden] { display: none; }
.tag-select-list { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); box-shadow: var(--shadow-lg); list-style: none; margin: 0; padding: 4px; max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.tag-select-opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.tag-select-opt.is-active { background: var(--primary-soft); }
.tag-select-empty { padding: 8px 10px; }
