:root {
  --bg: #08100d;
  --surface: #0d1814;
  --surface-2: #111f1a;
  --surface-3: #172822;
  --line: #263b33;
  --text: #f2f7f4;
  --muted: #8ca198;
  --green: #76f7a6;
  --green-2: #28c76f;
  --amber: #f4c86a;
  --red: #ff7c7c;
  --blue: #81b7ff;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.26);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 72% -10%, rgba(35, 145, 87, 0.18), transparent 30rem),
    var(--bg);
}

button, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 18px 20px;
  background: rgba(6, 15, 11, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: #07100c;
  font-weight: 900;
  background: var(--green);
  box-shadow: 0 0 28px rgba(118, 247, 166, 0.18);
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.sidebar-label {
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.case-list {
  display: grid;
  gap: 5px;
  overflow: auto;
  padding-right: 4px;
}

.upload-label { margin-top: 20px; }
.upload-box {
  display: grid;
  gap: 8px;
  margin: 0 6px 10px;
  padding: 11px;
  background: rgba(118, 247, 166, 0.04);
  border: 1px solid rgba(118, 247, 166, 0.16);
  border-radius: 11px;
}
.upload-box label { color: var(--green); font-size: 9px; font-weight: 900; letter-spacing: 0.08em; }
.upload-box input { width: 100%; color: var(--muted); font-size: 9px; }
.upload-box input::file-selector-button {
  margin-right: 7px;
  padding: 6px 8px;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.upload-box button {
  padding: 8px;
  color: #06100b;
  font-size: 10px;
  font-weight: 900;
  background: var(--green);
  border: 0;
  border-radius: 7px;
}
.upload-box button:disabled { opacity: 0.5; cursor: wait; }
.upload-box small, .sidebar-empty { margin: 0; color: var(--muted); font-size: 8px; line-height: 1.45; }
.document-list { display: grid; gap: 5px; max-height: 190px; overflow: auto; padding: 0 5px; }
.document-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  padding: 8px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
}
.document-button.active { color: var(--text); background: var(--surface-3); border-color: #315243; }
.document-type { color: var(--blue); font-size: 7px; font-weight: 900; }
.document-name { overflow: hidden; font-size: 9px; white-space: nowrap; text-overflow: ellipsis; }
.document-status { font-size: 7px; }
.document-status.parsed { color: var(--green); }
.document-status.extraction_failed { color: var(--red); }

.case-button {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 9px;
  align-items: center;
  width: 100%;
  padding: 10px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
}

.case-button:hover {
  color: var(--text);
  background: var(--surface-2);
}

.case-button.active {
  color: var(--text);
  background: var(--surface-3);
  border-color: #315243;
}

.case-index {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: var(--green);
  background: rgba(118, 247, 166, 0.08);
  font-size: 10px;
  font-weight: 800;
}

.case-button span:last-child {
  overflow: hidden;
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 16px 10px 4px;
  border-top: 1px solid var(--line);
}

.sidebar-footer strong, .sidebar-footer span { display: block; }
.sidebar-footer strong { font-size: 11px; }
.sidebar-footer span:not(.status-dot) { margin-top: 3px; color: var(--muted); font-size: 10px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
}

.workspace {
  width: min(1500px, 100%);
  padding: 34px clamp(22px, 4vw, 64px) 80px;
}

.topbar, .case-heading, .panel-header, .decision-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 3vw, 38px); letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: 22px; letter-spacing: -0.025em; }
h3 { margin: 0; font-size: 15px; }

.panel-actions { display: flex; align-items: center; gap: 8px; }
.panel-button {
  padding: 6px 9px;
  color: var(--green);
  font-size: 9px;
  font-weight: 900;
  background: rgba(118, 247, 166, 0.06);
  border: 1px solid rgba(118, 247, 166, 0.22);
  border-radius: 7px;
}
.panel-button:disabled { color: var(--muted); opacity: 0.55; cursor: not-allowed; }

.topbar-subtitle {
  max-width: 760px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.topbar-actions { display: flex; align-items: end; gap: 10px; }

.mode-control { display: grid; gap: 5px; }
.mode-control span { color: var(--muted); font-size: 10px; font-weight: 800; }

select, textarea {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}

select { min-width: 142px; padding: 10px 12px; }
textarea { width: 100%; padding: 12px; resize: vertical; }
select:focus, textarea:focus { border-color: var(--green-2); }

.primary-button, .secondary-button {
  padding: 11px 17px;
  border-radius: 10px;
  border: 0;
  font-weight: 800;
}

.primary-button {
  color: #06100b;
  background: var(--green);
}

.primary-button:hover { background: #9affbd; }
.primary-button:disabled { opacity: 0.45; cursor: wait; }

.secondary-button {
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid #355547;
}

.secondary-button:disabled { opacity: 0.4; cursor: not-allowed; }

.capability-banner,
.safety-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
}

.capability-banner {
  margin: 28px 0 10px;
  background: rgba(129, 183, 255, 0.035);
  border: 1px solid rgba(129, 183, 255, 0.16);
}

.capability-banner span,
.safety-banner span {
  padding: 5px 8px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  border-radius: 6px;
}

.capability-banner .connected {
  color: var(--green);
  background: rgba(118, 247, 166, 0.07);
}

.capability-banner .planned {
  color: var(--amber);
  background: rgba(244, 200, 106, 0.08);
}

.capability-banner .disconnected {
  color: var(--red);
  background: rgba(255, 124, 124, 0.08);
}

.safety-banner {
  margin: 0 0 28px;
  background: rgba(118, 247, 166, 0.035);
  border: 1px solid rgba(118, 247, 166, 0.15);
}

.safety-banner span {
  color: var(--green);
  background: rgba(118, 247, 166, 0.07);
}

.quality-section {
  margin: 0 0 28px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(118, 247, 166, 0.07), rgba(13, 24, 20, 0.92));
  border: 1px solid rgba(118, 247, 166, 0.2);
  border-radius: 16px;
}

.quality-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.quality-run { color: var(--muted); font-size: 10px; text-align: right; }
.quality-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 9px; }
.quality-card {
  min-width: 0;
  padding: 13px;
  background: rgba(4, 11, 8, 0.38);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.quality-card.emphasis { border-color: rgba(118, 247, 166, 0.48); }
.quality-card span, .quality-card strong, .quality-card small { display: block; }
.quality-card span { color: var(--muted); font-size: 9px; font-weight: 800; }
.quality-card strong { margin: 7px 0 5px; color: var(--green); font-size: 21px; letter-spacing: -0.04em; }
.quality-card small { overflow: hidden; color: var(--muted); font-size: 8px; line-height: 1.4; text-overflow: ellipsis; }
.quality-caveat { margin: 12px 0 0; color: var(--muted); font-size: 9px; line-height: 1.5; }

.case-heading { margin: 0 0 18px; }
.case-state {
  padding: 7px 11px;
  color: var(--muted);
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.case-state.ready { color: var(--green); border-color: #2d6848; }

.review-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(17, 31, 26, 0.94), rgba(12, 23, 19, 0.96));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 58px;
  padding: 14px 17px;
  border-bottom: 1px solid var(--line);
}

.panel-header > div { display: flex; align-items: center; gap: 9px; }
.step { color: var(--green); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }
.panel-kicker { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.panel-body { min-height: 300px; padding: 17px; }

.decision-panel { grid-column: 1 / -1; }
.decision-panel .panel-body { min-height: auto; }

.meta-row, .fact-row, .evidence-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(38, 59, 51, 0.68);
}

.meta-row:last-child, .fact-row:last-child, .evidence-row:last-child { border-bottom: 0; }
.row-label { color: var(--muted); font-size: 10px; font-weight: 700; }
.row-value { min-width: 0; overflow-wrap: anywhere; font-size: 12px; line-height: 1.5; }
.row-value.missing { color: var(--amber); }

.message {
  margin-top: 14px;
  padding: 14px;
  color: #d5e2dc;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.18);
  border-left: 2px solid var(--green-2);
  border-radius: 4px 10px 10px 4px;
}

.attachment {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  padding: 10px;
  color: var(--muted);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.025);
  border-radius: 8px;
}

.tag {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 3px 6px;
  color: var(--blue);
  font-size: 9px;
  background: rgba(129, 183, 255, 0.08);
  border-radius: 5px;
}

.attention-list { display: grid; gap: 9px; margin-top: 14px; }
.attention {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 9px;
}
.attention.blocking { border-left-color: var(--red); }
.attention.warning { border-left-color: var(--amber); }
.attention.info { border-left-color: var(--blue); }
.attention strong { display: block; margin-bottom: 5px; font-size: 11px; }
.attention p { margin-bottom: 7px; color: #c8d6d0; font-size: 11px; line-height: 1.5; }
.evidence-ref { color: var(--muted); font-family: ui-monospace, monospace; font-size: 9px; overflow-wrap: anywhere; }

.summary {
  margin-bottom: 14px;
  padding: 13px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  background: rgba(118, 247, 166, 0.06);
  border-radius: 9px;
}

.empty-state {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.decision-body { display: grid; gap: 16px; }
.decision-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.decision-button {
  padding: 15px;
  color: var(--muted);
  text-align: left;
  background: rgba(0, 0, 0, 0.13);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.decision-button strong, .decision-button span { display: block; }
.decision-button strong { color: var(--text); font-size: 13px; }
.decision-button span { margin-top: 4px; font-size: 10px; }
.decision-button.selected.confirm { border-color: var(--green); background: rgba(118, 247, 166, 0.08); }
.decision-button.selected.correct { border-color: var(--amber); background: rgba(244, 200, 106, 0.08); }
.decision-button.selected.hold { border-color: var(--red); background: rgba(255, 124, 124, 0.08); }

.reason-field { display: grid; gap: 7px; }
.reason-field > span { color: var(--muted); font-size: 10px; font-weight: 800; }
.decision-submit p { margin: 0; color: var(--muted); font-size: 10px; }
.decision-result { min-height: 18px; color: var(--green); font-size: 11px; }

.audit-section { margin-top: 34px; padding-top: 26px; border-top: 1px solid var(--line); }
.audit-list { display: grid; gap: 8px; margin-top: 16px; }
.audit-event {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 11px 13px;
  font-size: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.audit-event code { color: var(--green); }
.audit-event time { color: var(--muted); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(440px, calc(100vw - 44px));
  padding: 12px 15px;
  color: var(--text);
  font-size: 11px;
  background: #172822;
  border: 1px solid #355547;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #7b4141; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .review-grid { grid-template-columns: 1fr; }
  .decision-panel { grid-column: auto; }
  .quality-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; }
  .case-list { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 220px; }
  .sidebar-footer { margin-top: 18px; }
  .workspace { padding: 24px 15px 60px; }
  .topbar, .case-heading { align-items: flex-start; flex-direction: column; }
  .quality-heading { align-items: flex-start; flex-direction: column; }
  .quality-run { text-align: left; }
  .quality-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-actions { width: 100%; }
  .mode-control { flex: 1; }
  select { width: 100%; }
  .decision-options { grid-template-columns: 1fr; }
  .decision-submit { align-items: flex-start; flex-direction: column; }
  .meta-row, .fact-row, .evidence-row { grid-template-columns: 105px 1fr; }
  .audit-event { grid-template-columns: 1fr; }
}
