@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ═══════════════════════════════════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════════════════════════════════ */
:root {
  /* Palette — Slate + Teal professional theme */
  --bg:            #f1f4f8;
  --bg-2:          #e8ecf2;
  --surface:       #ffffff;
  --surface-2:     #f8f9fb;
  --surface-3:     #edf0f5;
  --surface-glass: rgba(255,255,255,.72);
  --border:        #dde1ea;
  --border-strong: #bcc3d0;

  /* Text */
  --text:   #0e1520;
  --text-2: #344054;
  --muted:  #64748b;
  --muted-2:#94a3b8;

  /* Brand — Teal */
  --accent:        #0d9488;
  --accent-2:      #14b8a6;
  --accent-hover:  #0f766e;
  --accent-subtle: #f0fdfa;
  --accent-text:   #0f766e;
  --accent-glow:   0 0 0 3px rgba(13,148,136,.18);

  /* Risk — sharper, more distinct */
  --critical:         #dc2626;
  --critical-hover:   #b91c1c;
  --critical-bg:      #fef2f2;
  --critical-border:  #fecaca;
  --critical-text:    #b91c1c;
  --critical-glow:    0 0 16px rgba(220,38,38,.25);

  --high:         #ea580c;
  --high-hover:   #c2410c;
  --high-bg:      #fff7ed;
  --high-border:  #fed7aa;
  --high-text:    #c2410c;
  --high-glow:    0 0 16px rgba(234,88,12,.22);

  --medium:        #7c3aed;
  --medium-bg:     #f5f3ff;
  --medium-border: #ddd6fe;
  --medium-text:   #6d28d9;
  --medium-glow:   0 0 16px rgba(124,58,237,.2);

  --low:        #16a34a;
  --low-bg:     #f0fdf4;
  --low-border: #bbf7d0;
  --low-text:   #15803d;

  /* Status */
  --success: #16a34a;
  --warning: #d97706;
  --danger:  #dc2626;
  --info:    #0284c7;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.07), 0 4px 6px -2px rgba(0,0,0,.03);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,.09), 0 10px 10px -5px rgba(0,0,0,.04);
  --shadow-card: 0 1px 4px rgba(0,0,0,.05), 0 0 0 1px rgba(0,0,0,.04);

  /* Layout */
  --topbar-h: 54px;
  --app-top-offset: 0px;
  --mobile-topbar-extra: 0px;
  --feed-w:   340px;
  --r:    8px;
  --r-sm: 5px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 9999px;

  /* Motion */
  --ease: cubic-bezier(.4,0,.2,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
  --dur:  160ms;
  --dur-slow: 320ms;
}

[data-theme="dark"] {
  --bg:            #0b0f17;
  --bg-2:          #0f141e;
  --surface:       #141b26;
  --surface-2:     #192030;
  --surface-3:     #1e2739;
  --surface-glass: rgba(20,27,38,.78);
  --border:        #243044;
  --border-strong: #2f3f58;

  --text:   #e8edf5;
  --text-2: #a8b4c8;
  --muted:  #6b7e96;
  --muted-2:#3f5068;

  --accent:        #14b8a6;
  --accent-2:      #2dd4bf;
  --accent-hover:  #0d9488;
  --accent-subtle: #0d2d2a;
  --accent-text:   #5eead4;
  --accent-glow:   0 0 0 3px rgba(20,184,166,.22);

  --critical-bg:     #1e0a0a;
  --critical-border: #5c1a1a;
  --critical-text:   #fca5a5;
  --critical-glow:   0 0 16px rgba(220,38,38,.35);

  --high-bg:     #1e1000;
  --high-border: #7c2d12;
  --high-text:   #fdba74;
  --high-glow:   0 0 16px rgba(234,88,12,.3);

  --medium-bg:     #180e30;
  --medium-border: #5b21b6;
  --medium-text:   #c4b5fd;
  --medium-glow:   0 0 16px rgba(124,58,237,.3);

  --low-bg:     #052015;
  --low-border: #166534;
  --low-text:   #86efac;

  --success: #22c55e;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #38bdf8;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.45);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.3);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.55);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,.65);
  --shadow-card: 0 2px 12px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.04);
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  height: 100%;
  scroll-behavior: smooth;
  background: var(--surface-glass);
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  overflow: hidden;
}
button { font: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
p { margin: 0; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════════════════════════════ */
.app-shell {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: var(--app-top-offset);
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════════════════════════════════════ */
.topbar {
  align-items: center;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  gap: 10px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + var(--mobile-topbar-extra));
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--mobile-topbar-extra));
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 0;
  position: relative;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-brand {
  align-items: center;
  display: flex;
  gap: 9px;
  flex-shrink: 0;
}

.brand-icon {
  align-items: center;
  background: linear-gradient(135deg, #0d9488 0%, #6366f1 100%);
  border-radius: var(--r-sm);
  box-shadow: 0 2px 8px rgba(79,110,247,.35);
  color: white;
  display: flex;
  height: 30px;
  justify-content: center;
  width: 30px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -.4px;
  color: var(--text);
  line-height: 1.1;
}

.brand-sub {
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .2px;
  line-height: 1;
}

.topbar-pills {
  align-items: center;
  display: flex;
  gap: 8px;
  flex: 1;
}

.status-pill {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  display: flex;
  gap: 5px;
  padding: 4px 10px 4px 7px;
  transition: all var(--dur) var(--ease);
}

.pill-text {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  border-radius: 50%;
  display: block;
  flex-shrink: 0;
  height: 7px;
  width: 7px;
  background: var(--muted-2);
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.status-dot.ok    { background: var(--success); box-shadow: 0 0 0 2.5px rgba(56,161,105,.25); }
.status-dot.error { background: var(--danger);  box-shadow: 0 0 0 2.5px rgba(229,62,62,.25); }
.status-dot.warn  { background: var(--warning); box-shadow: 0 0 0 2.5px rgba(214,158,46,.25); }
.status-dot.pulse { animation: pulse-dot .9s ease-out; }

@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(79,110,247,.6); }
  70%  { box-shadow: 0 0 0 7px rgba(79,110,247,0); }
  100% { box-shadow: 0 0 0 0 rgba(79,110,247,0); }
}

.topbar-right {
  align-items: center;
  display: flex;
  gap: 7px;
  flex-shrink: 0;
}

.last-update-text {
  color: var(--muted-2);
  font-size: 11px;
  white-space: nowrap;
  display: none;
}
@media (min-width: 900px) { .last-update-text { display: block; } }

.icon-btn {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--muted);
  display: flex;
  height: 32px;
  justify-content: center;
  transition: all var(--dur) var(--ease);
  width: 32px;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); transform: scale(1.05); }
.icon-btn:active { transform: scale(.97); }
.icon-btn svg { pointer-events: none; }

.settings-link-btn {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--muted);
  display: flex;
  font-size: 12px;
  font-weight: 700;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
  text-decoration: none;
}
.settings-link-btn:hover { background: var(--surface-3); border-color: var(--border-strong); color: var(--text-2); }
.settings-link-btn:active { transform: scale(.97); }
.settings-link-btn svg { pointer-events: none; flex-shrink: 0; }
@media (max-width: 680px) {
  .settings-link-label { display: none; }
  .settings-link-btn { width: 32px; padding: 0; justify-content: center; }
}

.refresh-btn {
  align-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: var(--r-sm);
  box-shadow: 0 2px 8px rgba(79,110,247,.35);
  color: white;
  display: flex;
  font-size: 12px;
  font-weight: 700;
  gap: 5px;
  height: 32px;
  padding: 0 13px;
  transition: all var(--dur) var(--ease);
}
.refresh-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,110,247,.45); }
.refresh-btn:active { transform: translateY(0); }
.refresh-btn.loading svg { animation: spin .65s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  box-shadow: none;
  color: var(--muted);
}
.logout-btn:hover { background: var(--danger-bg, rgba(220,38,38,.08)); border-color: var(--danger); box-shadow: none; color: var(--danger); transform: translateY(-1px); }
.logout-btn:active { transform: translateY(0); }

/* ═══════════════════════════════════════════════════════════════════════════
   WORKSPACE
═══════════════════════════════════════════════════════════════════════════ */
.workspace {
  display: grid;
  grid-template-columns: var(--feed-w) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FEED PANEL
═══════════════════════════════════════════════════════════════════════════ */
.feed-panel {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.feed-header {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.feed-header-left { align-items: center; display: flex; gap: 8px; }
.feed-header-right { align-items: center; display: flex; gap: 8px; }

.feed-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
}

.feed-count-badge {
  align-items: center;
  background: var(--accent);
  border-radius: var(--r-full);
  box-shadow: 0 2px 6px rgba(79,110,247,.4);
  color: white;
  display: flex;
  font-size: 10px;
  font-weight: 800;
  height: 18px;
  justify-content: center;
  min-width: 18px;
  padding: 0 5px;
  transition: all var(--dur) var(--ease);
}
.feed-count-badge.zero { background: var(--surface-3); color: var(--muted-2); box-shadow: none; }

.feed-live-dot {
  animation: blink 2s ease-in-out infinite;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(56,161,105,.2);
  display: block;
  height: 7px;
  width: 7px;
}
.feed-live-dot.off { animation: none; background: var(--muted-2); box-shadow: none; }
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}

.feed-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONVERSATION CARDS
═══════════════════════════════════════════════════════════════════════════ */
.conv-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 112px;
  overflow: hidden;
  padding: 13px 13px 10px;
  position: relative;
  text-align: left;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  width: 100%;
  box-shadow: var(--shadow-card);
}

.conv-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
  border-radius: var(--r-md) 0 0 var(--r-md);
  transition: background var(--dur) var(--ease);
}

.conv-card:hover { transform: translateX(2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.conv-card:active { transform: translateX(1px) scale(.995); }

@keyframes critical-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .55; }
}
.conv-card.risk-critical::before { background: var(--critical); animation: critical-pulse 1.8s ease-in-out infinite; }
.conv-card.risk-high::before     { background: var(--high); }
.conv-card.risk-medium::before   { background: var(--medium); }
.conv-card.risk-low::before      { background: var(--low); }

/* ── Active / selected card ─────────────────────────────────────────────── */
.conv-card.active {
  transform: translateX(0);
  border-width: 2px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,148,136,.18), var(--shadow-md);
  background: var(--accent-subtle);
  position: relative;
  z-index: 1;
}

/* Left accent bar — wide and solid on active */
.conv-card.active::before { width: 5px; background: var(--accent); }
.conv-card.active.risk-critical::before { background: var(--critical); }
.conv-card.active.risk-high::before     { background: var(--high); }
.conv-card.active.risk-medium::before   { background: var(--medium); }

/* Active risk border/glow */
.conv-card.active.risk-critical {
  border-color: var(--critical);
  box-shadow: 0 0 0 3px rgba(220,38,38,.2), var(--shadow-md);
  background: var(--critical-bg);
}
.conv-card.active.risk-high {
  border-color: var(--high);
  box-shadow: 0 0 0 3px rgba(234,88,12,.18), var(--shadow-md);
  background: var(--high-bg);
}
.conv-card.active.risk-medium {
  border-color: var(--medium);
  box-shadow: 0 0 0 3px rgba(124,58,237,.15), var(--shadow-md);
  background: #faf5ff;
}

.conv-card.active .conv-name { font-weight: 700; }
.conv-card.active.risk-critical .conv-name { color: var(--critical-text); }
.conv-card.active.risk-high     .conv-name { color: var(--high-text); }
.conv-card.active.risk-medium   .conv-name { color: #6d28d9; }
.conv-card.active.risk-low      .conv-name { color: var(--accent-text); }

/* Selection arrow on right edge */
.conv-card.active::after {
  content: '';
  position: absolute;
  right: -1px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 8px solid var(--bg);
}

[data-theme="dark"] .conv-card.active::after { border-right-color: var(--bg); }

.conv-card-top {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  margin-bottom: 7px;
}

.conv-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.conv-avatar {
  align-items: center;
  border-radius: 50%;
  color: white;
  display: flex;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 800;
  height: 40px;
  justify-content: center;
  letter-spacing: .3px;
  width: 40px;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--surface);
  animation: badge-pop .25s cubic-bezier(.175,.885,.32,1.275) both;
}

@keyframes badge-pop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Pulse the card border when it has unread messages */
.conv-card.has-unread {
  border-color: var(--border-strong);
}
.conv-card.has-unread .conv-name {
  font-weight: 700;
}

.conv-meta { flex: 1; min-width: 0; }

.conv-name-row {
  align-items: center;
  display: flex;
  gap: 5px;
  margin-bottom: 1px;
  min-width: 0;
}

.conv-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.conv-name--email {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

/* ── NEW badge ───────────────────────────────────────────────────────────── */
.new-badge {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: var(--r-full);
  color: #fff;
  flex-shrink: 0;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .8px;
  padding: 2px 6px;
  text-transform: uppercase;
  animation: new-badge-in .35s cubic-bezier(.34,1.56,.64,1) both,
             new-badge-glow 2s ease-in-out .4s infinite;
}

@keyframes new-badge-in {
  from { transform: scale(0) rotate(-12deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}
@keyframes new-badge-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,.5); }
  50%       { box-shadow: 0 0 0 5px rgba(99,102,241,0); }
}

/* shimmer line across the top of unseen cards */
.conv-card.is-new::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #6366f1 40%, #8b5cf6 60%, transparent);
  border-radius: var(--r-md) var(--r-md) 0 0;
  animation: new-shimmer 2.4s ease-in-out infinite;
  overflow: hidden;
}
/* active arrow overrides the shimmer */
.conv-card.active.is-new::after,
.conv-card.active::after {
  content: '';
  position: absolute;
  right: -1px; top: 50%;
  transform: translateY(-50%);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 8px solid var(--bg);
  height: auto; left: auto; width: auto;
  background: none;
  animation: none;
  border-radius: 0;
}
[data-theme="dark"] .conv-card.active::after,
[data-theme="dark"] .conv-card.active.is-new::after { border-right-color: var(--bg); }

@keyframes new-shimmer {
  0%   { clip-path: inset(0 100% 0 0); }
  50%  { clip-path: inset(0 0% 0 0); }
  100% { clip-path: inset(0 0 0 100%); }
}

.conv-sub-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  min-width: 0;
  overflow: hidden;
}

.conv-company {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
}
.conv-company--none {
  opacity: .35;
  font-style: italic;
}

.conv-dot {
  color: var(--muted-2);
  font-size: 10px;
  flex-shrink: 0;
}

.conv-time-prominent {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
}

.conv-risk-badge {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 3px;
}

.conv-cur-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r-full);
  letter-spacing: .3px;
  text-transform: capitalize;
  border: 1px solid;
  flex-shrink: 0;
}
.conv-cur-badge.risk-low    { background: var(--low-bg);      color: var(--low-text);      border-color: var(--low-border); }
.conv-cur-badge.risk-medium { background: var(--medium-bg);   color: var(--medium-text);   border-color: var(--medium-border); }
.conv-cur-badge.risk-high   { background: var(--high-bg);     color: var(--high-text);     border-color: var(--high-border); }
.conv-cur-badge.risk-critical { background: var(--critical-bg); color: var(--critical-text); border-color: var(--critical-border); }

/* ── Message preview ──────────────────────────────────────────────────────── */
.conv-preview {
  color: var(--text-2);
  font-size: 11.5px;
  font-style: italic;
  line-height: 1.5;
  margin: 6px 0 8px 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: 3.2em;
}
[data-theme="dark"] .conv-preview { color: #8fa3bc; }
[data-theme="dark"] .conv-card.active .conv-preview { color: #a8b4c8; }

/* ── Card footer ──────────────────────────────────────────────────────────── */
.conv-card-footer {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  margin-top: auto;
}

.conv-topics-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.conv-topic-chip {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .2px;
  padding: 2px 7px;
  text-transform: lowercase;
}
.conv-card.risk-high .conv-topic-chip,
.conv-card.risk-critical .conv-topic-chip {
  background: var(--high-bg);
  border-color: var(--high-border);
  color: var(--high-text);
}
.conv-card.risk-critical .conv-topic-chip {
  background: var(--critical-bg);
  border-color: var(--critical-border);
  color: var(--critical-text);
}

.conv-score-pill {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: var(--r-full);
  border: 1px solid;
  flex-shrink: 0;
  letter-spacing: .2px;
}

.conv-footer-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.conv-assignee {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.conv-unread-pill {
  background: var(--accent);
  border-radius: var(--r-full);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: badge-pop .25s cubic-bezier(.175,.885,.32,1.275) both;
}

.conv-time { color: var(--muted-2); font-size: 10px; font-weight: 500; flex-shrink: 0; display: flex; align-items: center; gap: 3px; }

/* ═══════════════════════════════════════════════════════════════════════════
   RISK BADGE
═══════════════════════════════════════════════════════════════════════════ */
.risk-badge { align-items: center; border-radius: var(--r-sm); display: inline-flex; font-size: 10px; font-weight: 800; gap: 3px; letter-spacing: .5px; padding: 3px 8px 3px 6px; text-transform: uppercase; border: 1px solid; white-space: nowrap; }
.risk-badge svg { flex-shrink: 0; }
.risk-badge.critical { background: var(--critical-bg); color: var(--critical-text); border-color: var(--critical-border); }
.risk-badge.high     { background: var(--high-bg);     color: var(--high-text);     border-color: var(--high-border); }
.risk-badge.medium   { background: var(--medium-bg);   color: var(--medium-text);   border-color: var(--medium-border); }
.risk-badge.low      { background: var(--low-bg);      color: var(--low-text);      border-color: var(--low-border); }

.risk-badge-sub {
  font-size: 8px;
  font-weight: 500;
  opacity: .65;
  text-transform: lowercase;
  letter-spacing: .2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════════════════════════════════ */
.detail-empty {
  align-items: center;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: 48px 32px;
}

.empty-illustration {
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-rings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-ring {
  border-radius: 50%;
  border: 1px solid var(--border);
  position: absolute;
  animation: ring-pulse 3s ease-in-out infinite;
}
.ring-1 { width: 40px;  height: 40px;  animation-delay: 0s; }
.ring-2 { width: 60px;  height: 60px;  animation-delay: .4s; }
.ring-3 { width: 80px;  height: 80px;  animation-delay: .8s; }

@keyframes ring-pulse {
  0%, 100% { opacity: .4; transform: scale(1); }
  50%       { opacity: .15; transform: scale(1.04); }
}

.empty-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  width: 52px;
  position: relative;
  z-index: 1;
}

.empty-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.empty-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  max-width: 320px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SKELETON
═══════════════════════════════════════════════════════════════════════════ */
.skeleton {
  animation: shimmer 1.5s ease infinite;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}
.skel-line  { height: 9px; }
.skel-line.w-full { width: 100%; }
.skel-line.w-80   { width: 80%; }
.skel-line.w-60   { width: 60%; }
.skel-line.w-40   { width: 40%; }

/* ═══════════════════════════════════════════════════════════════════════════
   DETAIL PANEL
═══════════════════════════════════════════════════════════════════════════ */
.detail-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#detail-content {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#detail-content.visible { display: flex; }

/* ── Conversation header ─────────────────────────────────────────────────── */
.conv-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

/* ── Collapsible header ──────────────────────────────────────────────────── */
.conv-header-hero {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  user-select: none;
  transition: background var(--dur) var(--ease);
}
.conv-header-hero:hover { background: var(--surface-2); }

.conv-header-toggle {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  color: var(--muted);
  display: flex;
  flex-shrink: 0;
  height: 22px;
  justify-content: center;
  margin-left: auto;
  transition: all var(--dur) var(--ease);
  width: 22px;
}
.conv-header-hero:hover .conv-header-toggle { border-color: var(--border-strong); color: var(--text-2); }

.conv-header-toggle svg {
  transition: transform var(--dur) var(--ease);
}
.conv-header.collapsed .conv-header-toggle svg { transform: rotate(-90deg); }

/* Collapsible body */
.conv-header-body {
  overflow: hidden;
  transition: max-height var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease), padding var(--dur-slow) var(--ease);
  max-height: 300px;
  opacity: 1;
  padding: 0 20px 14px;
}
.conv-header.collapsed .conv-header-body {
  max-height: 0;
  opacity: 0;
  padding-bottom: 0;
  pointer-events: none;
}

.detail-avatar {
  align-items: center;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,.15);
  color: white;
  display: flex;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 800;
  height: 48px;
  justify-content: center;
  width: 48px;
}

.conv-header-identity { flex: 1; min-width: 0; }

.detail-name {
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.4px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-company {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-header-badges {
  align-items: center;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 5px;
  align-items: flex-end;
}

.needs-human-badge {
  align-items: center;
  animation: needshuman-pulse 2s ease-in-out infinite;
  background: var(--critical-bg);
  border: 1px solid var(--critical-border);
  border-radius: var(--r-sm);
  color: var(--critical-text);
  display: inline-flex;
  font-size: 10px;
  font-weight: 800;
  gap: 4px;
  letter-spacing: .3px;
  padding: 3px 8px;
  text-transform: uppercase;
}
@keyframes needshuman-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,62,62,0); }
  50%       { box-shadow: 0 0 0 4px rgba(229,62,62,.2); }
}

/* Score row */
.score-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.score-gauge-wrap {
  flex: 1;
  min-width: 0;
}

.score-gauge-labels {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.score-gauge-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
}

.score-gauge-value {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1;
}

.score-gauge-track {
  background: var(--surface-3);
  border-radius: var(--r-full);
  height: 7px;
  overflow: hidden;
  position: relative;
}

.score-gauge-fill {
  border-radius: var(--r-full);
  height: 100%;
  transition: width .7s var(--ease);
  position: relative;
}
.score-gauge-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.3) 100%);
  border-radius: var(--r-full);
}

.score-cur-pill {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 5px 12px;
  text-align: center;
}
.score-cur-pill-label { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.score-cur-pill-value { font-size: 14px; font-weight: 800; line-height: 1.2; }

/* Meta chips */
.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  display: inline-flex;
  gap: 4px;
  padding: 4px 10px 4px 8px;
  transition: all var(--dur) var(--ease);
}
.meta-chip:hover { border-color: var(--border-strong); background: var(--surface-3); }

.meta-chip-icon {
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.meta-chip-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.meta-chip-value {
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meta-chip-value.highlight { color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   ACTION BAR
═══════════════════════════════════════════════════════════════════════════ */
.action-bar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 7px;
  padding: 10px 20px;
}

.btn {
  align-items: center;
  border-radius: var(--r-sm);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  gap: 5px;
  height: 32px;
  padding: 0 13px;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
  letter-spacing: .1px;
  border: 1px solid transparent;
}
.btn svg { flex-shrink: 0; }
.btn:active { transform: scale(.96); }

.btn-danger {
  background: linear-gradient(135deg, var(--critical), #c53030);
  box-shadow: 0 2px 6px rgba(229,62,62,.35);
  color: white;
}
.btn-danger:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(229,62,62,.45); }

.btn-success {
  background: linear-gradient(135deg, var(--success), #2f855a);
  box-shadow: 0 2px 6px rgba(56,161,105,.35);
  color: white;
}
.btn-success:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(56,161,105,.45); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 2px 6px rgba(79,110,247,.35);
  color: white;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(79,110,247,.45); }

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-link {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-2);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  gap: 5px;
  height: 32px;
  padding: 0 13px;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
}
.btn-link:hover { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent-text); }

.tag-strip {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

.tag {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABS
═══════════════════════════════════════════════════════════════════════════ */
.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  padding: 0 20px;
  gap: 2px;
}

.tab-btn {
  align-items: center;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  font-weight: 700;
  gap: 5px;
  margin-bottom: -1px;
  padding: 10px 12px;
  transition: all var(--dur) var(--ease);
  letter-spacing: .1px;
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active { border-bottom-color: var(--accent); color: var(--accent); }

.tab-count {
  background: var(--surface-3);
  border-radius: var(--r-full);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  transition: all var(--dur) var(--ease);
}
.tab-btn.active .tab-count {
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.tab-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 20px 24px;
}
.tab-panel.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT STREAM
═══════════════════════════════════════════════════════════════════════════ */
.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  animation: msg-in .25s var(--ease) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg--customer  { flex-direction: row; }
.chat-msg--agent     { flex-direction: row-reverse; }
.chat-msg--bot       { flex-direction: row; }
.chat-msg--system    { flex-direction: row; opacity: .7; }

.chat-msg-avatar {
  align-items: center;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,.15);
  color: white;
  display: flex;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
  height: 30px;
  justify-content: center;
  margin-top: 2px;
  width: 30px;
}
.chat-avatar--customer { background: linear-gradient(135deg, #4299e1, #2b6cb0); }
.chat-avatar--agent    { background: linear-gradient(135deg, #48bb78, #276749); }
.chat-avatar--bot      { background: linear-gradient(135deg, #9f7aea, #6b46c1); }
.chat-avatar--system   { background: linear-gradient(135deg, #a0aec0, #718096); }
.chat-msg-avatar svg { pointer-events: none; }

.chat-msg-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
  max-width: 80%;
}
.chat-msg--agent .chat-msg-body { align-items: flex-end; }

.chat-msg-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chat-msg--agent .chat-msg-meta { flex-direction: row-reverse; }

.chat-msg-name {
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.chat-msg-topic {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  letter-spacing: .2px;
}

.msg-synced {
  align-items: center;
  color: var(--accent-text);
  display: inline-flex;
  font-size: 9px;
  font-weight: 700;
  gap: 2px;
  letter-spacing: .3px;
  background: var(--accent-subtle);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--r-full);
  padding: 1px 6px;
}

.chat-msg-time {
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 500;
  margin-left: auto;
}
.chat-msg--agent .chat-msg-time { margin-left: 0; margin-right: auto; }

.chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px 12px 12px 12px;
  box-shadow: var(--shadow-xs);
  padding: 9px 13px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.chat-msg--agent .chat-bubble {
  background: var(--accent-subtle);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 12px 3px 12px 12px;
}
.chat-msg--bot .chat-bubble {
  background: color-mix(in srgb, var(--medium) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--medium) 25%, transparent);
}
.chat-msg--system .chat-bubble {
  background: var(--surface-2);
  border-style: dashed;
  border-radius: 6px;
}

.chat-bubble--critical { border-color: var(--critical) !important; border-width: 1.5px; box-shadow: var(--critical-glow); }
.chat-bubble--high     { border-color: var(--high) !important;     border-width: 1.5px; box-shadow: var(--high-glow); }
.chat-bubble--medium   { border-color: var(--medium) !important;   border-width: 1.5px; box-shadow: var(--medium-glow); }

.chat-bubble-text {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* ── Inline risk assessment ──────────────────────────────────────────────── */
.risk-inline-card {
  animation: risk-slide-in .3s var(--ease) both;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 12px;
}
@keyframes risk-slide-in {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}
.risk-inline--critical { border-left-color: var(--critical); background: var(--critical-bg); }
.risk-inline--high     { border-left-color: var(--high);     background: var(--high-bg); }
.risk-inline--medium   { border-left-color: var(--medium);   background: var(--medium-bg); }
.risk-inline--low      { border-left-color: var(--low);      background: var(--low-bg); }

.risk-inline-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.risk-inline-score {
  align-items: center;
  display: flex;
  gap: 7px;
  flex: 1;
  min-width: 0;
}

.risk-score-bar-wrap {
  background: var(--surface-3);
  border-radius: var(--r-full);
  flex: 1;
  height: 4px;
  max-width: 70px;
  overflow: hidden;
}
.risk-score-bar-fill {
  border-radius: var(--r-full);
  display: block;
  height: 100%;
  transition: width .5s var(--ease);
}

.risk-inline-score strong { color: var(--text); font-size: 12px; font-weight: 800; }
.risk-score-max { color: var(--muted); font-size: 10px; }

.risk-needs-human {
  align-items: center;
  background: var(--critical-bg);
  border: 1px solid var(--critical-border);
  border-radius: var(--r-sm);
  color: var(--critical-text);
  display: inline-flex;
  font-size: 10px;
  font-weight: 800;
  gap: 3px;
  padding: 2px 7px;
}

.risk-topics {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.risk-inline-reason {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
  font-style: italic;
}

/* ── Topic chips ─────────────────────────────────────────────────────────── */
.topic-chip {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
}
.topic-chip.refund      { background: var(--critical-bg); border-color: var(--critical-border); color: var(--critical-text); }
.topic-chip.legal       { background: var(--critical-bg); border-color: var(--critical-border); color: var(--critical-text); }
.topic-chip.chargeback  { background: var(--high-bg);     border-color: var(--high-border);     color: var(--high-text); }
.topic-chip.cancellation { background: var(--high-bg);    border-color: var(--high-border);     color: var(--high-text); }
.topic-chip.frustration { background: var(--medium-bg);   border-color: var(--medium-border);   color: var(--medium-text); }
.topic-chip.escalation  { background: var(--medium-bg);   border-color: var(--medium-border);   color: var(--medium-text); }

/* ═══════════════════════════════════════════════════════════════════════════
   QA CARD
═══════════════════════════════════════════════════════════════════════════ */
.qa-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.qa-card-header {
  align-items: center;
  background: linear-gradient(135deg, var(--surface-2), var(--surface-3));
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 14px;
  padding: 14px 16px;
}

.qa-score-circle {
  align-items: center;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 54px;
  justify-content: center;
  width: 54px;
  border: 3px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.qa-score-num   { font-size: 17px; font-weight: 900; line-height: 1; }
.qa-score-label { color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.qa-outcome-good  { border-color: var(--success); color: var(--success); }
.qa-outcome-mixed { border-color: var(--warning); color: var(--warning); }
.qa-outcome-poor  { border-color: var(--danger);  color: var(--danger); }

.qa-meta { flex: 1; }
.qa-outcome-text { font-size: 14px; font-weight: 800; margin-bottom: 2px; text-transform: capitalize; }
.qa-timestamp { color: var(--muted); font-size: 11px; }

.qa-card-body    { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; }
.qa-summary      { color: var(--text-2); font-size: 13px; line-height: 1.6; }
.qa-section-title { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .5px; margin-bottom: 5px; text-transform: uppercase; }
.qa-recs         { display: flex; flex-direction: column; gap: 5px; list-style: none; }
.qa-recs li      { align-items: flex-start; color: var(--text-2); display: flex; font-size: 12px; gap: 8px; line-height: 1.5; }
.qa-recs li::before { background: var(--accent); border-radius: 50%; content: ''; display: block; flex-shrink: 0; height: 5px; margin-top: 5px; width: 5px; }

/* ═══════════════════════════════════════════════════════════════════════════
   DIAGNOSTIC ENTRIES (audit / webhooks)
═══════════════════════════════════════════════════════════════════════════ */
.diag-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  transition: all var(--dur) var(--ease);
  box-shadow: var(--shadow-xs);
}
.diag-entry:hover { border-color: var(--border-strong); transform: translateX(2px); }

.diag-head { align-items: center; display: flex; gap: 8px; margin-bottom: 4px; }
.diag-icon { color: var(--muted); display: flex; align-items: center; flex-shrink: 0; }
.diag-action { color: var(--text); font-size: 12px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diag-time   { color: var(--muted-2); font-size: 10px; flex-shrink: 0; }
.diag-meta   { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; line-height: 1.4; overflow-wrap: anywhere; }

.webhook-status {
  border-radius: var(--r-full);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .4px;
  padding: 2px 7px;
  text-transform: uppercase;
}
.webhook-status.processed { background: var(--low-bg);      color: var(--low-text); border: 1px solid var(--low-border); }
.webhook-status.received  { background: var(--surface-3);   color: var(--muted);    border: 1px solid var(--border); }
.webhook-status.failed    { background: var(--critical-bg); color: var(--critical-text); border: 1px solid var(--critical-border); }
.webhook-status.ignored   { background: var(--surface-3);   color: var(--muted-2);  border: 1px solid var(--border); }

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════════════════════════════════ */
.toast-container {
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  position: fixed;
  right: 20px;
  z-index: 9999;
}

.toast {
  align-items: center;
  animation: toast-in .22s var(--ease) forwards;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  display: flex;
  font-size: 13px;
  font-weight: 600;
  gap: 10px;
  max-width: 320px;
  padding: 12px 16px;
  pointer-events: all;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--info); }
.toast.out     { animation: toast-out .2s var(--ease) forwards; }
.toast-icon    { flex-shrink: 0; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(24px); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MONO UTILITY
═══════════════════════════════════════════════════════════════════════════ */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 900px)
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --feed-w: 280px; }
  .topbar-pills { gap: 6px; }
  .pill-text { max-width: 120px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 680px)
   Full-screen panels: feed fills screen, tap card → detail fills screen
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 680px) {
  :root {
    --topbar-h: 52px;
    --app-top-offset: 0px;
    --mobile-topbar-extra: 0px;
  }

  body { overflow: hidden; }

  .topbar {
    padding-top: 0;
    padding-right: 12px;
    padding-bottom: 0;
    padding-left: 12px;
    gap: 8px;
    height: 52px;
  }
  .brand-sub { display: none; }
  .topbar-pills { gap: 5px; flex: 1; }
  .status-pill { padding: 3px 8px 3px 6px; }
  .pill-text { max-width: 90px; font-size: 10px; }
  #health-pill .pill-text { display: none; }
  .last-update-text { display: none !important; }
  .refresh-label { display: none; }
  .alerts-label { display: none; }
  .refresh-btn { padding: 0; width: 32px; justify-content: center; }
  #enable-alerts-btn { width: 32px; padding: 0; justify-content: center; }
  .topbar-pills { display: none !important; }

  .workspace {
    display: block;
    position: relative;
    overflow: hidden;
    flex: 1;
    min-height: 0;
  }

  /* Feed fills the screen */
  .feed-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-right: none;
    transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
    z-index: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Detail panel slides in from the right */
  .detail-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease);
    z-index: 2;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* When detail is open */
  .workspace.detail-open .feed-panel {
    transform: translateX(-30%);
    opacity: 0;
    pointer-events: none;
  }
  .workspace.detail-open .detail-panel {
    transform: translateX(0);
  }

  /* Back button */
  .topbar-back { display: flex !important; }

  /* Larger touch targets */
  .conv-card { padding: 14px 12px 12px; }
  .feed-list { padding: 8px; gap: 7px; }

  /* Stack action bar items */
  .action-bar { padding: 10px 14px; gap: 6px; }
  .btn { height: 36px; font-size: 13px; }

  /* Full-width score row */
  .score-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .score-cur-pill { flex-direction: row; justify-content: space-between; align-items: center; padding: 8px 12px; }

  /* Tab panel */
  .tab-panel { padding: 12px 14px 24px; }

  /* Chat bubbles take more width on mobile */
  .chat-msg-body { max-width: 90%; }

  /* Conv header */
  .conv-header { padding: 14px 14px 12px; }
  .detail-avatar { width: 40px; height: 40px; font-size: 15px; }
  .detail-name { font-size: 15px; }

  /* Meta chips scroll horizontally */
  .meta-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .meta-chips::-webkit-scrollbar { height: 0; }

  /* Toast at bottom center */
  .toast-container { right: 12px; left: 12px; bottom: 16px; }
  .toast { max-width: 100%; }
}

@media (display-mode: standalone) and (max-width: 680px) {
  .topbar {
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY FEED STATE
═══════════════════════════════════════════════════════════════════════════ */
.feed-empty {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 48px 20px;
  text-align: center;
}
.feed-empty svg { opacity: .35; }
.feed-empty p { font-size: 13px; }
