/* ============================================
   DilSense v2 — Design System
   ============================================ */

:root {
  /* Dark theme (default) */
  --bg:        #0a0f1d;
  --bg-grad:   radial-gradient(1400px 700px at 0% 0%, #11203c 0%, #0a0f1d 55%, #07091a 100%);
  --panel:     #111a2e;
  --panel-2:   #162138;
  --panel-3:   #1a273e;
  --border:    #20304f;
  --border-strong: #2c3f63;
  --ink:       #e9eef8;
  --ink-dim:   #94a3bf;
  --ink-muted: #6a7795;
  --accent:    #d4af5c;
  --accent-2:  #e8c887;
  --accent-dim:#8a6e2c;
  --accent-soft: rgba(212,175,92,.10);
  --green:  #4ade80;
  --amber:  #fbbf24;
  --red:    #f87171;
  --blue:   #60a5fa;
  --violet: #a78bfa;
  --pink:   #f472b6;
  --cyan:   #22d3ee;

  --radius:   10px;
  --radius-lg:14px;
  --radius-sm:6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.25), 0 1px 0 rgba(255,255,255,.02) inset;
  --shadow:    0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.55), 0 1px 0 rgba(255,255,255,.04) inset;

  --sidebar-w: 224px;
  --sidebar-w-collapsed: 60px;

  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: "ss01", "cv11";
}

[data-theme="light"] {
  --bg:        #f5f7fb;
  --bg-grad:   radial-gradient(1200px 600px at 0% 0%, #eef2fa 0%, #f5f7fb 60%);
  --panel:     #ffffff;
  --panel-2:   #f4f6fc;
  --panel-3:   #eef1f8;
  --border:    #e0e5ef;
  --border-strong: #c7cfdf;
  --ink:       #14213d;
  --ink-dim:   #4a5874;
  --ink-muted: #7a87a3;
  --accent:    #b8902f;
  --accent-2:  #d4af5c;
  --accent-dim:#7d6020;
  --accent-soft: rgba(184,144,47,.12);
  --shadow-sm: 0 1px 2px rgba(20,33,61,.08);
  --shadow:    0 1px 3px rgba(20,33,61,.06), 0 8px 24px rgba(20,33,61,.06);
  --shadow-lg: 0 24px 60px rgba(20,33,61,.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

h1, h2, h3, h4 { margin: 0 0 .35em 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--ink); }
p  { margin: 0 0 .65em 0; }
.muted { color: var(--ink-muted); }
.dim   { color: var(--ink-dim); }
.mono  { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  font: inherit;
  font-size: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink-dim);
  line-height: 1.4;
  margin: 0 1px;
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s, box-shadow .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover { background: var(--panel-2); border-color: var(--border-strong); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:hover { background: transparent; border-color: var(--border); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
  color: #1a1305;
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 1px 2px rgba(0,0,0,.2);
}
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); background: linear-gradient(180deg, #f0d496 0%, var(--accent-2) 100%); }

.btn-ghost { border-color: transparent; }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--border); }

.btn-danger { border-color: rgba(248,113,113,.35); color: #fca5a5; }
.btn-danger:hover { background: rgba(248,113,113,.08); border-color: rgba(248,113,113,.5); }

.btn-success { border-color: rgba(74,222,128,.35); color: #86efac; }
.btn-success:hover { background: rgba(74,222,128,.08); }

.btn-small { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn-tiny  { padding: 2px 7px; font-size: 11px; border-radius: 5px; }

.icon-btn {
  width: 30px; height: 30px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 7px;
}

input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
[data-theme="light"] select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3e%3cpath fill='%237a87a3' d='M5 6L0 0h10z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
}
label { display: block; font-size: 11px; color: var(--ink-dim); margin: 0 0 5px 0; text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.field { margin-bottom: 14px; }
.row { display: grid; gap: 12px; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1fr 1fr 1fr; }
.row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  background: linear-gradient(180deg, #06091a 0%, #08102060 100%), #07091a;
  border-right: 1px solid var(--border);
  padding: 14px 10px 12px 10px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  z-index: 5;
  transition: padding .2s;
}
[data-theme="light"] .sidebar { background: linear-gradient(180deg, #ffffff 0%, #fafbfe 100%); }

.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 2px 4px 14px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  position: relative;
}
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--accent) 50%, var(--accent-dim) 100%);
  color: #1a1305;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .5px;
  box-shadow: 0 4px 12px rgba(212,175,92,.25), 0 1px 0 rgba(255,255,255,.4) inset;
  flex-shrink: 0;
}
.brand-text { overflow: hidden; }
.brand-name { font-weight: 700; letter-spacing: .3px; font-size: 14px; white-space: nowrap; }
.brand-sub  { font-size: 9.5px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .14em; white-space: nowrap; }

.version-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: 2px;
  font-weight: 700;
  letter-spacing: .04em;
}

.sidebar-collapse {
  position: absolute;
  right: -12px;
  top: 18px;
  width: 22px; height: 22px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink-dim);
  display: grid; place-items: center;
  z-index: 10;
}
.sidebar-collapse:hover { color: var(--ink); border-color: var(--accent-dim); background: var(--panel-2); }
body.sidebar-collapsed .sidebar-collapse svg { transform: rotate(180deg); }

#nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; overflow-x: hidden; }
#nav::-webkit-scrollbar { width: 0; }

.nav-group-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-muted);
  padding: 12px 9px 4px 9px;
  font-weight: 600;
}
body.sidebar-collapsed .nav-group-label { opacity: 0; height: 8px; padding: 4px 0 0 0; overflow: hidden; }

.nav-item {
  text-align: left;
  border: none;
  padding: 8px 9px;
  border-radius: 7px;
  color: var(--ink-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  position: relative;
  width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,.03); color: var(--ink); }
[data-theme="light"] .nav-item:hover { background: var(--panel-2); }
.nav-item.active {
  background: var(--panel-2);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent);
}

.nav-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  opacity: .85;
}
.nav-item.active .nav-icon { opacity: 1; }
[data-icon="dashboard"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'><rect x='3' y='3' width='7' height='9'/><rect x='14' y='3' width='7' height='5'/><rect x='14' y='12' width='7' height='9'/><rect x='3' y='16' width='7' height='5'/></svg>"); }
[data-icon="deals"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'><path d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/><polyline points='14 2 14 8 20 8'/><line x1='9' y1='13' x2='15' y2='13'/><line x1='9' y1='17' x2='13' y2='17'/></svg>"); }
[data-icon="board"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><rect x='3' y='3' width='5' height='18'/><rect x='10' y='3' width='5' height='12'/><rect x='17' y='3' width='4' height='8'/></svg>"); }
[data-icon="tasks"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' stroke-linecap='round' viewBox='0 0 24 24'><polyline points='9 11 12 14 22 4'/><path d='M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11'/></svg>"); }
[data-icon="calendar"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><rect x='3' y='4' width='18' height='18' rx='2'/><line x1='16' y1='2' x2='16' y2='6'/><line x1='8' y1='2' x2='8' y2='6'/><line x1='3' y1='10' x2='21' y2='10'/></svg>"); }
[data-icon="activity"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' stroke-linecap='round' viewBox='0 0 24 24'><polyline points='22 12 18 12 15 21 9 3 6 12 2 12'/></svg>"); }
[data-icon="investors"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><path d='M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2'/><circle cx='9' cy='7' r='4'/><path d='M23 21v-2a4 4 0 0 0-3-3.87'/><path d='M16 3.13a4 4 0 0 1 0 7.75'/></svg>"); }
[data-icon="contacts"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><path d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/><circle cx='12' cy='7' r='4'/></svg>"); }
[data-icon="analytics"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><line x1='18' y1='20' x2='18' y2='10'/><line x1='12' y1='20' x2='12' y2='4'/><line x1='6' y1='20' x2='6' y2='14'/></svg>"); }
[data-icon="workflows"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><circle cx='18' cy='5' r='3'/><circle cx='6' cy='12' r='3'/><circle cx='18' cy='19' r='3'/><line x1='8.59' y1='13.51' x2='15.42' y2='17.49'/><line x1='15.41' y1='6.51' x2='8.59' y2='10.49'/></svg>"); }
[data-icon="legal"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><rect x='3' y='3' width='18' height='18' rx='2'/><line x1='9' y1='8' x2='15' y2='8'/><line x1='9' y1='12' x2='15' y2='12'/><line x1='9' y1='16' x2='13' y2='16'/></svg>"); }
[data-icon="about"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><circle cx='12' cy='12' r='10'/><line x1='12' y1='16' x2='12' y2='12'/><circle cx='12' cy='8' r='.5' fill='%2394a3bf'/></svg>"); }

.nav-item.active .nav-icon { filter: drop-shadow(0 0 0 var(--accent)) brightness(1.4); }

.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.nav-badge {
  font-size: 10px;
  background: var(--panel-3);
  color: var(--ink-dim);
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.nav-badge:empty { display: none; }

body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-badge,
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .foot-meta { display: none; }
body.sidebar-collapsed .nav-item { justify-content: center; }
body.sidebar-collapsed .brand { justify-content: center; }

.sidebar-foot {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.foot-row { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
body.sidebar-collapsed .foot-row { flex-direction: column; }
.foot-meta {
  font-size: 10px;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
}

.theme-toggle, .cmd-hint {
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 6px;
}
.theme-toggle { width: 32px; padding: 5px 0; justify-content: center; }
.theme-icon-light, [data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-light { display: inline; }
[data-theme="light"] .theme-icon-dark { display: none; }

/* ============================================
   Main / topbar
   ============================================ */
.main { padding: 14px 22px 60px 22px; max-width: 100%; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.topbar-left { display: flex; gap: 14px; align-items: flex-end; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.mobile-menu { display: none; }

.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--ink-muted);
  font-size: 12px;
  width: 280px;
  justify-content: flex-start;
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--panel-2); color: var(--ink-dim); }
.search-trigger span { flex: 1; text-align: left; }
.search-trigger kbd { background: var(--panel-2); }

.view-root { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  position: relative;
}
.card-tight { padding: 10px 12px; }
.card-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 10px; }
.card-title h2 { margin: 0; }
.card-title .actions { display: flex; gap: 6px; align-items: center; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

@media (max-width: 1100px) {
  .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); }
}

/* KPIs */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi-val {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.025em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-lbl { font-size: 10px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .14em; font-weight: 600; }
.kpi-sub { font-size: 11px; color: var(--ink-dim); margin-top: 1px; }
.kpi-spark { height: 24px; margin-top: 6px; }
.kpi-trend { font-size: 11px; }
.kpi-trend.up   { color: #86efac; }
.kpi-trend.down { color: #fca5a5; }

/* ============================================
   Badges
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--ink-dim);
  font-weight: 500;
  line-height: 1.5;
}
.badge.green  { background: rgba(74,222,128,.10);  color: #86efac; border-color: rgba(74,222,128,.3); }
.badge.amber  { background: rgba(251,191,36,.10);  color: #fcd34d; border-color: rgba(251,191,36,.3); }
.badge.red    { background: rgba(248,113,113,.10); color: #fca5a5; border-color: rgba(248,113,113,.35); }
.badge.blue   { background: rgba(96,165,250,.10);  color: #93c5fd; border-color: rgba(96,165,250,.3); }
.badge.violet { background: rgba(167,139,250,.10); color: #c4b5fd; border-color: rgba(167,139,250,.3); }
.badge.cyan   { background: rgba(34,211,238,.10);  color: #67e8f9; border-color: rgba(34,211,238,.3); }
.badge.accent { background: var(--accent-soft);    color: var(--accent); border-color: rgba(212,175,92,.4); }

[data-theme="light"] .badge.green  { color: #166534; }
[data-theme="light"] .badge.amber  { color: #854d0e; }
[data-theme="light"] .badge.red    { color: #991b1b; }
[data-theme="light"] .badge.blue   { color: #1e40af; }
[data-theme="light"] .badge.violet { color: #5b21b6; }
[data-theme="light"] .badge.accent { color: var(--accent-dim); }

.badge.rag-green { background: rgba(74,222,128,.12);  color: #86efac; border-color: rgba(74,222,128,.4); }
.badge.rag-amber { background: rgba(251,191,36,.12);  color: #fcd34d; border-color: rgba(251,191,36,.4); }
.badge.rag-red   { background: rgba(248,113,113,.12); color: #fca5a5; border-color: rgba(248,113,113,.5); }

.badge.gate-approved    { background: rgba(74,222,128,.12);  color: #86efac; border-color: rgba(74,222,128,.4); }
.badge.gate-conditional { background: rgba(251,191,36,.12);  color: #fcd34d; border-color: rgba(251,191,36,.4); }
.badge.gate-rejected    { background: rgba(248,113,113,.12); color: #fca5a5; border-color: rgba(248,113,113,.5); }
.badge.gate-pending     { background: var(--panel-2); color: var(--ink-dim); border-color: var(--border); }

.badge.mandate-prospect { background: rgba(96,165,250,.10);  color: #93c5fd; border-color: rgba(96,165,250,.3); }
.badge.mandate-active   { background: rgba(212,175,92,.14);  color: var(--accent); border-color: rgba(212,175,92,.4); font-weight: 600; }
.badge.mandate-closed   { background: var(--panel-2); color: var(--ink-dim); border-color: var(--border); }

.tag {
  font-size: 11px;
  color: var(--ink-dim);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
}

.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-muted);
  margin-right: 5px;
  vertical-align: middle;
}
.dot.green  { background: var(--green); }
.dot.amber  { background: var(--amber); }
.dot.red    { background: var(--red); }
.dot.blue   { background: var(--blue); }
.dot.accent { background: var(--accent); }

/* ============================================
   Pipeline board
   ============================================ */
.pipeline {
  display: grid;
  grid-template-columns: repeat(8, minmax(170px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.pipe-col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 8px 6px 8px;
  min-width: 0;
  transition: background .15s, border-color .15s;
  min-height: 80px;
}
.pipe-col.drop-target { background: var(--accent-soft); border-color: var(--accent-dim); border-style: dashed; }
.pipe-col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 4px; padding: 0 2px; }
.pipe-col-head .label { font-size: 10px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipe-col-head .count { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; font-size: 10px; color: var(--ink-dim); flex-shrink: 0; font-weight: 500; }
.pipe-col-head .col-value { font-size: 10px; color: var(--accent); margin-top: 2px; }
.pipe-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 9px;
  margin-bottom: 6px;
  cursor: grab;
  transition: border-color .15s, background .15s, transform .1s;
  position: relative;
}
.pipe-card:hover { border-color: var(--border-strong); background: var(--panel-3); }
.pipe-card.dragging { opacity: .4; transform: rotate(1deg); }
.pipe-card .name { font-weight: 600; margin-bottom: 4px; font-size: 12px; line-height: 1.3; }
.pipe-card .meta { font-size: 10px; color: var(--ink-muted); display: flex; justify-content: space-between; gap: 4px; align-items: center; }
.pipe-card .rag { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.pipe-card .rag.green { background: var(--green); }
.pipe-card .rag.amber { background: var(--amber); }
.pipe-card .rag.red { background: var(--red); }

/* ============================================
   Tables
   ============================================ */
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 12px;
}
th {
  font-size: 10px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable .sort-arrow { font-size: 9px; margin-left: 4px; opacity: .4; }
th.sortable.sort-asc .sort-arrow,
th.sortable.sort-desc .sort-arrow { opacity: 1; color: var(--accent); }

tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
.row-link { cursor: pointer; }
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.table-scroll { overflow: auto; max-height: 70vh; }

.col-filter-row th { padding: 5px 7px; background: var(--panel-3); border-bottom: 1px solid var(--border); position: static; }
.col-filter-row input, .col-filter-row select { padding: 4px 7px; font-size: 11px; border-radius: 5px; }

.name-inferred { color: var(--ink-dim); font-weight: 500; font-style: italic; border-bottom: 1px dashed var(--border); cursor: help; }

/* ============================================
   Auth gate
   ============================================ */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(800px 500px at 50% 30%, #13203a 0%, var(--bg) 70%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 28px 24px 28px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-error {
  background: rgba(248,113,113,.10); color: #fca5a5;
  border: 1px solid rgba(248,113,113,.3);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 12px;
  margin: 6px 0 12px 0;
}
.auth-locked button[type="submit"] { opacity: .4; pointer-events: none; }
body.gated > *:not(#auth-gate) { display: none !important; }

/* ============================================
   Deal detail
   ============================================ */
.deal-header { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.deal-meta {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 8px;
}
.deal-meta strong { color: var(--ink); font-weight: 500; }
.deal-meta-item { display: flex; flex-direction: column; gap: 1px; }
.deal-meta-item .lbl { font-size: 10px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .08em; }

.stage-strip {
  display: flex;
  gap: 4px;
  margin: 14px 0 4px 0;
  overflow-x: auto;
  padding: 2px 0 6px 0;
}
.stage-strip::-webkit-scrollbar { height: 4px; }
.stage-pill {
  white-space: nowrap;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
  font-weight: 500;
}
.stage-pill:hover { color: var(--ink); border-color: var(--border-strong); background: var(--panel-2); }
.stage-pill.past    { color: var(--ink); border-color: var(--accent-dim); background: var(--accent-soft); }
.stage-pill.actual  { background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #1a1305; border-color: var(--accent); font-weight: 700; box-shadow: 0 0 0 3px rgba(212,175,92,.15); }
.stage-pill.viewing { background: var(--panel-2); color: var(--ink); border-color: var(--accent-dim); font-weight: 600; }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: start;
  gap: 10px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.checklist li:hover { background: var(--panel-2); }
.checklist li:last-child { border-bottom: none; }
.checklist input[type="checkbox"] { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--accent); cursor: pointer; }
.checklist .item-body { display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.checklist .item-label { color: var(--ink); font-size: 13px; }
.checklist .item-sub   { font-size: 11px; color: var(--ink-muted); }
.checklist .done .item-label { color: var(--ink-muted); text-decoration: line-through; }

.progress-track { height: 8px; background: var(--panel-3); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill  { height: 100%; background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%); transition: width .4s ease; }
.progress-fill.green { background: linear-gradient(90deg, #4ade80, #86efac); }
.progress-fill.amber { background: linear-gradient(90deg, #fbbf24, #fcd34d); }
.progress-fill.red   { background: linear-gradient(90deg, #f87171, #fca5a5); }

/* ============================================
   Modal
   ============================================ */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 8, 20, .72);
  backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 50;
  padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .2s ease;
}
.modal-wide { max-width: 920px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ============================================
   Investor list
   ============================================ */
.inv-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.inv-filters > * { min-width: 140px; }

.inv-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr auto;
  align-items: center;
  gap: 14px;
  transition: border-color .15s, background .15s;
}
.inv-card:hover { border-color: var(--border-strong); background: var(--panel-3); }
.inv-card .inv-name { font-weight: 600; font-size: 13px; }
.inv-card .inv-notes { font-size: 12px; color: var(--ink-dim); grid-column: 1 / -1; }
.inv-card .match-score {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 5px;
}

/* ============================================
   Tabs
   ============================================ */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  background: transparent;
  border: none;
  padding: 8px 12px;
  color: var(--ink-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: 12px;
  border-radius: 0;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--ink); background: transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab .tab-count { font-size: 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; margin-left: 4px; color: var(--ink-dim); }

/* ============================================
   Utilities
   ============================================ */
.stack > * + * { margin-top: 14px; }
.hstack { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hstack-tight { display: flex; gap: 6px; align-items: center; }
.right { display: flex; justify-content: flex-end; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.sep { height: 1px; background: var(--border); margin: 12px 0; }

.empty {
  padding: 50px 30px;
  text-align: center;
  color: var(--ink-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.empty-icon { font-size: 32px; margin-bottom: 8px; opacity: .5; }
.empty-title { color: var(--ink); font-weight: 600; margin-bottom: 6px; }

/* ============================================
   Gate cards / banners
   ============================================ */
.gate-banner {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.gate-banner.gate-approved    { border-color: rgba(74,222,128,.4);  background: rgba(74,222,128,.05); }
.gate-banner.gate-conditional { border-color: rgba(251,191,36,.4);  background: rgba(251,191,36,.05); }
.gate-banner.gate-rejected    { border-color: rgba(248,113,113,.5); background: rgba(248,113,113,.05); }

.gate-card { padding: 14px 16px; }
.gate-card.gate-approved    { border-left: 3px solid var(--green); }
.gate-card.gate-conditional { border-left: 3px solid var(--amber); }
.gate-card.gate-rejected    { border-left: 3px solid var(--red); }
.gate-card.gate-pending     { border-left: 3px solid var(--border-strong); }

.capital-chain {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-top: 12px;
  flex-wrap: wrap;
}
.chain-node {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 13px;
  min-width: 140px;
  flex: 1;
}
.chain-arrow {
  display: flex;
  align-items: center;
  font-size: 22px;
  color: var(--accent);
  padding: 0 4px;
}

.auth-line {
  font-size: 12px;
  padding: 7px 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.auth-line.auth-ok      { background: rgba(74,222,128,.06);  color: #86efac; border-color: rgba(74,222,128,.3); }
.auth-line.auth-missing { background: rgba(251,191,36,.08);  color: #fcd34d; border-color: rgba(251,191,36,.4); }

.auth-declaration {
  background: var(--accent-soft);
  border: 1px solid rgba(212,175,92,.4);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}

.legal-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.legal-item:last-child { border-bottom: none; }
.legal-item .title { font-weight: 600; color: var(--ink); margin-bottom: 4px; font-size: 14px; }
.legal-item .relevance { font-size: 13px; color: var(--ink-dim); }

/* ============================================
   Toasts
   ============================================ */
.toast-stack {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 14px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--ink);
  display: flex;
  gap: 10px;
  align-items: center;
  animation: toastIn .25s ease;
  pointer-events: auto;
  max-width: 100%;
}
.toast.toast-success { border-left: 3px solid var(--green); }
.toast.toast-error   { border-left: 3px solid var(--red); }
.toast.toast-info    { border-left: 3px solid var(--blue); }
.toast.toast-warn    { border-left: 3px solid var(--amber); }
.toast .toast-icon { font-size: 16px; }
.toast.fade-out { animation: toastOut .2s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(20px); } }

/* ============================================
   Command palette
   ============================================ */
.cmd-palette {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: start center;
  padding: 80px 20px 20px 20px;
}
.cmd-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 8, 20, .68);
  backdrop-filter: blur(6px);
  animation: fadeIn .12s ease;
}
.cmd-box {
  position: relative;
  width: 100%;
  max-width: 580px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideUp .15s ease;
}
.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.cmd-input-wrap svg { color: var(--ink-muted); flex-shrink: 0; }
.cmd-input-wrap input {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 14px;
  flex: 1;
}
.cmd-input-wrap input:focus { box-shadow: none; }
.cmd-results { max-height: 60vh; overflow-y: auto; padding: 4px; }
.cmd-section { padding: 4px 0; }
.cmd-section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-muted);
  padding: 8px 10px 4px 10px;
  font-weight: 600;
}
.cmd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-dim);
}
.cmd-item .cmd-meta { font-size: 11px; color: var(--ink-muted); margin-left: auto; }
.cmd-item.active, .cmd-item:hover { background: var(--panel-2); color: var(--ink); }
.cmd-item.active { background: var(--accent-soft); }
.cmd-foot {
  display: flex;
  gap: 16px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 11px;
  color: var(--ink-muted);
}

/* Help overlay (uses cmd-palette variants) */
.help-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  padding: 20px;
}
.help-box {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slideUp .15s ease;
}
.help-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 16px;
  align-items: center;
  font-size: 13px;
}
.help-grid > div:nth-child(odd) { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ============================================
   Charts (custom SVG)
   ============================================ */
.chart-wrap { position: relative; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 0 4px; }
.chart-bar {
  flex: 1;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  position: relative;
  transition: filter .15s;
  cursor: pointer;
}
.chart-bar:hover { filter: brightness(1.15); }
.chart-bar-tip { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--panel-3); border: 1px solid var(--border); padding: 4px 8px; border-radius: 5px; font-size: 11px; white-space: nowrap; opacity: 0; transition: opacity .15s; pointer-events: none; }
.chart-bar:hover .chart-bar-tip { opacity: 1; }
.chart-axis-x { display: flex; gap: 6px; padding: 6px 4px 0 4px; font-size: 9px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .05em; }
.chart-axis-x > span { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.funnel-row {
  display: grid;
  grid-template-columns: 130px 1fr 60px;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.funnel-bar {
  height: 22px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 4px;
  position: relative;
  transition: filter .15s;
}
.funnel-bar:hover { filter: brightness(1.1); }
.funnel-row .label { font-size: 12px; color: var(--ink-dim); }
.funnel-row .count { font-size: 12px; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.heat-grid { display: grid; gap: 3px; }
.heat-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}
.heat-cell:hover { border-color: var(--accent); }

/* ============================================
   Calendar
   ============================================ */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-muted);
  padding: 6px 4px;
  text-align: center;
  font-weight: 600;
}
.cal-day {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 80px;
  padding: 6px;
  font-size: 11px;
  position: relative;
  transition: border-color .15s;
}
.cal-day:hover { border-color: var(--border-strong); }
.cal-day.other-month { opacity: .35; }
.cal-day.today { border-color: var(--accent); background: var(--accent-soft); }
.cal-day .day-num { font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.cal-event {
  background: var(--accent-soft);
  border: 1px solid rgba(212,175,92,.3);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 10px;
  color: var(--accent);
  margin-bottom: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event.amber { background: rgba(251,191,36,.10); border-color: rgba(251,191,36,.3); color: #fcd34d; }
.cal-event.red { background: rgba(248,113,113,.10); border-color: rgba(248,113,113,.3); color: #fca5a5; }
.cal-event.blue { background: rgba(96,165,250,.10); border-color: rgba(96,165,250,.3); color: #93c5fd; }

/* ============================================
   Activity stream
   ============================================ */
.activity-list { display: flex; flex-direction: column; gap: 0; }
.activity-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.activity-row:last-child { border-bottom: none; }
.activity-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-size: 14px;
}
.activity-body { font-size: 13px; }
.activity-body .actor { font-weight: 600; }
.activity-body .meta { font-size: 11px; color: var(--ink-muted); margin-top: 2px; }
.activity-time { font-size: 11px; color: var(--ink-muted); white-space: nowrap; }

/* ============================================
   Drag and drop
   ============================================ */
.draggable { user-select: none; }
.drag-ghost { position: fixed; pointer-events: none; opacity: .85; z-index: 1000; transform: rotate(-2deg); }

/* ============================================
   Filter chips
   ============================================ */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink-dim);
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--ink); }
.chip.active { background: var(--accent-soft); border-color: var(--accent-dim); color: var(--accent); font-weight: 600; }
.chip .chip-x { font-size: 13px; opacity: .6; line-height: 1; margin-left: 2px; }
.chip .chip-x:hover { opacity: 1; }

/* ============================================
   Sparkline
   ============================================ */
.spark { display: block; }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  body.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .25s; }
  body.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .main { padding: 14px 16px 60px 16px; }
  .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr 1fr; }
  .pipeline { grid-template-columns: repeat(8, 200px); }
  .mobile-menu { display: inline-grid; }
  .search-trigger { width: auto; min-width: 180px; }
}

@media (max-width: 600px) {
  .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  .row-2, .row-3, .row-4 { grid-template-columns: 1fr; }
  .top-actions { width: 100%; }
  .search-trigger { flex: 1; }
}

/* Print */
@media print {
  body { display: block; background: white; color: black; }
  .sidebar, .topbar .top-actions, .toast-stack, #modal-root, .cmd-palette, .help-overlay { display: none !important; }
  .main { padding: 0; max-width: 100%; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }
}

/* ============================================
   v3 additions
   ============================================ */

/* Sync status pill */
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--ink-muted);
  padding: 5px 8px;
  margin: 0 0 12px 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s;
}
.sync-status:hover { border-color: var(--border-strong); color: var(--ink-dim); }
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-muted);
  flex-shrink: 0;
}
.sync-status.connected .sync-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(74,222,128,.15); }
.sync-status.syncing .sync-dot { background: var(--amber); animation: syncPulse 1s infinite; }
.sync-status.error .sync-dot { background: var(--red); }
@keyframes syncPulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.sync-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.sidebar-collapsed .sync-text { display: none; }
body.sidebar-collapsed .sync-status { justify-content: center; padding: 6px; }

/* Settings icon */
[data-icon="settings"] .nav-icon { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3bf' stroke-width='1.7' viewBox='0 0 24 24'><circle cx='12' cy='12' r='3'/><path d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z'/></svg>"); }

/* Stage advance guard */
.advance-guard {
  padding: 11px 14px;
  border-radius: 8px;
  background: rgba(248,113,113,.08);
  border: 1px solid rgba(248,113,113,.35);
  color: #fca5a5;
  font-size: 12px;
  margin: 8px 0 12px 0;
}
.advance-guard.ok {
  background: rgba(74,222,128,.06);
  border-color: rgba(74,222,128,.3);
  color: #86efac;
}
.advance-guard-title { font-weight: 600; margin-bottom: 4px; font-size: 12px; }
.advance-guard ul { margin: 4px 0 0 0; padding-left: 18px; font-size: 11px; color: var(--ink-dim); }
.advance-guard ul li { margin-bottom: 2px; }

/* Task checklist with deadline + sub-task */
.checklist li.with-meta {
  grid-template-columns: 22px 1fr auto;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.task-meta .task-due {
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--ink-dim);
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.task-meta .task-due.overdue { color: #fca5a5; border-color: rgba(248,113,113,.4); background: rgba(248,113,113,.08); }
.task-meta .task-due.soon { color: #fcd34d; border-color: rgba(251,191,36,.35); background: rgba(251,191,36,.08); }
.task-meta .task-owner { background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; border: 1px solid rgba(212,175,92,.35); }
.task-meta .task-note { color: var(--ink-muted); font-style: italic; }
.task-meta .task-required { background: rgba(248,113,113,.10); color: #fca5a5; border: 1px solid rgba(248,113,113,.3); padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.task-meta .task-evidence-needed { background: rgba(251,191,36,.10); color: #fcd34d; border: 1px solid rgba(251,191,36,.35); padding: 1px 6px; border-radius: 4px; font-size: 10px; }

.task-action-btn {
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 5px;
}

/* Tasks-by-deal accordion */
.task-group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.task-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  transition: background .15s;
}
.task-group-head:hover { background: var(--panel-3); }
.task-group-head .deal-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.task-group-head .deal-title .expander { width: 16px; height: 16px; flex-shrink: 0; transition: transform .15s; color: var(--ink-dim); }
.task-group.expanded .expander { transform: rotate(90deg); }
.task-group-head .deal-name { font-weight: 600; font-size: 13px; color: var(--ink); }
.task-group-head .deal-client { font-size: 11px; color: var(--ink-muted); }
.task-group-stats { display: flex; gap: 8px; align-items: center; flex-shrink: 0; font-size: 11px; color: var(--ink-dim); }
.task-group-body { padding: 8px 14px; display: none; }
.task-group.expanded .task-group-body { display: block; }
.task-group-stage {
  font-size: 10px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 10px 2px 4px 2px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

/* Investor side panel */
.side-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 100%;
  max-width: 540px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 60px rgba(0,0,0,.5);
  z-index: 60;
  display: flex;
  flex-direction: column;
  animation: slideInRight .2s ease;
}
@keyframes slideInRight { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.side-panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(4,8,20,.5);
  backdrop-filter: blur(3px);
  z-index: 59;
  animation: fadeIn .15s ease;
}
.side-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 22px 14px 22px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
}
.side-panel-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: var(--panel-2);
}
.side-panel .kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.side-panel .kv dt { color: var(--ink-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding-top: 2px; }
.side-panel .kv dd { margin: 0; color: var(--ink); }
.side-panel .kv dd input, .side-panel .kv dd select, .side-panel .kv dd textarea { padding: 4px 8px; font-size: 12px; }

/* Team pill select */
.team-chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  min-height: 38px;
  cursor: text;
}
.team-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid rgba(212,175,92,.35);
  font-weight: 600;
}
.team-chip .x { cursor: pointer; opacity: .7; font-size: 13px; line-height: 1; }
.team-chip .x:hover { opacity: 1; }
.team-chip-select select {
  border: none;
  background: transparent;
  padding: 2px 4px;
  width: auto;
  flex: 1;
  min-width: 120px;
  font-size: 12px;
}

/* AI brief modal */
.ai-brief {
  background: var(--panel-2);
  border: 1px solid rgba(167,139,250,.3);
  border-left: 3px solid var(--violet);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
}
.ai-brief-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ai-brief-head .ai-tag {
  font-size: 10px;
  background: rgba(167,139,250,.15);
  color: #c4b5fd;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  border: 1px solid rgba(167,139,250,.3);
}
.ai-brief-prompt {
  background: #0a0f1d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}
[data-theme="light"] .ai-brief-prompt { background: #f6f8fc; color: var(--ink-dim); }
.ai-brief-hint { font-size: 11px; color: var(--ink-dim); margin-top: 8px; }

/* Settings page */
.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-right: 1px solid var(--border);
  min-width: 180px;
}
.settings-nav button {
  text-align: left;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink-dim);
  font-size: 13px;
  justify-content: flex-start;
}
.settings-nav button:hover { background: var(--panel-2); color: var(--ink); }
.settings-nav button.active { background: var(--panel-2); color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.settings-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 500px;
}
.settings-body { padding: 18px 22px; }

/* Editable workflow list */
.wf-list { display: flex; flex-direction: column; gap: 6px; }
.wf-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.wf-step .step-num { font-size: 10px; color: var(--ink-muted); width: 22px; text-align: center; font-weight: 600; }
.wf-step input { flex: 1; padding: 4px 8px; font-size: 12px; }
.wf-step .wf-grip { color: var(--ink-muted); cursor: grab; font-size: 14px; user-select: none; }

/* Document data room */
.doc-card {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  transition: border-color .15s;
}
.doc-card:hover { border-color: var(--border-strong); }
.doc-icon {
  width: 30px; height: 30px;
  border-radius: 6px;
  background: var(--panel-3);
  display: grid; place-items: center;
  font-size: 14px;
  color: var(--accent);
}
.doc-name { font-size: 13px; font-weight: 500; color: var(--ink); }
.doc-sub { font-size: 11px; color: var(--ink-muted); }
.doc-actions { display: flex; gap: 6px; align-items: center; }
.doc-expired { background: rgba(248,113,113,.08) !important; border-color: rgba(248,113,113,.35) !important; }
.doc-expiring { background: rgba(251,191,36,.05) !important; border-color: rgba(251,191,36,.3) !important; }

.doc-dropzone {
  border: 2px dashed var(--border);
  border-radius: 9px;
  padding: 24px;
  text-align: center;
  color: var(--ink-muted);
  transition: all .15s;
  cursor: pointer;
}
.doc-dropzone:hover, .doc-dropzone.drag-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Watchlist star */
.star-btn {
  width: 24px; height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.star-btn.starred { color: var(--accent); }
.star-btn:hover { color: var(--accent); }

/* Mentions tray */
.notif-bell {
  position: relative;
  padding: 5px 9px;
  border-radius: 7px;
  background: var(--panel);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.notif-bell:hover { background: var(--panel-2); border-color: var(--border-strong); }
.notif-bell .notif-count {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  border: 2px solid var(--bg);
  min-width: 16px;
  text-align: center;
  line-height: 1.2;
}
.notif-tray {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 480px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 40;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.notif-tray-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}
.notif-tray-body { flex: 1; overflow-y: auto; }
.notif-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-dim);
  transition: background .1s;
}
.notif-item:hover { background: var(--panel-2); color: var(--ink); }
.notif-item.unread { background: rgba(212,175,92,.04); border-left: 3px solid var(--accent); }
.notif-item .notif-time { font-size: 10px; color: var(--ink-muted); margin-top: 3px; }

/* Inline edit */
.inline-edit {
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color .15s;
  padding: 1px 2px;
  border-radius: 3px;
}
.inline-edit:hover { border-bottom-color: var(--accent-dim); background: var(--accent-soft); }

/* Recent items dropdown */
.recent-items-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  min-width: 260px;
  max-height: 380px;
  overflow-y: auto;
}
.recent-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.recent-item:last-child { border-bottom: none; }
.recent-item:hover { background: var(--panel-2); }
.recent-item .recent-meta { font-size: 10px; color: var(--ink-muted); }

/* Origination format badge */
.badge.orig-format {
  background: rgba(96,165,250,.08);
  color: #93c5fd;
  border-color: rgba(96,165,250,.3);
  font-size: 10px;
}

/* Required / Optional task indicator */
.task-required-star { color: var(--red); margin-left: 3px; font-size: 12px; }

/* Settings section */
.settings-section { margin-bottom: 22px; }
.settings-section h3 { margin-bottom: 8px; }
.settings-section .help { font-size: 12px; color: var(--ink-muted); margin-bottom: 12px; }

.filepicker-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
  color: #1a1305;
  border: 1px solid var(--accent);
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.filepicker-btn:hover { filter: brightness(1.05); }
.filepicker-btn[disabled] { opacity: .4; cursor: not-allowed; }

.folder-info {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink-dim);
  font-family: ui-monospace, Menlo, monospace;
}

/* Audit log table */
.audit-row { font-family: ui-monospace, Menlo, monospace; font-size: 11px; }
.audit-row td { padding: 6px 10px; }
.audit-hash { color: var(--ink-muted); font-size: 10px; }


/* ============================================
   v4 additions
   ============================================ */
.ai-tag-inline {
  font-size: 10px;
  background: rgba(167,139,250,.15);
  color: #c4b5fd;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  border: 1px solid rgba(167,139,250,.3);
  margin-right: 6px;
  vertical-align: 2px;
}
.ai-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--violet);
  border-radius: 50%;
  margin: 0 auto;
  animation: aiSpin .9s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

.ai-result {
  max-height: 480px;
  overflow-y: auto;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
}
.ai-result h2, .ai-result h3, .ai-result h4 { margin: 18px 0 8px 0; color: var(--ink); }
.ai-result h2 { font-size: 16px; }
.ai-result h3 { font-size: 14px; }
.ai-result h4 { font-size: 13px; color: var(--ink-dim); }
.ai-result p  { margin: 0 0 10px 0; }
.ai-result ul, .ai-result ol { margin: 6px 0 12px 0; padding-left: 22px; }
.ai-result li { margin-bottom: 3px; }
.ai-result code {
  background: var(--panel-3);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
  font-family: ui-monospace, Menlo, monospace;
}
.ai-result strong { color: var(--ink); }

.ai-citations {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ai-citation {
  display: inline-block;
  background: var(--panel-3);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 11px;
  color: var(--blue);
  text-decoration: none;
}
.ai-citation:hover { border-color: var(--accent-dim); text-decoration: none; }


/* ============================================
   v4.1 — Syntropy AI chat popup
   ============================================ */
.chat-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 12px 18px 12px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--accent) 100%);
  color: #1a1305;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(212,175,92,.35), 0 1px 0 rgba(255,255,255,.25) inset;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 55;
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.chat-fab:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 12px 32px rgba(212,175,92,.45), 0 1px 0 rgba(255,255,255,.25) inset; }
.chat-fab:active { transform: translateY(0); }
.chat-fab-glyph {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  background: rgba(26,19,5,.15);
  border-radius: 50%;
  font-size: 13px;
}

/* Chat panel (bottom-right, fixed, not a full-screen modal) */
.chat-panel {
  position: fixed;
  right: 20px;
  bottom: 86px;
  width: 440px;
  max-width: calc(100vw - 40px);
  height: 620px;
  max-height: calc(100vh - 140px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 32px 80px rgba(0,0,0,.55), 0 2px 0 rgba(255,255,255,.04) inset;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 54;
  animation: chatIn .2s ease;
}
@keyframes chatIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.chat-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.chat-head-title { display: flex; align-items: center; gap: 10px; }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.chat-chip {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: all .12s;
}
.chat-chip:hover { border-color: var(--accent-dim); color: var(--accent); background: var(--accent-soft); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--ink-muted);
}

.chat-msg {
  display: flex;
  max-width: 92%;
}
.chat-msg-user { align-self: flex-end; }
.chat-msg-ai   { align-self: flex-start; }

.chat-bubble {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  word-wrap: break-word;
}
.chat-msg-user .chat-bubble {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  color: #1a1305;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.chat-msg-ai .chat-bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.chat-bubble p { margin: 0 0 6px 0; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h2, .chat-bubble h3, .chat-bubble h4 { margin: 10px 0 4px 0; font-size: 13px; }
.chat-bubble ul, .chat-bubble ol { margin: 4px 0 6px 0; padding-left: 20px; }
.chat-bubble li { margin-bottom: 2px; }
.chat-bubble code {
  background: var(--panel-3);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-family: ui-monospace, Menlo, monospace;
}

.chat-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.chat-citations .ai-citation {
  font-size: 10px;
  padding: 2px 7px;
}

/* Typing indicator */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}
.chat-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: chatTyping 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatTyping {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-3px); }
}

/* Input row */
.chat-input-row {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  padding: 8px 10px;
  min-height: 36px;
  max-height: 180px;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  line-height: 1.4;
  overflow-y: auto;
}
.chat-input-row textarea:focus { border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-input-row button { height: 36px; padding: 0 16px; }

@media (max-width: 640px) {
  .chat-panel { right: 10px; left: 10px; width: auto; bottom: 76px; height: 70vh; }
  .chat-fab { right: 14px; bottom: 14px; padding: 10px 14px 10px 12px; }
  .chat-fab-label { display: none; }
}


/* ============================================
   v4.2 — locked AI fields, plain-text AI output, plain tables
   ============================================ */
.kv-locked {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 8px 11px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--ink-dim);
  letter-spacing: .03em;
  width: 100%;
  min-height: 36px;
  user-select: none;
}

/* Plain-text AI rendering */
.ai-result p, .chat-bubble p { margin: 0 0 6px 0; line-height: 1.65; }
.ai-result p.plain-heading,
.chat-bubble p.plain-heading {
  font-weight: 700;
  color: var(--ink);
  margin: 14px 0 6px 0;
  font-size: 13px;
  letter-spacing: -0.005em;
}
.ai-result p.plain-num,
.chat-bubble p.plain-num {
  margin: 4px 0 4px 8px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.ai-result p.plain-num-marker,
.chat-bubble p.plain-num-marker { color: var(--accent); font-weight: 600; min-width: 22px; }
.ai-result p.plain-bullet,
.chat-bubble p.plain-bullet {
  margin: 3px 0;
  padding-left: 4px;
  color: var(--ink);
}

.plain-table-wrap {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  background: var(--panel);
}
.plain-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.plain-table th, .plain-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: top;
}
.plain-table th:last-child, .plain-table td:last-child { border-right: none; }
.plain-table th {
  background: var(--panel-3);
  font-weight: 600;
  color: var(--ink-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.plain-table tr:last-child td { border-bottom: none; }
.plain-table tr:hover td { background: var(--panel-2); }

/* Tables inside chat bubbles need to fit and stay readable */
.chat-bubble .plain-table-wrap { margin: 8px -2px; max-width: 100%; }
.chat-bubble .plain-table { font-size: 11.5px; }
.chat-bubble .plain-table th, .chat-bubble .plain-table td { padding: 6px 8px; }
