:root {
  --ink-900: #0f1b2d;
  --ink-800: #16243a;
  --ink-700: #223655;
  --ink-600: #33507a;
  --ink-500: #4c6a99;
  --ink-400: #7c93b8;
  --ink-300: #aebdd6;
  --ink-200: #d6e0ef;
  --ink-100: #eef2f9;
  --ink-50:  #f7f9fc;

  --teal-600: #0d7a72;
  --teal-500: #12938a;
  --teal-100: #dcf3f0;

  --blue-600: #1d5fd6;
  --blue-100: #e3ecfd;

  --amber-600: #b5720a;
  --amber-100: #fdf0d8;

  --violet-600: #6d3fc0;
  --violet-100: #ece2fa;

  --green-600: #1c8a4b;
  --green-100: #dcf5e6;

  --red-600: #c8372f;
  --red-100: #fbe3e1;

  --slate-600: #5b6b82;
  --slate-100: #eaeef3;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15,27,45,.06), 0 1px 1px rgba(15,27,45,.04);
  --shadow-md: 0 4px 16px rgba(15,27,45,.10);
  --shadow-lg: 0 12px 32px rgba(15,27,45,.16);
  --sidebar-w: 240px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink-900);
  background: var(--ink-50);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
ul { margin: 0; padding: 0; list-style: none; }
h1,h2,h3,h4,p { margin: 0; }
input, select, textarea { font-family: inherit; }

#app-root { min-height: 100vh; }
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--ink-900);
  color: var(--ink-100);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; font-weight: 700; font-size: 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--teal-500), var(--blue-600));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: white;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar-section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-400); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink-200); font-size: 14px; font-weight: 500;
  margin-bottom: 2px; position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(18,147,138,.22); color: #fff; }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px;
  background: var(--teal-500); border-radius: 3px;
}
.nav-item .ico { width: 18px; text-align: center; opacity: .85; }
.nav-badge {
  margin-left: auto; background: var(--red-600); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 6px;
}
.sidebar-foot {
  padding: 12px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 11px; color: var(--ink-400);
}

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  background: #fff; border-bottom: 1px solid var(--ink-200);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-500); flex: 1; min-width: 0; overflow: hidden; }
.breadcrumbs .crumb { white-space: nowrap; }
.breadcrumbs .crumb.current { color: var(--ink-900); font-weight: 600; }
.breadcrumbs .sep { color: var(--ink-300); }
.crumb-link:hover { color: var(--teal-600); text-decoration: underline; cursor: pointer; }

.back-banner {
  display: flex; align-items: center; gap: 8px;
  background: var(--blue-100); color: var(--ink-800);
  padding: 8px 20px; font-size: 13px; border-bottom: 1px solid var(--ink-200);
}
.back-banner button.link-btn { color: var(--blue-600); font-weight: 600; }

.page-content { padding: 24px 28px 60px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page-content.wide { max-width: 1520px; }

.role-switch {
  position: relative;
}
.role-switch-btn {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--ink-200); background: var(--ink-50);
  border-radius: 999px; padding: 5px 12px 5px 5px; font-size: 13px; font-weight: 600;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--teal-600); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}
.role-menu {
  position: absolute; right: 0; top: 44px; width: 320px;
  background: #fff; border: 1px solid var(--ink-200); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 8px; z-index: 40;
}
.role-menu-head { font-size: 11px; text-transform: uppercase; color: var(--ink-400); padding: 8px 10px 4px; letter-spacing: .05em; }
.role-menu-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); font-size: 13px;
}
.role-menu-item:hover { background: var(--ink-100); }
.role-menu-item.active { background: var(--teal-100); }
.role-menu-item .meta { display: flex; flex-direction: column; }
.role-menu-item .meta b { font-size: 13px; }
.role-menu-item .meta span { font-size: 11px; color: var(--ink-500); }
.context-pill {
  font-size: 11px; background: var(--violet-100); color: var(--violet-600);
  border-radius: 999px; padding: 2px 8px; font-weight: 700; margin-left: auto;
}

.icon-btn {
  width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--ink-200);
  background: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--ink-600);
}
.icon-btn:hover { background: var(--ink-100); }

.h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.h2 { font-size: 19px; font-weight: 700; }
.h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--ink-500); }
.small { font-size: 12.5px; }
.tiny { font-size: 11px; }
.mono { font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-10 { gap: 10px; }
.gap-12 { gap: 12px; } .gap-14 { gap: 14px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; } .gap-24 { gap: 24px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-6 { margin-bottom: 6px; } .mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-20 { margin-bottom: 20px; } .mb-24 { margin-bottom: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.card {
  background: #fff; border: 1px solid var(--ink-200); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--ink-100); }
.card-body { padding: 16px 18px; }
.card.clickable { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.card.clickable:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.btn-primary { background: var(--teal-600); color: #fff; }
.btn-primary:hover { background: var(--teal-500); }
.btn-secondary { background: #fff; border-color: var(--ink-200); color: var(--ink-800); }
.btn-secondary:hover { background: var(--ink-100); }
.btn-ghost { background: transparent; color: var(--ink-600); }
.btn-ghost:hover { background: var(--ink-100); }
.btn-danger { background: #fff; border-color: var(--red-100); color: var(--red-600); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: none; padding: 0; color: var(--teal-600); font-weight: 600; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tone-slate { background: var(--slate-100); color: var(--slate-600); }
.tone-amber { background: var(--amber-100); color: var(--amber-600); }
.tone-blue { background: var(--blue-100); color: var(--blue-600); }
.tone-violet { background: var(--violet-100); color: var(--violet-600); }
.tone-teal { background: var(--teal-100); color: var(--teal-600); }
.tone-green { background: var(--green-100); color: var(--green-600); }
.tone-red { background: var(--red-100); color: var(--red-600); }
.tone-red { background: var(--red-100); color: var(--red-600); }

.priority-high { color: var(--red-600); }
.priority-medium { color: var(--amber-600); }
.priority-low { color: var(--slate-600); }

.pipeline { display: flex; align-items: center; gap: 4px; }
.pipeline .seg { height: 6px; flex: 1; border-radius: 3px; background: var(--ink-200); }
.pipeline .seg.done { background: var(--teal-500); }
.pipeline .seg.current { background: var(--blue-600); }

.field-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
}
.field-row + .field-row { border-top: 1px solid var(--ink-100); border-radius: 0; }
.field-row:hover { background: var(--ink-50); }
.field-label { font-size: 12.5px; color: var(--ink-500); font-weight: 600; }
.field-value-line { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.field-value { font-size: 15px; font-weight: 700; }

.field-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; text-transform: uppercase; letter-spacing: .03em;
}
.chip-ai { background: var(--violet-100); color: var(--violet-600); }
.chip-verified { background: var(--green-100); color: var(--green-600); }
.chip-locked { background: var(--slate-100); color: var(--slate-600); }
.chip-review { background: var(--amber-100); color: var(--amber-600); }
.chip-editable { background: var(--blue-100); color: var(--blue-600); }

.state-editable { border-bottom: 1.5px dashed var(--ink-400); cursor: text; }
.state-locked { color: var(--ink-600); }
.state-clickable { cursor: pointer; }
.state-clickable:hover .field-value { color: var(--teal-600); text-decoration: underline; text-underline-offset: 3px; }

.lock-ico { color: var(--ink-400); font-size: 12px; }

.field-row.highlight-selected {
  background: var(--teal-100); border-left: 3px solid var(--teal-500); padding-left: 11px;
}

.trace-split { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,420px); gap: 20px; align-items: flex-start; }
.trace-sidebar { position: sticky; top: 84px; align-self: start; }
.doc-preview {
  background: var(--ink-900); border-radius: var(--radius-md); padding: 16px;
}
.doc-page {
  background: #fff; border-radius: 6px; aspect-ratio: 8.5 / 11; position: relative; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.doc-page .fake-lines { position: absolute; inset: 0; padding: 24px; }
.doc-page .fake-line { height: 6px; background: var(--ink-100); border-radius: 3px; margin-bottom: 10px; }
.doc-page .fake-line.w60 { width: 60%; } .doc-page .fake-line.w40 { width: 40%; } .doc-page .fake-line.w80 { width: 80%; } .doc-page .fake-line.w30 { width: 30%; }
.doc-highlight {
  position: absolute; border: 2px solid var(--teal-500); background: rgba(18,147,138,.15);
  border-radius: 4px; transition: all .2s ease; animation: pulseHi 1.4s ease-in-out infinite;
}
@keyframes pulseHi { 0%,100% { box-shadow: 0 0 0 0 rgba(18,147,138,.35);} 50% { box-shadow: 0 0 0 6px rgba(18,147,138,0);} }
.doc-caption { color: var(--ink-200); font-size: 12px; margin-top: 10px; display: flex; justify-content: space-between; }

.trail {
  display: flex; flex-direction: column; gap: 0;
}
.trail-step { display: flex; gap: 10px; padding: 10px 0; position: relative; }
.trail-step .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--teal-100); color: var(--teal-600); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.trail-step:not(:last-child)::before { content: ""; position: absolute; left: 9px; top: 30px; bottom: -4px; width: 2px; background: var(--ink-200); }
.trail-step .body { font-size: 13px; }
.trail-step .body b { display: block; margin-bottom: 2px; }

.ai-panel { border: 1px solid var(--violet-100); background: linear-gradient(180deg, #fbf9ff, #ffffff); border-radius: var(--radius-md); }
.ai-panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--violet-100); }
.ai-spark { width: 24px; height: 24px; border-radius: 7px; background: var(--violet-600); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; }
.confidence-bar { height: 5px; border-radius: 3px; background: var(--ink-200); overflow: hidden; width: 70px; }
.confidence-fill { height: 100%; border-radius: 3px; }
.conf-high { background: var(--ink-400); } .conf-med { background: var(--amber-600); } .conf-low { background: var(--red-600); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--ink-200); }
.tab-btn { padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--ink-500); border-bottom: 2px solid transparent; }
.tab-btn:hover { color: var(--ink-800); }
.tab-btn.active { color: var(--teal-600); border-bottom-color: var(--teal-600); }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-500); padding: 8px 12px; border-bottom: 1px solid var(--ink-200); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--ink-100); font-size: 13.5px; vertical-align: middle; }
.tbl tr.clickable-row:hover { background: var(--ink-50); cursor: pointer; }

.input, .select {
  border: 1px solid var(--ink-200); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13.5px; background: #fff;
}
.input:focus, .select:focus { outline: 2px solid var(--teal-500); outline-offset: 1px; }
.search-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--ink-200); border-radius: var(--radius-sm); padding: 8px 12px; background: #fff; }
.search-box input { border: none; outline: none; flex: 1; font-size: 13.5px; }

.progress-ring-wrap { position: relative; width: 64px; height: 64px; }
.checklist-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--ink-200); border-radius: var(--radius-md); background: #fff; }
.checklist-item + .checklist-item { margin-top: 8px; }
.check-circle { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink-300); display: flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; }
.check-circle.done { background: var(--teal-600); border-color: var(--teal-600); color: #fff; }
.check-circle.current { border-color: var(--blue-600); color: var(--blue-600); }

.msg-thread-list .thread-item {
  padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; min-height: 82px;
}
.msg-thread-list .thread-item:hover { background: var(--ink-50); }
.msg-thread-list .thread-item.active {
  background: rgba(18, 147, 138, .07); border-left: 3px solid var(--teal-500); padding-left: 14px;
}
.thread-item-subject {
  font-size: 13.5px; font-weight: 700; color: var(--ink-800);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item-preview {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.linked-doc-card {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  margin: 14px 18px 0; padding: 10px 12px;
  border: 1px solid var(--ink-200); border-radius: var(--radius-sm); background: var(--ink-50);
  transition: background .15s, border-color .15s;
}
.linked-doc-card:hover { background: #fff; border-color: var(--teal-500); box-shadow: var(--shadow-sm); }
.linked-doc-ico {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0; font-size: 14px;
  background: var(--blue-100); color: var(--blue-600); display: flex; align-items: center; justify-content: center;
}
.linked-doc-name { font-size: 13px; font-weight: 600; color: var(--ink-800); flex: 1; }
.linked-doc-cta { font-size: 12px; font-weight: 600; color: var(--teal-600); white-space: nowrap; }
.bubble { max-width: min(70%, 720px); padding: 10px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; }
.bubble.client { background: var(--ink-100); align-self: flex-start; border-bottom-left-radius: 3px; }
.bubble.firm { background: var(--blue-100); align-self: flex-end; border-bottom-right-radius: 3px; }
.bubble.internal { background: var(--amber-100); align-self: flex-end; border: 1px dashed var(--amber-600); border-bottom-right-radius: 3px; }
.composer {
  margin: 0 18px 18px; padding: 10px 12px;
  border: 1px solid var(--ink-200); border-radius: var(--radius-md);
}
.composer-input {
  width: 100%; border: none; outline: none; resize: none; background: transparent;
  font: inherit; padding: 2px;
}
.composer-attach { font-weight: 600; }

.linked-panel { border: 1px dashed var(--ink-300); border-radius: var(--radius-md); background: var(--ink-50); }
.linked-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); }
.linked-item:hover { background: #fff; }
.linked-ico { width: 26px; height: 26px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }

.divider { height: 1px; background: var(--ink-200); border: none; margin: 16px 0; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-500); }
.kbd { background: var(--ink-100); border: 1px solid var(--ink-200); border-radius: 4px; padding: 1px 6px; font-size: 11px; font-family: monospace; }
.scrollbox { overflow-y: auto; }
.highlight-flash { animation: flash 1.4s ease; }
@keyframes flash { 0% { background: var(--amber-100); } 100% { background: transparent; } }

.role-tag { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; text-transform: uppercase; }
.two-pane { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: flex-start; }
.three-pane { display: grid; grid-template-columns: 260px 1fr 320px; gap: 18px; align-items: flex-start; }

@media (max-width: 1100px) {
  .trace-split { grid-template-columns: 1fr; }
  .three-pane { grid-template-columns: 1fr; }
}

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink-900); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow-lg); }
