/*
  Tenon: support inbox for Bramble Drive (Screenery template)
  A quiet two-pane tool in warm greys with one oxblood accent: Rubik for words, PT Mono for times, ids and money.
  The app fills the viewport: rail, conversation list, thread with composer, customer panel; Reports swaps in for list and thread.

  Contents
   1. Tokens
   2. Base and browser surfaces
   3. Primitives: icons, buttons, kbd, tags, avatars, fields
   4. App grid and banner
   5. Rail
   6. Conversation list and rows
   7. Thread: header, SLA ruler, actions, messages, composer
   8. Customer panel
   9. Reports: figures, charts, tables
  10. Popover, dialogs, toasts
  11. States: skeleton, empty, error
  12. Motion
  13. Narrow screens (1360, 1080, 720)
*/

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light;

  /* Warm greys, from the floor up */
  --floor: #ebe7e1;   /* behind panes, rail */
  --paper: #f4f1ec;   /* list pane */
  --sheet: #fbf9f6;   /* thread pane, cards, dialogs */
  --hover: #ede9e3;
  --sel: #e4dfd7;     /* selected row */
  --sand: #f1eadf;    /* internal notes */
  --line: #ddd7ce;
  --line-2: #cbc4b9;
  --line-3: #b2aa9e;

  /* Ink */
  --ink: #221f1b;
  --ink-2: #4f4942;
  --ink-3: #605951;   /* lowest text tone: 4.9:1 on the selected row, 5.6:1 on --floor */

  /* The one accent: oxblood. Primary action, unread, and time that has run out. */
  --ox: #7a1f2b;
  --ox-hover: #651823;
  --ox-ink: #fbf6f2;
  --ox-soft: #f3e4e2;
  --ox-line: #d9b5b2;

  /* Type */
  --sans: "Rubik", ui-sans-serif, system-ui, sans-serif;
  --mono: "PT Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --fs-xs: 11.5px;
  --fs-sm: 12.5px;
  --fs: 13.5px;
  --fs-md: 15px;
  --fs-lg: 19px;
  --fs-xl: 26px;

  /* Space, radius, size */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
  --r-sm: 4px; --r: 6px; --r-lg: 10px;
  --rail-w: 216px;
  --list-w: 352px;
  --cust-w: 300px;
  --bbar-h: 60px;

  /* Depth: offset, soft */
  --shadow-pop: 0 8px 24px -6px rgba(46, 36, 26, .18), 0 2px 6px rgba(46, 36, 26, .08);
  --shadow-dlg: 0 24px 60px -12px rgba(46, 36, 26, .3), 0 4px 12px rgba(46, 36, 26, .1);

  /* Motion */
  --ease: cubic-bezier(.16, 1, .3, 1);
  --t: 180ms;
}

/* ---------- 2. Base and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--floor);
  color: var(--ink);
  font: 400 var(--fs)/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  accent-color: var(--ox);
  caret-color: var(--ox);
}
::selection { background: var(--ox); color: var(--ox-ink); }
* { scrollbar-width: thin; scrollbar-color: var(--line-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
:focus-visible { outline: 2px solid var(--ox); outline-offset: 2px; border-radius: var(--r-sm); }
a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
h1, h2, h3, p { margin: 0; }
h1, h2 { text-wrap: balance; font-weight: 500; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.defs { position: absolute; width: 0; height: 0; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: var(--sheet); padding: 8px 12px; border-radius: var(--r); }
.skip:focus { top: 12px; }
.num, time, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- 3. Primitives ---------- */
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

kbd {
  font: 400 11px/1 var(--mono);
  color: var(--ink-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 2px 4px 1px;
  background: var(--sheet);
  white-space: nowrap;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 34px; padding: 0 var(--s3);
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--sheet); color: var(--ink);
  font-weight: 500; font-size: var(--fs-sm);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn--primary { background: var(--ox); border-color: var(--ox); color: var(--ox-ink); }
.btn--primary:hover { background: var(--ox-hover); }
.btn--primary kbd { background: transparent; color: var(--ox-ink); border-color: rgba(251, 246, 242, .45); }
.btn--quiet { background: transparent; }
.btn--sm { min-height: 28px; padding: 0 var(--s2); font-size: var(--fs-xs); }
.btn[disabled], .btn[aria-busy="true"] { opacity: .7; cursor: progress; }
.btn .spin { width: 12px; height: 12px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }

.iconbtn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--r);
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
}
.iconbtn:hover { background: var(--hover); color: var(--ink); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); line-height: 1; color: var(--ink-2);
  padding: 3px 7px 3px 6px; border: 1px solid var(--line-2); border-radius: 20px;
  white-space: nowrap;
}
.tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--line-3); }
.tag--urgent { color: var(--ox); border-color: var(--ox-line); }
.tag--urgent::before { background: var(--ox); }
button.tag { background: transparent; cursor: pointer; min-height: 24px; }
button.tag:hover { background: var(--hover); }

.av {
  display: inline-grid; place-items: center; flex: none;
  width: 22px; height: 22px; border-radius: 50%;
  font: 500 10px/1 var(--sans); letter-spacing: .02em;
  background: var(--sel); color: var(--ink-2);
  border: 1px solid var(--line-2);
}
.av--lg { width: 36px; height: 36px; font-size: 13px; }
.av--none { background: transparent; border-style: dashed; }

.field { display: grid; gap: 6px; margin-bottom: var(--s4); }
.field label { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.field input, .field textarea, .pop__extra input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--sheet); font-size: var(--fs);
}
.field textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.field input:focus-visible, .field textarea:focus-visible, .pop__extra input:focus-visible { outline: 2px solid var(--ox); outline-offset: 0; border-color: var(--ox); }
.field [aria-invalid="true"] { border-color: var(--ox); background: var(--ox-soft); }
.field-msg { font-size: var(--fs-sm); color: var(--ox); min-height: 0; }
.field-msg:empty { display: none; }
.field-msg--ok { color: var(--ink-2); }
.check { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--ink-2); margin-bottom: var(--s3); min-height: 24px; }
.check input { width: 16px; height: 16px; margin: 0; }

/* ---------- 4. App grid and banner ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr) var(--cust-w);
  height: 100vh; height: 100dvh;
}
.has-banner .app { height: calc(100dvh - 38px); }
.app[data-view="reports"] { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
.app[data-view="reports"] .list,
.app[data-view="reports"] .thread,
.app[data-view="reports"] .cust { display: none; }

.banner {
  display: flex; align-items: center; justify-content: center; gap: var(--s3);
  height: 38px; padding: 0 var(--s4);
  background: var(--ox); color: var(--ox-ink); font-size: var(--fs-sm);
}
.banner[hidden] { display: none; }
.banner .btn { color: var(--ox-ink); border-color: rgba(251, 246, 242, .5); }
.banner .btn:hover { background: var(--ox-hover); }

/* ---------- 5. Rail ---------- */
.rail {
  display: flex; flex-direction: column; gap: var(--s5);
  padding: var(--s4) var(--s3);
  background: var(--floor);
  border-right: 1px solid var(--line);
  overflow-y: auto; min-height: 0;
}
.rail__brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--s2); }
.mark { width: 28px; height: 28px; flex: none; }
.mark rect { fill: var(--ox); }
.mark path { fill: none; stroke: var(--ox-ink); stroke-width: 1.7; stroke-linecap: round; }
.rail__ws { font-weight: 500; font-size: var(--fs-md); line-height: 1.2; }
.rail__app { font-size: var(--fs-xs); color: var(--ink-3); }
.rail__new { width: 100%; justify-content: flex-start; }
.rail__new kbd { margin-left: auto; }

.views { display: grid; gap: 1px; }
.view {
  display: flex; align-items: center; gap: 10px;
  min-height: 34px; padding: 0 var(--s2);
  border-radius: var(--r); text-decoration: none; color: var(--ink-2);
  transition: background var(--t) var(--ease);
}
.view:hover { background: var(--hover); color: var(--ink); }
.view[aria-current="page"] { background: var(--sheet); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(46, 36, 26, .08); }
.view__n { margin-left: auto; font: 400 var(--fs-sm)/1 var(--mono); color: var(--ink-3); }
.view__n.is-hot { color: var(--ox); }
.view--gap { margin-top: var(--s3); }

.rail__h { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3); padding: 0 var(--s2); margin-bottom: 6px; }
.rail__tags { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.rail__tags button {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  min-height: 28px; padding: 0 var(--s2); border: 0; border-radius: var(--r);
  background: transparent; color: var(--ink-2); font-size: var(--fs-sm); text-align: left;
}
.rail__tags button:hover { background: var(--hover); }
.rail__tags button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); font-weight: 500; }
.rail__tags .num { margin-left: auto; color: var(--ink-3); font-size: var(--fs-xs); }
.rail__tags .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-3); flex: none; }
.rail__tags [aria-pressed="true"] .dot { background: var(--ox); }

.team { list-style: none; margin: 0; padding: 0 var(--s2); display: grid; gap: 8px; }
.team li { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--ink-2); }
.team .who { flex: 1; min-width: 0; }
.team .st { font-size: var(--fs-xs); color: var(--ink-3); }
.team .av { position: relative; }
.team .av::after { content: ""; position: absolute; right: -2px; bottom: -2px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--floor); background: var(--line-3); }
.team .av[data-p="on"]::after { background: #4f6b4a; }
.team .av[data-p="away"]::after { background: #b08a3e; }

.rail__foot { margin-top: auto; display: grid; gap: var(--s2); padding: var(--s3) var(--s2) 0; border-top: 1px solid var(--line); }
.cover { font-size: var(--fs-xs); color: var(--ink-3); }
.sync { display: flex; align-items: center; gap: 6px; min-height: 28px; padding: 0; border: 0; background: none; color: var(--ink-2); font-size: var(--fs-sm); text-align: left; }
.sync:hover { color: var(--ink); }
.sync[aria-pressed="true"] { color: var(--ox); }
.rail__foot .btn { justify-content: flex-start; padding: 0; border: 0; color: var(--ink-2); }
.rail__foot .btn kbd { margin-left: auto; }

/* ---------- 6. Conversation list ---------- */
.list {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--paper);
  border-right: 1px solid var(--line);
}
.list__head { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: var(--s2); padding: var(--s4) var(--s4) var(--s3); }
.list__menu { display: none; }
.list__title { font-size: var(--fs-lg); line-height: 1.2; grid-column: 2; }
.list__sub { grid-column: 2; font-size: var(--fs-xs); color: var(--ink-3); }
.list__tools { display: flex; gap: var(--s2); padding: 0 var(--s4) var(--s3); }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s2);
  height: 34px; padding: 0 var(--s2) 0 10px;
  border: 1px solid var(--line-2); border-radius: var(--r); background: var(--sheet); color: var(--ink-3);
}
.search:focus-within { border-color: var(--ox); box-shadow: 0 0 0 1px var(--ox); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: var(--fs-sm); color: var(--ink); }
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }
.search--block { margin-bottom: var(--s3); }
.sort {
  position: relative; display: flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 0 0 8px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--sheet); color: var(--ink-3);
}
.sort:focus-within { border-color: var(--ox); box-shadow: 0 0 0 1px var(--ox); }
.sort select { border: 0; background: transparent; outline: none; font-size: var(--fs-sm); color: var(--ink); padding: 0 8px 0 0; height: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--s4); }
.chips:empty { display: none; }
.chips { padding-bottom: var(--s3); }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 26px; padding: 0 6px 0 9px; border: 1px solid var(--ox-line); border-radius: 20px; background: var(--ox-soft); color: var(--ox); font-size: var(--fs-xs); }
.chip .i { width: 12px; height: 12px; }

.list__body { flex: 1; min-height: 0; overflow-y: auto; border-top: 1px solid var(--line); position: relative; }
.rows { list-style: none; margin: 0; padding: 0; outline: none; }
.row {
  position: relative;
  display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s3);
  padding: 12px var(--s4) 12px 26px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background var(--t) var(--ease);
}
.row:hover { background: var(--hover); }
.row[aria-selected="true"] { background: var(--sel); }
.rows:focus-visible .row[aria-selected="true"] { outline: 2px solid var(--ox); outline-offset: -2px; border-radius: 0; }
.row__unread { position: absolute; left: 11px; top: 19px; width: 7px; height: 7px; border-radius: 50%; background: var(--ox); }
.row__who { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.is-read .row__who { font-weight: 400; }
.row__time { font: 400 var(--fs-xs)/1.8 var(--mono); color: var(--ink-3); text-align: right; }
.row__subj { grid-column: 1 / -1; font-size: var(--fs-sm); color: var(--ink); line-height: 1.35; }
.row__prev { grid-column: 1 / -1; font-size: var(--fs-sm); color: var(--ink-3); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.row__foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; margin-top: 6px; min-height: 22px; }
.row__foot .tags { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; flex: 1; }
.row__ch { color: var(--ink-3); display: inline-flex; }
.row__ch .i { width: 14px; height: 14px; }

/* SLA chip: quiet when time is left, oxblood when it has run out */
.due { font: 400 var(--fs-xs)/1 var(--mono); color: var(--ink-2); white-space: nowrap; padding: 4px 6px; border-radius: var(--r-sm); border: 1px solid transparent; }
.due--soon { color: var(--ox); border-color: var(--ox-line); }
.due--over { color: var(--ox-ink); background: var(--ox); }
.due--paused { color: var(--ink-3); }

/* ---------- 7. Thread ---------- */
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--sheet); outline: none; }
.thread__head { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s5) var(--s6) var(--s3); }
.thread__back { display: none; margin: -4px 0 0 -8px; }
.thread__title { flex: 1; min-width: 0; }
.thread__subj { font-size: var(--fs-xl); line-height: 1.2; letter-spacing: -.01em; max-width: 30ch; }
.thread__meta { margin-top: 6px; font-size: var(--fs-sm); color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.thread__meta .mono { color: var(--ink-2); }

/* SLA ruler: the target as a tick on a hairline track; the used part fills, oxblood once over */
.sla { flex: none; width: 188px; padding-top: 6px; }
.sla__row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); font-size: var(--fs-xs); color: var(--ink-3); }
.sla__val { font: 400 var(--fs-md)/1.2 var(--mono); color: var(--ink); }
.sla.is-over .sla__val { color: var(--ox); }
.sla__track { position: relative; height: 6px; margin: 8px 0 4px; border-top: 1px solid var(--line-2); }
.sla__fill { position: absolute; left: 0; top: -1px; height: 3px; background: var(--ink-2); max-width: 100%; transition: width .6s var(--ease); }
.sla.is-over .sla__fill { background: var(--ox); }
.sla__tick { position: absolute; top: -5px; width: 1px; height: 9px; background: var(--ink); }
.sla__scale { display: flex; justify-content: space-between; font: 400 11px/1 var(--mono); color: var(--ink-3); }

.actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 var(--s6) var(--s3); border-bottom: 1px solid var(--line); }
.act {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 8px;
  border: 1px solid transparent; border-radius: var(--r); background: transparent; color: var(--ink-2); font-size: var(--fs-sm);
}
.act:hover { background: var(--hover); color: var(--ink); }
.act[aria-expanded="true"] { background: var(--sel); color: var(--ink); }
.act kbd { font-size: 10.5px; }
.act--solve { margin-left: auto; border-color: var(--line-2); color: var(--ink); }
.act--cust { display: none; }
.act--cust[aria-expanded="true"] { background: var(--sel); }

.thread__tags { display: flex; flex-wrap: wrap; gap: 6px; padding: var(--s3) var(--s6) 0; }
.thread__tags:empty { display: none; }

.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s2) var(--s6) var(--s6); }
.msg { padding: var(--s5) 0; border-bottom: 1px solid var(--line); max-width: 72ch; }
.msg:last-child { border-bottom: 0; }
.msg__by { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); }
.msg__name { font-weight: 500; }
.msg__role { font-size: var(--fs-xs); color: var(--ink-3); }
.msg__time { margin-left: auto; font: 400 var(--fs-xs)/1 var(--mono); color: var(--ink-3); }
.msg__body { color: var(--ink); }
.msg__body p + p { margin-top: .7em; }
.msg--agent .msg__body { color: var(--ink-2); }
.msg--note {
  margin: var(--s3) 0; padding: var(--s3) var(--s4);
  background: var(--sand); border: 1px dashed var(--line-3); border-radius: var(--r);
}
.msg--note + .msg { border-top: 0; }
.msg--note .msg__role { color: var(--ink-2); }
.msg--pending { opacity: .62; }
.msg__fail { margin-top: var(--s2); font-size: var(--fs-sm); color: var(--ox); display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.ev { display: flex; gap: var(--s2); align-items: baseline; padding: 10px 0; font-size: var(--fs-xs); color: var(--ink-3); border-bottom: 1px solid var(--line); max-width: 72ch; }
.ev time { margin-left: auto; }
.ev b { font-weight: 500; color: var(--ink-2); }
.ev__dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line-3); flex: none; transform: translateY(-1px); }
.mergemark { color: var(--ink-2); }

.composer { flex: none; margin: 0 var(--s6) var(--s5); border: 1px solid var(--line-2); border-radius: var(--r-lg); background: var(--sheet); box-shadow: 0 2px 8px -4px rgba(46, 36, 26, .12); }
.composer:focus-within { border-color: var(--line-3); }
.composer.is-note { background: var(--sand); border-style: dashed; }
.composer__modes { display: flex; align-items: center; gap: 2px; padding: 6px 8px 0; flex-wrap: wrap; }
.mode { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 8px; border-radius: var(--r); font-size: var(--fs-sm); color: var(--ink-2); cursor: pointer; }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode:has(input:checked) { color: var(--ink); font-weight: 500; background: var(--hover); }
.mode:has(input:focus-visible) { outline: 2px solid var(--ox); outline-offset: 1px; }
.mode kbd { font-size: 10.5px; font-weight: 400; }
.composer__to { margin-left: auto; padding-right: 6px; font-size: var(--fs-xs); color: var(--ink-3); min-width: 0; overflow-wrap: anywhere; }
.composer textarea {
  display: block; width: 100%; min-height: 92px; max-height: 40vh; resize: vertical;
  padding: 10px 14px; border: 0; background: transparent; outline: none; line-height: 1.55;
}
.composer textarea::placeholder { color: var(--ink-3); }
.composer .field-msg { padding: 0 14px 6px; }
.composer__bar { display: flex; align-items: center; gap: var(--s2); padding: 8px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.composer__count { font: 400 var(--fs-xs)/1 var(--mono); color: var(--ink-3); margin-right: auto; }
.composer.is-note #send-solve { display: none; }

.thread__empty { flex: 1; display: grid; place-content: center; text-align: center; gap: var(--s2); padding: var(--s8); color: var(--ink-3); }
.thread__empty h2 { font-size: var(--fs-lg); color: var(--ink); }
.thread.is-blank .thread__head, .thread.is-blank .actions, .thread.is-blank .thread__tags, .thread.is-blank .composer { display: none; }

/* ---------- 8. Customer panel ---------- */
.cust { display: flex; flex-direction: column; min-height: 0; background: var(--paper); border-left: 1px solid var(--line); }
.cust__head { display: flex; align-items: center; gap: var(--s2); padding: var(--s5) var(--s4) var(--s2); }
.cust__name { flex: 1; font-size: var(--fs-md); line-height: 1.3; }
.cust__close { display: none; }
.cust__body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--s4) var(--s6); }
.cust__id { display: flex; gap: var(--s3); align-items: center; margin-bottom: var(--s4); }
.cust__id p { font-size: var(--fs-sm); color: var(--ink-2); overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s3); margin: 0 0 var(--s5); font-size: var(--fs-sm); }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; color: var(--ink); overflow-wrap: anywhere; }
.cust__h { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3); margin: var(--s5) 0 var(--s2); display: flex; justify-content: space-between; }
.order { border-top: 1px solid var(--line); padding: var(--s3) 0; }
.order:last-of-type { border-bottom: 1px solid var(--line); }
.order__top { display: flex; justify-content: space-between; gap: var(--s2); align-items: baseline; }
.order__no { font: 400 var(--fs-sm)/1.3 var(--mono); }
.order__st { font-size: var(--fs-xs); color: var(--ink-2); }
.order__st.is-moving { color: var(--ox); }
.order__date { font-size: var(--fs-xs); color: var(--ink-3); }
.order ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; font-size: var(--fs-sm); color: var(--ink-2); }
.order li { display: flex; justify-content: space-between; gap: var(--s3); }
.order li .mono { color: var(--ink); white-space: nowrap; }
.order__total { display: flex; justify-content: space-between; margin-top: 6px; padding-top: 6px; border-top: 1px dotted var(--line-2); font-size: var(--fs-sm); }
.order__total .mono { font-weight: 400; }
.others { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.others button { width: 100%; text-align: left; display: grid; gap: 1px; padding: 8px; border: 0; border-radius: var(--r); background: transparent; font-size: var(--fs-sm); min-height: 40px; }
.others button:hover { background: var(--hover); }
.others .mono { font-size: var(--fs-xs); color: var(--ink-3); }
.cust__none { font-size: var(--fs-sm); color: var(--ink-3); }

/* ---------- 9. Reports ---------- */
.reports { min-width: 0; min-height: 0; overflow-y: auto; background: var(--sheet); padding: var(--s6) var(--s8) var(--s10); }
.reports[hidden] { display: none; }
.rep__head { display: flex; align-items: flex-end; gap: var(--s4); flex-wrap: wrap; padding-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.rep__head > div:first-of-type { flex: 1; min-width: 200px; }
.rep__title { font-size: var(--fs-xl); line-height: 1.2; }
.rep__range { font: 400 var(--fs-sm)/1.5 var(--mono); color: var(--ink-3); margin-top: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); padding: 2px; background: var(--paper); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; min-height: 30px; padding: 0 12px; border-radius: 4px; font-size: var(--fs-sm); color: var(--ink-2); cursor: pointer; }
.seg input:checked + span { background: var(--sheet); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(46, 36, 26, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--ox); outline-offset: 1px; }
.rep__lede { font-size: var(--fs-md); line-height: 1.6; max-width: 68ch; margin: var(--s5) 0 var(--s4); color: var(--ink); }
.rep__lede .mono { font-size: .95em; }
.figs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 var(--s8); border-top: 1px solid var(--line); }
.figs div { padding: var(--s3) var(--s4) var(--s3) 0; border-bottom: 1px solid var(--line); }
.figs div + div { padding-left: var(--s4); border-left: 1px solid var(--line); }
.figs dt { font-size: var(--fs-xs); color: var(--ink-3); }
.figs dd { margin: 2px 0 0; font: 400 var(--fs-lg)/1.3 var(--mono); }
.figs .delta { display: block; font: 400 var(--fs-xs)/1.4 var(--sans); color: var(--ink-3); margin-top: 2px; }
.figs .delta.is-worse { color: var(--ox); }

.chart { margin-bottom: var(--s8); }
.chart__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.chart__h { font-size: var(--fs-md); margin-bottom: 4px; }
.legend { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; font-size: var(--fs-xs); color: var(--ink-3); }
.key { display: inline-block; width: 10px; height: 10px; margin-right: -4px; }
.key--in { background: var(--ink-2); }
.key--out { background: var(--line-2); border: 1px solid var(--line-3); }
.key--line { height: 2px; background: var(--ox); width: 14px; }
.key--target { height: 0; border-top: 1px dashed var(--ink-2); width: 14px; }
.readout { font: 400 var(--fs-sm)/1.5 var(--mono); color: var(--ink-2); min-height: 1.5em; margin-bottom: var(--s2); }
.chart__frame { position: relative; width: 100%; }
.chart__frame svg { display: block; width: 100%; overflow: visible; }
.ax text { font: 400 11px var(--mono); fill: var(--ink-3); }
.ax line, .ax path { stroke: var(--line-2); stroke-width: 1; shape-rendering: crispEdges; }
.ax .grid { stroke: var(--line); }
.bar-in { fill: var(--ink-2); }
.bar-out { fill: var(--line-2); stroke: var(--line-3); stroke-width: 1; }
.day { cursor: default; outline: none; }
.day .hit { fill: transparent; }
.day:hover .hit, .day:focus-visible .hit, .day.is-on .hit { fill: rgba(122, 31, 43, .06); }
.day:focus-visible .hit { stroke: var(--ox); stroke-width: 1.5; }
.day.is-weekend .lbl { fill: var(--ink-3); }
.frt-line { fill: none; stroke: var(--ox); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.frt-dot { fill: var(--sheet); stroke: var(--ox); stroke-width: 1.5; }
.frt-target { stroke: var(--ink-2); stroke-dasharray: 4 3; stroke-width: 1; }
.target-lbl { font: 400 11px var(--mono); fill: var(--ink-2); }
.day.is-on .frt-dot, .day:focus-visible .frt-dot { fill: var(--ox); }

.rep__tables { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--s8); align-items: start; }
.tblwrap { border-top: 1px solid var(--line); margin-top: var(--s2); }
.tblwrap--scroll { max-height: 360px; overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th, .tbl td { text-align: left; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { font-weight: 500; color: var(--ink-3); font-size: var(--fs-xs); background: var(--sheet); position: sticky; top: 0; }
.tbl td.n, .tbl th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; padding-right: 0; padding-left: 10px; }
.tbl tfoot td { font-weight: 500; border-bottom: 0; border-top: 1px solid var(--line-3); }
.tbl .bar { display: inline-block; height: 6px; background: var(--ink-2); vertical-align: middle; margin-right: 8px; }

/* ---------- 10. Popover, dialogs, toasts ---------- */
.pop {
  position: fixed; z-index: 60; width: 280px; max-width: calc(100vw - 24px);
  background: var(--sheet); border: 1px solid var(--line-2); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); padding: 6px;
}
.pop[hidden] { display: none; }
.pop__h { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 500; padding: 6px 8px 4px; }
.pop__filter { width: 100%; height: 32px; padding: 0 8px; margin-bottom: 4px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--paper); font-size: var(--fs-sm); outline: none; }
.pop__filter:focus-visible { border-color: var(--ox); }
.pop__list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.opt { display: flex; align-items: center; gap: var(--s2); min-height: 34px; padding: 4px 8px; border-radius: var(--r); font-size: var(--fs-sm); cursor: pointer; }
.opt[aria-selected="true"] { background: var(--hover); }
.opt__sub { margin-left: auto; font: 400 var(--fs-xs)/1.3 var(--mono); color: var(--ink-3); text-align: right; }
.opt__box { width: 14px; height: 14px; border: 1px solid var(--line-3); border-radius: 3px; display: grid; place-items: center; flex: none; }
.opt[data-on="true"] .opt__box { background: var(--ox); border-color: var(--ox); }
.opt__box .i { width: 12px; height: 12px; color: var(--ox-ink); opacity: 0; }
.opt[data-on="true"] .opt__box .i { opacity: 1; }
.opt__two { display: grid; min-width: 0; }
.opt__two small { font-size: var(--fs-xs); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt--none { color: var(--ink-3); cursor: default; }
.pop__extra:empty { display: none; }
.pop__extra { border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 4px 4px; display: grid; gap: 6px; }
.pop__extra label { font-size: var(--fs-xs); color: var(--ink-3); }
.pop__extra .row2 { display: flex; gap: 6px; }

.dlg {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-lg);
  background: var(--sheet); color: var(--ink); box-shadow: var(--shadow-dlg);
}
.dlg::backdrop { background: rgba(34, 31, 27, .32); }
.dlg--keys { width: min(760px, calc(100vw - 24px)); }
.dlg__form { padding: var(--s5) var(--s6) var(--s5); }
.dlg__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s4); }
.dlg__head h2 { font-size: var(--fs-lg); }
.dlg__head .iconbtn { margin-right: -8px; }
.dlg__lede { font-size: var(--fs-sm); color: var(--ink-2); margin-bottom: var(--s4); max-width: 60ch; }
.dlg__foot { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }
.pick { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; border-top: 1px solid var(--line); }
.pick li { display: grid; grid-template-columns: auto 1fr auto; gap: 2px var(--s3); align-items: center; padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: var(--fs-sm); }
.pick li:hover { background: var(--hover); }
.pick li[aria-selected="true"] { background: var(--sel); }
.pick .radio { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--line-3); }
.pick li[aria-selected="true"] .radio { border: 4px solid var(--ox); }
.pick .mono { font-size: var(--fs-xs); color: var(--ink-3); }
.pick .same { font-size: var(--fs-xs); color: var(--ox); }
.pick__empty { color: var(--ink-3); cursor: default !important; }
.merge__preview { margin-top: var(--s3); font-size: var(--fs-sm); color: var(--ink-2); min-height: 1.5em; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s6); }
.keys dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 10px var(--s3); align-content: start; font-size: var(--fs-sm); }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--ink-2); }

.toasts { position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); z-index: 70; display: grid; gap: var(--s2); justify-items: center; pointer-events: none; }
.toast { display: flex; align-items: center; gap: var(--s3); padding: 8px 8px 8px 14px; background: var(--ink); color: var(--sheet); border-radius: var(--r); font-size: var(--fs-sm); box-shadow: var(--shadow-pop); pointer-events: auto; max-width: calc(100vw - 32px); }
.toast button { border: 1px solid rgba(251, 249, 246, .3); background: transparent; color: var(--sheet); border-radius: var(--r-sm); min-height: 28px; padding: 0 8px; font-size: var(--fs-xs); }
.toast button:hover { background: rgba(251, 249, 246, .12); }
.gkey { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 70; background: var(--ink); color: var(--sheet); font: 400 var(--fs-xs)/1 var(--mono); padding: 8px 10px; border-radius: var(--r); }
.gkey[hidden] { display: none; }

.bbar { display: none; }
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(34, 31, 27, .28); }
.scrim[hidden] { display: none; }

/* ---------- 11. States ---------- */
.state { padding: var(--s8) var(--s5); display: grid; gap: var(--s3); justify-items: start; color: var(--ink-2); font-size: var(--fs-sm); max-width: 44ch; }
.state[hidden] { display: none; }
.state__h { font-size: var(--fs-md); font-weight: 500; color: var(--ink); }
.state__code { font: 400 var(--fs-xs)/1.4 var(--mono); color: var(--ink-3); }
.state--static { max-width: none; }
.state--static .tbl td { white-space: normal; }
.sk { list-style: none; margin: 0; padding: 0; }
.sk li { padding: 14px var(--s4) 14px 26px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.sk i { display: block; height: 10px; border-radius: 3px; background: var(--hover); }
.sk i:nth-child(1) { width: 46%; }
.sk i:nth-child(2) { width: 82%; }
.sk i:nth-child(3) { width: 64%; }
.sk-thread { padding: var(--s6); display: grid; gap: 14px; }
.sk-thread i { display: block; height: 12px; border-radius: 3px; background: var(--hover); }
.sk-thread i:first-child { height: 22px; width: 52%; margin-bottom: var(--s4); }
.sk-thread i:nth-child(3n) { width: 70%; }

/* ---------- 12. Motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: no-preference) {
  .sk i, .sk-thread i { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: .45; } }
  /* Signature: a solved or moved row folds shut, and the queue closes up beneath it */
  .row.is-leaving { animation: fold 360ms var(--ease) forwards; overflow: hidden; }
  @keyframes fold { 0% { opacity: 1; max-height: 140px; } 40% { opacity: 0; } 100% { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; border-bottom-width: 0; } }
  .msg.is-new, .ev.is-new { animation: rise 420ms var(--ease); }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } }
  .pop:not([hidden]) { animation: pop-in 160ms var(--ease); }
  @keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }
  .dlg[open] { animation: pop-in 200ms var(--ease); }
  .toast { animation: rise 260ms var(--ease); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
  .btn .spin { animation: none; border-right-color: currentColor; opacity: .5; }
}

/* ---------- 13. Narrow screens ---------- */

/* Up to 1360: the customer panel becomes a drawer over the thread, opened with I */
@media (max-width: 1360px) {
  .app { grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); }
  .act--cust { display: inline-flex; }
  .cust {
    position: fixed; z-index: 45; top: 0; right: 0; bottom: 0; width: min(340px, 92vw);
    box-shadow: var(--shadow-dlg); transform: translateX(105%); visibility: hidden;
    transition: transform 260ms var(--ease), visibility 0s linear 260ms;
  }
  .app.cust-open .cust { transform: none; visibility: visible; transition: transform 260ms var(--ease); }
  .cust__close { display: inline-grid; }
}

/* Up to 1080: the rail becomes a drawer too */
@media (max-width: 1080px) {
  :root { --list-w: 320px; }
  .app, .app[data-view="reports"] { grid-template-columns: var(--list-w) minmax(0, 1fr); }
  .app[data-view="reports"] { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; z-index: 45; top: 0; left: 0; bottom: 0; width: 260px;
    box-shadow: var(--shadow-dlg); transform: translateX(-105%); visibility: hidden;
    transition: transform 260ms var(--ease), visibility 0s linear 260ms;
  }
  .app.rail-open .rail { transform: none; visibility: visible; transition: transform 260ms var(--ease); }
  .list__menu { display: inline-grid; margin: -6px 0 0 -8px; grid-row: 1 / 3; align-self: start; }
  .list__head { grid-template-columns: auto 1fr; }
  .thread__head { padding: var(--s4) var(--s5) var(--s3); }
  .actions, .thread__tags { padding-left: var(--s5); padding-right: var(--s5); }
  .msgs { padding-left: var(--s5); padding-right: var(--s5); }
  .composer { margin: 0 var(--s5) var(--s4); }
  .sla { width: 150px; }
  .act kbd { display: none; }
  .thread__subj { font-size: 22px; }
  .reports { padding: var(--s5) var(--s5) var(--s10); }
  .rep__tables { grid-template-columns: 1fr; }
}

/* Up to 860: SLA ruler moves under the subject */
@media (max-width: 860px) {
  .thread__head { flex-wrap: wrap; }
  .sla { width: 100%; order: 3; padding-top: 0; }
  .sla__scale { display: none; }
}

/* Up to 720: phones. One pane at a time, with a bottom bar */
@media (max-width: 720px) {
  :root { --fs: 14px; }
  .app, .app[data-view="reports"] { grid-template-columns: minmax(0, 1fr); height: calc(100dvh - var(--bbar-h)); }
  .has-banner .app { height: calc(100dvh - var(--bbar-h) - 38px); }
  .app[data-pane="thread"] .list { display: none; }
  .app[data-pane="list"] .thread { display: none; }
  .list { border-right: 0; }
  .thread__back { display: inline-grid; }
  .thread__head { padding: var(--s3) var(--s4) var(--s2); }
  .thread__subj { font-size: 19px; }
  .actions { padding: 0 var(--s3) var(--s2); gap: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .act { flex: none; min-height: 40px; }
  .act--solve { margin-left: 0; }
  .thread__tags, .msgs { padding-left: var(--s4); padding-right: var(--s4); }
  .composer { margin: 0 var(--s3) var(--s3); }
  .composer textarea { min-height: 72px; }
  .composer__to { display: none; }
  #send-btn kbd { display: none; }
  .composer__count { display: none; }
  #saved-btn { margin-right: auto; }
  .btn, .iconbtn { min-height: 40px; }
  .iconbtn { width: 40px; height: 40px; }
  .search, .sort { height: 40px; }
  .search kbd { display: none; }
  .row { padding: 14px var(--s4) 14px 26px; }
  .bbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: var(--bbar-h);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--floor); border-top: 1px solid var(--line-2);
  }
  .bbar a { position: relative; display: grid; justify-items: center; align-content: center; gap: 3px; text-decoration: none; color: var(--ink-3); font-size: 11px; }
  .bbar a[aria-current="page"] { color: var(--ink); font-weight: 500; }
  .bbar a[aria-current="page"] .i { color: var(--ox); }
  .bbar .i { width: 18px; height: 18px; }
  .bbar b { position: absolute; top: 7px; left: calc(50% + 7px); font: 400 10px/1 var(--mono); color: var(--ink-2); }
  .cust { width: 100vw; }
  .reports { padding: var(--s4) var(--s4) var(--s8); }
  .rep__head { align-items: flex-start; }
  .rep__head .list__menu { display: none; }
  .seg { width: 100%; }
  .seg label { flex: 1; }
  .seg span { justify-content: center; width: 100%; min-height: 36px; }
  .figs { grid-template-columns: 1fr 1fr; }
  .figs div:nth-child(3) { padding-left: 0; border-left: 0; }
  .keys { grid-template-columns: 1fr; gap: var(--s4); }
  .toasts { bottom: calc(var(--bbar-h) + var(--s3)); }
  .dlg__form { padding: var(--s4); }
  .dlg__foot .btn { flex: 1; }
  .list__menu { display: inline-grid; }
}

/* ---------- Rail tags as compact wrapping pills (keeps the rail foot on screen at 900px) ---------- */
.rail__tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 var(--s2); }
.rail__tags button {
  width: auto; min-height: 26px; padding: 0 8px; gap: 5px;
  border: 1px solid var(--line-2); border-radius: 20px; font-size: var(--fs-xs);
}
.rail__tags button[aria-pressed="true"] { border-color: var(--ox); color: var(--ox); background: var(--ox-soft); }
.rail__tags .num { margin-left: 0; }
.rail { gap: var(--s4); }
@media (max-width: 720px) { .bbar b { top: 6px; left: calc(50% + 10px); } }
@media (max-width: 720px) {
  .composer textarea { min-height: 52px; }
  .mode kbd { display: none; }
  .act { padding: 0 9px; }
  .act:not([data-act="assign"]):not([data-act="solve"]) .act__l { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .actions { justify-content: space-between; }
}
@media (max-width: 860px) {
  .act:not([data-act="assign"]):not([data-act="solve"]) .act__l { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .composer__count, #send-btn kbd { display: none; }
}

/* Toasts sit at the foot of the list on wide screens, clear of the composer and its Send button */
@media (min-width: 721px) { .toasts { left: calc(var(--rail-w) + var(--s4)); transform: none; justify-items: start; } }
@media (min-width: 721px) and (max-width: 1080px) { .toasts { left: var(--s4); } }

/* Without JavaScript: the static queue summary in the list carries the page; hide controls that need a script */
.no-js .actions, .no-js .composer, .no-js .sla, .no-js .rail__new, .no-js .list__tools, .no-js .rail__group, .no-js .sync, .no-js #keys-btn, .no-js .cust, .no-js .bbar { display: none; }
.no-js .app { grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); }
@media (max-width: 1080px) { .no-js .app { grid-template-columns: minmax(0, 1fr); } .no-js .thread { display: none; } }

/* Phones: drawers stop above the bottom bar, and the bar sits over the scrim, so it stays reachable with the customer panel open */
@media (max-width: 720px) {
  .cust, .rail { bottom: var(--bbar-h); }
  .bbar { z-index: 50; }
}
