/* ============================================================================
   cockpit.css — the 3-pane shell: top bar, inbox, conversation, intelligence,
   intro overlay. Layout metrics come from tokens.css.
   ==========================================================================*/

.cockpit {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

/* ============================================================================
   TOP BAR
   ==========================================================================*/
.topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
  background: linear-gradient(180deg, var(--bg-alt) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-topbar);
  min-width: 0;
}

.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  flex: 0 0 auto;
}
.brand-mark {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  background: radial-gradient(120% 120% at 30% 20%, #2b2b33, #0f0f12);
  border: 1px solid var(--border-lit);
  box-shadow: inset 0 0 0 1px rgba(203,213,225,.10);
}
.brand-mark svg { width: 16px; height: 16px; color: var(--ember); }
.brand-name {
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.brand-sep { color: var(--ink-faint); font-family: var(--font-mono); }
.brand-sub {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.topbar-tag {
  font-family: var(--font-mono);
  font-size: var(--fs-10);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.topbar-spacer { flex: 1 1 auto; min-width: var(--sp-2); }

.topbar-metrics { display: flex; align-items: center; gap: var(--sp-5); flex: 0 0 auto; }
.tb-metric { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.tb-metric .tb-metric-val {
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  display: flex; align-items: center; gap: 6px;
}
.tb-metric .tb-metric-label {
  font-family: var(--font-mono);
  font-size: var(--fs-9);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--ink-dim);
  line-height: 1;
}
.tb-clock { color: var(--ink-muted); }

/* ============================================================================
   THREE-PANE BODY
   ==========================================================================*/
.panes {
  grid-row: 2;
  display: grid;
  grid-template-columns: var(--pane-inbox-w) var(--pane-gap) 1fr var(--pane-gap) var(--pane-intel-w);
  min-height: 0;
  background: var(--border);   /* the gutters show through as hairlines */
}
.pane {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.pane-inbox { grid-column: 1; }
.pane-convo { grid-column: 3; background: var(--bg-sunken); }
.pane-intel { grid-column: 5; }

.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--bg-alt);
}
.pane-head h2 {
  display: flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 500;
}
.pane-head h2 svg { width: 14px; height: 14px; color: var(--ink-dim); }
.pane-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; min-height: 0; }

/* ============================================================================
   LEFT — UNIFIED INBOX
   ==========================================================================*/
.inbox-filters {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--bg);
}

/* channel constellation viz (flow1 renders into #channel-flow) */
.constellation {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.inbox-list { display: flex; flex-direction: column; }

/* inbox row */
.msg-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "chan  sender time"
    "chan  preview preview";
  column-gap: var(--sp-3);
  row-gap: 3px;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease);
  border-left: 2px solid transparent;
}
.msg-row:hover { background: var(--bg-alt-2); }
.msg-row.is-selected {
  background: var(--bg-alt-2);
  border-left-color: var(--ember);
}
.msg-row.is-unread .msg-sender { color: var(--ink); }
.msg-row.is-unread::before {
  content: "";
  position: absolute; left: 7px; top: 50%; transform: translateY(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--ember);
}

.msg-row .msg-chan { grid-area: chan; align-self: start; padding-top: 2px; }
.msg-row .msg-chan .chan-glyph { width: 22px; height: 22px; }
.msg-row .msg-chan .chan-glyph svg { width: 13px; height: 13px; }

.msg-sender {
  grid-area: sender;
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--ink-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-time {
  grid-area: time;
  font-family: var(--font-mono);
  font-size: var(--fs-10);
  color: var(--ink-dim);
  white-space: nowrap;
  align-self: center;
}
.msg-preview {
  grid-area: preview;
  display: flex; align-items: center; gap: var(--sp-2);
  min-width: 0;
}
.msg-preview .msg-text {
  font-size: var(--fs-12);
  color: var(--ink-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0; flex: 1 1 auto;
}
.msg-preview .msg-flags { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.msg-riskdot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.msg-riskdot.risk-medium { background: var(--warn); }
.msg-riskdot.risk-high   { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* arrival animation — subtle slide + fade */
.msg-row.arriving {
  animation: msgArrive var(--dur-4) var(--ease) both;
}
@keyframes msgArrive {
  from { opacity: 0; transform: translateY(-10px); background: var(--ember-soft); }
  60%  { background: var(--ember-soft); }
  to   { opacity: 1; transform: translateY(0); background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-row.arriving { animation: none; }
}

/* ============================================================================
   CENTER — CONVERSATION + DRAFT
   ==========================================================================*/
.convo {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0;
}
.convo-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; padding: var(--sp-5); }

/* customer context card */
.ctx-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-3) var(--sp-4);
  align-items: center;
  margin-bottom: var(--sp-5);
}
.ctx-avatar {
  width: 44px; height: 44px; border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: var(--fs-15);
  color: var(--ink);
  background: var(--bg-alt-3);
  border: 1px solid var(--border-lit);
  flex: 0 0 auto;
}
.ctx-id { min-width: 0; }
.ctx-name { font-family: var(--font-mono); font-size: var(--fs-15); font-weight: 500; color: var(--ink); }
.ctx-handle { font-family: var(--font-mono); font-size: var(--fs-11); color: var(--ink-dim); }
.ctx-meta {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
.ctx-meta .ctx-metric { display: flex; flex-direction: column; gap: 1px; }
.ctx-meta .ctx-metric .k {
  font-family: var(--font-mono); font-size: var(--fs-9);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--ink-dim);
}
.ctx-meta .ctx-metric .v {
  font-family: var(--font-mono); font-size: var(--fs-13); color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* the customer message thread */
.thread { display: flex; flex-direction: column; gap: var(--sp-4); }
.bubble {
  max-width: 78%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  font-size: var(--fs-14);
  line-height: var(--lh-body);
}
.bubble.from-customer {
  align-self: flex-start;
  background: var(--bg-alt-2);
  border: 1px solid var(--border);
  border-top-left-radius: var(--r-xs);
  color: var(--ink);
}
.bubble.from-customer .bubble-meta {
  margin-top: var(--sp-2);
  font-family: var(--font-mono); font-size: var(--fs-9);
  letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--ink-dim);
}
.bubble .bubble-subject {
  font-family: var(--font-mono); font-size: var(--fs-11);
  color: var(--ink-muted); margin-bottom: var(--sp-2);
  padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border);
}

/* draft dock (bottom of convo pane; flow2 mounts here) */
.draft-dock {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  padding: var(--sp-4);
}

/* ============================================================================
   RIGHT — INTELLIGENCE PANEL
   ==========================================================================*/
.pane-intel .pane-scroll { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); }

/* live stats strip */
.stats-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.stats-strip .stat {
  background: var(--bg-alt-2);
  padding: var(--sp-3) var(--sp-4);
}
.stats-strip .stat.wide { grid-column: 1 / -1; }

/* ============================================================================
   INTRO OVERLAY
   ==========================================================================*/
.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: radial-gradient(120% 90% at 50% 0%, rgba(203,213,225,.05), transparent 60%),
              rgba(8,8,11,.86);
  backdrop-filter: blur(6px);
  animation: overlayIn var(--dur-3) var(--ease) both;
}
.overlay.closing { animation: overlayOut var(--dur-2) var(--ease-in) both; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlayOut { from { opacity: 1; } to { opacity: 0; } }

.overlay-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, var(--bg-alt-2), var(--bg-alt));
  border: 1px solid var(--border-lit);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-pop);
  padding: var(--sp-8);
  animation: cardIn var(--dur-4) var(--ease) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

.overlay-eyebrow {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-mono); font-size: var(--fs-10);
  letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--ember);
  margin-bottom: var(--sp-4);
}
.overlay-h {
  font-family: var(--font-mono);
  font-size: var(--fs-28);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.15;
  margin-bottom: var(--sp-4);
  text-wrap: balance;
}
.overlay-body {
  font-size: var(--fs-15);
  color: var(--ink-muted);
  line-height: var(--lh-body);
  margin-bottom: var(--sp-6);
  max-width: 46ch;
}
.overlay-fine {
  font-family: var(--font-mono);
  font-size: var(--fs-10);
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}
.overlay-actions { display: flex; align-items: center; gap: var(--sp-3); }
.overlay-actions .btn-primary { padding: 10px 18px; font-size: var(--fs-13); }

/* channel roster shown in overlay so the "6 channels → 1" promise reads instantly */
.overlay-channels { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-6); }

/* ============================================================================
   RESPONSIVE — collapse to single column (phone-first fallback)
   ==========================================================================*/
@media (max-width: 1080px) {
  :root { --pane-inbox-w: 300px; --pane-intel-w: 300px; }
}

@media (max-width: 900px) {
  .cockpit { height: auto; min-height: 100vh; min-height: 100dvh; }
  .panes {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 1px;
    min-height: 0;
  }
  .pane-inbox { grid-column: 1; grid-row: 1; max-height: 60vh; }
  .pane-convo { grid-column: 1; grid-row: 2; }
  .pane-intel { grid-column: 1; grid-row: 3; }
  .pane { overflow: visible; }
  .pane-scroll { overflow-y: visible; }
  .pane-inbox .pane-scroll { max-height: 42vh; overflow-y: auto; }
  .convo-scroll { max-height: none; }
  .topbar-metrics { gap: var(--sp-4); }
}

@media (max-width: 620px) {
  .topbar { gap: var(--sp-3); padding: 0 var(--sp-3); }
  .brand-sub, .topbar-tag { display: none; }
  .tb-metric.hide-sm { display: none; }
  .overlay-card { padding: var(--sp-6); }
  .overlay-h { font-size: var(--fs-22); }
  .bubble { max-width: 92%; }
}
