/* Support Console: page layout and console-specific pieces. Components (buttons, inputs, selects, badges, tables,
   dialogs) come from Basecoat (public/assets/vendor/basecoat-1.1.0, shadcn/ui design, default "Vega" style), and the
   aliases below map the console's own names onto Basecoat's theme tokens, so everything shares one look.
   Dark mode: <html class="dark"> (theme cookie), or the system setting via the media query further down. */

:root {
  --canvas: var(--background);
  --panel: var(--card);
  --sunken: var(--muted);
  --text: var(--foreground);
  --text-2: var(--foreground);
  --line: var(--border);
  --line-strong: var(--input);
  --hover: var(--accent);
  --link: var(--foreground);
  --primary-text: var(--primary-foreground);
  --focus: color-mix(in oklab, var(--ring) 50%, transparent);
  --shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  /* Status tints, which Basecoat leaves to the app */
  --in: #15803d;
  --in-bg: #f0fdf4;
  --in-line: #bbf7d0;
  --warn: #a16207;
  --warn-bg: #fefce8;
  --warn-line: #fde68a;
  --danger: var(--destructive);
  --danger-bg: #fef2f2;
  --danger-line: #fecaca;
}

html.dark {
  --in: #86efac;
  --in-bg: #052e16;
  --in-line: #14532d;
  --warn: #fde047;
  --warn-bg: #2a2306;
  --warn-line: #713f12;
  --danger-bg: #2a0e0e;
  --danger-line: #7f1d1d;
  --shadow: none;
}

body { background: var(--background); color: var(--foreground); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--foreground); text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--foreground) 30%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--foreground); }
.sidebar a, a.tag, .brand a, a.btn, [role=menuitem] { text-decoration: none; }
h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 1rem; font-weight: 600; margin: 28px 0 10px; letter-spacing: -.01em; }
p { margin: .5rem 0; }
ul { margin: .4rem 0; padding-left: 1.2rem; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted-foreground); }
.small { font-size: .86rem; }
.i { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Shell: Basecoat's sidebar (collapsible; a drawer on phones) and a slim top bar with the toggle. */

.sidebar > nav > header .product { display: flex; align-items: center; gap: 10px; padding: 6px 8px; font-weight: 600; color: var(--sidebar-foreground); text-decoration: none; }
.sidebar > nav > section h3 { margin: 0; }
.sidebar > nav li > a .i { width: 16px; height: 16px; }
.sidebar > nav > footer { border-top: 1px solid var(--sidebar-border); }
.user-menu { width: 100%; }
.user-trigger { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: var(--radius); background: transparent; color: inherit; text-align: left; cursor: pointer; font: inherit; }
.user-trigger:hover, .user-trigger[aria-expanded=true] { background: var(--sidebar-accent); }
.user-trigger .who { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.user-trigger .who strong { font-weight: 500; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-trigger .who small { font-size: .75rem; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu [role=menu] { min-width: 220px; }
.user-menu [role=menuitemradio], .user-menu [role=menuitem] { width: 100%; border: 0; background: transparent; font: inherit; color: inherit; text-align: left; text-decoration: none; }
.user-menu [role=menuitemradio][aria-checked=true] { font-weight: 600; }
.user-menu [role=menuitemradio][aria-checked=true]::after { content: "✓"; margin-left: auto; }

.avatar {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: .72rem;
  font-weight: 600;
}
.avatar.initials { border-radius: 50%; width: 30px; height: 30px; }

.main { min-width: 0; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 16px;
  background: color-mix(in oklab, var(--background) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 500; font-size: .9rem; color: var(--muted-foreground); }
.page { padding: 24px 36px 56px; max-width: 1240px; width: 100%; }

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--muted-foreground); margin-top: 3px; }

.toolbar { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar label { font-size: .8rem; color: var(--muted-foreground); display: flex; flex-direction: column; gap: 4px; }
.toolbar .spacer { flex: 1; }

/* Controls: Basecoat's .btn, .input, .select and .textarea do the styling (added by dom.js and in the Blade views).
   Only console-specific sizing lives here. */

.toolbar .input, .toolbar .select { min-width: 140px; }
form.stack, .panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 620px;
  padding: 24px;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid color-mix(in oklab, var(--foreground) 10%, transparent);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  font-size: .875rem;
}
form.stack { gap: 20px; }
.panel { gap: 12px; margin-bottom: 16px; max-width: none; }
.panel h2 { margin: 0; font-size: 1rem; line-height: 1.4; }
.panel h2 + p { margin-top: -6px; color: var(--muted-foreground); }
/* Basecoat .field does labels, controls and help text; our global margins must not fight it. */
.field { gap: 8px; }
.field > p, .field section > p { margin: -2px 0 0; }
.field > label .badge { font-weight: 500; }
.field .hint { font-size: .8rem; color: var(--muted-foreground); font-weight: 400; }
.field[data-orientation=horizontal] { gap: 10px; align-items: flex-start; }
.field[data-orientation=horizontal] > label, .field[data-orientation=horizontal] section > label { font-weight: 400; }
.checks { display: flex; flex-direction: column; gap: 10px; }
.card > header h2, .card > header p, .empty h2, .empty p { margin: 0; }
.card > section > :first-child { margin-top: 0; }
.card > section > :last-child { margin-bottom: 0; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 150px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input.input[type=checkbox] { width: 1rem; min-width: 0; flex: none; } /* Basecoat draws the box; never stretch it */
.field > .select, .field > .input, .field > .textarea { width: 100%; max-width: 100%; }


/* Messages: a soft tint and an icon drawn with a mask */

.notice, .error, .warning {
  position: relative;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 11px 14px 11px 40px;
  margin-bottom: 16px;
  background: var(--card);
  font-size: .875rem;
}
.notice::before, .error::before, .warning::before, .empty::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 13px;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.notice { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E"); }
.notice::before { color: var(--muted-foreground); }
.notice.done { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E"); }
.notice.done::before { color: var(--in); }
.error { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E");
  color: var(--danger); background: var(--danger-bg); border-color: var(--danger-line); }
.error .code { display: block; font-size: .78rem; opacity: .75; margin-top: 2px; }
.warning { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3M12 9v4M12 17h.01'/%3E%3C/svg%3E");
  color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.warning a, .error a { color: inherit; text-decoration: underline; }

.empty {
  position: relative;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 56px 24px 32px;
  text-align: center;
  color: var(--muted-foreground);
  background: var(--panel);
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-6l-2 3h-4l-2-3H2'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E");
}
.empty::before { left: 50%; top: 22px; width: 24px; height: 24px; margin-left: -12px; }

/* Tables live in panels */

.wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 500; font-size: .8rem; color: var(--muted-foreground); background: color-mix(in oklab, var(--muted) 50%, transparent); white-space: nowrap; height: 2.5rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in oklab, var(--muted) 50%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.code { white-space: nowrap; color: var(--muted-foreground); }

/* .tag is a Basecoat .badge (dom.js adds the class) in the secondary style, with our tints for state. */
.tag {
  gap: 4px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: transparent;
  vertical-align: 1px;
}
.tag.ok { background: var(--in-bg); color: var(--in); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--danger-bg); color: var(--danger); }

/* Brand badge: neutral pill with a small dot in the brand's colour (set from JS, so no inline styles). */
.brand-badge { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 500; color: var(--text-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 8px 0 6px; white-space: nowrap; background: var(--panel); }
.brand-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-foreground); }

/* Key/value rows and the requirement checklist */

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted-foreground); }
dl.kv dd { margin: 0; }
ul.checks { list-style: none; padding: 0; margin: 0; }
ul.checks li { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--line); }
ul.checks li:last-child { border-bottom: 0; }
ul.checks .tag { flex: none; }
pre.output { background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: .82rem; margin: 0; white-space: pre-wrap; }

/* Sign-in and setup */

.signin { max-width: 380px; margin: 14vh auto; padding: 0 16px; }
.signin.wide { max-width: 620px; margin-top: 8vh; }
.signin .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-bottom: 18px; }
.signin h1 { margin-bottom: 4px; }
.signin form.stack { margin-top: 18px; }
.qr { background: #fff; padding: 12px; border-radius: 8px; width: max-content; border: 1px solid var(--line); }

/* Phase 2: search, customer view and admin pages */
.toolbar label.grow { flex: 1; min-width: 240px; }
.toolbar label.grow input { width: 100%; font-size: 1rem; }
tr.group td { background: var(--sunken); padding-top: 7px; padding-bottom: 7px; }
tr.group.suggestion td { background: var(--warn-bg); color: var(--warn); }
tr.group .link { color: inherit; text-decoration: underline; margin-left: 6px; }
form.stack > div:empty, form.actions > div:empty { display: none; }
tr.overdue td { background: var(--danger-bg); }
tbody tr.overdue:hover td { background: var(--danger-bg); }
details.panel summary, details > summary { cursor: pointer; }
details.panel { gap: 14px; }
details form.stack { margin-top: 12px; box-shadow: none; }
form.stack.wide { max-width: none; }
td select, td input { width: 100%; min-width: 140px; }

/* Phase 3: queue and ticket */
.toolbar select { min-width: 140px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 12px; }
.msg header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.msg header time { margin-left: auto; }
/* Staff replies: soft green, so they never look like the customer's. Notes keep their amber. */
.msg.staff { background: var(--in-bg); border-color: var(--in-line); }
.msg.note { background: var(--warn-bg); border-color: var(--warn-line); }
.msg .body { overflow-wrap: anywhere; }
.msg .body blockquote { margin: .5rem 0; padding-left: 12px; border-left: 3px solid var(--line-strong); color: var(--text-2); }
.msg .body pre { white-space: pre-wrap; background: var(--hover); padding: 8px 10px; border-radius: 6px; }
ul.attachments { list-style: none; padding: 8px 0 0; margin: 8px 0 0; border-top: 1px solid var(--line); display: flex; gap: 14px; flex-wrap: wrap; font-size: .86rem; }
.panel.side { padding: 14px 16px; gap: 6px; }
.panel.side h2 { font-size: .86rem; color: var(--muted-foreground); font-weight: 500; }
.panel.side p { margin: 0; }
ul.side-list { list-style: none; padding: 0; margin: 0; font-size: .92rem; }
ul.side-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
ul.side-list li:last-child { border-bottom: 0; }
@media (max-width: 1000px) { .ticket-layout { grid-template-columns: 1fr; } }

/* Phase 4: compose, editor, presence */
.compose { max-width: none; gap: 10px; margin-top: 4px; }
.compose.note-mode { background: var(--warn-bg); border-color: var(--warn-line); }
.compose .actions .spacer { flex: 1; }
.editor { display: flex; flex-direction: column; gap: 6px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.editor-tabs { display: flex; gap: 4px; padding: 3px; background: var(--hover); border-radius: 8px; width: max-content; }
.editor-tabs { background: var(--muted); }
.editor-tabs button { height: 28px; color: var(--muted-foreground); }
.editor-tabs button.active, .editor-tabs button.active:hover { background: var(--background); color: var(--foreground); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.editor-tools { display: flex; gap: 2px; flex-wrap: wrap; }
.editor-tools button { color: var(--muted-foreground); }
.editor textarea { width: 100%; resize: vertical; min-height: 150px; line-height: 1.5; field-sizing: fixed; }
.editor .preview { min-height: 150px; border: 1px solid var(--input); border-radius: var(--radius); padding: 10px 12px; background: var(--panel); overflow-wrap: anywhere; }
.editor-hint { margin-top: -2px; }
.msg.new { border-color: var(--danger-line); box-shadow: 0 0 0 3px var(--danger-bg); }
.presence-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
#head-actions select { min-width: 160px; }
.editor-tools button:nth-child(1) { font-weight: 700; }
.editor-tools button:nth-child(2) { font-style: italic; font-family: Georgia, serif; }
th.center, td.center { text-align: center; }
.restored { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.live-update { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Console statuses: coloured badges and swatches (colours set from JS) */
.status-tag { gap: 5px; }
.status-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--muted-foreground); box-shadow: 0 0 0 1px var(--line); }
.nowrap { flex-wrap: nowrap; }
input[type=color], td input[type=color] { width: 38px; min-width: 0; height: 36px; padding: 3px; flex: none; border: 1px solid var(--input); border-radius: var(--radius); background: transparent; }
td input[type=checkbox] { width: 1rem; min-width: 0; }
.add-status { margin-top: 4px; }
.add-status input[type=text] { min-width: 200px; }

/* Queue: your own tickets on top */
h2.queue-section { font-size: .86rem; color: var(--muted-foreground); font-weight: 500; margin: 18px 0 8px; }
h2.queue-section:first-child { margin-top: 0; }
tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--link); }
tr.mine td { background: color-mix(in srgb, var(--link) 5%, var(--panel)); }
table.queue-table { table-layout: fixed; }
table.queue-table td { overflow-wrap: anywhere; }
.col-brand { width: 13%; } .col-subject { width: 35%; } .col-status { width: 17%; } .col-department { width: 20%; } .col-activity { width: 15%; }
@media (max-width: 800px) { table.queue-table { table-layout: auto; min-width: 720px; } }
.subject { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tag.priority { font-size: .7rem; padding: 0 6px; height: 18px; }
.token-copy { margin-top: 8px; flex-wrap: nowrap; }
.token-value { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.draft-card { background: var(--in-bg); border: 1px dashed var(--in-line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.draft-card summary { cursor: pointer; margin-bottom: 8px; }
.draft-card .body { margin-bottom: 10px; overflow-wrap: anywhere; }
.stack-inner { display: flex; flex-direction: column; gap: 16px; }
.stack-inner:empty { display: none; }
details > .field, details > .actions, details > p { margin-top: 10px; }

/* Basecoat dialog (confirmDialog in dom.js) */
dialog.dialog > div > header p { margin: 0; }
dialog.dialog > div > footer { display: flex; justify-content: flex-end; gap: 8px; }

/* Overview (home page) */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 8px; }
.stat-label { font-size: .85rem; color: var(--muted-foreground); }
.stat-value { font-size: 1.9rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: .8rem; color: var(--muted-foreground); }
.stat.warn .stat-value { color: var(--warn); }
.stat.bad .stat-value { color: var(--danger); }
.brand-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.brand-card > header h2 { font-size: 1rem; }
.brand-body { display: grid; grid-template-columns: 1fr 170px; gap: 20px; align-items: start; }
.brand-title { display: inline-flex; align-items: center; gap: 8px; }
.brand-title .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted-foreground); }
dl.brand-kpis { display: grid; grid-template-columns: repeat(3, 1fr); row-gap: 12px; gap: 14px 12px; margin: 0; }
dl.brand-kpis dt { font-size: .78rem; color: var(--muted-foreground); }
dl.brand-kpis dd { margin: 0; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
dl.brand-kpis .warn dd { color: var(--warn); }
dl.brand-kpis .bad dd { color: var(--danger); }
.donut-wrap .chart.donut { aspect-ratio: 1; }
.donut-wrap .chart-legend { gap: 4px 10px; padding-top: 6px; }
.donut-empty { text-align: center; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-grid .wide { grid-column: 1 / -1; }
.chart-grid .wide .chart { aspect-ratio: auto; height: 260px; }
.chart-grid .chart { aspect-ratio: auto; height: 220px; }
@media (max-width: 900px) {
  .brand-grid, .chart-grid { grid-template-columns: 1fr; }
  .brand-body { grid-template-columns: 1fr; }
}

/* Basecoat cards and tables hold dropdown menus, which must not be clipped. */
.card { overflow: visible; }
.wrap thead tr:first-child th:first-child { border-top-left-radius: calc(var(--radius) + 3px); }
.wrap thead tr:first-child th:last-child { border-top-right-radius: calc(var(--radius) + 3px); }
td.row-actions, th.row-actions { width: 1%; white-space: nowrap; text-align: right; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack-cards { display: flex; flex-direction: column; gap: 16px; }
.card > header .card-action { display: flex; gap: 6px; align-items: center; }
.card > footer { gap: 8px; flex-wrap: wrap; }
.card + .card, .card + h2, .wrap + h2 { margin-top: 0; }
.accordion > details > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; list-style: none; }
.accordion > details > summary::-webkit-details-marker { display: none; }
.summary-text { display: flex; flex-direction: column; gap: 2px; }
.summary-text small { font-weight: 400; color: var(--muted-foreground); font-size: .8rem; }
.accordion > details > section { padding-bottom: 14px; }
.tabs > [role=tabpanel] { padding-top: 12px; }
.tabs > [role=tablist] { max-width: 100%; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
dialog.form-dialog > div { max-width: min(560px, calc(100% - 2rem)); }
dialog.form-dialog > div > section { overflow-y: auto; }
dialog.form-dialog form.stack { border: 0; box-shadow: none; padding: 0; max-width: none; background: transparent; }
dialog.form-dialog > div > button[aria-label=Close] { position: absolute; top: 12px; right: 12px; }

/* Phones: a smaller type scale and tighter spacing, not just a narrower layout. Tables become stacked cards. */
@media (max-width: 640px) {
  html { font-size: 15px; }
  body { font-size: 13.5px; }
  h1 { font-size: 1.25rem; }
  h2 { font-size: .95rem; margin: 20px 0 8px; }
  .page { padding: 14px 12px 40px; }
  .topbar { height: 44px; padding: 0 8px; }
  .head { margin-bottom: 12px; gap: 10px; }
  .head .sub { font-size: .82rem; }
  .card { gap: 14px; padding-block: 14px; }
  .card > header, .card > section, .card > footer { padding-inline: 14px; }
  .panel, form.stack { padding: 14px; }
  .btn:not([data-size]) { height: 34px; }
  .toolbar { gap: 8px; }
  .toolbar label { flex: 1 1 45%; min-width: 0; }
  .toolbar .input, .toolbar .select { min-width: 0; width: 100%; }
  .toolbar label.grow { flex-basis: 100%; }
  table.stackable thead { display: none; }
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td { display: block; width: 100%; }
  table.stackable tr { padding: 10px 12px; border-bottom: 1px solid var(--border); position: relative; }
  table.stackable tbody tr:last-child { border-bottom: 0; }
  table.stackable td { border: 0; padding: 3px 0; text-align: left !important; }
  table.stackable td[data-label]:not(.primary-cell):not(.row-actions) { display: grid; grid-template-columns: 6.5rem 1fr; gap: 8px; align-items: baseline; }
  table.stackable td[data-label]:not(.primary-cell):not(.row-actions)::before { content: attr(data-label); font-size: .75rem; color: var(--muted-foreground); }
  table.stackable td:empty { display: none !important; }
  table.stackable td.row-actions { position: absolute; top: 8px; right: 8px; width: auto; padding: 0; }
  table.stackable td.primary-cell { font-weight: 500; padding-right: 40px; }
  tbody tr:hover td { background: transparent; }
  .stat-value { font-size: 1.5rem; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  dialog.form-dialog > div { max-height: calc(100% - 1rem); }
  .hide-phone { display: none !important; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dt { font-size: .75rem; margin-top: 6px; }
  .card > header .card-action { gap: 2px; }
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card .wrap { box-shadow: none; }
.danger-zone { border-color: var(--danger-line); }
[role=tab] .count { font-size: .72rem; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
tr.group td::before { display: none !important; }

/* Queue filters: search always shown; the rest fold behind "Filters" on phones. */
.queue-filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.queue-filters .search input { width: 100%; }
.filter-drawer > summary { display: none; list-style: none; }
.filter-drawer > summary::-webkit-details-marker { display: none; }
.filter-drawer .toolbar { margin-bottom: 0; }
.filter-count:not(:empty) { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--primary); color: var(--primary-foreground); font-size: .7rem; }

@media (max-width: 640px) {
  .filter-drawer > summary { display: inline-flex; gap: 6px; }
  .filter-drawer[open] > summary { margin-bottom: 10px; }
  /* Queue rows as a compact list: subject first, then status and age, then brand and department. */
  table.queue-table, table.queue-table tbody { display: block; min-width: 0; }
  table.queue-table thead, table.queue-table colgroup { display: none; }
  table.queue-table tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "subject subject" "status activity" "brand dept"; gap: 4px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table.queue-table tbody tr:last-child { border-bottom: 0; }
  table.queue-table td { display: block; padding: 0; border: 0; }
  table.queue-table td::before { display: none !important; }
  table.queue-table .q-subject { grid-area: subject; }
  table.queue-table .q-status { grid-area: status; }
  table.queue-table .q-status .small { display: none; }
  table.queue-table .q-activity { grid-area: activity; text-align: right; }
  table.queue-table .q-brand { grid-area: brand; }
  table.queue-table .q-dept { grid-area: dept; text-align: right; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }
  table.queue-table .subject a { font-weight: 500; }
  tr.mine td:first-child { box-shadow: none; }
  tr.mine { box-shadow: inset 3px 0 0 var(--link); }
  tr.mine td { background: transparent !important; }
  table.queue-table tr.mine { background: color-mix(in srgb, var(--link) 5%, var(--card)); }
}

/* Tab strips without panels (reply/note, write/preview): Basecoat's tab look, our own switching. */
.tab-strip > [role=tablist] { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--radius); background: var(--muted); }
.tab-strip [role=tab] { height: 30px; padding: 0 12px; border: 1px solid transparent; border-radius: calc(var(--radius) - 2px); background: transparent; color: var(--muted-foreground); font: inherit; font-size: .85rem; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab-strip [role=tab]:hover { color: var(--foreground); }
.tab-strip [role=tab][aria-selected=true] { background: var(--background); color: var(--foreground); border-color: var(--border); box-shadow: var(--shadow); }
.tab-strip.small-tabs [role=tab] { height: 26px; padding: 0 10px; font-size: .8rem; }
.compose.card { padding: 16px; gap: 10px; }

/* Ticket side cards: collapsible. */
details.side-card { padding: 0; gap: 0; margin-bottom: 12px; }
details.side-card > summary { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; cursor: pointer; list-style: none; }
details.side-card > summary::-webkit-details-marker { display: none; }
details.side-card > summary h2 { margin: 0; font-size: .82rem; font-weight: 500; color: var(--muted-foreground); }
details.side-card > summary .i { transition: transform .15s; color: var(--muted-foreground); }
details.side-card[open] > summary .i { transform: rotate(180deg); }
details.side-card > section { padding: 0 16px 14px; }
details.side-card > section p { margin: 0 0 4px; }

@media (max-width: 640px) {
  .ticket-layout { gap: 12px; }
  .msg { padding: 10px 12px; margin-bottom: 8px; }
  .msg header { gap: 6px; margin-bottom: 4px; }
  .msg header time { font-size: .72rem; }
  .compose.card { padding: 12px; }
  .compose .actions { gap: 6px; }
  .compose .actions .spacer { display: none; }
  .compose .actions > .select { flex: 1 1 100%; }
  .compose .actions > .small.muted { flex: 1; font-size: .72rem; }
  .editor-tools button { padding: 0 6px; }
  .editor textarea, .editor .preview { min-height: 120px; }
  #head-actions { width: 100%; }
  #head-actions .actions { flex: 1; flex-wrap: nowrap; }
  #head-actions .select { flex: 1; min-width: 0; }
  details.side-card > summary { padding: 10px 12px; }
  details.side-card > section { padding: 0 12px 12px; }
}
.card form.stack { border: 0; box-shadow: none; padding: 0; background: transparent; }
ol.steps { margin: 0; padding-left: 1.4rem; list-style: decimal; display: flex; flex-direction: column; gap: 8px; }
ol.steps .token-copy { margin-top: 6px; }

/* Pager under lists */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; }
.pager-pages { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.pager-pages [aria-current=page] { pointer-events: none; }
.pager-gap { padding: 0 4px; color: var(--muted-foreground); }
.pager .select { width: auto; }
@media (max-width: 640px) {
  .pager { justify-content: center; }
  .pager-count { width: 100%; text-align: center; }
  .pager-pages button[aria-label^='Page']:not([aria-current]), .pager-gap { display: none; } /* phones: ‹ current › only */
}
.time-row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.timer { font-variant-numeric: tabular-nums; color: var(--in); font-weight: 500; }

/* Automations form */
fieldset.rule-part { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 14px; }
fieldset.rule-part > legend { padding: 0 6px; font-weight: 600; font-size: .85rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 14px; }
.when-row .narrow { width: 90px; flex: none; }
.when-row .select { width: auto; }
td .url { overflow-wrap: anywhere; }
.applies .actions { margin-top: 4px; gap: 4px; }
dialog.form-dialog > div { max-width: min(640px, calc(100% - 2rem)); }
@media (max-width: 640px) { .when-row { flex-wrap: wrap; } }
.action-list { display: flex; flex-direction: column; gap: 10px; }
.action-list:empty::before { content: "No actions yet."; color: var(--muted-foreground); font-size: .85rem; }
.action-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 10px; background: var(--card); }
.action-card > header { display: flex; align-items: center; gap: 6px; }
.action-card > header .spacer { flex: 1; }
.action-card > p { margin: -6px 0 0; }
.step-number { color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
ol.then-list, ul.run-steps { margin: 0; padding-left: 1.1rem; }
ul.run-steps { list-style: none; padding: 0; margin-top: 4px; }
table.fixed-table { table-layout: fixed; }
table.fixed-table td { overflow-wrap: anywhere; }
table.automation-table th:nth-child(1) { width: 18%; } table.automation-table th:nth-child(2) { width: 22%; }
table.automation-table th:nth-child(3) { width: 20%; } table.automation-table th:nth-child(4) { width: 18%; }
table.automation-table th:nth-child(5) { width: 16%; } table.automation-table th:nth-child(6) { width: 6%; }
@media (max-width: 640px) { table.fixed-table { table-layout: auto; } }
.picker { width: 100%; }
.picker > button { width: 100%; justify-content: space-between; }
.picker > button .i { opacity: .5; }
.row > .field { min-width: 180px; }
.snooze-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.snooze-banner .spacer { flex: 1; }
