:root {
  --bg: #0a0c10;
  --sidebar-bg: #0c0e13;
  --topbar-bg: #0a0c10;
  --panel: #12151b;
  --panel-2: #1a1e26;
  --panel-3: #212630;
  --border: #232833;
  --border-strong: #323a48;
  --text: #eef0f4;
  --text-secondary: #b0b6c2;
  --muted: #767e8c;

  --accent: #4d7cfe;
  --accent-strong: #6690ff;
  --accent-soft: rgba(77, 124, 254, 0.12);

  --green: #2ecf85;
  --green-soft: rgba(46, 207, 133, 0.12);
  --red: #f0546b;
  --red-soft: rgba(240, 84, 107, 0.12);
  --amber: #e3a83b;
  --amber-soft: rgba(227, 168, 59, 0.12);
  --neutral-soft: rgba(118, 126, 140, 0.14);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --sidebar-width: 248px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- app shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1.4rem 1.2rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 0.86rem; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.brand-subtext { font-size: 0.72rem; color: var(--muted); margin-top: 0.1rem; }

.sidebar-nav {
  flex: 1;
  padding: 0.9rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow-y: auto;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.6rem 0.7rem;
  font-size: 0.86rem;
  font-family: var(--sans);
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab-btn .nav-icon { flex-shrink: 0; opacity: 0.85; }
.tab-btn:hover { background: var(--panel-2); color: var(--text); }
.tab-btn.active { background: var(--accent-soft); color: var(--accent-strong); }
.tab-btn.active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 1rem 1.1rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.footer-note {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- main column ---------- */

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-topbar {
  padding: 1.4rem clamp(1.25rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-topbar h1 {
  margin: 0 0 0.3rem;
  font-size: 1.28rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.page-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  max-width: 62ch;
  line-height: 1.5;
}

.app-content {
  flex: 1;
  padding: 1.5rem clamp(1.25rem, 3vw, 2.5rem) 4rem;
  width: 100%;
  max-width: 1760px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- form surfaces ---------- */

.panel-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.25rem;
}

.panel-divider {
  height: 1px;
  background: var(--border);
  margin: 1.2rem 0;
}

.panel-subhead {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.8rem;
}

.panel-note {
  color: var(--text-secondary);
  font-size: 0.86rem;
  line-height: 1.6;
  margin: 0 0 1.1rem;
  max-width: 72ch;
}

.form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 160px;
}
.field-full { min-width: 100%; }
.field-id { min-width: 160px; }
.field-tenant { min-width: 260px; flex: 1 1 260px; }

.field-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-static {
  font-size: 0.86rem;
  color: var(--text-secondary);
  padding: 0.56rem 0;
  font-family: var(--mono);
}

.field-help {
  font-size: 0.76rem;
  color: var(--muted);
}

input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.56rem 0.7rem;
  font-size: 0.88rem;
  font-family: var(--sans);
  min-width: 160px;
  transition: border-color 0.12s ease, background 0.12s ease;
}
input::placeholder { color: var(--muted); }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; }

/* ---------- buttons ---------- */

button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.05rem;
  font-size: 0.86rem;
  font-family: var(--sans);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  transition: filter 0.12s ease, background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-verify { padding-inline: 1.4rem; }

.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--border-strong); background: var(--panel-3); }

.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: var(--panel-2); }

.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }

.btn-block { width: 100%; justify-content: center; }

/* ---------- lender checkbox grid ---------- */

.lender-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1.1rem;
}
.lender-check-grid label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease;
}
.lender-check-grid label:hover { border-color: var(--border-strong); color: var(--text); }
.lender-check-grid input[type="checkbox"] {
  min-width: auto;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  margin: 0;
}

/* ---------- status / hints ---------- */

.hint { color: var(--muted); font-size: 0.82rem; margin: 0 0 0.75rem; line-height: 1.5; }

.status-line { color: var(--muted); font-size: 0.84rem; min-height: 1.2rem; margin: 0.6rem 0; }
.status-line.error { color: var(--red); }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.badge-match { background: var(--green-soft); color: var(--green); }
.badge-divergent { background: var(--red-soft); color: var(--red); }
.badge-not_applicable { background: var(--neutral-soft); color: var(--muted); }
.badge-no_source_document { background: var(--amber-soft); color: var(--amber); }
.badge-error { background: var(--red-soft); color: var(--red); }

/* ---------- summary strip ---------- */

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.25rem;
}
.summary-chip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: capitalize;
}
.summary-chip b {
  font-size: 1.4rem;
  font-family: var(--mono);
  font-weight: 600;
  display: block;
  color: var(--text);
  margin-bottom: 0.15rem;
}

/* ---------- result cards ---------- */

.result-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem;
  margin-bottom: 0.85rem;
}
.result-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}
.result-header .case-label { font-family: var(--mono); font-size: 0.83rem; color: var(--text-secondary); }

/* ---------- overview rows (as expandable data rows) ---------- */

details.overview-item {
  border-bottom: 1px solid var(--border);
}
details.overview-item:last-child { border-bottom: none; }

details.overview-item summary.sweep-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  list-style: none;
  border-bottom: none;
  transition: background 0.1s ease;
}
details.overview-item summary.sweep-row::-webkit-details-marker { display: none; }
details.overview-item summary.sweep-row::before {
  content: "";
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  margin-right: 0.1rem;
}
details.overview-item[open] summary.sweep-row::before { transform: rotate(45deg); }
details.overview-item summary.sweep-row:hover { background: var(--panel-2); }

.sweep-row .case-id { font-family: var(--mono); width: 62px; flex-shrink: 0; color: var(--text-secondary); }
.sweep-row .case-label { flex-shrink: 0; font-weight: 500; min-width: 220px; }
.sweep-row .reason {
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
}

.overview-item-body { padding: 0.3rem 0.9rem 1.2rem; }

/* card wrapper around a grouped set of overview rows (per lender) */
.overview-group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 0.85rem;
  overflow: hidden;
}
.overview-group-head {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.section-heading {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin: 0.4rem 0 0.75rem;
}

.subhead {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
}
.subhead:first-child { margin-top: 0; }

/* ---------- steps table ---------- */

table.steps {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
table.steps th, table.steps td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
}
table.steps th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.steps td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.steps tr.mismatch td { color: var(--red); }
table.steps tr.match-row td.num { color: var(--green); }
table.steps tr.skipped td { color: var(--muted); font-style: italic; }
table.steps .root-marker { color: var(--red); font-weight: 700; margin-left: 0.5rem; font-style: normal; }

/* ---------- reason / diagnosis boxes ---------- */

.reason-box {
  background: var(--panel-2);
  border-left: 3px solid var(--amber);
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  line-height: 1.55;
  border-radius: var(--radius-sm);
  margin-top: 0.65rem;
}
.reason-box.error-box { border-left-color: var(--red); background: var(--red-soft); }
.reason-box.diagnosis-box { border-left-color: var(--green); background: var(--green-soft); }

/* ---------- collapsible detail sections ---------- */

details.raw-io { margin-top: 0.85rem; }
details.raw-io summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.82rem;
  padding: 0.4rem 0;
  font-weight: 500;
}
details.raw-io summary b { color: var(--text); }
details.raw-io pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  overflow-x: auto;
  font-size: 0.76rem;
  max-height: 340px;
  font-family: var(--mono);
}

table.kv-table td:first-child { color: var(--muted); width: 45%; }

pre.trace-block {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.74rem;
  line-height: 1.5;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 0;
  }
  .sidebar-brand { border-bottom: none; border-right: 1px solid var(--border); padding: 0.9rem 1rem; }
  .sidebar-nav { flex-direction: row; padding: 0.6rem; overflow-x: auto; }
  .tab-btn span { display: none; }
  .sidebar-footer { display: none; }
  .app-topbar, .app-content { padding-left: 1rem; padding-right: 1rem; }
  .form-row { flex-direction: column; align-items: stretch; }
  .field { min-width: 0; width: 100%; }
}
