:root {
  --ink: #202321;
  --muted: #626a66;
  --line: #d8dcd7;
  --line-strong: #aeb6b0;
  --canvas: #f1f3ef;
  --surface: #ffffff;
  --sidebar: #171918;
  --sidebar-ink: #f6f4ec;
  --primary: #b83a24;
  --primary-dark: #8f2b1a;
  --blue: #006f65;
  --blue-soft: #e1f3ef;
  --green: #166b45;
  --green-soft: #e3f2e8;
  --signal: #f2c94c;
  --amber: #725100;
  --amber-soft: #fff1c7;
  --red: #a61b35;
  --red-soft: #fde8ed;
  --shadow: 0 12px 32px rgba(23, 25, 24, 0.15);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--canvas); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
[hidden] { display: none !important; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; line-height: 1.2; font-weight: 650; }
h2 { margin-bottom: 0; font-size: 18px; line-height: 1.25; font-weight: 650; }
h3 { margin-bottom: 6px; font-size: 14px; }

.eyebrow {
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: var(--sidebar);
}

.login-panel {
  width: min(430px, 100%);
  padding: 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 6px solid var(--signal);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-lockup strong, .brand-lockup span { display: block; }
.brand-lockup strong { font-size: 15px; }
.brand-lockup div > span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.brand-logo { width: 42px; height: 42px; flex: 0 0 auto; object-fit: contain; }
.sidebar-brand .brand-logo { width: 39px; height: 39px; }
.login-copy { margin: 42px 0 28px; }
.login-copy h1 { font-size: 30px; }
.login-copy > p:last-child { margin: 10px 0 0; color: var(--muted); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
}
.sidebar-brand { padding: 0 8px 25px; border-bottom: 1px solid rgba(255,255,255,.13); }
.sidebar-brand div > span { color: #b9beb9; }
.primary-nav { display: grid; gap: 4px; margin-top: 20px; }
.nav-item {
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #d5d8d3;
  text-align: left;
  font-weight: 600;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { border-left-color: var(--primary); background: var(--signal); color: #171918; }
.sidebar-status { margin-top: auto; display: flex; gap: 9px; align-items: flex-start; padding: 15px 8px 0; border-top: 1px solid rgba(255,255,255,.13); }
.sidebar-status strong, .sidebar-status span { display: block; }
.sidebar-status strong { font-size: 12px; }
.sidebar-status div > span { margin-top: 3px; color: #b9beb9; font-size: 11px; line-height: 1.35; }
.status-dot { width: 9px; height: 9px; margin-top: 3px; border-radius: 50%; background: #aeb6b0; flex: 0 0 auto; }
.status-dot.ok { background: #49c781; }
.status-dot.error { background: #f06b75; }

.main-shell { min-width: 0; }
.topbar {
  min-height: 82px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 16px 30px;
  background: var(--surface);
  border-bottom: 4px solid var(--signal);
}
.topbar-actions { display: flex; gap: 8px; }
.mode-switch { flex: 0 0 auto; }
.mode-switch button { min-width: 92px; }
.mode-switch button[data-client-mode="playground"].active { background: #075f57; }
.mode-switch button[data-client-mode="live"].active { background: var(--red); }
.mode-switch.single-mode { opacity: .78; }
.content { width: min(1400px, 100%); padding: 24px 30px 50px; }
.view { display: none; }
.view.active { display: block; }

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
}
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { border-color: var(--line-strong); background: #fff; color: var(--ink); }
.button.secondary:hover { border-color: var(--blue); background: var(--blue-soft); }
.button.quiet { background: transparent; color: var(--muted); }
.button.danger { border-color: #ddadad; background: #fff; color: var(--red); }
.button.small { min-height: 30px; padding: 4px 9px; font-size: 12px; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.metric { min-width: 0; padding: 18px 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span, .metric strong { display: block; }
.metric span { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; }
.metric strong { overflow-wrap: anywhere; font-size: 17px; }
.metric strong.ok { color: var(--green); }
.metric strong.error { color: var(--red); }

.section-band {
  margin-top: 22px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.section-band.compact-top { margin-top: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 20px; }
.filter-row { display: grid; grid-template-columns: auto minmax(180px, 390px) auto; align-items: end; gap: 10px; margin-bottom: 15px; }
.filter-row label { align-self: center; }

label { display: block; margin-bottom: 6px; color: #3f4743; font-size: 12px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  min-height: 39px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,111,101,.16); }
.stack-form { display: grid; gap: 15px; }
.form-grid { display: grid; gap: 16px; margin-bottom: 18px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.classification-block { margin: 6px 0 18px; padding: 13px 0 0; border-top: 1px solid var(--line); }
.classification-block summary { margin-bottom: 15px; color: var(--blue); cursor: pointer; font-weight: 650; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 20px; }
.inline-message { color: var(--muted); }
.field-help { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.intake-content { align-items: start; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 12px; }

.tag, .badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
}
.badge.queued, .badge.processing, .badge.pending { background: var(--amber-soft); color: var(--amber); }
.badge.completed, .badge.active, .badge.ready { background: var(--green-soft); color: var(--green); }
.badge.failed, .badge.rejected { background: var(--red-soft); color: var(--red); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #ecefea; color: #505953; font-size: 11px; text-transform: uppercase; white-space: nowrap; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fff8df; }
.table-action { color: var(--blue); border: 0; background: transparent; font-weight: 650; }
.mapping-subject td:first-child { padding-left: 28px; color: var(--muted); }
.identifier { color: #075f57; font: 12px/1.45 Consolas, "Courier New", monospace; }
.identifier-detail { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.empty-state { margin: 18px 0 0; padding: 28px; border: 1px dashed var(--line-strong); color: var(--muted); text-align: center; }
.mode-notice { display: grid; grid-template-columns: minmax(150px, .35fr) minmax(0, 1fr); gap: 18px; margin: 18px 0; padding: 14px 18px; border-left: 4px solid var(--signal); background: #fff8df; }
.mode-notice[hidden] { display: none; }
.mode-notice strong { color: var(--ink); }
.mode-notice span { color: var(--muted); line-height: 1.45; }

.local-record-list { border-top: 1px solid var(--line); }
.local-record { padding: 22px 0; border-bottom: 1px solid var(--line); }
.local-record-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.local-record-header h3 { margin: 0; font-size: 17px; }
.local-link-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  padding: 16px;
  border-left: 4px solid var(--signal);
  background: var(--canvas);
}
.local-link-grid span, .local-link-grid strong { display: block; overflow-wrap: anywhere; }
.local-link-grid span { margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.local-link-grid strong { font-size: 13px; }
.local-stage { display: grid; align-content: start; gap: 5px; min-width: 0; }
.local-stage .badge { justify-self: start; }
.link-arrow { color: var(--primary); font-size: 20px; font-weight: 700; }
.local-record-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.local-record-meta span { padding: 4px 8px; background: var(--blue-soft); color: var(--blue); font-size: 11px; font-weight: 700; }
.local-subject-links { margin-top: 13px; color: var(--muted); font: 12px/1.55 Consolas, "Courier New", monospace; }
.local-content-workspace { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin-top: 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.local-content-panel { min-width: 0; padding: 20px 24px 20px 0; }
.local-content-panel + .local-content-panel { padding-right: 0; padding-left: 24px; border-left: 1px solid var(--line); }
.local-content-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.local-content-heading h4 { margin: 0; font-size: 14px; }
.local-content-heading > span { min-width: 26px; padding: 3px 7px; background: var(--ink); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.local-item-list { display: grid; gap: 7px; }
.local-item-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.local-item-row strong, .local-item-row span { display: block; overflow-wrap: anywhere; }
.local-item-row strong { font-size: 12px; line-height: 1.4; }
.local-item-row span { margin-top: 3px; color: var(--muted); font: 10px/1.4 Consolas, "Courier New", monospace; }
.local-item-empty { margin: 0; padding: 12px 0; color: var(--muted); font-size: 12px; }
.local-item-form { margin-top: 16px; padding-top: 16px; border-top: 2px solid var(--line-strong); }
.local-form-grid { display: grid; grid-template-columns: minmax(150px, .8fr) minmax(210px, 1.2fr); gap: 12px; }
.local-form-grid .wide { grid-column: 1 / -1; }
.local-form-grid label { min-width: 0; }
.local-form-grid input, .local-form-grid select, .local-form-grid textarea { width: 100%; }
.local-form-actions { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 12px; }
.local-form-actions span { color: var(--muted); font-size: 10px; line-height: 1.35; }
.local-record-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 17px; }
.local-json { margin-top: 17px; border-top: 1px solid var(--line); padding-top: 13px; }
.local-json summary { color: var(--blue); cursor: pointer; font-weight: 650; }
.local-json pre { max-height: 360px; margin: 12px 0 0; padding: 14px; overflow: auto; background: #171918; color: #e4f2e8; font: 12px/1.55 Consolas, "Courier New", monospace; white-space: pre-wrap; word-break: break-word; }

.subjects-editor { display: grid; gap: 14px; }
.subject-row { padding: 18px; border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 4px; }
.subject-row-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.subject-row-header h3 { margin: 0; }
.subject-person-fields, .subject-business-fields { min-width: 0; }

.workspace-loader { display: grid; grid-template-columns: minmax(260px, 560px) auto; align-items: end; gap: 10px; }
.workspace-metrics { margin-top: 22px; }
.split-section { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 34px; }
.split-section > div + div { padding-left: 34px; border-left: 1px solid var(--line); }
.resource-list { display: grid; gap: 8px; margin-top: 18px; }
.resource-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 12px; border: 1px solid var(--line); border-radius: 4px; }
.resource-row strong, .resource-row span { display: block; overflow-wrap: anywhere; }
.resource-row span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.resource-actions { display: flex; align-items: center; gap: 7px; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; }
.segmented button { min-height: 34px; padding: 6px 12px; border: 0; border-right: 1px solid var(--line-strong); background: #fff; color: var(--muted); }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--ink); color: #fff; }
.timeline-list { border-left: 2px solid var(--line); margin-left: 7px; padding-left: 22px; }
.timeline-item { position: relative; padding: 0 0 22px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before { content: ""; position: absolute; top: 3px; left: -28px; width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.timeline-item p { margin: 5px 0 0; color: var(--muted); line-height: 1.45; }
.timeline-meta { color: var(--muted); font-size: 11px; }

.action-grid { display: grid; grid-template-columns: minmax(170px, .7fr) minmax(210px, 1fr) minmax(250px, 1.5fr) auto; align-items: end; gap: 12px; }

.activity-list { display: grid; border-top: 1px solid var(--line); }
.activity-row { display: grid; grid-template-columns: 180px 140px minmax(0, 1fr); gap: 15px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.activity-row time, .activity-row span { color: var(--muted); font-size: 12px; }
.trace-list { display: grid; gap: 12px; }
.trace-item { border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.trace-header { display: flex; justify-content: space-between; gap: 15px; padding: 10px 12px; background: #ecefea; border-bottom: 1px solid var(--line); }
.trace-header code { color: var(--blue); }
.trace-item pre { margin: 0; padding: 14px; overflow: auto; background: #171918; color: #e4f2e8; font: 12px/1.55 Consolas, "Courier New", monospace; white-space: pre-wrap; word-break: break-word; }

.toast-region { position: fixed; z-index: 20; right: 20px; bottom: 20px; display: grid; gap: 8px; width: min(380px, calc(100vw - 40px)); }
.toast { padding: 13px 15px; border: 1px solid #e1c873; border-left: 4px solid var(--signal); border-radius: 4px; background: #fff; box-shadow: var(--shadow); }
.toast.error { border-color: #e7aab5; border-left-color: var(--red); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 184px minmax(0, 1fr); }
  .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .split-section { grid-template-columns: 1fr; }
  .split-section > div + div { padding: 30px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .local-content-workspace { grid-template-columns: 1fr; }
  .local-content-panel, .local-content-panel + .local-content-panel { padding: 18px 0; border-left: 0; }
  .local-content-panel + .local-content-panel { border-top: 1px solid var(--line); }
}

@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 14px; }
  .sidebar-brand { padding-bottom: 13px; }
  .primary-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 12px; }
  .sidebar-status { margin-top: 12px; }
  .topbar { min-height: 74px; padding: 14px 18px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .mode-switch { order: 2; width: 100%; }
  .mode-switch button { flex: 1; }
  .content { padding: 16px 14px 35px; }
  .metric-strip, .form-grid.three, .action-grid { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .section-band { padding: 18px 15px; }
  .section-heading { align-items: flex-start; }
  .filter-row, .workspace-loader { grid-template-columns: 1fr; }
  .activity-row { grid-template-columns: 1fr; gap: 4px; }
  .mode-notice { grid-template-columns: 1fr; gap: 5px; }
  .local-link-grid { grid-template-columns: 1fr; gap: 8px; }
  .link-arrow { text-align: center; transform: rotate(90deg); }
  .local-form-grid { grid-template-columns: 1fr; }
  .local-form-grid .wide { grid-column: auto; }
  .local-form-actions { align-items: stretch; flex-direction: column; }
  .login-panel { padding: 26px 22px; }
}
