/* ──────────────────────────────────────────────────────────────────────
   Support console — design tokens are inherited from
   /design-system/colors_and_type.css. This file only adds layout and
   component-level rules specific to the support app.
   ────────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html, body {
  background: var(--n-50);
  color: var(--n-900);
  font-family: var(--font-sans);
  margin: 0;
  min-height: 100vh;
}

a { color: var(--kiss-red); }

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

/* ── Header ───────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--n-200);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-header__home { display: inline-flex; align-items: center; }
.app-header__wordmark { height: 22px; width: auto; }

.app-header__divider {
  width: 1px; height: 18px; background: var(--n-300);
}

.app-header__label {
  color: var(--n-600);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.app-header__nav {
  display: flex;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-header__nav a {
  color: var(--n-500);
  text-decoration: none;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
}
.app-header__nav a:hover { color: var(--n-900); background: var(--n-100); }
.app-header__nav a[aria-current="page"] {
  color: var(--n-0);
  background: var(--n-900);
}

.app-header__user {
  display: flex; align-items: center; gap: var(--space-3);
  font-family: var(--font-mono); font-size: 12px;
  color: var(--n-600);
}
.app-header__user button {
  background: transparent; border: 0; color: var(--n-500);
  cursor: pointer; font-family: inherit; font-size: 11px;
  text-decoration: underline;
}

/* Missed-calls counter — lives between nav and user, only renders when count > 0. */
.missed-badge {
  display: none;            /* shown via JS when count > 0 */
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--error-soft);
  color: #991b1b;
  border: 1px solid #fca5a5;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-decoration: none;
  animation: missedPulse 2.4s ease-in-out infinite;
}
.missed-badge:hover { background: #fecaca; }

@keyframes missedPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.15); }
}

/* ── Auth gate ────────────────────────────────────────────────────── */

.auth-card {
  max-width: 380px;
  margin: 12vh auto 0;
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
}
.auth-card h1 { margin: 0 0 var(--space-2); font-size: 22px; }
.auth-card p  { margin: 0 0 var(--space-6); color: var(--n-600); font-size: 14px; }
.auth-card label { display: block; font-size: 12px; color: var(--n-700); margin-bottom: var(--space-1); }
.auth-card input {
  width: 100%; padding: var(--space-3); border: 1px solid var(--n-300);
  border-radius: var(--radius-md); font: inherit; background: var(--n-0);
}
.auth-card button {
  margin-top: var(--space-4); width: 100%;
  background: var(--kiss-red); color: var(--kiss-red-contrast);
  border: 0; padding: var(--space-3); border-radius: var(--radius-md);
  font: inherit; font-weight: 600; cursor: pointer;
}
.auth-card button:hover { background: var(--kiss-red-hover); }
.auth-card .auth-card__msg { margin-top: var(--space-4); font-size: 13px; min-height: 1em; }
.auth-card .auth-card__msg.error   { color: var(--error); }
.auth-card .auth-card__msg.success { color: var(--success); }

/* ── Generic patterns ─────────────────────────────────────────────── */

.section { margin-bottom: var(--space-10); }
.section__heading {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--n-500);
  margin: 0 0 var(--space-3);
}

.callout {
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.muted { color: var(--n-500); }
.empty {
  color: var(--n-500);
  font-style: italic;
  padding: var(--space-6);
  text-align: center;
  border: 1px dashed var(--n-200);
  border-radius: var(--radius-lg);
}

/* ── Live call queue ──────────────────────────────────────────────── */

/* Filter / count toolbar above the queue. Gets compact when the detail
   pane is open (master collapses to a left rail). */
.queue-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.queue-toolbar .section__heading { margin: 0; }
.queue-toolbar__controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.filter-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--n-500);
}
.queue-filter {
  padding: 4px var(--space-2);
  border: 1px solid var(--n-300);
  border-radius: var(--radius-md);
  background: var(--n-0);
  font: inherit;
  font-size: 12px;
  color: var(--n-900);
}
.queue-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--n-500);
  white-space: nowrap;
}

.queue {
  display: grid;
  gap: var(--space-3);
}

.queue-footer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  justify-content: center;
}
.queue-footer .btn { font-size: 13px; padding: var(--space-2) var(--space-4); }

/* In the compact (detail-open) layout, the toolbar drops the controls and
   shows just the heading, since horizontal space is tight. */
.inbox--detail-open .queue-toolbar {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}
.inbox--detail-open .queue-toolbar__controls {
  width: 100%;
  flex-wrap: wrap;
}
.inbox--detail-open .filter-label { display: none; }
.inbox--detail-open .queue-filter { flex: 1; min-width: 0; }

.queue-row {
  display: grid;
  grid-template-columns: 1.4fr 2fr 1fr 1fr auto;
  gap: var(--space-4);
  align-items: center;
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  text-decoration: none;
  color: inherit;
  transition: border-color 120ms ease, transform 120ms ease;
}
.queue-row:hover { border-color: var(--kiss-red); transform: translateY(-1px); }

.queue-row__caller .phone {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--n-700);
  white-space: nowrap;
}
.queue-row__caller .name { font-weight: 600; }
.queue-row__agent {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--n-500);
  margin-top: 2px;
}

.queue-row__context { color: var(--n-700); font-size: 13px; }
.queue-row__context strong { color: var(--n-900); }

.queue-row__category {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--n-600);
}

.queue-row__when {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--n-500);
  text-align: right;
}

.queue-row__status {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}
.queue-row__status.open      { background: var(--warning-soft); color: #92400e; }
.queue-row__status.resolved  { background: var(--success-soft); color: #065f46; }
.queue-row__status.ringing   { background: var(--kiss-red);     color: var(--kiss-red-contrast); animation: ringingPulse 1.4s ease-in-out infinite; }
.queue-row__status.live      { background: #1E40E8;             color: #FFFFFF; }
.queue-row__status.pending   { background: var(--warning-soft); color: #92400e; }
.queue-row__status.missed    { background: var(--error-soft);   color: #991b1b; }
.queue-row__status.followup  { background: var(--info-soft);    color: var(--n-700); }

@keyframes ringingPulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(216, 8, 18, 0.6); }
  50%      { transform: scale(1.04); box-shadow: 0 0 0 6px rgba(216, 8, 18, 0); }
}

.queue-row.is-ringing { border-color: var(--kiss-red); box-shadow: 0 0 0 2px rgba(216, 8, 18, 0.18); }
.queue-row.is-live    { border-color: #1E40E8;        box-shadow: 0 0 0 2px rgba(30, 64, 232, 0.16); }
.queue-row.is-missed  { border-color: #DC2626; }
.queue-row.is-selected{ border-color: var(--n-900);   background: var(--n-50); }

/* ── Inbox layout (master + slide-in detail) ────────────────────────── */

.inbox {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
  align-items: start;
}

/* When a call is selected, queue collapses to a left rail, detail pane
   takes the rest of the page. On narrow screens, queue fully hides and
   detail is the whole view (back-button via Close link). */
.inbox.inbox--detail-open {
  grid-template-columns: 280px 1fr;
}

.inbox__queue { min-width: 0; }   /* flexbox/grid overflow guard */
.inbox__detail {
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  min-width: 0;
}

.detail-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-3);
}

@media (max-width: 900px) {
  .inbox.inbox--detail-open { grid-template-columns: 1fr; }
  .inbox.inbox--detail-open .inbox__queue { display: none; }
}

/* Compact queue rows when the detail pane is open (more rows visible). */
.inbox--detail-open .queue-row {
  grid-template-columns: 1fr auto;
  padding: var(--space-3) var(--space-4);
  gap: var(--space-2);
}
.inbox--detail-open .queue-row__context,
.inbox--detail-open .queue-row__category,
.inbox--detail-open .queue-row__when {
  display: none;
}
.inbox--detail-open .queue-row__caller {
  min-width: 0;
}
.inbox--detail-open .queue-row__caller .phone {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inbox--detail-open .queue-row__status {
  font-size: 9px;
  padding: 1px 6px;
}

.context-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-family: var(--font-mono);
}
.context-pill.resolved { background: var(--success-soft); color: #065f46; }
.context-pill.pending  { background: var(--info-soft);    color: var(--n-700); }
.context-pill.failed,
.context-pill.unknown  { background: var(--error-soft);   color: #991b1b; }

/* ── Single-call view ─────────────────────────────────────────────── */

/* Detail layout. Top section is a 2-col split: caller context (left) +
   reference aside (right). Below the top, AI summary / transcript /
   resolution form go full width since they want horizontal room. */
.call-detail {
  display: grid;
  gap: var(--space-6);
}

.call-detail__top {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--space-6);
  align-items: start;
}
@media (max-width: 1100px) {
  .call-detail__top { grid-template-columns: 1fr; }
}

/* Resolution form: side-by-side resolution + notes textareas, then
   category / promote / confirm in a single action row. */
.resolution-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 900px) {
  .resolution-grid { grid-template-columns: 1fr; }
}

.resolution-actions {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-wrap: wrap;
  padding: var(--space-4) 0 0;
  border-top: 1px solid var(--n-200);
  margin-top: var(--space-4);
}

.resolution-actions__category {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.resolution-actions__category select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--n-300);
  border-radius: var(--radius-md);
  font: inherit;
  background: var(--n-0);
  min-width: 220px;
}
.resolution-actions__spacer { flex: 1; }

.call-back {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--n-500);
  text-decoration: none;
  display: inline-block;
  margin-bottom: var(--space-5);
}

.call-context {
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.call-context dl { display: grid; grid-template-columns: 110px 1fr; gap: var(--space-2) var(--space-4); margin: 0; }
.call-context dt { color: var(--n-500); font-size: 12px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }
.call-context dd { margin: 0; color: var(--n-900); font-size: 14px; }
.call-context__top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
}
.call-context__top h2 { margin: 0; font-size: 18px; }
.btn-link {
  background: transparent; border: 0;
  color: var(--kiss-red); font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer; padding: 0;
}
.btn-link:hover { color: var(--kiss-red-hover); text-decoration: underline; }

.transcript {
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.55;
  color: var(--n-700);
}
.transcript.collapsed { max-height: 120px; }

.field-block {
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.field-block label {
  display: block; margin-bottom: var(--space-2);
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--n-500);
}
.field-block textarea, .field-block input, .field-block select {
  width: 100%; padding: var(--space-3); border: 1px solid var(--n-300);
  border-radius: var(--radius-md); font: inherit; background: var(--n-0);
  color: var(--n-900); resize: vertical; min-height: 84px;
}
.field-block textarea { font-family: var(--font-sans); line-height: 1.5; }

.btn {
  background: var(--kiss-red); color: var(--kiss-red-contrast);
  border: 0; padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md); font: inherit; font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--kiss-red-hover); }
.btn.secondary {
  background: var(--n-0); color: var(--n-900); border: 1px solid var(--n-300);
}
.btn.secondary:hover { background: var(--n-100); }

.actions-row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-weight: normal !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--n-700) !important;
  font-family: var(--font-sans) !important;
  font-size: 14px !important;
}
.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
}
/* Hover-revealing "what does this mean?" indicator on the KB checkbox.
   The label carries a `title` attribute that browsers render as a tooltip;
   this badge gives users a visual cue that hovering will explain the
   criteria so the right calls — non-obvious fixes worth reusing — get
   promoted and routine flows don't add noise. */
.kb-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--n-200);
  color: var(--n-600);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: help;
  user-select: none;
}
.checkbox-row:hover .kb-hint { background: var(--n-300); color: var(--n-900); }

.aside-panel {
  background: var(--n-0);
  border: 1px solid var(--n-200);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.aside-panel h3 {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--n-700);
}
.aside-panel .item {
  border-top: 1px solid var(--n-100);
  padding: var(--space-3) 0;
}
.aside-panel .item:first-of-type { border-top: 0; padding-top: 0; }
.aside-panel .item__title { font-weight: 600; font-size: 14px; }
.aside-panel .item__sub { font-size: 12px; color: var(--n-500); margin-top: 2px; }
.aside-panel .item__body { font-size: 13px; color: var(--n-700); margin-top: var(--space-2); }
.aside-panel a { text-decoration: none; }

/* ── Activity timeline (right aside on the call detail view) ─────── */

.timeline-panel { padding: var(--space-4) var(--space-5) var(--space-3); }
.timeline-panel h3 {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--n-700);
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 560px;
  overflow-y: auto;
  /* Subtle inset so the scroll affordance reads as part of the panel,
     not a frame. */
  margin: 0 calc(-1 * var(--space-2));
  padding: 0 var(--space-2) var(--space-2);
}

a.timeline-item, div.timeline-item {
  display: block;
  border: 1px solid var(--n-200);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  background: var(--n-0);
  text-decoration: none;
  color: inherit;
  transition: border-color 80ms ease, background 80ms ease;
}
a.timeline-item:hover { border-color: var(--n-400); background: var(--n-50); }
.timeline-item.is-active {
  border-color: var(--n-900);
  background: var(--n-50);
  box-shadow: inset 3px 0 0 var(--kiss-red);
}

/* Card head: three columns — activity (left), actor (middle), time
   (right). The middle column flexes so long names truncate before the
   time column collapses. No body row anymore — the full SMS body now
   lives in the main detail pane when the row is selected. */
.timeline-item__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}
.timeline-item__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--n-900);
  flex: 0 0 auto;
  white-space: nowrap;
}
.timeline-item__name {
  font-size: 12px;
  color: var(--n-700);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.timeline-item__time {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--n-500);
  white-space: nowrap;
  flex: 0 0 auto;
}

/* SMS rows share the same shape as call rows — a dashed border is the
   only visual cue that this is a message, not a call. */
.timeline-item--sms {
  border-style: dashed;
}

/* Outbound calls are clickable just like inbound now (the body view
   shows their resolution form), but the muted background keeps them
   visually distinct so a row of green-pill answered calls still reads
   as the operator's pickups. */
.timeline-item--outbound {
  background: var(--n-50);
}
.timeline-item--outbound:hover {
  background: var(--n-100);
}

/* SMS body in the main detail pane — readable, monospace-ish, with a
   light background to distinguish it from running prose. */
.sms-detail-body {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

/* ── SMS bar (compact) + thread ──────────────────────────────────── */

/* Lives just below the call-context card. Single small button by default;
   if a template needs operator input, the button expands inline. Goal:
   stay out of the way until the agent wants it. */
.sms-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.sms-bar__send {
  padding: var(--space-2) var(--space-4);
  font-size: 13px;
  font-weight: 500;
  background: var(--n-0);
  color: var(--n-900);
  border: 1px solid var(--n-300);
}
.sms-bar__send:hover { background: var(--n-100); border-color: var(--n-400); }
.sms-bar__send:disabled { opacity: 0.5; cursor: wait; }

.sms-bar__status {
  font-size: 12px;
  font-family: var(--font-mono);
}
.sms-bar__status.error { color: var(--error); }

.sms-template-form {
  border: 1px solid var(--n-300);
  border-radius: var(--radius-md);
  background: var(--n-0);
  overflow: hidden;
}
.sms-template-form > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  font-size: 13px;
  font-weight: 500;
  color: var(--n-900);
}
.sms-template-form > summary::-webkit-details-marker { display: none; }
.sms-template-form > summary:hover { background: var(--n-100); }
.sms-template-form[open] > summary { border-bottom: 1px solid var(--n-200); }

.sms-template-form__body {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--n-50);
}
.sms-template-form__body label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--n-500);
  margin: 0;
  white-space: nowrap;
}
.sms-template-form__body input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--n-300);
  border-radius: var(--radius-md);
  font: inherit;
  font-family: var(--font-mono);
  text-transform: uppercase;
  background: var(--n-0);
  min-width: 100px;
}

.sms-msg-status {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--n-500);
}
.sms-msg-status.error { color: var(--error); }

/* ── KB pages ─────────────────────────────────────────────────────── */

.kb-search-row {
  display: flex; gap: var(--space-3); margin-bottom: var(--space-6);
}
.kb-search-row input {
  flex: 1; padding: var(--space-3); border: 1px solid var(--n-300);
  border-radius: var(--radius-md); font: inherit; background: var(--n-0);
}

.kb-list { display: grid; gap: var(--space-3); }

.kb-row {
  display: block; background: var(--n-0); border: 1px solid var(--n-200);
  border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
  text-decoration: none; color: inherit;
}
.kb-row:hover { border-color: var(--kiss-red); }
.kb-row__title { font-weight: 600; margin-bottom: 4px; }
.kb-row__sub   { font-size: 12px; color: var(--n-500); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }
.kb-row__body  { margin-top: var(--space-3); color: var(--n-700); font-size: 14px; line-height: 1.55; }

/* ── Client support tickets ───────────────────────────────────────── */

.tickets-main {
  padding: var(--space-6) var(--space-6) var(--space-16);
  max-width: 1100px; margin: 0 auto;
}

.tickets-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); margin-bottom: var(--space-4);
}
.tickets-toolbar .section__heading { margin: 0; }

/* Filter row — search + status + company + awaiting toggle + result count. */
.tickets-filterbar {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--n-50, #fafafa); border: 1px solid var(--n-200);
  border-radius: var(--radius-md);
}
.tickets-filter__search {
  flex: 1; min-width: 220px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--n-300); border-radius: var(--radius-md);
  font: inherit; font-size: 14px;
  background: var(--n-0);
}
.tickets-filter__search:focus { outline: 2px solid var(--kiss-red); outline-offset: -1px; }
.tickets-filter__select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--n-300); border-radius: var(--radius-md);
  font: inherit; font-size: 14px;
  background: var(--n-0); cursor: pointer;
}
.tickets-filter__toggle {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: 13px; color: var(--n-700); cursor: pointer;
  user-select: none;
}
.tickets-filter__count {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 12px; color: var(--n-600);
}

/* Awaiting indicator on list rows. Pill styling matches the missed-calls
   "Response needed" badge on the Lock Support page (soft red fill, dark
   red text, lighter red outline) — same visual vocabulary across the
   "this needs human attention" surfaces. */
.ticket-row--awaiting > td:first-child {
  box-shadow: inset 3px 0 0 0 var(--kiss-red);
}
.ticket-awaiting-badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px var(--space-2);
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--error-soft); color: #991b1b;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.primary-btn {
  background: var(--kiss-red); color: var(--kiss-red-contrast);
  border: 0; padding: var(--space-2) var(--space-4); border-radius: var(--radius-md);
  font: inherit; font-weight: 600; cursor: pointer;
}
.primary-btn:hover { background: var(--kiss-red-hover); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Outlined secondary button — pairs with .primary-btn (e.g. "Send to dev team"). */
.secondary-btn {
  background: var(--n-0); color: var(--n-800);
  border: 1px solid var(--n-300); padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md); font: inherit; font-weight: 600; cursor: pointer;
}
.secondary-btn:hover { background: var(--n-100); }
.secondary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.tickets-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--n-0); border: 1px solid var(--n-200);
  border-radius: var(--radius-lg); overflow: hidden;
  font-size: 14px;
}
.tickets-table th, .tickets-table td {
  padding: var(--space-3) var(--space-4); text-align: left;
  border-bottom: 1px solid var(--n-100);
}
.tickets-table th {
  font-family: var(--font-mono); font-size: 12px; color: var(--n-600);
  text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--n-50, #fafafa); font-weight: 600;
}
.tickets-table tbody tr:last-child td { border-bottom: 0; }
.ticket-row { cursor: pointer; }
.ticket-row:hover td { background: var(--n-50, #fafafa); }
.ticket-row__company { font-weight: 600; }
.ticket-row__subject { color: var(--n-800); }
.ticket-row__when    { color: var(--n-600); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }

/* Status pills (5 lifecycle values from migration 021). */
.ticket-status {
  display: inline-flex; align-items: center;
  padding: 2px var(--space-2); border-radius: var(--radius-pill);
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
  background: var(--n-100); color: var(--n-700);
}
.ticket-status--open              { background: var(--warning-soft); color: #92400e; }
.ticket-status--awaiting_customer { background: var(--n-100);        color: var(--n-700); }
.ticket-status--resolved          { background: var(--success-soft); color: #065f46; }
.ticket-status--closed            { background: var(--n-100);        color: var(--n-500); }

/* Priority pills — sized to match .ticket-status so they line up cleanly
   when shown side by side on the list view. */
.ticket-priority {
  display: inline-flex; align-items: center; margin-left: var(--space-2);
  padding: 2px var(--space-2); border-radius: var(--radius-pill);
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
  background: var(--n-100); color: var(--n-700);
}
.ticket-priority--low    { color: var(--n-500); }
.ticket-priority--high   { background: #ffedd5; color: #9a3412; }   /* orange — clearly hotter than normal, below urgent */
.ticket-priority--urgent { background: var(--kiss-red); color: var(--kiss-red-contrast); }

/* Detail view */

.ticket-detail { display: grid; gap: var(--space-5); }

.ticket-detail__back a {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--n-600); text-decoration: none;
}
.ticket-detail__back a:hover { color: var(--kiss-red); }

.ticket-detail__header {
  background: var(--n-0); border: 1px solid var(--n-200);
  border-radius: var(--radius-lg); padding: var(--space-5);
}
.ticket-detail__title {
  display: flex; align-items: center; gap: var(--space-3);
  flex-wrap: wrap; margin-bottom: var(--space-4);
}
.ticket-detail__title h2 { margin: 0; font-size: 20px; }

.ticket-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3) var(--space-5); margin: 0;
}
.ticket-meta > div { display: grid; gap: 2px; }
.ticket-meta dt {
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--n-500);
}
.ticket-meta dd { margin: 0; font-size: 14px; color: var(--n-900); }

.ticket-thread { display: grid; gap: var(--space-3); }
.ticket-thread .section__heading { margin: 0 0 var(--space-2); }

/* Message accordion. Each message is a <details>; only the latest renders
   open by default. Collapsed messages show a one-line preview so staff can
   scan the thread without expanding everything. */
.ticket-message {
  background: var(--n-0); border: 1px solid var(--n-200);
  border-radius: var(--radius-lg); padding: var(--space-3) var(--space-5);
  margin-bottom: var(--space-2);
}
.ticket-message[open] { padding-bottom: var(--space-4); }
.ticket-message--inbound  { border-left: 3px solid var(--kiss-red); }
.ticket-message--outbound { border-left: 3px solid var(--info, #1E40E8); }
.ticket-message--note     { background: #fdf8ec; background: color-mix(in srgb, var(--warning-soft) 45%, var(--n-0)); border-color: #f3e8cf; }

.ticket-message__header {
  display: flex; align-items: center; gap: var(--space-3);
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--n-600);
  cursor: pointer;
  list-style: none;
  padding: var(--space-1) 0;
}
.ticket-message__header::-webkit-details-marker { display: none; }
.ticket-message[open] > .ticket-message__header { margin-bottom: var(--space-2); }

.ticket-message__author { color: var(--n-900); font-weight: 600; text-transform: none; letter-spacing: 0; font-family: inherit; font-size: 14px; }
.ticket-message__direction { background: var(--n-100); color: var(--n-700); padding: 1px var(--space-2); border-radius: var(--radius-pill); }
.ticket-message__preview {
  color: var(--n-600); text-transform: none; letter-spacing: 0;
  font-family: inherit; font-size: 13px; font-weight: 400;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}
.ticket-message[open] > .ticket-message__header .ticket-message__preview { display: none; }
.ticket-message__time { margin-left: auto; flex-shrink: 0; }
.ticket-message__body { color: var(--n-800); font-size: 14px; line-height: 1.55; }

/* AI-drafted pending replies — visually emphasized so staff see them as the
   next-action surface, not just another thread row. */
.ticket-message--ai-draft {
  border-left: 3px solid var(--kiss-red);
  background: var(--n-50, #fafafa);
}
.ticket-message__direction--ai {
  background: var(--kiss-red); color: #fff;
}
/* Action buttons under an AI draft. */
.ticket-draft__actions {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-3); padding-top: var(--space-3);
  border-top: 1px dashed var(--n-200);
}
/* Send / Revise / Discard share identical metrics — only the fill differs —
   so they're the same size + font and "Revise…" no longer truncates. */
.ticket-draft__actions .primary-btn,
.ticket-draft__actions .secondary-btn,
.ticket-draft__actions .ghost-btn {
  font: inherit; font-size: 13px; font-weight: 600; line-height: 1.2;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
}
.ticket-draft__actions .primary-btn         { background: var(--kiss-red); color: var(--kiss-red-contrast); border-color: var(--kiss-red); }
.ticket-draft__actions .primary-btn:hover   { background: var(--kiss-red-hover); border-color: var(--kiss-red-hover); }
.ticket-draft__actions .secondary-btn       { background: var(--n-0); color: var(--n-800); border-color: var(--n-300); }
.ticket-draft__actions .secondary-btn:hover { background: var(--n-100); }
.ticket-draft__actions .ghost-btn           { background: transparent; color: var(--n-600); border-color: transparent; }
.ticket-draft__actions .ghost-btn:hover     { background: var(--n-100); color: var(--n-800); }
.ticket-draft__msg {
  font-family: var(--font-mono); font-size: 12px; color: var(--n-600);
  margin-left: auto;
}
.ticket-draft__msg.error { color: var(--kiss-red); }

/* Inline revise form. Shown when staff clicks Revise. */
.ticket-draft__revise,
.ticket-draft__edit {
  margin-top: var(--space-3); padding: var(--space-3);
  background: var(--n-100); border-radius: var(--radius-md);
}
.ticket-draft__revise textarea,
.ticket-draft__edit textarea {
  width: 100%; font-family: inherit; font-size: 14px;
  padding: var(--space-2); border: 1px solid var(--n-300);
  border-radius: var(--radius-md); resize: vertical;
}
.ticket-draft__revise-actions {
  display: flex; gap: var(--space-2); margin-top: var(--space-2);
}

/* Sequential KISS-N reference chip. Surfaces in the list, the detail header,
   and anywhere else we want the human-friendly handle (vs the ULID PK). */
.ticket-ref {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--n-100); color: var(--n-800);
  padding: 2px var(--space-2);
  border-radius: var(--radius-md);
  white-space: nowrap;
}
.ticket-ref--lg {
  font-size: 12px;
  padding: 3px var(--space-2);
  background: var(--kiss-red); color: #fff;
}
.ticket-row__ref { width: 80px; }
.ticket-detail__ref { margin-bottom: var(--space-2); }

/* Unassigned-company tickets (sender wasn't in support_company_users at the
   time of receipt). Staff triages by picking a company from the detail-view
   Company select. */
.ticket-row--needs-triage .ticket-row__ref .ticket-ref {
  background: var(--warning-soft, #fff7e6);
  color: var(--warning-strong, #9a6500);
}
.ticket-company--unassigned {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--warning-strong, #9a6500);
  background: var(--warning-soft, #fff7e6);
  padding: 2px var(--space-2);
  border-radius: var(--radius-md);
  white-space: nowrap;
}

/* The "new content" portion of an inbound — emphasized over signature + quoted tails. */
.ticket-message__fresh { white-space: pre-wrap; }

/* Sender signature (after the "-- " delimiter) — muted, smaller, still readable. */
.ticket-message__signature {
  color: var(--n-500); font-size: 12px; line-height: 1.45;
  margin-top: var(--space-3); padding-top: var(--space-2);
  border-top: 1px dashed var(--n-200);
  white-space: pre-wrap;
}

/* Quoted-reply tail — collapsed by default; staff can expand if they need the history. */
.ticket-message__quoted {
  margin-top: var(--space-3);
}
.ticket-message__quoted > summary {
  cursor: pointer; color: var(--n-600); font-size: 12px;
  font-family: var(--font-mono); letter-spacing: 0.04em;
  padding: var(--space-1) var(--space-2);
  background: var(--n-100); border-radius: var(--radius-md);
  display: inline-block; list-style: none;
}
.ticket-message__quoted > summary::-webkit-details-marker { display: none; }
.ticket-message__quoted[open] > summary { background: var(--n-200); }
.ticket-message__quoted-body {
  color: var(--n-500); font-size: 13px; line-height: 1.5;
  margin-top: var(--space-2); padding-left: var(--space-3);
  border-left: 2px solid var(--n-200);
  white-space: pre-wrap;
}

.ticket-detail__footnote {
  color: var(--n-500); font-size: 12px; font-family: var(--font-mono);
  text-align: center; padding: var(--space-3);
}

/* Inline controls in the meta dl (status/assignee/priority). */
.ticket-control {
  width: 100%; padding: var(--space-1) var(--space-2);
  border: 1px solid var(--n-300); border-radius: var(--radius-md);
  font: inherit; font-size: 14px; background: var(--n-0);
  cursor: pointer;
}
.ticket-control:disabled { opacity: 0.6; cursor: not-allowed; }

/* Reply composer */
.ticket-composer {
  background: var(--n-0); border: 1px solid var(--n-200);
  border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5);
}
.ticket-composer .section__heading { margin: 0 0 var(--space-3); }
.ticket-composer textarea {
  width: 100%; padding: var(--space-3); border: 1px solid var(--n-300);
  border-radius: var(--radius-md); font: inherit; background: var(--n-0);
  box-sizing: border-box; resize: vertical; min-height: 100px;
}
.ticket-composer__actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-top: var(--space-3);
}
.ticket-composer__note {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: 13px; color: var(--n-700); cursor: pointer;
}
.ticket-composer__msg { margin-top: var(--space-2); font-size: 13px; min-height: 1em; color: var(--n-600); }
.ticket-composer__msg.error { color: var(--error); }

/* New-ticket form (overlay) */

.ticket-form-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--space-8) var(--space-4);
  overflow-y: auto;
}
.ticket-form {
  background: var(--n-0); border-radius: var(--radius-lg);
  padding: var(--space-6); width: 100%; max-width: 560px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}
.ticket-form h3 { margin: 0 0 var(--space-4); font-size: 18px; }
.ticket-form__field { display: grid; gap: var(--space-1); margin-bottom: var(--space-4); }
.ticket-form__field > span {
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--n-600);
}
.ticket-form__field > span em { color: var(--n-500); font-style: normal; }
.ticket-form__field input,
.ticket-form__field select,
.ticket-form__field textarea {
  width: 100%; padding: var(--space-3); border: 1px solid var(--n-300);
  border-radius: var(--radius-md); font: inherit; background: var(--n-0);
  box-sizing: border-box;
}
.ticket-form__field textarea { resize: vertical; min-height: 100px; }
.ticket-form__row { display: grid; grid-template-columns: 1fr 200px; gap: var(--space-4); }
.ticket-form__actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-2); }
.ticket-form__actions button[type="button"] {
  background: transparent; border: 1px solid var(--n-300); color: var(--n-700);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-md);
  font: inherit; cursor: pointer;
}
.ticket-form__msg { margin-top: var(--space-3); font-size: 13px; min-height: 1em; }
.ticket-form__msg.error { color: var(--error); }

/* Dev-team (Linear) escalation badge — shown on a ticket/call once escalated. */
.dev-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--n-100, #f1f5f9);
  border: 1px solid var(--n-200, #e2e8f0);
  color: var(--n-700, #334155);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.dev-badge a { color: inherit; text-decoration: underline; }
.dev-badge--pending { color: var(--n-500); font-style: italic; }
.ticket-detail__devteam { margin-top: var(--space-3); display: flex; align-items: center; gap: 10px; }
.ticket-detail__devteam-msg { font-size: 13px; color: var(--n-500); }
.ticket-detail__devteam-msg.error { color: var(--error); }
