/* ═══════════════════════════════════════════════════════════
   InterVentis Design System
   Deep navy, muted gold, serif ledger numerals.
   Signature motif: the bracket [ ] — active nav marker,
   page-title flanks, empty-state anchor.
   ═══════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #1B2B3A;
  --navy-deep: #0E1726;
  --navy-mid: #152238;
  --gold: #B8943E;
  --gold-light: #D4B15A;
  --gold-dim: rgba(184, 148, 62, 0.12);
  --gold-faint: rgba(184, 148, 62, 0.06);
  --white: #FFFFFF;
  --off-white: #F8F7F4;
  --warm-gray: #F0EEEA;
  --text: #2A2A2A;
  --text-mid: #555;
  --text-light: #7A7A7A;
  --border: #DDD9D0;
  --border-soft: #E9E6DF;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #B45309;
  --warning-bg: #fffbeb;
  --danger: #DC2626;
  --danger-bg: #fef2f2;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(27,43,58,0.06), 0 1px 2px rgba(27,43,58,0.04);
  --shadow-md: 0 4px 6px rgba(27,43,58,0.05), 0 2px 4px rgba(27,43,58,0.04);
  --shadow-lg: 0 10px 25px rgba(27,43,58,0.06), 0 4px 10px rgba(27,43,58,0.04);
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--sans); font-size: 15px; line-height: 1.6;
  color: var(--text); background: var(--off-white);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 500; color: var(--navy); }
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}

/* ── Utilities ─────────────────────────────────────── */
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: 0.75rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.text-light { color: var(--text-light); }
.text-sm { font-size: 0.85rem; }

.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1.5rem; align-items: start;
}

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.75rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.25rem; padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-soft);
}
.card-header h3 { margin: 0; font-size: 1.25rem; }
.card-title { font-size: 1.1rem; color: var(--navy); margin-bottom: 1rem; }

/* Flush cards: list/table cards with padding:0 get aligned inner headers */
.card > .table-wrap { margin: 0; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.6rem 1.25rem; border-radius: 6px; font-size: 0.85rem;
  font-weight: 500; border: 1px solid var(--border); background: var(--white);
  color: var(--text); cursor: pointer; transition: all 0.2s; text-decoration: none;
  font-family: var(--sans); line-height: 1.4;
}
.btn:hover { background: var(--off-white); border-color: var(--text-light); color: var(--text); }
.btn-primary {
  background: var(--gold); color: var(--white); border-color: var(--gold);
}
.btn-primary:hover { background: var(--gold-light); border-color: var(--gold-light); color: var(--white); }
.btn-ghost {
  background: transparent; color: var(--gold); border-color: var(--gold);
}
.btn-ghost:hover { background: var(--gold-dim); color: var(--gold); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; color: #fff; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.78rem; }
.btn-lg { padding: 0.85rem 2rem; font-size: 0.95rem; }
.btn-block { width: 100%; }

/* ── Forms ──────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem;
}
.form-label {
  display: block; font-size: 0.82rem; font-weight: 500;
  color: var(--text); margin-bottom: 0.4rem; letter-spacing: 0.02em;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 0.65rem 0.85rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.9rem; font-family: var(--sans);
  background: var(--white); color: var(--text); transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 148, 62, 0.1);
}
/* Selects: strip the native chrome, add a brand chevron */
.form-select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23B8943E' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2.4rem;
  cursor: pointer;
}
.form-select:disabled { cursor: not-allowed; opacity: 0.6; }
.form-textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.form-hint { font-size: 0.78rem; color: var(--text-light); margin-top: 0.3rem; }
.check-row {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.75rem 0.9rem; margin-bottom: 0.5rem; cursor: pointer;
  border: 1px solid var(--border-soft); border-radius: 6px;
  transition: border-color 0.2s, background 0.2s;
  font-size: 0.88rem;
}
.check-row:hover { border-color: var(--gold); background: var(--gold-faint); }
.check-row input[type="checkbox"] { margin-top: 0.2rem; accent-color: var(--gold); }
.check-row strong { display: block; color: var(--navy); font-weight: 600; }
.check-hint { display: block; font-size: 0.78rem; color: var(--text-light); margin-top: 0.15rem; }

/* ── Badges ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 0.2rem 0.6rem;
  border-radius: 20px; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; line-height: 1.5;
  vertical-align: middle;
}
/* semantic set (emitted by badge helpers) */
.badge-primary, .badge-new, .badge-client { background: var(--gold-dim); color: var(--gold); }
.badge-success, .badge-responded, .badge-active { background: var(--success-bg); color: var(--success); }
.badge-warning, .badge-urgent { background: var(--warning-bg); color: var(--warning); }
.badge-danger, .badge-crisis, .badge-inactive { background: var(--danger-bg); color: var(--danger); }
.badge-muted, .badge-read, .badge-archived, .badge-general { background: var(--warm-gray); color: var(--text-light); }
.badge-admin { background: var(--navy); color: var(--white); }
.badge-in { background: #dbeafe; color: #1d4ed8; }
.badge-out { background: #fef3c7; color: #92400e; }

/* ── Tables ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse; font-size: 0.88rem;
}
.table th {
  text-align: left; padding: 0.7rem 1.5rem; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-light);
  border-bottom: 1px solid var(--border); font-weight: 600;
  background: var(--off-white);
}
.table td {
  padding: 0.9rem 1.5rem; border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover td { background: var(--gold-faint); }
.table a { color: var(--navy); font-weight: 500; }
.table a:hover { color: var(--gold); }

/* ── Stat Cards — serif ledger numerals ────────────── */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.25rem; margin-bottom: 2rem; }
.stat-card {
  display: block;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem 1.5rem 1.35rem; box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}
a.stat-card:hover {
  box-shadow: var(--shadow-md); transform: translateY(-1px);
  border-color: var(--gold); color: inherit;
}
.stat-card-value {
  font-family: var(--serif); font-size: 2.6rem; color: var(--navy);
  font-weight: 500; line-height: 1.05; margin-bottom: 0.35rem;
  font-variant-numeric: lining-nums;
}
.stat-card-label {
  font-size: 0.7rem; color: var(--text-light); letter-spacing: 0.09em;
  text-transform: uppercase; font-weight: 600;
}
.stat-card-accent { border-top: 2px solid var(--gold); }
.stat-card .stat-attn {
  color: var(--gold); font-size: 1.4rem; vertical-align: 0.5rem;
  font-family: var(--serif);
}

/* ── Alerts ────────────────────────────────────────── */
.alert {
  padding: 0.85rem 1.25rem; border-radius: 6px; font-size: 0.88rem;
  margin-bottom: 1.25rem; border: 1px solid;
}
.alert-success { background: var(--success-bg); color: #065f46; border-color: #a7f3d0; }
.alert-error { background: var(--danger-bg); color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }

/* ── Portal Layout ─────────────────────────────────── */
.portal { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--navy-mid) 0%, var(--navy-deep) 30%);
  color: var(--white);
  display: flex; flex-direction: column; flex-shrink: 0;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
}
.sidebar-brand {
  padding: 1.6rem 1.5rem 1.4rem;
  border-bottom: 1px solid rgba(184,148,62,0.18);
}
.sidebar-brand img { height: 22px; display: block; }
.sidebar-brand .bracket-tag,
.sidebar-brand-sub {
  font-family: var(--serif); font-size: 0.7rem; color: var(--gold-light);
  opacity: 0.65; margin-top: 0.6rem; letter-spacing: 0.22em; text-transform: uppercase;
}

.sidebar-nav { flex: 1; padding: 1.25rem 0; overflow-y: auto; }
.sidebar-nav .nav-group { margin-bottom: 1.75rem; }
.sidebar-nav .nav-group-label {
  padding: 0 1.5rem; font-size: 0.62rem; text-transform: uppercase;
  letter-spacing: 0.16em; color: rgba(255,255,255,0.32); margin-bottom: 0.55rem;
  font-weight: 600;
}
.nav-divider {
  height: 1px; background: rgba(255,255,255,0.07);
  margin: 1rem 1.5rem;
}
.sidebar-nav .nav-link,
.sidebar-nav > a {
  position: relative;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.5rem; color: rgba(255,255,255,0.62);
  font-size: 0.85rem; transition: color 0.2s, background 0.2s; text-decoration: none;
}
.sidebar-nav .nav-link:hover,
.sidebar-nav > a:hover {
  color: var(--white); background: rgba(255,255,255,0.04);
}
/* Active item: gold bracket marker — the house motif, not a border */
.sidebar-nav .nav-link.active,
.sidebar-nav > a.active {
  color: var(--gold-light); background: rgba(184,148,62,0.08);
}
.sidebar-nav .nav-link.active::before,
.sidebar-nav > a.active::before {
  content: '['; position: absolute; left: 0.7rem;
  font-family: var(--serif); font-size: 1rem; color: var(--gold);
  line-height: 1;
}
.sidebar-nav .nav-link .badge,
.sidebar-nav > a .badge {
  margin-left: auto; font-size: 0.62rem; padding: 0.12rem 0.5rem;
  background: var(--gold); color: var(--navy-deep); font-weight: 700;
}

.sidebar-footer {
  padding: 1.1rem 1.5rem; border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.75rem;
  display: flex; align-items: center; gap: 0.75rem;
}
.sidebar-footer .avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--gold-dim); border: 1px solid rgba(184,148,62,0.4);
  color: var(--gold-light); font-family: var(--serif); font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.02em;
}
.sidebar-footer .user-name { color: rgba(255,255,255,0.85); font-weight: 500; font-size: 0.82rem; }
.sidebar-footer .user-info { color: rgba(255,255,255,0.4); font-size: 0.7rem; }

.portal-content {
  flex: 1; margin-left: 260px;
  min-height: 100vh; background: var(--off-white);
  display: flex; flex-direction: column;
}

/* Letterhead page header */
.portal-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 1rem; flex-wrap: wrap;
  padding: 1.35rem 2.5rem 1.2rem;
  background: rgba(248,247,244,0.92);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.portal-header h1 {
  font-size: 1.7rem; font-weight: 500; color: var(--navy); line-height: 1.2;
}
.portal-header h1::before { content: '[ '; color: var(--gold); opacity: 0.4; }
.portal-header h1::after { content: ' ]'; color: var(--gold); opacity: 0.4; }
.portal-header-meta {
  display: flex; align-items: baseline; gap: 1.25rem;
}
.portal-header-date {
  font-size: 0.72rem; color: var(--text-light);
  text-transform: uppercase; letter-spacing: 0.12em; font-weight: 500;
}
.portal-header-user {
  font-family: var(--serif); font-size: 0.95rem; color: var(--navy);
}
.portal-header-user .bracket { color: var(--gold); opacity: 0.55; }

.portal-body {
  width: 100%;
  padding: 2rem 2.5rem 3rem;
}

/* Client layout places content directly in .portal-content */
.portal-content > .alert { margin: 1.5rem 2rem 0; }

.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem;
}
.page-header h1 {
  font-size: 1.6rem; font-weight: 500; color: var(--navy);
}
.page-header p { font-size: 0.88rem; color: var(--text-light); margin-top: 0.25rem; }

/* ── Auth Layout ───────────────────────────────────── */
.auth-layout { display: flex; min-height: 100vh; }
.auth-panel {
  width: 45%; background: var(--navy); display: flex;
  align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.auth-panel::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(184,148,62,0.06), transparent 60%);
}
.auth-panel-inner { position: relative; text-align: center; padding: 3rem; }
.auth-panel-inner img { width: 220px; margin-bottom: 2rem; }
.auth-panel-tagline {
  font-family: var(--serif); font-size: 2rem; color: var(--white);
  font-weight: 300; margin-bottom: 2.5rem;
}
.auth-panel-tagline em { font-style: normal; color: var(--gold); }
.auth-panel-quote {
  font-family: var(--serif); font-style: italic; font-size: 1rem;
  color: rgba(255,255,255,0.4); max-width: 320px; margin: 0 auto; line-height: 1.6;
}
.auth-form-panel {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 3rem; background: var(--white);
}
.auth-form-wrapper { width: 100%; max-width: 420px; }
.auth-form-wrapper h2 {
  font-size: 1.8rem; color: var(--navy); margin-bottom: 0.5rem;
}
.auth-form-wrapper .subtitle {
  color: var(--text-light); font-size: 0.9rem; margin-bottom: 2rem;
}
.auth-back { margin-top: 2rem; text-align: center; font-size: 0.85rem; }
.auth-back a { color: var(--text-light); }
.auth-back a:hover { color: var(--gold); }

/* ── List / Message Items ──────────────────────────── */
.message-item {
  display: block;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border-soft);
  border-left: 3px solid transparent;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.message-item:last-child { border-bottom: none; }
.message-item:hover { background: var(--gold-faint); color: inherit; }
.message-item.unread { border-left-color: var(--gold); background: var(--gold-faint); }

.message-item-header,
.message-meta {
  display: flex; align-items: center; gap: 0.6rem;
  margin-bottom: 0.35rem; flex-wrap: wrap;
}
.message-item-subject,
.message-subject {
  font-weight: 600; color: var(--navy); font-size: 0.92rem;
}
.message-item-preview,
.message-preview {
  font-size: 0.85rem; color: var(--text-light); line-height: 1.55;
}
.message-item-date,
.message-date {
  font-size: 0.75rem; color: var(--text-light); margin-left: auto;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}

.thread-bubble,
.message-bubble {
  padding: 1.25rem 1.5rem; border-radius: var(--radius); margin-bottom: 1rem;
  max-width: 80%; line-height: 1.7; font-size: 0.9rem;
}
.thread-bubble.outgoing,
.message-bubble.outgoing {
  background: var(--gold-dim); margin-left: auto;
  border-bottom-right-radius: 2px;
}
.thread-bubble.incoming,
.message-bubble.incoming {
  background: var(--white); border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}
.thread-bubble-meta,
.message-bubble-meta {
  font-size: 0.72rem; color: var(--text-light); margin-top: 0.5rem;
}

/* ── Empty State — anchored by the house brackets ──── */
.empty-state {
  text-align: center; padding: 3.5rem 2rem; color: var(--text-light);
}
.empty-state::before {
  content: '[ ]'; display: block;
  font-family: var(--serif); font-size: 2.4rem; color: var(--gold);
  opacity: 0.35; margin-bottom: 0.75rem; letter-spacing: 0.1em;
}
.empty-state-icon { display: none; }
.empty-state p { font-size: 0.9rem; max-width: 400px; margin: 0 auto; }

/* ── Search ────────────────────────────────────────── */
.search-bar {
  display: flex; gap: 0.75rem; margin-bottom: 1.5rem;
}
.search-bar .form-input { flex: 1; max-width: 380px; }

/* ── Filter Tabs ───────────────────────────────────── */
.filter-tabs {
  display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.filter-tab {
  padding: 0.4rem 1rem; border-radius: 20px; font-size: 0.8rem;
  border: 1px solid var(--border); background: var(--white);
  color: var(--text-mid); text-decoration: none; transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.filter-tab:hover { border-color: var(--gold); color: var(--gold); }
.filter-tab.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.filter-tab.active .filter-count { color: var(--gold-light); }
.filter-count { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Cases ─────────────────────────────────────────── */
.case-ref {
  font-family: var(--serif); font-weight: 600; letter-spacing: 0.05em;
  color: var(--navy); white-space: nowrap; font-variant-numeric: tabular-nums;
}
a.case-ref:hover { color: var(--gold); }
.case-ref-line { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.4rem; }
.case-ref-line .case-ref { font-size: 1.05rem; color: var(--gold); }
.case-head {
  display: flex; justify-content: space-between; gap: 2rem; align-items: flex-start;
  border-top: 2px solid var(--gold); flex-wrap: wrap;
}
.case-title { font-size: 1.5rem; margin-bottom: 0.4rem; }
.case-head-meta {
  text-align: right; font-size: 0.85rem; flex-shrink: 0;
  display: grid; gap: 0.35rem; align-content: start;
}
.meta-label {
  display: inline-block; font-size: 0.62rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-light); margin-right: 0.5rem; font-weight: 600;
}
.case-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1.5rem; align-items: start; }

/* ── Case Log Timeline ─────────────────────────────── */
.timeline-entry { position: relative; display: flex; gap: 1.1rem; padding-bottom: 1.5rem; }
.timeline-entry::before {
  content: ''; position: absolute; left: 5px; top: 18px; bottom: 0;
  width: 1px; background: var(--border-soft);
}
.timeline-entry:last-child { padding-bottom: 0; }
.timeline-entry:last-child::before { display: none; }
.timeline-marker {
  flex-shrink: 0; width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--gold); background: var(--white);
  margin-top: 5px; position: relative; z-index: 1;
}
.kind-milestone .timeline-marker { background: var(--gold); }
.kind-status .timeline-marker { border-color: var(--border); }
.timeline-body { flex: 1; min-width: 0; }
.timeline-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.3rem; }
.timeline-date { font-size: 0.75rem; color: var(--text-light); font-variant-numeric: tabular-nums; }
.timeline-text { font-size: 0.9rem; line-height: 1.7; }
.kind-status .timeline-text { color: var(--text-light); font-size: 0.85rem; }

/* ── Documents ─────────────────────────────────────── */
.doc-list { display: grid; gap: 0.5rem; }
.doc-item {
  display: flex; align-items: center; gap: 0.9rem; padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-soft); border-radius: 6px; background: var(--off-white);
}
.doc-icon { font-family: var(--serif); color: var(--gold); font-size: 1rem; opacity: 0.7; flex-shrink: 0; }
.doc-info { flex: 1; min-width: 0; }
.doc-name {
  font-size: 0.88rem; font-weight: 500; color: var(--navy); display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-name:hover { color: var(--gold); }
.doc-meta { font-size: 0.72rem; color: var(--text-light); }

/* ── Messages Inbox ────────────────────────────────── */
.msg-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.5rem; align-items: start; }
.message-item.selected { background: var(--gold-faint); border-left-color: var(--navy); }
.msg-thread-scroll {
  max-height: 55vh; overflow-y: auto;
  padding: 0.25rem 0 1rem; margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-soft);
}

.event-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem;
  background: var(--warm-gray); padding: 0.1rem 0.4rem; border-radius: 4px; color: var(--navy);
}

/* ── Developer Console ─────────────────────────────── */
.dev-actions { display: grid; gap: 0.85rem; }
.dev-actions form { display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; }
.dev-actions form .btn { min-width: 180px; justify-content: flex-start; }
.dev-actions form span { flex: 1; min-width: 200px; }

/* ── Analytics ─────────────────────────────────────── */
.chart-bars {
  display: flex; align-items: flex-end; gap: 2px;
  height: 180px; padding-top: 0.5rem;
}
.chart-col {
  flex: 1; height: 100%; display: flex; align-items: flex-end;
  position: relative; cursor: default;
}
.chart-bar {
  width: 100%; background: var(--gold); opacity: 0.85;
  border-radius: 4px 4px 0 0; min-height: 2px;
  transition: opacity 0.15s;
}
.chart-col:hover .chart-bar { opacity: 1; background: var(--navy); }
.chart-col::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); background: var(--navy-deep); color: var(--white);
  font-size: 0.72rem; padding: 0.3rem 0.6rem; border-radius: 4px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 5;
}
.chart-col:hover::after { opacity: 1; }
.chart-x {
  display: flex; justify-content: space-between; margin-top: 0.5rem;
  font-size: 0.72rem; color: var(--text-light); font-variant-numeric: tabular-nums;
}
.inline-bar {
  height: 8px; background: var(--warm-gray); border-radius: 4px; overflow: hidden;
  min-width: 60px; flex: 1;
}
.inline-bar span { display: block; height: 100%; background: var(--gold); border-radius: 4px; }
.split-row { display: flex; align-items: center; gap: 0.85rem; padding: 0.4rem 0; }
.split-row > .text-sm:first-child { width: 4.5rem; flex-shrink: 0; }
.split-divider { height: 1px; background: var(--border-soft); margin: 1rem 0; }

.seo-list { }
.seo-item {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.8rem 1.5rem; border-bottom: 1px solid var(--border-soft);
  font-size: 0.88rem;
}
.seo-item:last-child { border-bottom: none; }
.seo-mark {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem;
}
.seo-mark.pass { background: var(--success-bg); color: var(--success); }
.seo-mark.fail { background: var(--danger-bg); color: var(--danger); }
.seo-label { font-weight: 500; color: var(--navy); }
.seo-detail { font-size: 0.76rem; color: var(--text-light); }

/* ── Analytics (extended) ──────────────────────────── */
.analytics-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.analytics-controls { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.range-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 20px; overflow: hidden; background: var(--white); }
.range-tabs a {
  padding: 0.35rem 0.9rem; font-size: 0.8rem; color: var(--text-mid);
  font-variant-numeric: tabular-nums; border-right: 1px solid var(--border-soft);
}
.range-tabs a:last-child { border-right: none; }
.range-tabs a:hover { background: var(--gold-faint); color: var(--gold); }
.range-tabs a.active { background: var(--navy); color: var(--white); }
.csv-links { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.csv-links .csv-label { color: var(--text-light); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.68rem; font-weight: 600; }
.csv-links a {
  padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 6px;
  color: var(--navy); background: var(--white);
}
.csv-links a:hover { border-color: var(--gold); color: var(--gold); background: var(--gold-faint); }

.delta { display: inline-block; margin-top: 0.5rem; font-size: 0.72rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--text-light); }

.metric-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1.25rem; }
.metric-mini {
  background: var(--white); border: 1px solid var(--border); border-left: 3px solid var(--gold);
  border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow);
}
.metric-mini-value { font-family: var(--serif); font-size: 1.9rem; color: var(--navy); line-height: 1.1; }
.metric-mini-value .metric-mini-split { color: var(--text-light); font-size: 1.3rem; }
.metric-mini-label { font-size: 0.68rem; color: var(--text-light); letter-spacing: 0.09em; text-transform: uppercase; font-weight: 600; margin-top: 0.35rem; }
.metric-mini-note { font-size: 0.73rem; color: var(--text-light); margin-top: 0.35rem; }

.svg-chart { width: 100%; }
.svg-chart svg { width: 100%; height: 220px; display: block; }
.chart-legend { font-size: 0.75rem; color: var(--text-light); display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend .lg { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.chart-legend .lg-views { background: var(--gold); }
.chart-legend .lg-uniq { background: var(--navy); }
.chart-x span { flex: 1; }
.chart-x span:nth-child(2) { text-align: center; }
.chart-x span:last-child { text-align: right; }

.chart-bars.mini { height: 110px; }
.chart-bar.navy { background: var(--navy); opacity: 0.75; }
.chart-col:hover .chart-bar.navy { background: var(--gold); opacity: 1; }
.chart-bars.dow { gap: 6px; }

.section-label {
  font-size: 0.7rem; color: var(--text-light); letter-spacing: 0.08em;
  text-transform: uppercase; font-weight: 600; margin-bottom: 0.5rem;
}

.funnel { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.funnel-step { flex: 1; min-width: 90px; text-align: center; padding: 0.5rem 0; }
.funnel-num { font-family: var(--serif); font-size: 2rem; color: var(--navy); line-height: 1; }
.funnel-num.accent { color: var(--gold); }
.funnel-lbl { font-size: 0.72rem; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 0.3rem; }
.funnel-arrow { color: var(--gold); font-size: 1.2rem; opacity: 0.6; }

.feed { max-height: 640px; overflow-y: auto; }
.feed-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 1.5rem; border-bottom: 1px solid var(--border-soft); font-size: 0.82rem;
}
.feed-item:last-child { border-bottom: none; }
.feed-time { width: 4.5rem; flex-shrink: 0; color: var(--text-light); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.feed-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-src { color: var(--text-light); font-size: 0.75rem; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-dev { flex-shrink: 0; }

.seo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.seo-grid .seo-item { border-right: 1px solid var(--border-soft); }

/* ── Responsive Portal ─────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 220px; }
  .portal-content { margin-left: 220px; }
  .portal-header { padding: 1.1rem 1.5rem 1rem; }
  .portal-body { padding: 1.5rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .case-layout { grid-template-columns: 1fr; }
  .msg-layout { grid-template-columns: 1fr; }
  .case-head-meta { text-align: left; }
}
@media (max-width: 680px) {
  .sidebar {
    width: 100%; height: auto; position: relative;
    flex-direction: column; overflow: visible;
  }
  .sidebar-brand {
    padding: 0.8rem 1rem; border-bottom: 1px solid rgba(184,148,62,0.18);
    display: flex; align-items: center; gap: 0.75rem;
  }
  .sidebar-brand img { height: 18px; }
  .sidebar-brand .bracket-tag, .sidebar-brand-sub {
    display: block; margin-top: 0; opacity: 0.55; font-size: 0.62rem;
  }
  /* nav wraps to as many rows as needed — every item visible, no sideways scroll */
  .sidebar-nav { display: flex; flex-flow: row wrap; gap: 0.35rem; padding: 0.7rem 0.85rem; }
  .sidebar-nav .nav-group { display: contents; }
  .sidebar-nav .nav-group-label { display: none; }
  .nav-divider { display: none; }
  .sidebar-nav .nav-link,
  .sidebar-nav > a {
    padding: 0.5rem 0.85rem; white-space: nowrap; font-size: 0.78rem;
    border-radius: 20px; border: 1px solid rgba(255,255,255,0.12);
  }
  .sidebar-nav .nav-link.active,
  .sidebar-nav > a.active {
    background: rgba(184,148,62,0.14); border-color: var(--gold); color: var(--gold-light);
  }
  .sidebar-nav .nav-link.active::before,
  .sidebar-nav > a.active::before { display: none; }
  .sidebar-nav .nav-link .badge,
  .sidebar-nav > a .badge { margin-left: 0.4rem; }
  .sidebar-footer { display: none; }
  .portal { flex-direction: column; }
  .portal-content { margin-left: 0; }
  .portal-header { position: static; padding: 1rem; }
  .portal-header h1 { font-size: 1.35rem; }
  .portal-header-date { display: none; }
  .portal-body { padding: 1rem; }
  .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-toolbar { align-items: flex-start; }
  .seo-grid { grid-template-columns: 1fr; }
  .seo-grid .seo-item { border-right: none; }
  .svg-chart svg { height: 170px; }
  .case-head-meta { text-align: left; }
  .chart-col::after { display: none; }
  .dev-actions form .btn { min-width: 0; width: 100%; }
  .auth-layout { flex-direction: column; }
  .auth-panel { width: 100%; min-height: 200px; }
  .auth-panel-inner img { width: 150px; margin-bottom: 1rem; }
  .auth-panel-tagline { font-size: 1.5rem; margin-bottom: 1rem; }
  .auth-panel-quote { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
