/* ==========================================================================
   Joy Travel CRM — design system

   Chart colours come from a validated data-visualisation palette: the booking
   pipeline uses a single-hue ordinal blue ramp (checked for monotone lightness,
   visible step gaps and contrast against the white card surface), and workload
   bars use one hue with the agent's colour carried by a dot beside the label
   rather than by the bar. Text never wears a data colour.
   ========================================================================== */

:root {
  /* Neutral ink ramp (one scale used app-wide, charts included) */
  --ink-900: #111827;
  --ink-700: #374151;
  --ink-600: #4b5563;
  --ink-500: #6b7280;
  --ink-400: #9ca3af;

  /* Surfaces */
  --rail: #111827;
  --rail-hover: #1f2937;
  --plane: #f7f8fa;
  --surface: #ffffff;
  --surface-sunken: #f9fafb;

  /* Lines */
  --line: #e5e7eb;
  --line-soft: #f1f3f5;

  /* Accent */
  --accent: #2a78d6;
  --accent-hover: #1c5cab;
  --accent-wash: #eff6ff;

  /* Status (reserved — never reused as a series colour) */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-wash: #ecfdf3;
  --warning-wash: #fffbeb;
  --critical-wash: #fef2f2;

  /* Booking pipeline — validated ordinal ramp, light → dark */
  --stage-1: #86b6ef;
  --stage-2: #5598e7;
  --stage-3: #2a78d6;
  --stage-4: #1c5cab;
  --stage-5: #104281;
  --stage-exit: #cbd5e1; /* cancelled: an exit, not a step in the progression */

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-card: 0 1px 2px rgba(17, 24, 39, 0.04), 0 1px 3px rgba(17, 24, 39, 0.06);
  --shadow-pop: 0 10px 30px rgba(17, 24, 39, 0.14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink-900);
  background: var(--plane);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--ink-500); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.tiny.err { color: var(--critical); }
.nowrap { white-space: nowrap; }
.hint { font-weight: 400; color: var(--ink-500); font-size: 11px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--accent); }

/* ============================================================ app shell === */

.shell { display: grid; grid-template-columns: 68px 1fr; height: 100vh; }

.rail {
  background: var(--rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 12px;
  gap: 6px;
}
.rail-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(140deg, #34d399, #2a78d6);
  display: grid; place-items: center;
  color: white; font-weight: 700; font-size: 13px;
  margin-bottom: 12px; flex-shrink: 0;
}
.rail-item {
  position: relative;
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center;
  color: #9aa4b2; text-decoration: none;
  background: none; border: none; cursor: pointer;
  transition: background 0.13s, color 0.13s;
}
.rail-item:hover { background: var(--rail-hover); color: #e5e7eb; }
.rail-item.active { background: var(--accent); color: white; }
.rail-item svg { width: 20px; height: 20px; }
.rail-item .rail-badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--critical); color: white;
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--rail);
}
.rail-tip {
  position: absolute; left: 54px; top: 50%; transform: translateY(-50%);
  background: var(--ink-900); color: white; padding: 5px 9px; border-radius: 6px;
  font-size: 12px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.12s; z-index: 60; box-shadow: var(--shadow-pop);
}
.rail-item:hover .rail-tip { opacity: 1; }
.rail-spacer { flex: 1; }

.main { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; }
.topbar .sub { font-size: 12px; color: var(--ink-500); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.whoami { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.whoami .role { font-size: 11px; color: var(--ink-500); }

/* ================================================================ avatar === */

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  color: white; user-select: none;
}
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.avatar.xs { width: 18px; height: 18px; font-size: 8px; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

/* =============================================================== buttons === */

.btn {
  background: var(--accent); color: white; border: none;
  padding: 8px 15px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: background 0.13s, opacity 0.13s;
}
.btn:hover { background: var(--accent-hover); }
a.btn { text-decoration: none; display: inline-block; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--ink-700); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--surface-sunken); }
.btn.danger { background: var(--critical); }
.btn.danger:hover { filter: brightness(0.92); }
.btn.tiny { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; }

/* ================================================================= forms === */

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-600); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit; background: var(--surface); color: var(--ink-900);
  transition: border-color 0.13s, box-shadow 0.13s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.13);
}
input:disabled { background: var(--surface-sunken); color: var(--ink-500); }
select { cursor: pointer; }
.two-up { display: flex; gap: 7px; }

/* ================================================================= chips === */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; white-space: nowrap;
}
/* Conversation status chips are coloured inline from each status's own colour
   (see chipStyle() in shell.js), since statuses are user-defined. These three
   remain as generic tone classes for fixed states like an agent being active. */
.chip.open { background: var(--good-wash); color: #067306; }
.chip.pending { background: var(--warning-wash); color: #92600a; }
.chip.resolved { background: var(--surface-sunken); color: var(--ink-500); }
.chip.unassigned { background: var(--critical-wash); color: #a52121; }
.chip.reply { background: var(--critical-wash); color: #a52121; }
.chip.test-data { background: #f3e8ff; color: #7c3aed; letter-spacing: 0.04em; }
.chip.due { background: var(--critical-wash); color: #a52121; }
.chip.snoozed { background: #eef2ff; color: #4338ca; }
.chip.collab-overflow { background: var(--surface-sunken); color: var(--ink-500); font-weight: 700; }
.owner-chip svg { width: 10px; height: 10px; }

.label-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; border: 1px solid;
}
.chip-x {
  border: none; background: none; cursor: pointer; padding: 0;
  font-size: 14px; line-height: 1; color: inherit; opacity: 0.55;
}
.chip-x:hover { opacity: 1; }
.label-add {
  width: auto; padding: 2px 7px; font-size: 11px; border-radius: 20px;
  border: 1px dashed var(--line); color: var(--ink-500); background: var(--surface);
}

.stage-pill {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.stage-new { background: #eef4fd; color: #1c5cab; }
.stage-quoted { background: var(--warning-wash); color: #92600a; }
.stage-confirmed { background: var(--accent-wash); color: #1c5cab; }
.stage-booked { background: var(--good-wash); color: #067306; }
.stage-completed { background: #f0fdfa; color: #0f766e; }
.stage-cancelled { background: var(--surface-sunken); color: var(--ink-500); }

/* ================================================================= inbox === */

.inbox { display: grid; grid-template-columns: 330px 1fr 340px; flex: 1; overflow: hidden; min-height: 0; }
.col { display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border-right: 1px solid var(--line); min-width: 0; }
.col:last-child { border-right: none; border-left: 1px solid var(--line); }
.col-scroll { overflow-y: auto; flex: 1; min-height: 0; }

.search-wrap { padding: 12px 12px 8px; }
.search-input { padding-left: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af' stroke-width='2'%3E%3Cpath stroke-linecap='round' d='m21 21-4.3-4.3M19 11a8 8 0 1 1-16 0 8 8 0 0 1 16 0Z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 9px center; background-size: 15px; }

/* Saved-view pills (spec 2.3) */
.views-strip { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 12px 8px; }
.view-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; font-size: 11.5px; font-weight: 600; font-family: inherit;
  border-radius: 20px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-600); cursor: pointer; transition: background 0.13s, color 0.13s, border-color 0.13s;
}
.view-pill:hover { background: var(--surface-sunken); }
.view-pill.active { background: var(--accent-wash); color: var(--accent-hover); border-color: var(--accent); }
.view-count {
  font-size: 10px; font-weight: 700; min-width: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--surface-sunken); color: var(--ink-500);
  display: inline-grid; place-items: center; line-height: 16px;
}
.view-count.hot { background: var(--critical-wash); color: #a52121; }
.view-pill.active .view-count { background: var(--accent); color: white; }

.filter-bar { display: flex; gap: 6px; padding: 0 12px 10px; }
.filter-bar select { padding: 5px 7px; font-size: 12px; min-width: 0; flex: 1; }

.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-item {
  display: flex; gap: 10px; padding: 11px 13px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer; border-left: 3px solid transparent;
  transition: background 0.11s;
}
.conv-item:hover { background: var(--surface-sunken); }
.conv-item.active { background: var(--accent-wash); border-left-color: var(--accent); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 11px; color: var(--ink-400); flex-shrink: 0; }
.conv-preview {
  font-size: 12.5px; color: var(--ink-500); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-item.needs-reply .conv-preview { color: var(--ink-700); font-weight: 500; }
/* Unread reads like WhatsApp: bold name, green time, green count pill */
.conv-item.needs-reply .conv-name { font-weight: 700; }
.conv-item.needs-reply .conv-time { color: #1fa855; font-weight: 600; }
.conv-preview-row { display: flex; align-items: center; gap: 6px; }
.conv-preview-row .conv-preview { flex: 1; min-width: 0; margin-top: 2px; }
.unread-pill {
  background: #25d366; color: white; flex-shrink: 0;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 10px;
  font-size: 10.5px; font-weight: 700; display: grid; place-items: center;
}
.conv-meta { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-top: 6px; }

/* 24h reply-window triage dot (conversation list) */
.window-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.window-dot.open { background: var(--good); }
.window-dot.amber { background: var(--warning); }
.window-dot.closed { background: var(--ink-400); }

/* ================================================================== chat === */

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 16px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.chat-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-who h2 { font-size: 15px; }
.chat-who .sub { font-size: 12px; color: var(--ink-500); }
.chat-controls { display: flex; gap: 7px; flex-shrink: 0; }
.chat-controls select { width: auto; font-size: 12px; padding: 6px 8px; }

/* Presence — "Rivky is typing…" in the thread header (spec 1.5) */
.presence-line { color: var(--accent); font-weight: 500; }

/* 24h reply-window badge (thread header) */
.window-badge {
  display: inline-flex; align-items: center; flex-shrink: 0;
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; white-space: nowrap;
}
.window-badge.open { background: var(--good-wash); color: #067306; }
.window-badge.amber { background: var(--warning-wash); color: #92600a; }
.window-badge.closed { background: var(--surface-sunken); color: var(--ink-500); }

.label-strip {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface-sunken); flex-shrink: 0;
}
.label-strip.tight { padding: 0; border: none; background: none; }

/* Column layout + margin-top:auto on the inner wrapper anchors a short thread to
   the bottom, the way a chat should read, without breaking scroll when it's long. */
.thread { flex: 1; overflow-y: auto; padding: 18px 18px 8px; background: var(--plane); min-height: 0; display: flex; flex-direction: column; }
.thread-inner { margin-top: auto; }
.day-sep { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; }
.day-sep::before, .day-sep::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.day-sep span { font-size: 11px; color: var(--ink-400); font-weight: 500; }

/* Case boundary — a heavier marker than a day separator, since it's a bigger
   break in the (still continuous) chat log. */
.case-sep { display: flex; align-items: center; gap: 10px; margin: 20px 0 14px; }
.case-sep::before, .case-sep::after { content: ""; height: 1px; background: var(--accent); opacity: 0.25; flex: 1; }
.case-sep span {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent-hover); background: var(--accent-wash); padding: 3px 10px; border-radius: 20px;
}

.chip.case-chip { background: var(--surface-sunken); color: var(--ink-600); font-variant-numeric: tabular-nums; }

.merge-banner {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 12px; color: #92600a;
  background: var(--warning-wash); border-bottom: 1px solid #fde68a; flex-shrink: 0;
}
.merge-banner select { width: auto; font-size: 12px; padding: 4px 7px; }

.stale-banner {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 8px 16px; font-size: 12.5px; color: #92600a;
  background: var(--warning-wash); border-bottom: 1px solid #fde68a; flex-shrink: 0;
}
.stale-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stale-line a { color: #92600a; text-decoration: underline; text-underline-offset: 2px; }
.stale-line a:hover { color: #6b4703; }
.stale-detail summary { cursor: pointer; list-style: none; }
.stale-detail summary::-webkit-details-marker { display: none; }
.stale-detail summary::before { content: '▸ '; }
.stale-detail[open] summary::before { content: '▾ '; }
.stale-group { margin: 6px 0 0 14px; }
.stale-group + .stale-group { margin-top: 4px; }
.stale-dismiss {
  border: none; background: transparent; color: #92600a; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 2px 4px; flex-shrink: 0;
}
.stale-dismiss:hover { color: #6b4703; }

/* ------------------------------------------------------------ kanban board */

.board-filter-bar { padding: 10px 16px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.board-filter-bar select { width: auto; font-size: 12.5px; padding: 5px 8px; }

.board-scroll {
  flex: 1; overflow-x: auto; overflow-y: hidden;
  display: flex; gap: 12px; padding: 14px 16px; align-items: flex-start;
}

.board-col {
  flex: 0 0 260px; display: flex; flex-direction: column;
  background: var(--surface-sunken); border-radius: 10px; max-height: 100%;
}
.board-col-head {
  display: flex; align-items: center; gap: 7px; padding: 10px 12px;
  border-top: 3px solid var(--ink-400); border-radius: 10px 10px 0 0;
  font-weight: 600; font-size: 12.5px; color: var(--ink-700);
}
.board-col-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.board-col-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-col-count { color: var(--ink-400); font-weight: 500; }
.board-col-body { flex: 1; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.board-col-body.drag-over { background: var(--accent-wash); border-radius: 8px; }
.board-col-empty { font-size: 11.5px; color: var(--ink-400); text-align: center; padding: 14px 0; }

.board-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 10px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.board-card:active { cursor: grabbing; }
.board-card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.board-card-time { margin-left: auto; }
.board-card-name { font-weight: 600; font-size: 13px; color: var(--ink-900); margin-bottom: 3px; }
.board-card-summary {
  font-size: 11.5px; color: var(--ink-500); margin-bottom: 7px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.board-card-bottom { display: flex; align-items: center; gap: 6px; }

.case-history { margin-top: 10px; }
.case-history summary { font-size: 11.5px; font-weight: 600; color: var(--ink-500); cursor: pointer; }
.case-history-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 12.5px;
}
.case-history-row:last-child { border-bottom: none; }
.case-history-row.current { font-weight: 600; }

.msg-row { display: flex; margin-bottom: 8px; }
.msg-row.out { justify-content: flex-end; }
.bubble-wrap { position: relative; display: inline-block; max-width: 65%; }
.bubble {
  padding: 9px 13px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.45; word-wrap: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(17, 24, 39, 0.05);
}
.msg-row.in .bubble { background: var(--surface); border-bottom-left-radius: 5px; }
/* Outbound wears WhatsApp's light green with dark ink — the colour agents'
   eyes already parse as "mine", and blue read-ticks stay legible on it. */
.msg-row.out .bubble { background: #d9fdd3; color: #111b21; border-bottom-right-radius: 5px; }
.bubble .meta { font-size: 10px; margin-top: 4px; opacity: 0.7; }
.msg-row.out .bubble .meta { opacity: 1; color: rgba(17, 27, 33, 0.55); }

/* Delivery ticks (WhatsApp familiarity) */
.ticks { display: inline-flex; align-items: center; gap: 3px; margin-left: 4px; color: rgba(17, 27, 33, 0.4); }
.ticks svg { width: 15px; height: 10px; }
.ticks.read { color: #53bdeb; }
.ticks.failed { color: var(--critical); font-weight: 700; }
.ticks.failed svg { width: 12px; height: 12px; }
.msg-image { display: block; max-width: 100%; max-height: 260px; border-radius: 8px; margin-bottom: 5px; }
.msg-video { display: block; max-width: 260px; max-height: 260px; border-radius: 8px; margin-bottom: 5px; background: #000; }
.msg-audio { display: block; width: 240px; margin-bottom: 5px; }
/* Stickers render small and never full-width, unlike photos. */
.msg-sticker { display: block; width: 96px; height: 96px; object-fit: contain; margin-bottom: 5px; }

.doc-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 11px; border-radius: 10px; margin-bottom: 5px;
  background: var(--surface-sunken); border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 500; text-decoration: none; color: inherit;
}
.msg-row.out .doc-chip { background: rgba(255, 255, 255, 0.6); border-color: rgba(17, 27, 33, 0.12); color: inherit; }
.doc-size { opacity: 0.6; font-weight: 400; }

.media-notice { font-size: 12.5px; color: var(--ink-500); font-style: italic; margin-bottom: 2px; }
.msg-row.out .media-notice { color: rgba(17, 27, 33, 0.6); }

.location-card, .contact-card {
  padding: 2px 0 4px; margin-bottom: 2px;
}
.location-name, .contact-name { font-weight: 600; font-size: 13.5px; }
.location-address, .contact-phone { font-size: 12.5px; opacity: 0.85; margin-top: 1px; }
.location-card .btn, .contact-card .btn { margin-top: 7px; }
.contact-card + .contact-card { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(0, 0, 0, 0.08); }

/* An emoji reaction hangs off the bubble's outer bottom corner, like the
   messaging apps this is meant to feel familiar to. */
.reaction-chip {
  position: absolute; bottom: -9px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 1px 5px; font-size: 13px; line-height: 1.3; box-shadow: var(--shadow-card);
}
.msg-row.in .reaction-chip { right: -6px; }
.msg-row.out .reaction-chip { left: -6px; }

.composer-wrap { border-top: 1px solid var(--line); flex-shrink: 0; background: var(--surface); }
.composer-mode { display: flex; gap: 6px; padding: 8px 14px 0; }
.mode-btn {
  padding: 4px 11px; font-size: 11.5px; font-weight: 600; font-family: inherit;
  border-radius: 20px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-500); cursor: pointer; transition: background 0.13s, color 0.13s, border-color 0.13s;
}
.mode-btn.active { background: var(--accent-wash); color: var(--accent-hover); border-color: var(--accent); }
.composer { display: flex; gap: 8px; padding: 8px 14px 12px; align-items: flex-end; }
.emoji-btn { font-size: 15px; line-height: 1; padding: 7px 9px; flex-shrink: 0; }
.emoji-picker {
  position: absolute; bottom: calc(100% - 2px); left: 10px; z-index: 40;
  width: min(340px, calc(100% - 20px));
  display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 2px;
  padding: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-pop);
}
.emoji-picker[hidden] { display: none; }
.emoji-cell {
  border: none; background: none; cursor: pointer; font-size: 20px; line-height: 1;
  padding: 5px 0; border-radius: 6px;
}
.emoji-cell:hover { background: var(--surface-sunken); }

.attach-btn { padding: 8px 10px; flex-shrink: 0; line-height: 0; }
.attach-btn svg { width: 16px; height: 16px; }
.composer textarea {
  resize: none; max-height: 120px; line-height: 1.4;
  /* rows=1 + JS auto-grow: starts input-height, grows with Shift+Enter newlines */
  min-height: 36px;
}

/* Canned-reply picker (spec 1.6) — floats above the composer while the draft
   is a "/shortcut". */
.composer-wrap { position: relative; }
.canned-picker {
  position: absolute; bottom: calc(100% - 2px); left: 10px; right: 10px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop); overflow: hidden;
}
.canned-item {
  display: flex; align-items: baseline; gap: 8px; padding: 8px 11px;
  cursor: pointer; border-bottom: 1px solid var(--line-soft); min-width: 0;
}
.canned-item:last-child { border-bottom: none; }
.canned-item.active, .canned-item:hover { background: var(--accent-wash); }
.canned-shortcut { font-size: 12px; font-weight: 700; color: var(--accent-hover); flex-shrink: 0; }
.canned-title { font-size: 12.5px; font-weight: 600; flex-shrink: 0; }
.canned-preview {
  font-size: 12px; color: var(--ink-500);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.composer.note-mode textarea {
  border-color: var(--warning); background: var(--warning-wash);
}
.composer.note-mode textarea:focus { box-shadow: 0 0 0 3px rgba(250, 178, 25, 0.18); }
.btn.note { background: var(--warning); color: #5a3d00; }
.btn.note:hover { filter: brightness(0.95); }
.composer-notice { padding: 0 14px 10px; font-size: 11.5px; color: var(--ink-500); }

/* Approved-template picker (spec 1.3) — replaces the composer once the 24h
   window is closed. */
.template-picker { padding: 8px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.template-picker select { font-size: 13px; }
.template-vars { display: flex; flex-direction: column; gap: 6px; }
.template-var { font-size: 12.5px; padding: 7px 9px; }
.template-preview {
  font-size: 12.5px; line-height: 1.45; color: var(--ink-700); padding: 9px 11px;
  background: var(--surface-sunken); border: 1px solid var(--line); border-radius: var(--radius-sm);
  white-space: pre-wrap; word-wrap: break-word;
}

/* =========================================================== right panel === */

.tabs { display: flex; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.tab {
  flex: 1; padding: 11px 8px; border: none; background: none; cursor: pointer;
  font-size: 12.5px; font-weight: 600; font-family: inherit; color: var(--ink-500);
  border-bottom: 2px solid transparent; transition: color 0.13s;
}
.tab:hover { color: var(--ink-700); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.section { padding: 15px 16px; border-bottom: 1px solid var(--line); }
.section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-500); margin-bottom: 11px;
}
.deal-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px; margin-bottom: 10px; }
.deal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; font-size: 13px; font-weight: 600; }
.new-deal-form { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 11px; margin-top: 10px; }

/* Internal notes list (Details sidebar) — amber like the old inline note
   bubble was, so the "private, never sent" association carries over, but as
   a compact log entry rather than a chat bubble. */
.notes-list { display: flex; flex-direction: column; gap: 8px; }
.note-entry {
  background: var(--warning-wash); border: 1px solid #fde68a; border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.note-entry-head { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: #92600a; margin-bottom: 4px; }
.note-entry-head svg { width: 11px; height: 11px; flex-shrink: 0; }
.note-entry-head .chip-x { margin-left: auto; color: #92600a; }
.note-entry-body { font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }

/* ============================================================== timeline === */

.timeline { display: flex; flex-direction: column; }
.tl-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.tl-item:last-child { border-bottom: none; }
.tl-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.tl-body { flex: 1; min-width: 0; }
.tl-head { font-size: 12.5px; line-height: 1.4; }
.tl-change { font-size: 12px; margin-top: 3px; }
.tl-change .arrow { color: var(--ink-400); }
.tl-detail { font-size: 12px; color: var(--ink-500); margin-top: 3px; word-wrap: break-word; }
.tl-time { font-size: 10.5px; color: var(--ink-400); margin-top: 3px; }

/* ============================================================= dashboard === */

.page { flex: 1; overflow-y: auto; padding: 22px; min-height: 0; }
.page-wrap { max-width: 1180px; margin: 0 auto; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}
.card > h3 { font-size: 14px; margin-bottom: 3px; }
.card > .card-sub { font-size: 12px; color: var(--ink-500); margin-bottom: 15px; }

.hero-card { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.hero-figure { font-size: 52px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.hero-figure.attention { color: var(--critical); }
.hero-figure.calm { color: var(--good); }
.hero-text h3 { font-size: 15px; margin-bottom: 4px; }
.hero-text p { margin: 0; font-size: 13px; color: var(--ink-500); }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow-card);
}
.kpi-value { font-size: 27px; font-weight: 600; line-height: 1.1; letter-spacing: -0.01em; }
.kpi-label { font-size: 12px; color: var(--ink-500); margin-top: 5px; }
.kpi.attention .kpi-value { color: var(--critical); }
a.kpi.linked { text-decoration: none; color: inherit; display: block; transition: border-color 0.13s, box-shadow 0.13s; }
a.kpi.linked:hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.1); }

/* Deal-stage nudges (spec 2.4) */
.nudge-card { border-left: 3px solid var(--warning); }
.nudge-row {
  display: grid; grid-template-columns: 44px 1fr auto auto 90px; gap: 12px; align-items: center;
  padding: 9px 4px; border-bottom: 1px solid var(--line-soft);
  text-decoration: none; color: inherit; font-size: 13px;
}
.nudge-row:last-child { border-bottom: none; }
.nudge-row:hover { background: var(--surface-sunken); }
.nudge-days { font-weight: 700; color: #92600a; font-variant-numeric: tabular-nums; }
.nudge-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nudge-route { color: var(--ink-500); font-size: 12px; }
.nudge-agent { color: var(--ink-500); font-size: 12px; }
.nudge-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* Horizontal bar chart. Bars are capped at 22px, square at the baseline with a
   4px rounded data-end, values direct-labelled at the tip so no value depends on
   reading a colour. Single series, so no legend — the row label names each mark. */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 10px; }
.bar-label { font-size: 12px; color: var(--ink-600); text-align: right; }
.bar-track { background: var(--surface-sunken); border-radius: 3px; height: 22px; position: relative; overflow: hidden; }
.bar-fill {
  height: 100%; border-radius: 0 4px 4px 0; min-width: 3px;
  transition: width 0.35s ease;
}
.bar-fill.zero { background: var(--line) !important; min-width: 3px; }
.bar-value { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }

.workload-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.workload-row:last-child { border-bottom: none; }
.workload-who { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ================================================================= admin === */

.admin-tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 20px; flex-shrink: 0; }
.admin-tabs .tab { flex: 0 0 auto; padding: 12px 18px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-500); font-weight: 600;
}
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table td input, .table td select { padding: 5px 7px; font-size: 12px; }
.table td input[type="color"] { width: 42px; padding: 2px; height: 28px; }
.table tr.inactive { opacity: 0.5; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 12px; margin-bottom: 13px; align-items: end; }
.form-grid input[type="color"], .field input[type="color"] { width: 54px; height: 34px; padding: 2px; cursor: pointer; }
.filter-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-row .field { margin: 0; min-width: 165px; }
.inline-error { background: var(--critical-wash); color: #a52121; padding: 8px 11px; border-radius: var(--radius-sm); font-size: 12px; margin-top: 11px; }

/* ================================================================= login === */

.auth-body { display: grid; place-items: center; background: var(--rail); overflow: auto; }
.auth-card {
  background: var(--surface); border-radius: 14px; padding: 32px;
  width: 100%; max-width: 400px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); margin: 24px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-brand h1 { font-size: 17px; }
.auth-brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-500); }
.auth-form .field { margin-bottom: 15px; }
.auth-form input { padding: 10px 11px; font-size: 14px; }
.auth-submit { width: 100%; margin-top: 6px; padding: 11px; font-size: 14px; }
.auth-error { background: var(--critical-wash); color: #a52121; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 16px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 10px 12px; font-size: 14px; font-weight: 500;
  background: var(--surface, #fff); color: inherit; border: 1px solid var(--line, #d5d9e0);
}
.google-btn:hover { background: var(--surface-sunken, #f5f6f8); }
.auth-divider {
  display: flex; align-items: center; gap: 10px; margin: 16px 0;
  color: var(--ink-500, #7a8194); font-size: 12px;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; border-top: 1px solid var(--line, #d5d9e0); }
.auth-notice { background: var(--accent-wash); color: #1c5cab; padding: 11px 12px; border-radius: var(--radius-sm); font-size: 12px; margin-bottom: 16px; line-height: 1.55; }

/* =============================================== misc / empty / tooltip === */

.empty {
  display: grid; place-items: center; height: 100%; min-height: 140px;
  color: var(--ink-500); font-size: 13px; text-align: center; padding: 24px;
}
.empty-inner { max-width: 260px; line-height: 1.6; }

.viz-tip {
  position: fixed; z-index: 200; pointer-events: none;
  background: var(--ink-900); color: white; padding: 7px 10px;
  border-radius: 6px; font-size: 12px; line-height: 1.4;
  box-shadow: var(--shadow-pop); opacity: 0; transition: opacity 0.1s;
}
.viz-tip.on { opacity: 1; }

.dev-tools { border-top: 1px solid var(--line); flex-shrink: 0; }
.dev-tools summary {
  padding: 9px 13px; font-size: 11px; font-weight: 600; color: var(--ink-500);
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px;
  user-select: none;
}
.dev-tools summary::-webkit-details-marker { display: none; }
.dev-tools summary::before { content: '▸'; font-size: 9px; transition: transform 0.12s; }
.dev-tools[open] summary::before { transform: rotate(90deg); }

.sim-box { padding: 12px 13px; background: var(--warning-wash); border-top: 1px solid #fde68a; max-height: 60vh; overflow-y: auto; }
.sim-box h4 { font-size: 11px; color: #92600a; margin-bottom: 8px; line-height: 1.45; font-weight: 600; }
.sim-box input { margin-bottom: 6px; font-size: 12px; padding: 6px 8px; border-color: #fde68a; }
.harness-group { margin-bottom: 12px; }
.harness-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #92600a; margin-bottom: 6px; }
.harness-buttons { display: flex; flex-wrap: wrap; gap: 5px; }
.harness-buttons .btn { border-color: #fde68a; }

/* Raw webhook payload viewer (Admin -> WhatsApp) */
.payload {
  margin: 0; padding: 12px; background: var(--rail); color: #d1d5db;
  border-radius: var(--radius-sm); font-size: 11.5px; line-height: 1.5;
  overflow-x: auto; max-height: 320px; white-space: pre-wrap; word-break: break-word;
}
code { background: var(--surface-sunken); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ==========================================================================
   Responsive layouts (spec 1.8 "usable at tablet width" + mobile)

   Three tiers. Tablet (≤1024px): the details column becomes a slide-over so
   the thread keeps its width. Phone (≤760px): one pane at a time — list,
   thread as a full-screen layer, details above that — with the nav rail as a
   bottom bar. State lives in two body classes (chat-open, right-open) that
   only mean anything at these widths; desktop ignores them entirely.
   ========================================================================== */

/* Buttons that only exist for the smaller layouts */
.mobile-back, .details-toggle { display: none; }
.icon-btn { padding: 7px 10px; line-height: 0; flex-shrink: 0; }
.icon-btn svg { width: 16px; height: 16px; }

/* --- Small desktop / tablet landscape ------------------------------------- */
@media (max-width: 1180px) {
  .inbox { grid-template-columns: 290px 1fr 300px; }
}

/* --- Tablet ---------------------------------------------------------------- */
@media (max-width: 1024px) {
  .inbox { grid-template-columns: 300px 1fr; }

  .details-toggle { display: inline-flex; }

  /* Details column slides in from the right instead of owning permanent width */
  #rightCol {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 80;
    width: min(380px, 94vw);
    border-left: 1px solid var(--line); box-shadow: var(--shadow-pop);
    transform: translateX(102%);
    transition: transform 0.22s ease;
  }
  body.right-open #rightCol { transform: none; }

  /* Scrim behind the slide-over; clicks on it land on <body> (see app.js) */
  body.right-open::after {
    content: ""; position: fixed; inset: 0; z-index: 70;
    background: rgba(17, 24, 39, 0.35);
  }
}

/* --- Phone ------------------------------------------------------------------ */
@media (max-width: 760px) {
  /* Rail becomes a bottom bar; dvh tracks the real viewport when the browser
     chrome and keyboard come and go */
  .shell {
    display: flex; flex-direction: column-reverse;
    height: 100vh; height: 100dvh;
  }
  .rail {
    flex-direction: row; width: 100%; height: 56px;
    padding: 0 10px calc(env(safe-area-inset-bottom) / 2);
    justify-content: space-around; align-items: center; gap: 0;
    border-top: 1px solid var(--rail-hover); flex-shrink: 0;
  }
  .rail-logo, .rail-spacer, .rail-tip { display: none; }
  .main { flex: 1; min-height: 0; }

  .topbar { padding: 0 14px; height: 50px; }

  /* One pane at a time: the list owns the page… */
  .inbox { display: flex; }
  .inbox > .col { flex: 1; border-right: none; }

  /* …and the thread slides over it, above the bottom bar */
  #chatCol {
    position: fixed; top: 0; left: 0; right: 0; bottom: 56px; z-index: 60;
    display: flex; transform: translateX(102%);
    transition: transform 0.22s ease;
    border-left: none;
  }
  body.chat-open #chatCol { transform: none; }

  /* Details covers the full phone width, above the thread */
  #rightCol { width: 100vw; bottom: 56px; }

  .mobile-back { display: inline-flex; }

  .chat-head { flex-wrap: wrap; padding: 9px 12px; gap: 8px; }
  .chat-controls { flex-wrap: wrap; }
  .bubble-wrap { max-width: 85%; }
  .thread { padding: 12px 12px 8px; }

  /* Comfortable touch targets */
  .conv-item { padding: 13px; }
  .view-pill { padding: 5px 11px; }
  .mode-btn { padding: 6px 13px; }

  /* Dashboard / admin pages */
  .page { padding: 14px; }
  .page-wrap { max-width: none; }
  .hero-figure { font-size: 38px; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 9px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 22px; }
  .admin-tabs { overflow-x: auto; padding: 0 10px; }
  .admin-tabs .tab { padding: 12px 13px; white-space: nowrap; }
  /* Wide tables scroll inside their card instead of stretching the page */
  .card { overflow-x: auto; }
  .table { min-width: 560px; }
  .nudge-row { grid-template-columns: 40px 1fr 80px; }
  .nudge-route, .nudge-agent { display: none; }
}
