/* ============================================================
   ViaChat — Supervisor Console · design system
   World: ISP fiber support. Light = signal through glass.
   Depth: soft layered shadows + optical halo. Light mode.
   ============================================================ */

:root {
  /* — canvas & surfaces — */
  --canvas:        #F7F8F7;
  --canvas-grad:   none;
  --glass:         rgba(255,255,255,0.95);
  --glass-solid:   #FFFFFF;
  --inset:         #F0F2F5;
  --surface:       #FFFFFF;
  --thread-bg:    #E9EDF4;
  --chrome:        var(--surface);
  /* Navigation chrome: sober graphite, visually separate from product actions. */
  --rail-bg:         oklch(29% 0.022 240);
  --rail-active:     oklch(38% 0.026 240);
  --rail-ink:        oklch(84% 0.014 240);
  --rail-ink-strong: oklch(97% 0.006 240);
  --rail-line:       oklch(100% 0 0 / 0.14);
  --rail-marker:     oklch(78% 0.035 225);
  --rail-avatar:     oklch(48% 0.035 235);
  --mine:         #DFF7D7;
  --mine-border:  rgba(31,168,85,0.16);

  /* — ink: graphite scale, not black — */
  --ink:        #111B21;
  --ink-soft:   #3B4A54;
  --ink-muted:  #667781;
  --ink-faint:  #8696A0;

  /* — action accent: violet — the brand colour for chrome, active, unread, send,
     and app actions. Kept clear of the optical-signal hues (teal --good, amber,
     red) AND of the green conversation voice, so "brand" never reads as "signal"
     or as "the customer's words". — */
  --accent:       #6E56CF;
  --accent-press: #5A45B5;
  --accent-tint:  rgba(110,86,207,0.10);
  --accent-tint-2: rgba(110,86,207,0.18);

  /* Compatibility aliases used by existing component rules. */
  --violet:        var(--accent);
  --violet-press:  var(--accent-press);
  --violet-tint:   var(--accent-tint);
  --violet-tint-2: var(--accent-tint-2);

  /* — human / operator chrome (queue status tag/chip): blue, part of the app — */
  --human:       var(--accent);
  --human-tint:  var(--accent-tint);

  /* — conversation voice: the green message register (bubbles + sender labels).
     Deliberately distinct from the blue chrome accent — green is the chat, blue
     is the app. Kept clear of the teal --good signal LED. — */
  --voice:       #1FA855;

  /* — optical signal: ONU status LEDs + 650nm fault locator — */
  --good:      #14B8A0;   /* healthy light in glass        */
  --marginal:  #E1A33D;   /* ONU warning LED               */
  --lost:      #E2564B;   /* fault-locator red · LOS       */
  --power-loss:#4B83D1;   /* Varuna dying-gasp / no power  */
  --dark:      #ABA6B6;   /* no light · offline            */

  /* — lines: soft separators — */
  --line:        rgba(17,27,33,0.10);
  --line-soft:   rgba(17,27,33,0.06);
  --line-strong: rgba(17,27,33,0.16);

  /* — shadows: whisper-quiet, layered, cool — */
  --shadow-sm:    0 1px 2px rgba(17,27,33,0.06);
  --shadow-card:  0 1px 2px rgba(17,27,33,0.05), 0 10px 26px rgba(17,27,33,0.08);
  --shadow-float: 0 2px 6px rgba(17,27,33,0.07), 0 18px 50px rgba(17,27,33,0.14);
  --glow-violet:  0 8px 22px rgba(110,86,207,0.24);

  /* — radius: generous / calm — */
  --r-sm:   10px;
  --r-md:   16px;
  --r-lg:   22px;
  --r-pill: 999px;

  /* — type — */
  --sans: "General Sans", system-ui, -apple-system, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", monospace;
}

/* — dark theme: same token names, dark surfaces; voices + signal LEDs kept — */
html[data-theme="dark"] {
  /* Surfaces: a soft, warm-cool dark with a violet undertone — deliberately NOT
     near-black. Luminance climbs canvas → thread → surface → inset → glass-solid. */
  --canvas:        #1A1822;   /* floor — soft, never black                          */
  --canvas-grad:
    radial-gradient(1200px 820px at 86% -16%, rgba(140,114,238,0.18) 0%, rgba(140,114,238,0) 60%),
    radial-gradient(1000px 700px at -6% 4%, rgba(116,146,236,0.09) 0%, rgba(116,146,236,0) 55%),
    linear-gradient(180deg, #201C2C 0%, #18151F 100%);
  --glass:         rgba(48,45,62,0.72);
  --glass-solid:   #322F42;   /* most-elevated: popovers, input card, field focus   */
  --inset:         #2B2838;   /* wells: search, segmented, customer bubble          */
  --surface:       #24222F;   /* panels — comfortable working surface, not black    */
  --thread-bg:     #1E1C28;   /* chat scroll + composer — a calm step under panels  */
  --chrome:        var(--surface); /* neutral structural chrome, not an action hue */
  --rail-bg:         oklch(19% 0.018 240);
  --rail-active:     oklch(28% 0.024 240);
  --rail-ink:        oklch(84% 0.014 240);
  --rail-ink-strong: oklch(97% 0.006 240);
  --rail-line:       oklch(100% 0 0 / 0.13);
  --rail-marker:     oklch(82% 0.035 225);
  --rail-avatar:     oklch(45% 0.032 235);
  --mine:          rgba(28,176,122,0.20);
  --mine-border:   rgba(28,176,122,0.34);

  --ink:        #EEEFF4;
  --ink-soft:   #CBCED9;
  --ink-muted:  #9398AB;
  --ink-faint:  #71768A;

  --accent:        #9A8AF2;
  --accent-press:  #B3A6F7;
  --accent-tint:   rgba(154,138,242,0.18);
  --accent-tint-2: rgba(154,138,242,0.30);

  --violet:        var(--accent);
  --violet-press:  var(--accent-press);
  --violet-tint:   var(--accent-tint);
  --violet-tint-2: var(--accent-tint-2);

  --human:       var(--accent-press);
  --human-tint:  var(--accent-tint);
  --voice:       #1FC08A;   /* emerald — balanced, not the neon mint it was        */

  --good:      #2DD4BF;
  --marginal:  #ECB45A;
  --lost:      #F06A5F;
  --dark:      #6F7388;

  --line:        rgba(255,255,255,0.10);
  --line-soft:   rgba(255,255,255,0.06);
  --line-strong: rgba(255,255,255,0.18);

  --shadow-sm:    0 1px 2px rgba(0,0,0,0.4);
  --shadow-card:  0 1px 2px rgba(0,0,0,0.35), 0 10px 26px rgba(0,0,0,0.45);
  --shadow-float: 0 2px 6px rgba(0,0,0,0.4), 0 18px 50px rgba(0,0,0,0.6);
  --glow-violet:  0 8px 26px rgba(154,138,242,0.42);

  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas) var(--canvas-grad) fixed;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--violet-tint-2); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
:where(a, button, input, textarea, select):focus-visible { outline: 3px solid var(--accent);
  outline-offset: 2px; }

/* subtle scrollbars */
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: rgba(15,23,42,0.14); border-radius: 9px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(15,23,42,0.24); background-clip: content-box; }
html[data-theme="dark"] *::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); background-clip: content-box; }
html[data-theme="dark"] *::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.24); background-clip: content-box; }
/* tooltip: in dark the ink token flips to near-white, making the dark tooltip unreadable; pin to a dark surface */
html[data-theme="dark"].rail-collapsed [data-tip]:hover::after { background: var(--inset); }

/* ============================================================ LAYOUT */
/* rail is always icon-only — fixed 68px column */
.app { display: grid; grid-template-columns: 68px 1fr; height: 100vh; }

.rail { display: flex; flex-direction: column; align-items: center;
  padding: 18px 12px; gap: 4px; background: var(--rail-bg); border-right: 1px solid var(--rail-line);
  color: var(--rail-ink);
}
.isp-chip {
  margin-left: auto; font-size: 11px; font-weight: 500; color: var(--ink-soft);
  background: var(--glass-solid); border: 1px solid var(--line-soft);
  padding: 3px 9px; border-radius: var(--r-pill); box-shadow: var(--shadow-sm);
}
.nav { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rail-foot { margin-top: auto; padding-top: 12px; }
.op-wrap { position: relative; width: 44px; }
.op { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-sm);
  width: 100%; min-height: 44px; transition: background .14s ease; }
.op:hover { background: var(--rail-active); }
.op[aria-expanded="true"] { background: var(--rail-active); }
.op-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; line-height: 1; color: var(--rail-ink-strong); flex: none;
  background: var(--rail-avatar); box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.18); }
.op-name { font-size: 13px; font-weight: 600; }
.op-role { font-size: 11px; color: var(--ink-muted); }
.op-chevron { width: 14px; height: 14px; margin-left: auto; color: var(--ink-faint);
  flex: none; transition: transform .18s ease; transform: rotate(180deg); }
.op[aria-expanded="true"] .op-chevron { transform: rotate(0deg); }

/* Compact account menu: identity, useful preferences, secondary records, then
   an isolated session action. It grows from the rail avatar without nesting. */
@keyframes op-pop-in {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.op-popover { position: absolute; bottom: calc(100% + 10px); left: 0;
  width: min(248px, calc(100vw - 20px));
  background: var(--glass-solid); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: 0 4px 8px rgba(17,27,33,0.14);
  padding: 6px; overflow: hidden; z-index: 200;
  transform-origin: bottom left; animation: op-pop-in .16s cubic-bezier(.16,1,.3,1); }
.op-popover[hidden] { display: none; }
.op-pop-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 10px; }
.op-pop-avatar { width: 36px; height: 36px; display: grid; place-items: center; flex: none;
  border-radius: 50%; background: var(--inset); color: var(--ink-soft);
  font-size: 12px; font-weight: 600; line-height: 1; }
.op-pop-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.op-pop-name { font-size: 14px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-pop-sub { font-size: 12px; line-height: 1.2; color: var(--ink-muted); }
.op-pop-sep { height: 1px; background: var(--line-soft); margin: 0 6px; }
.op-pop-group { padding: 3px 0; }
.op-pop-group-label { padding: 6px 10px 4px; color: var(--ink-muted);
  font-size: 11px; font-weight: 600; line-height: 1.2; }
.op-pop-item { display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 40px; padding: 8px 10px; border-radius: 8px;
  font-size: 13px; color: var(--ink-soft);
  transition: background .12s ease, color .12s ease; }
.op-pop-item .ico { width: 16px; height: 16px; flex: none; color: var(--ink-muted);
  transition: color .12s ease; }
.op-pop-item-meta { margin-left: auto; color: var(--ink-muted); font-size: 11.5px; }
/* Account navigation stays neutral; logout alone carries a semantic color. */
.op-pop-item:hover { background: var(--inset); color: var(--ink); }
.op-pop-item:hover .ico { color: var(--ink); }
.op-pop-item:active { background: color-mix(in srgb, var(--rail-marker) 12%, var(--inset)); }
.op-pop-item:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.op-pop-item[aria-current="page"] { background: var(--accent-tint); color: var(--ink); }
.op-pop-footer { padding-top: 3px; }
.op-pop-logout:hover { background: color-mix(in srgb, var(--lost) 12%, transparent); color: var(--ink); }
.op-pop-logout:hover .ico { color: var(--lost); }
.op-pop-logout:active { background: color-mix(in srgb, var(--lost) 20%, transparent); }

/* ---- main: three floating glass panels ---- */
.main { display: grid; grid-template-columns: 320px minmax(0,1fr) 288px;
  gap: 12px; padding: 14px 14px 14px 2px; min-width: 0; }

/* ============================================================ INBOX (Operator) */
.inbox { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
/* The conversation gives up horizontal space when the optional context column opens. */
.inbox-body { flex: 1; display: grid; grid-template-columns: 340px minmax(0,1fr);
  min-width: 0; min-height: 0; position: relative; }
.inbox[data-context-open="true"] .inbox-body {
  grid-template-columns: 340px minmax(0,1fr) 320px;
}

/* WhatsApp-style flush columns: solid surfaces divided by hairlines, no floating
   cards. Selectors are doubled (.panel.x) to outrank the base .panel card rule,
   which is defined later in the file — otherwise its radius/shadow/glass win. */
.panel.queue-panel, .panel.thread-panel, .panel.context-panel {
  background: var(--surface); border: none; border-radius: 0; box-shadow: none;
  backdrop-filter: none; -webkit-backdrop-filter: none;
}
.panel.context-panel[hidden] { display: none !important; }
.panel.queue-panel  { border-right: 1px solid var(--line); }
.panel.thread-panel { border-right: 1px solid var(--line); }
/* empty chat area (no conversation selected) keeps the thread background, not white */
.panel.thread-panel.placeholder-panel { background: var(--thread-bg); }

/* queue-live is a polled fragment wrapper — make it grid-transparent so the
   inner .queue-panel becomes the direct grid child and stretches to full height */
.queue-live { display: contents; }

/* queue search */
/* search reads as an inset well (slate-100) on the near-white panel, lifting to white on focus */
.queue-search { display: flex; align-items: center; gap: 7px; margin-top: 8px;
  background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 7px 10px; transition: border-color .14s ease, background .14s ease; }
.queue-search:focus-within { border-color: var(--line-strong); background: var(--glass-solid); }
.queue-search .ico { width: 13px; height: 13px; color: var(--ink-faint); flex: none; }
.queue-search input { flex: 1; border: none; outline: none; background: none; font: inherit;
  font-size: 12.5px; color: var(--ink); }
.queue-search input::placeholder { color: var(--ink-faint); }

/* Active and closed conversations are two states of this inbox, not separate
   application destinations. A restrained local tab row keeps that hierarchy clear. */
.queue-mode-nav { flex: none; display: flex; align-self: stretch; gap: 16px; margin-left: auto; }
.queue-mode-link { position: relative; min-height: 30px; display: inline-flex; align-items: center;
  color: var(--ink-muted); font-size: 12.5px; font-weight: 600; }
.queue-mode-link:hover { color: var(--ink); }
.queue-mode-link[aria-current="true"] { color: var(--ink); }
.queue-mode-link[aria-current="true"]::after { content: ""; position: absolute;
  right: 0; bottom: 0; left: 0; height: 2px; border-radius: var(--r-pill);
  background: var(--accent); }

/* ============================================================ QUEUE TOGGLE */
/* Segmented control follows the service lifecycle: assistant → waiting → human.
   Every segment stays compact (icon + count); the selected one is a raised chip.
   Active state lives on [data-filter], so it survives queue-fragment swaps. */
.seg { display: flex; gap: 3px; margin-top: 10px; padding: 3px;
  background: var(--inset); border: 1px solid var(--line-soft); border-radius: var(--r-pill); }
.seg-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 4px; border: none; background: none; border-radius: calc(var(--r-pill) - 3px);
  color: var(--ink-muted); cursor: pointer; transition: color .14s ease, background .14s ease, box-shadow .14s ease; }
.seg-btn .ico { width: 15px; height: 15px; flex: none; }
.seg-n { font-family: var(--mono); font-size: 11px; font-weight: 600; }
.seg-btn:hover { color: var(--ink-soft); }
/* Active segment = a raised white chip (icon + count; accessible name via aria-label). */
.inbox[data-filter="handoff_requested"] .seg-btn[data-filter-status="handoff_requested"],
.inbox[data-filter="human_active"]      .seg-btn[data-filter-status="human_active"],
.inbox[data-filter="bot_active"]        .seg-btn[data-filter-status="bot_active"] {
  background: var(--glass-solid); color: var(--ink); box-shadow: var(--shadow-sm);
}
/* Show only the active group's cards (and its empty-state). Both carry data-status. */
.inbox[data-filter="handoff_requested"] [data-status]:not([data-status="handoff_requested"]),
.inbox[data-filter="human_active"]      [data-status]:not([data-status="human_active"]),
.inbox[data-filter="bot_active"]        [data-status]:not([data-status="bot_active"]) { display: none; }
.queue-empty { padding: 28px 16px; text-align: center; font-size: 13px; color: var(--ink-muted); }
.queue-empty--all { display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 56px 16px; color: var(--ink-faint); }
.qe-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--inset); color: var(--ink-faint); }
.qe-icon .ico { width: 22px; height: 22px; }
.panel {
  background: var(--glass); backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card); display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.panel-head { padding: 18px 20px 12px; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.panel-sub { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
/* ============================================================ QUEUE */
/* Inset rows with breathing room — selection is a floating rounded highlight
   (macOS-sidebar register), never a full-bleed block. No dividers; whitespace
   separates rows. The list shares the header's 20px side inset, so the selection
   highlight lines up flush with the search field + toggle above (no overhang). */
.queue { flex: 1; overflow: auto; padding: 6px 20px; display: flex; flex-direction: column; gap: 2px; }
.qcard {
  display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center;
  width: 100%; text-align: left; padding: 10px 10px; border-radius: 10px;
  transition: background .14s ease;
}
.qcard:hover { background: var(--inset); }
/* In dark mode, lift the queue row with a faint white wash. */
html[data-theme="dark"] .qcard:hover { background: rgba(255,255,255,0.045); }
/* selected = a whisper-faint inset rounded fill — present but never loud. */
.qcard.sel { background: var(--inset); }
html[data-theme="dark"] .qcard.sel { background: rgba(255,255,255,0.07); }
html[data-theme="dark"] .qcard.sel:hover { background: rgba(255,255,255,0.09); }
.inbox.is-navigating .thread-panel,
.inbox.is-navigating .context-panel { cursor: progress; }
.qmain { min-width: 0; }
.who { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snip { color: var(--ink-muted); font-size: 12.5px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qmeta { display: flex; align-items: flex-end; flex: none; }
.time { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.queue-search-empty { padding: 28px 16px; text-align: center; color: var(--ink-muted); font-size: 13px; }

/* ---- avatar + optical signal as presence dot (the signature) ---- */
.avatar { position: relative; width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 600; color: var(--ink-soft);
  background: var(--inset); }
.avatar .ico { width: 18px; height: 18px; color: var(--ink-faint); }
.avatar.lg { width: 42px; height: 42px; font-size: 15px; }
/* profile photo overlays the placeholder icon; on load it covers it, on error
   (no photo / fetch failed) JS adds .is-broken and the icon shows through. */
.avatar-photo { position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%; }
.avatar-photo.is-broken { display: none; }

.signal { width: 11px; height: 11px; border-radius: 50%; flex: none; display: inline-block; }
.avatar .signal { position: absolute; right: -1px; bottom: -1px; border: 2px solid var(--glass-solid); }
.avatar.lg .signal { width: 13px; height: 13px; }
.signal--good     { background: radial-gradient(circle at 34% 32%, #79E6D6, var(--good));
  box-shadow: 0 0 0 3px rgba(20,184,160,0.12), 0 0 9px 1px rgba(20,184,160,0.50); }
.signal--marginal { background: radial-gradient(circle at 34% 32%, #F3CE8C, var(--marginal));
  box-shadow: 0 0 0 3px rgba(225,163,61,0.12), 0 0 9px 1px rgba(225,163,61,0.45); }
.signal--lost     { background: radial-gradient(circle at 34% 32%, #F0897E, var(--lost));
  box-shadow: 0 0 0 3px rgba(226,86,75,0.13), 0 0 10px 1px rgba(226,86,75,0.45);
  animation: pulse 2.6s ease-in-out infinite; }
.signal--power    { background: radial-gradient(circle at 34% 32%, #91B9EF, var(--power-loss));
  box-shadow: 0 0 0 3px rgba(75,131,209,0.13), 0 0 9px 1px rgba(75,131,209,0.38); }
.signal--dark     { background: var(--dark); opacity: .65; }
.signal--alert    { background: radial-gradient(circle at 34% 32%, #F3CE8C, var(--marginal));
  animation: pulse-alert 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(226,86,75,0.13), 0 0 8px 1px rgba(226,86,75,0.35); }
  50% { box-shadow: 0 0 0 3px rgba(226,86,75,0.16), 0 0 13px 2px rgba(226,86,75,0.55); } }
@keyframes pulse-alert { 0%,100% { box-shadow: 0 0 0 3px rgba(225,163,61,0.13), 0 0 8px 1px rgba(225,163,61,0.35); }
  50% { box-shadow: 0 0 0 3px rgba(225,163,61,0.22), 0 0 13px 2px rgba(225,163,61,0.55); } }

/* ---- tiny state tags ---- */
.tag { font-size: 10.5px; font-weight: 600; letter-spacing: .01em; padding: 2px 7px;
  border-radius: var(--r-pill); white-space: nowrap; }
.tag-wait  { color: var(--accent); background: var(--accent-tint-2); }
.tag-you   { color: var(--human);  background: var(--human-tint); }
.tag-bot   { color: var(--ink-muted); background: var(--inset); }
.tag-risk  { color: var(--marginal); background: rgba(225,163,61,0.13); }

/* ============================================================ THREAD */
.thread-panel { padding: 0; }
.thread-head { display: flex; align-items: center; gap: 13px; padding: 16px 72px 16px 22px;
  background: var(--chrome); border-bottom: 1px solid var(--line); }
.inbox[data-context-open="true"] .thread-head { padding-right: 22px; }
.thread-who { min-width: 0; flex: 1; }
.tw-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.tw-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.tw-handle { font-family: var(--mono); font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.ch-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500;
  color: var(--ink-soft); background: var(--glass-solid); border: 1px solid var(--line);
  padding: 3px 9px; border-radius: var(--r-pill); }
.chip--ok { color: var(--good); background: rgba(20,184,160,0.10); border-color: rgba(20,184,160,0.25); }
html[data-theme="dark"] .chip--ok { background: rgba(45,212,191,0.14); border-color: rgba(45,212,191,0.30); }
.chip--muted { color: var(--ink-muted); background: var(--inset); }
.chip--mono { font-family: var(--mono); color: var(--ink-muted); }
.chip--signal { color: var(--ink-soft); }
.chip--signal .signal { width: 8px; height: 8px; }
.chip--state { font-weight: 600; }
.chip--state-human_active { color: var(--human); background: var(--human-tint); border-color: var(--accent-tint-2); }
.chip--state-handoff_requested { color: var(--accent); background: var(--accent-tint); border-color: var(--accent-tint-2); }
.chip--state-bot_active { color: var(--accent); background: var(--accent-tint); border-color: var(--accent-tint-2); }
.chip--state-closed { color: var(--ink-muted); background: var(--inset); }
.thread-actions { margin-left: auto; display: flex; align-items: center; justify-content: flex-end;
  gap: 4px; flex: none; }
.thread-close-trigger { width: 40px; min-height: 40px; padding: 0; display: inline-flex;
  align-items: center; justify-content: center; flex: none; border: none; border-radius: 8px;
  color: var(--ink-muted); background: transparent; transition: color .14s ease, background .14s ease; }
.thread-close-trigger:hover { color: var(--ink-soft); background: var(--inset); }
.thread-close-trigger .ico { width: 16px; height: 16px; color: currentColor; }

.context-toggle { position: absolute; top: 18px; right: 16px; z-index: 43;
  width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
  border: none; border-radius: 50%; color: var(--ink-soft); background: var(--inset);
  transition: color .14s ease, background .14s ease,
              transform .18s cubic-bezier(.16,1,.3,1); }
.context-toggle:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 10%, var(--inset)); }
.inbox[data-context-open="true"] .context-toggle { transform: translateX(-252px); }
.context-toggle .ico { width: 17px; height: 17px; }
.context-toggle-expand, .context-toggle-collapse { place-items: center; line-height: 0; }
.context-toggle-expand { display: grid; }
.context-toggle-collapse { display: none; }
.inbox[data-context-open="true"] .context-toggle-expand { display: none; }
.inbox[data-context-open="true"] .context-toggle-collapse { display: grid; }

.close-popover { position: fixed; inset: 72px 16px auto auto; width: min(320px, calc(100vw - 24px));
  margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); box-shadow: 0 4px 8px rgba(17,27,33,0.14); }
.close-popover::backdrop { background: transparent; }
.close-popover-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.close-popover-head h2 { font-size: 15px; line-height: 1.3; }
.close-popover-head button { width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 8px; color: var(--ink-muted); }
.close-popover-head button:hover { color: var(--ink); background: var(--inset); }
.close-popover-head .ico { width: 17px; height: 17px; }
.close-popover > p { margin-top: 6px; color: var(--ink-muted); font-size: 12.5px; line-height: 1.45; }
.close-popover .btn-primary { width: 100%; box-shadow: none; }

.thread-body { flex: 1; overflow: auto; padding: 22px 30px; display: flex; flex-direction: column; gap: 2px;
  background: var(--thread-bg); }
.thread-body::before { content: ""; margin-top: auto; }
/* Same-sender runs stay grouped; side and color carry authorship visually. */
.msg-group { display: flex; flex-direction: column; margin-top: 16px; }
.msg-group:first-child { margin-top: 0; }
.msg-group.cliente { align-items: flex-start; }
.msg-group.assistente, .msg-group.atendente { align-items: flex-end; }
.msg-group .msg { margin-top: 3px; }
.msg-group .msg:first-of-type { margin-top: 0; }
/* markdown inside bubbles */
.bubble strong { font-weight: 600; }
.btxt { overflow-wrap: anywhere; }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.bubble code { font-family: var(--mono); font-size: .92em; background: var(--inset);
  padding: 1px 5px; border-radius: 6px; }

/* day separator — calm centered hairline + pill */
.day-sep { display: flex; align-items: center; gap: 12px; margin: 18px 2px 6px; }
.day-sep::before, .day-sep::after { content: ""; height: 1px; flex: 1; background: var(--line-soft); }
.day-sep span { font-size: 11px; font-weight: 600; letter-spacing: .03em; color: var(--ink-muted);
  background: var(--inset); padding: 3px 12px; border-radius: var(--r-pill); }
.msg { max-width: 76%; display: flex; flex-direction: column; }
/* One uniform bubble shape for every voice — same rounded rectangle; only side +
   colour distinguish customer / bot / operator (no mirrored speech-bubble tail).
   The bubble is a wrapping flex row so the timestamp tucks at the bottom-right:
   inline for short messages, on its own corner line for long ones (WhatsApp). */
.msg .bubble { padding: 9px 13px; border-radius: 16px; font-size: 14px; color: var(--ink);
  display: flex; flex-wrap: wrap; align-items: flex-end; }
.btxt { min-width: 0; }
.bmeta { margin-left: auto; padding-left: 10px; display: inline-flex; align-items: center;
  align-self: flex-end; gap: 3px; line-height: 1; white-space: nowrap; }
.btime { font-family: var(--mono); font-size: 10px; color: var(--ink-faint); line-height: 1; }
.delivery-state { display: inline-grid; place-items: center; flex: none; width: 13px; height: 13px;
  color: var(--ink-muted); line-height: 0; }
.delivery-check { display: block; width: 13px; height: 13px; stroke-width: 2.35; }
.delivery-checks { position: relative; display: block; width: 17px; height: 13px; }
.delivery-checks .delivery-check { position: absolute; top: 0; left: 0; }
.delivery-checks .delivery-check:last-child { left: 4px; }
.delivery-state--delivered, .delivery-state--read { width: 17px; }
.delivery-state--read { color: var(--accent); }
.delivery-pending-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.send-fail { flex-basis: 100%; }

.msg.cliente { align-self: flex-start; }
.msg.cliente .bubble { background: var(--glass-solid); border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-sm); }
/* dark: customer keeps the light recipe exactly — glass-solid surface + soft
   hairline + soft shadow, all token-driven — so it's the dark twin of the white
   incoming bubble. (No background override needed; the base rule's tokens adapt.) */

/* Outgoing voices share the Cliente bubble's lifted look (border + shadow); they
   differ only by hue — Assistente = blue, Atendente = green. */
.msg.assistente { align-self: flex-end; }
.msg.assistente .bubble { background: #E8F0FE; border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-sm); }
/* dark: same shape/lift as light, hue kept (blue) and darkened; light ink for read. */
html[data-theme="dark"] .msg.assistente .bubble { background: #32497C; color: #F2F5FB; }

.msg.atendente { align-self: flex-end; }
.msg.atendente .bubble { background: var(--mine); border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-sm); }
/* dark: the operator's green, kept in light's grass-green hue and darkened. */
html[data-theme="dark"] .msg.atendente .bubble { background: #2A6B43; color: #F1FBF4; }

/* Playable/visual media is already its own surface. Avoid nesting it in a
   second white bubble; keep only the quiet timestamp beneath it. */
.msg .bubble.bubble--media-only {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.bubble--media-only .bmeta {
  flex-basis: 100%;
  justify-content: flex-end;
  margin-top: 4px;
  padding: 0 4px;
}

/* timestamps sit on the darker fills — translucent white reads cleaner than ink-faint. */
html[data-theme="dark"] .msg.assistente .btime,
html[data-theme="dark"] .msg.atendente .btime { color: rgba(255,255,255,0.6); }
html[data-theme="dark"] .msg.assistente .delivery-state:not(.delivery-state--read),
html[data-theme="dark"] .msg.atendente .delivery-state:not(.delivery-state--read) {
  color: rgba(255,255,255,0.66);
}
html[data-theme="dark"] .msg.assistente .bubble a,
html[data-theme="dark"] .msg.atendente .bubble a { color: #fff; }

.msg.system { align-self: center; max-width: 90%; }
.msg.system .bubble { display: flex; align-items: center; gap: 8px; padding: 6px 14px;
  font-size: 12px; color: var(--ink-muted); background: transparent;
  border: 1px dashed var(--line-strong); border-radius: var(--r-pill); }
.msg.system .ico { width: 13px; height: 13px; }
.system-send-fail { color: var(--lost); font-weight: 600; }

/* ---- composer / takeover (DIA-style floating bar) ---- */
.composer { padding: 14px 18px 18px; position: relative;
  background: var(--thread-bg); border-top: none; }
.composer-card { background: var(--glass-solid); border: 1px solid var(--line-soft);
  border-radius: 18px; box-shadow: var(--shadow-float); padding: 7px; }
/* handoff prompt: minimal — just the centered CTA (state already shown in the queue). */
.assumir-bar { display: flex; justify-content: center; padding: 8px 4px 4px; }
.btn-primary { flex: none; background: var(--violet); color: #fff; font-weight: 600; font-size: 13.5px;
  padding: 11px 18px; border: none; border-radius: var(--r-sm); box-shadow: var(--glow-violet);
  cursor: pointer; transition: background .14s ease, transform .14s ease, box-shadow .14s ease; }
.btn-primary:hover { background: var(--violet-press); box-shadow: 0 10px 28px rgba(110,86,207,0.38); }
.btn-primary:active { transform: translateY(1px); }
/* the takeover CTA: pill + headset icon (you're about to put on the headset). */
.btn-assumir { display: inline-flex; align-items: center; gap: 8px; border-radius: var(--r-pill);
  padding: 11px 22px; font-size: 13.5px; }
.btn-assumir .ico { width: 16px; height: 16px; flex: none; }

/* ---- reply row ---- */
.reply { display: flex; align-items: flex-end; gap: 8px; padding: 4px 4px 4px 14px; }
.reply textarea { flex: 1; border: none; outline: none; background: none; font: inherit;
  color: var(--ink); padding: 10px 0; resize: none; overflow-y: hidden;
  min-height: 40px; max-height: 180px; line-height: 1.5; }
.reply textarea::placeholder { color: var(--ink-faint); }
.reply-image-preview { display: flex; align-items: center; gap: 10px; min-height: 58px;
  margin: 2px 4px 5px; padding: 6px 8px; border-radius: 12px; background: var(--inset);
  color: var(--ink-muted); font-size: 12px; }
.reply-image-preview[hidden] { display: none; }
.reply-image-preview img { width: 46px; height: 46px; flex: none; border-radius: 9px;
  object-fit: cover; background: var(--surface); }
.reply-image-preview [data-image-name] { min-width: 0; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.reply-image-preview button { width: 32px; height: 32px; flex: none; display: inline-flex;
  align-items: center; justify-content: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-muted); cursor: pointer; }
.reply-image-preview button:hover { background: var(--surface); color: var(--ink); }
.reply-image-preview button .ico { width: 15px; height: 15px; }
.reply-image-preview--error { color: var(--lost); background: color-mix(in srgb, var(--lost) 8%, var(--inset)); }
.reply-image-preview--error img { display: none; }
.btn-attach { width: 40px; height: 40px; flex: none; display: inline-flex; align-items: center;
  justify-content: center; border-radius: 50%; color: var(--ink-muted); cursor: pointer;
  transition: background .14s ease, color .14s ease; }
.btn-attach:hover { background: var(--inset); color: var(--ink); }
.btn-attach:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-attach .ico { width: 18px; height: 18px; }
.media-preview { display: block; flex-basis: 100%; margin: -3px -3px 8px; border-radius: 12px;
  overflow: hidden; background: var(--inset); border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-sm); }
.media-preview img { display: block; width: min(360px, 100%); max-height: 320px; object-fit: contain; }
.audio-player { display: flex; align-items: center; gap: 10px; width: 320px; max-width: 100%;
  min-height: 56px; margin: 2px 0 8px; padding: 8px 12px 8px 8px; border-radius: var(--r-md);
  background: var(--glass-solid); color: var(--ink); box-shadow: var(--shadow-sm); }
.audio-play-toggle { width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--accent-tint); color: var(--accent);
  cursor: pointer; transition: background .16s ease, color .16s ease, transform .16s ease; }
.audio-play-toggle:hover { background: var(--accent-tint-2); }
.audio-play-toggle:active { transform: scale(.96); }
.audio-play-toggle:focus-visible,
.audio-progress:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.audio-play-toggle:disabled { color: var(--ink-faint); background: var(--inset); cursor: not-allowed; }
.audio-toggle-icon { width: 0; height: 0; margin-left: 2px;
  border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  border-left: 9px solid currentColor; }
.audio-player.is-playing .audio-toggle-icon { width: 10px; height: 12px; margin-left: 0;
  border: 0; background: linear-gradient(to right,
    currentColor 0 3px, transparent 3px 7px, currentColor 7px 10px); }
.audio-time { flex: none; min-width: 70px; color: var(--ink-soft);
  font: 500 11px/1 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.audio-player:not(.has-duration) .audio-time { min-width: 34px; }
.audio-time-separator { color: var(--ink-faint); }
.audio-progress { --audio-progress: 0%; min-width: 0; height: 24px; flex: 1;
  margin: 0; padding: 0; border: 0; appearance: none; -webkit-appearance: none;
  background: transparent; cursor: pointer; }
.audio-progress:disabled { cursor: default; }
.audio-progress::-webkit-slider-runnable-track { height: 4px; border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--accent) 0 var(--audio-progress),
    var(--line-strong) var(--audio-progress) 100%); }
.audio-progress::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -5px;
  border: 0; border-radius: 50%; appearance: none; -webkit-appearance: none;
  background: var(--accent); }
.audio-progress::-moz-range-track { height: 4px; border: 0; border-radius: var(--r-pill);
  background: var(--line-strong); }
.audio-progress::-moz-range-progress { height: 4px; border-radius: var(--r-pill);
  background: var(--accent); }
.audio-progress::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%;
  background: var(--accent); }
.audio-progress:disabled::-webkit-slider-thumb { opacity: 0; box-shadow: none; }
.audio-progress:disabled::-moz-range-thumb { opacity: 0; box-shadow: none; }
.audio-player.is-error .audio-time { color: var(--ink-soft); }
.media-audio { display: block; width: 100%; }
.audio-player.is-enhanced .media-audio { display: none; }
.audio-player:not(.is-enhanced) .audio-play-toggle,
.audio-player:not(.is-enhanced) .audio-time,
.audio-player:not(.is-enhanced) .audio-progress { display: none; }
.bubble--media-only .media-preview,
.bubble--media-only .audio-player,
.bubble--media-only .media-document { margin: 0; }
.media-document { display: inline-flex; align-items: center; gap: 9px; min-height: 42px; margin: 2px 0 8px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--inset); color: var(--ink); font-weight: 600; }
.media-document:hover { border-color: var(--accent); color: var(--accent); }

/* icon-only send button */
/* Send button: muted while the composer is empty, green once it has text or media. */
.btn-send { flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center;
  justify-content: center; border: none; border-radius: 50%;
  background: var(--inset); color: var(--ink-faint); cursor: default;
  transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease; }
/* the paper-plane's visual mass leans up-right; nudge to optically centre it. */
.btn-send .ico { width: 17px; height: 17px; transform: translate(-1px, 1px); }
.reply.has-content .btn-send { background: var(--voice); color: #fff; cursor: pointer;
  box-shadow: 0 4px 14px rgba(31,168,85,0.32); transform: scale(1.05); }
.reply.has-content .btn-send:hover { filter: brightness(0.96); }
.reply.has-content .btn-send:active { transform: scale(0.98); }

/* closed banner reuses the takeover shell, muted */
.closed-banner { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 12px; font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.closed-banner .ico { width: 16px; height: 16px; color: var(--voice); }
.closed-banner > div { display: inline-flex; align-items: center; gap: 8px; }
.closed-banner form { margin-left: 6px; }
.action-feedback { margin: 0 14px 10px; padding: 9px 12px; border-radius: 8px; font-size: 12px; }
.action-feedback--warn { color: var(--marginal); background: color-mix(in srgb, var(--marginal) 11%, var(--surface)); border: 1px solid color-mix(in srgb, var(--marginal) 30%, transparent); }
.action-feedback--ok { color: var(--voice); background: color-mix(in srgb, var(--voice) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--voice) 30%, transparent); }
.btn-secondary { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); font: 600 12px var(--sans); cursor: pointer; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.close-form { margin-top: 12px; display: grid; gap: 8px; }
.close-form label { font-size: 12px; font-weight: 600; color: var(--ink-muted); }
.close-form textarea { width: 100%; resize: vertical; min-height: 74px; padding: 10px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.close-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* inline send-status notes in the transcript (never hide a failure) */
.send-fail { margin-top: 6px; font-size: 11.5px; color: var(--lost); }
.retry-send { margin-left: 3px; color: inherit; font-size: inherit; font-weight: 700; text-decoration: underline;
  text-underline-offset: 2px; }
.send { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--violet); color: #fff; box-shadow: var(--glow-violet); flex: none; }
.send:hover { background: var(--violet-press); }
.send .ico { width: 18px; height: 18px; }

/* ============================================================ CONTEXT */
/* Header stays quiet while reserving room for the panel toggle. */
.ctx-head { min-height: 75px; display: flex; align-items: center; justify-content: flex-end;
  gap: 10px; padding-left: 64px; text-align: right; }
.context-scrim { display: none; }
.id-badge { flex: none; display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 4px 10px 4px 8px; border-radius: var(--r-pill); }
.id-badge .id-ico { width: 13px; height: 13px; }
.id-badge--ok { color: var(--voice); background: rgba(31,168,85,0.12); }
.id-badge--no { color: var(--ink-muted); background: var(--inset); padding-left: 10px; }

.ctx-body { flex: 1; overflow: auto; padding: 4px 20px 20px; }
.ctx-muted { color: var(--ink-faint); }

/* Group labels use spacing, not nested cards or decorative dividers. */
.ctx-section { margin-top: 20px; }
.ctx-section:first-child { margin-top: 4px; }
.ctx-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 4px; }
.ctx-section-label { font-size: 10.5px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--ink-muted); margin: 0 0 6px; }
.ctx-section-heading .ctx-section-label { margin-bottom: 0; }
.ctx-summary { color: var(--ink-soft); font-size: 13px; line-height: 1.55;
  overflow-wrap: anywhere; }

.ctx-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; }
.ctx-row .k { color: var(--ink-muted); font-size: 12.5px; flex: none; }
.ctx-row .v { font-weight: 500; font-size: 12.5px; color: var(--ink-soft); min-width: 0;
  display: flex; align-items: center; gap: 7px; justify-content: flex-end; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-row .v.mono, .ctx-row .mono { font-family: var(--mono); font-size: 12px; }
.ctx-row .v.ctx-unavailable { color: var(--ink-faint); font-weight: 400; }
.context-panel .signal, .ctx-state-dot, .ctx-power-dot { width: 8px; height: 8px; }
.context-panel .signal { box-shadow: none; animation: none; }
.ctx-state-dot, .ctx-power-dot { border-radius: 50%;
  flex: none; background: var(--dark); }
.ctx-state--ok .ctx-state-dot { background: var(--voice); }
.ctx-state--danger .ctx-state-dot { background: var(--lost); }
.ctx-state--warning .ctx-state-dot { background: var(--marginal); }
.ctx-state--neutral .ctx-state-dot, .ctx-state--unknown .ctx-state-dot {
  background: var(--dark); }
.ctx-state--unknown { color: var(--ink-faint) !important; font-weight: 400 !important; }
.ctx-power--normal { color: var(--good) !important; }
.ctx-power--warning { color: var(--marginal) !important; }
.ctx-power--critical { color: var(--lost) !important; }
.ctx-power--normal .ctx-power-dot { background: var(--good); }
.ctx-power--warning .ctx-power-dot { background: var(--marginal); }
.ctx-power--critical .ctx-power-dot { background: var(--lost); }
.ctx-row--stacked { align-items: flex-start; }
.ctx-row--stacked .v { white-space: normal; line-height: 1.4; }

.ctx-empty { padding: 6px 0 2px; color: var(--ink-faint); font-size: 12.5px; line-height: 1.45; }

.ctx-events { list-style: none; display: grid; gap: 11px; }
.ctx-events li { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: baseline;
  gap: 10px; color: var(--ink-soft); font-size: 12.5px; line-height: 1.4; }
.ctx-events span { overflow-wrap: anywhere; }
.ctx-events time { color: var(--ink-faint); font: 500 10.5px var(--mono); white-space: nowrap; }

/* ============================================================ PERSONALIZAR */
.editor { height: 100vh; overflow: auto; background: var(--canvas) var(--canvas-grad) fixed; }
.editor-topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 14px 24px; position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--canvas) 92%, transparent); border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(12px); }
.editor-title { font-size: 18px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
.editor-subtitle { margin-top: 2px; color: var(--ink-muted); font-size: 12px; }
.editor-top-actions { display: flex; align-items: center; gap: 10px; }
.editor-save { display: inline-flex; align-items: center; justify-content: center;
  gap: 7px; min-height: 40px; padding: 0 14px; color: var(--accent-press);
  background: var(--accent-tint); border: 1px solid var(--accent-tint-2); box-shadow: none; }
.editor-save:hover { color: var(--accent-press); background: var(--accent-tint-2); box-shadow: none; }
.editor-save .ico { width: 16px; height: 16px; }
.bot-picker select { min-height: 42px; max-width: 260px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font: inherit;
  font-size: 13px; padding: 0 34px 0 12px; }
.save-notice { max-width: 1080px; margin: 16px auto 0; padding: 10px 14px; display: flex;
  align-items: center; gap: 8px; color: #0E8C7D; background: rgba(20,184,160,.10);
  border-radius: var(--r-sm); font-size: 13px; font-weight: 600; }
.save-notice .ico { width: 16px; height: 16px; }
.editor-shell { width: min(720px, 100%); margin: 0 auto; padding: 32px 28px 72px; }
.editor-empty { min-height: 100vh; display: grid; place-items: center; }
.personalization-card { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); overflow: hidden; }
.personalization-section { padding: 24px; border: 0; min-width: 0; }
.personalization-section + .personalization-section { border-top: 1px solid var(--line-soft); }
.personalization-section h2, .personalization-section legend {
  font-size: 14px; font-weight: 700; line-height: 1.35; }
.personalization-section p { margin-top: 5px; color: var(--ink-muted); font-size: 12.5px;
  line-height: 1.5; text-wrap: pretty; }
.ed-name-input { display: block; width: min(360px, 100%); min-height: 44px; margin-top: 16px;
  padding: 0 13px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--inset); color: var(--ink); font: 600 14.5px var(--sans);
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease; }
.ed-name-input::placeholder { color: var(--ink-faint); font-weight: 500; }
.ed-name-input:hover { border-color: var(--line-strong); }
.ed-name-input:focus { outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-tint); }
.form-error { margin: 20px 24px 0; padding: 10px 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500; color: var(--lost);
  background: rgba(226,86,75,0.10); border: 1px solid rgba(226,86,75,0.22); }
.response-styles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px; margin-top: 16px; }
.response-style { position: relative; display: flex; min-width: 0; cursor: pointer; }
.response-style input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0;
  cursor: pointer; }
.response-style-copy { width: 100%; min-height: 104px; padding: 14px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface);
  transition: border-color .14s ease, background .14s ease, box-shadow .14s ease; }
.response-style-icon { display: grid; place-items: center; width: 30px; height: 30px;
  margin-bottom: 11px; border-radius: 9px; color: var(--ink-muted);
  background: var(--inset); transition: color .14s ease, background .14s ease; }
.response-style-icon .ico { width: 16px; height: 16px; }
.response-style-copy strong { display: block; font-size: 13.5px; line-height: 1.35; }
.response-style-copy > span { display: block; margin-top: 5px; color: var(--ink-muted);
  font-size: 12px; line-height: 1.45; }
.response-style:hover .response-style-copy { border-color: var(--line-strong);
  background: var(--inset); }
.response-style input:checked + .response-style-copy { border-color: var(--accent);
  background: var(--accent-tint); box-shadow: inset 0 0 0 1px var(--accent); }
.response-style input:checked + .response-style-copy strong { color: var(--accent-press); }
.response-style input:checked + .response-style-copy .response-style-icon {
  color: var(--accent-press); background: var(--accent-tint-2); }
.response-style input:focus-visible + .response-style-copy { outline: 3px solid var(--accent);
  outline-offset: 2px; }

/* ============================================================ LOGIN */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 384px; background: var(--glass-solid);
  border: 1px solid var(--line-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow-float); padding: 38px 34px 34px;
}
/* The canonical mark and wordmark travel together on identity surfaces. */
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-brand-mark { width: 42px; height: 42px; flex: none; }
.login-wordmark { font-size: 24px; font-weight: 700; letter-spacing: -0.03em;
  color: var(--ink); }
.login-wordmark span { color: var(--accent); margin-left: 7px; }
.login-error {
  margin-bottom: 16px; padding: 10px 13px; border-radius: var(--r-sm); font-size: 12.5px;
  color: var(--lost); background: rgba(226,86,75,0.10); border: 1px solid rgba(226,86,75,0.20);
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
/* placeholder-style label: the label sits inside the empty field and gently fades
   out the moment the field is focused or filled — minimal, no static labels above. */
.field { position: relative; }
.field-input {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 13px 14px; outline: none;
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
.field-label {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  font-size: 15px; color: var(--ink-faint); pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
/* placeholder is a single space, so :placeholder-shown == empty field */
.field-input:focus + .field-label,
.field-input:not(:placeholder-shown) + .field-label {
  opacity: 0; transform: translateY(-50%) translateX(2px);
}
.field-input:focus { background: var(--glass-solid); border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint-2); }
.login-form .btn-primary { margin-top: 8px; padding: 13px; font-size: 14px; }

/* ============================================================ PLACEHOLDERS */
.placeholder-panel { align-items: stretch; }
.placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 32px; color: var(--ink-muted);
}
.placeholder--sm { justify-content: flex-start; padding: 14px 20px; align-items: flex-start; text-align: left; }
.placeholder-ico { width: 40px; height: 40px; color: var(--ink-faint); margin-bottom: 4px; }
.placeholder-h { font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.placeholder-s { font-size: 12.5px; color: var(--ink-muted); max-width: 260px; }

/* operator footer logout */
.logout-link { display: block; margin-top: 6px; padding: 6px 8px; font-size: 12px;
  color: var(--ink-muted); border-radius: var(--r-sm); transition: background .14s ease, color .14s ease; }
.logout-link:hover { background: var(--accent-tint); color: var(--ink-soft); }

/* ============================================================ SOLO PAGE (single panel) */
/* Auditoria + Configurações: one wide centered glass panel. */
.solo-main { grid-template-columns: minmax(0, 1fr); padding: 16px; }
.solo-main > .panel { max-width: 1040px; width: 100%; margin: 0 auto; }

/* shared status pill — calm dot + label, three tones */
.status-pill { flex: none; display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: var(--r-pill);
  background: var(--inset); color: var(--ink-soft); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dark); }
.status--ok    { color: var(--good); background: rgba(20,184,160,0.10); }
.status--ok    .status-dot { background: var(--good); box-shadow: 0 0 7px 1px rgba(20,184,160,.45); }
.status--warn  { color: var(--marginal); background: rgba(225,163,61,0.12); }
.status--warn  .status-dot { background: var(--marginal); }
.status--muted { color: var(--ink-muted); background: var(--inset); }
.status--muted .status-dot { background: var(--ink-faint); }

/* ============================================================ AUDITORIA */
.audit-tools { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line-soft); }
.audit-tools input, .audit-tools select { min-height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--inset); color: var(--ink); font: 13px var(--sans); }
.audit-tools input { width: min(360px, 42vw); padding: 0 11px; }
.audit-tools select { padding: 0 30px 0 10px; }
.audit-tools input:focus, .audit-tools select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.audit-count { margin-left: auto; color: var(--ink-muted); font-size: 12px; white-space: nowrap; }
.audit-no-results { margin: 18px 20px; padding: 20px; border: 1px dashed var(--line-strong); border-radius: 10px; color: var(--ink-muted); text-align: center; font-size: 13px; }
.audit-body { overflow: auto; padding: 4px 14px 16px; }
.audit-head-row, .audit-row {
  display: grid; grid-template-columns: 1.4fr 1.2fr 0.7fr 2fr 1fr;
  gap: 14px; align-items: center; padding: 11px 12px;
}
.audit-head-row { position: sticky; top: 0; background: var(--glass); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.ah { font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.ah-time, .ar-time { text-align: right; }
.audit-row { border-top: 1px solid var(--line-soft); }
.audit-row:hover { background: var(--accent-tint); }
.ar { font-size: 12.5px; color: var(--ink-soft); min-width: 0; }
.ar-evt { display: flex; align-items: center; gap: 9px; font-weight: 600; color: var(--ink); }
.evt-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--accent);
  box-shadow: 0 0 6px 1px rgba(110,86,207,.35); }
.audit-row[data-event="channel_send_failed"] .evt-dot,
.audit-row[data-event="agent_error"] .evt-dot { background: var(--lost); box-shadow: 0 0 6px 1px rgba(226,86,75,.4); }
.conv-ref { font-family: var(--mono); font-size: 12px; color: var(--ink-muted); }
.ar-payload { font-family: var(--mono); font-size: 11.5px; color: var(--ink-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ar-time { font-size: 11.5px; color: var(--ink-muted); }
.dash { color: var(--ink-faint); }

/* ============================================================ RAIL (always icon-only) */
.nav-item { display: grid; place-items: center; position: relative;
  width: 44px; height: 44px; border-radius: var(--r-md);
  color: var(--rail-ink); transition: background .14s ease, color .14s ease; }
.nav-item .ico { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--rail-active); color: var(--rail-ink-strong); }
/* Active navigation uses a raised graphite chip plus a quiet steel marker. */
.nav-item.active { background: var(--rail-active); color: var(--rail-ink-strong); }
.nav-item.active .ico { color: var(--rail-ink-strong); }
/* left accent bar — the "you are here" marker at the rail edge */
.nav-item.active::before { content: ""; position: absolute; left: -13px; top: 50%;
  transform: translateY(-50%); width: 3px; height: 22px; border-radius: 0 3px 3px 0;
  background: var(--rail-marker); }

.nav-item:focus-visible, .op:focus-visible { outline-color: var(--rail-ink-strong); }

.nav-label, .op-text, .op-chevron { display: none; }
.op { justify-content: center; padding: 8px 0; }
.op-text { min-width: 0; flex: 1; }

.theme-ico { display: inline-flex; }
.theme-ico--dark { display: none; }
html[data-theme="dark"] .theme-ico--light { display: none; }
html[data-theme="dark"] .theme-ico--dark  { display: inline-flex; }

/* tooltips — always visible since labels are always hidden */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 12px); top: 50%;
  transform: translateY(-50%); background: var(--ink); color: #fff;
  font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 8px;
  white-space: nowrap; box-shadow: var(--shadow-float); z-index: 80; pointer-events: none;
}
.rail [data-tip]:focus-visible::after { content: attr(data-tip); position: absolute;
  left: calc(100% + 12px); top: 50%; transform: translateY(-50%); background: var(--ink);
  color: var(--surface); font-size: 12px; font-weight: 600; padding: 5px 10px;
  border-radius: 8px; white-space: nowrap; z-index: 80; }

.mobile-back { display: none; }

.live-status { position: fixed; top: 12px; right: 14px; z-index: 200; padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--marginal) 35%, transparent);
  border-radius: var(--r-pill); background: color-mix(in srgb, var(--marginal) 12%, var(--surface));
  box-shadow: var(--shadow-float); color: var(--ink-soft); font-size: 12px; font-weight: 600; }

/* ============================================================ NEWMSG PILL */
.newmsg-pill {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(100% + 10px); /* float just above the composer, whatever its height */
  background: var(--accent, #6E56CF); color: #fff; border: none; cursor: pointer;
  padding: 6px 14px; border-radius: 999px; font: inherit; font-size: 13px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18); z-index: 5;
}
.thread-panel { position: relative; }

/* ============================================================ RESPONSIVE */
@media (max-width: 1120px) {
  .inbox-body, .inbox[data-context-open="true"] .inbox-body {
    grid-template-columns: 300px minmax(0, 1fr);
  }
  .context-panel { display: none; position: absolute; inset: 0 0 0 auto;
    width: min(340px, 100%); z-index: 41; box-shadow: -8px 0 24px rgba(17,27,33,0.12); }
  .inbox.context-ready[data-context-open="true"] .context-panel:not([hidden]) { display: flex; }
  .inbox.context-ready[data-context-open="true"] .context-scrim { display: block; position: absolute;
    inset: 0; z-index: 40; background: rgba(17,27,33,0.24); cursor: default; }
  .inbox[data-context-open="true"] .context-toggle { transform: none;
    right: calc(min(340px, 100%) - 52px); }
  .close-popover { right: 12px; }
}

@media (max-width: 900px) {
  .audit-head-row, .audit-row { grid-template-columns: 1.4fr 1fr 1.5fr .8fr; }
  .ah-conv, .ar-conv { display: none; }
}

@media (max-width: 760px) {
  .app { display: block; min-height: 100dvh; height: auto; padding-bottom: 64px; }
  .rail { position: fixed; inset: auto 0 0; z-index: 100; height: 64px; padding: 8px 10px;
    flex-direction: row; justify-content: center; border-right: 0; border-top: 1px solid var(--rail-line);
    box-shadow: 0 -2px 8px oklch(12% 0.015 240 / 0.20); }
  .nav { flex: 1; flex-direction: row; justify-content: space-around; gap: 2px; }
  .nav-item { width: 44px; height: 44px; border-radius: var(--r-sm); }
  .nav-item.active::before { left: 50%; top: auto; bottom: -8px; width: 22px; height: 3px;
    transform: translateX(-50%); border-radius: 3px 3px 0 0; }
  .rail [data-tip]:hover::after, .rail [data-tip]:focus-visible::after { display: none; }
  .rail-foot { margin: 0 0 0 4px; padding: 0; }
  .op { min-width: 44px; height: 44px; padding: 6px; }
  .op-popover { left: auto; right: 0; bottom: calc(100% + 12px); }

  .inbox { height: calc(100dvh - 64px); }
  .inbox-body { display: block; min-height: 0; overflow: hidden; }
  .queue-live, .queue-panel, .thread-panel { width: 100%; height: 100%; }
  .inbox[data-selected="true"] .queue-live { display: none; }
  .inbox:not([data-selected]) .thread-panel,
  .inbox:not([data-selected]) .context-panel { display: none; }
  .context-panel { width: 100%; }
  .inbox[data-context-open="true"] .context-toggle { right: calc(100% - 52px); }
  .thread-head { padding-left: 14px; padding-right: 60px; }
  .inbox[data-context-open="true"] .thread-head { padding-right: 14px; }
  .mobile-back { display: flex; width: 36px; height: 36px; flex: none; align-items: center; justify-content: center;
    border-radius: 50%; color: var(--ink-soft); background: var(--inset); }
  .mobile-back .ico { width: 19px; height: 19px; }
  .thread-who { min-width: 0; }
  .tw-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .thread-body { padding-left: 12px; padding-right: 12px; }
  .composer { padding-inline: 10px; }

  .editor { min-height: calc(100dvh - 64px); height: auto; padding-bottom: 16px; }
  .editor-topbar { position: static; min-height: auto; padding: 16px; align-items: flex-start; }
  .editor-top-actions { flex-direction: column-reverse; align-items: stretch; }
  .bot-picker select { width: 100%; max-width: none; }
  .editor-shell { padding: 16px 16px 48px; gap: 32px; }
  .editor-save span { display: none; }
  .editor-save { width: 44px; min-width: 44px; padding: 0; }
  .save-notice { margin: 12px 16px 0; }

  .solo-main { padding: 10px; min-height: calc(100dvh - 64px); }
  .solo-main > .panel { min-height: calc(100dvh - 84px); }
  .audit-body { overflow-x: auto; }
  .audit-head-row, .audit-row { min-width: 660px; }
}

@media (max-width: 480px) {
  .editor-title { font-size: 16px; }
  .personalization-section { padding: 20px; }
  .response-styles { grid-template-columns: 1fr; }
  .response-style-copy { min-height: 0; }
  .queue-head { padding-inline: 12px; }
  .msg .bubble { max-width: 92%; }
}

@media (max-width: 260px) {
  .queue-panel .panel-head-row { align-items: flex-start; flex-wrap: wrap; gap: 4px 16px; }
  .queue-panel .queue-mode-nav { flex-basis: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important;
    animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
