/* KERA AI — clinical instrument UI (v6) */

:root {
  --ink: #142028;
  --ink-soft: #3a4d5a;
  --muted: #6a7d8a;
  --line: #cfd9e0;
  --line-soft: #e6ecf0;
  --surface: #fff;
  --surface-2: #f3f6f8;
  --bg: #e9eef1;
  --brand: #0b2f38;
  --accent: #12665c;
  --accent-deep: #0d4f47;
  --safe: #0d6b3c;
  --caution: #8a5a00;
  --stop: #a31b12;
  --radius: 6px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Header — brand first, quiet chrome */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }

.brand-mark {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -0.03em;
  line-height: 1;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.theme-toggle {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 0.04em;
}
.theme-toggle:hover { color: var(--ink); border-color: #aebcc6; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 56px;
}

/* Tabs — mode switcher, not marketing */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.tab-muted { opacity: 0.55; }
.tab-note {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 4px;
  color: var(--muted);
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fade 0.25s var(--ease); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
}
.panel.compact { padding: 14px 18px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.error { border-color: #e2b4b0; background: #faf2f1; color: var(--stop); }

.panel h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.panel-head h3 { margin-bottom: 0; }

.hint { font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 0.78rem; }
.error-text { color: var(--stop); font-size: 0.85rem; }

/* Forms */
.form-row-3, .form-row-4 {
  display: grid;
  gap: 10px 12px;
}
.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-row-4 { grid-template-columns: repeat(4, 1fr); }

.field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}
.field input, .field select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(18, 102, 92, 0.12);
}

.btn-run {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 160px;
  padding: 11px 18px;
  margin: 4px 0 16px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 4px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
}
.btn-run:hover { background: #0a2530; }

.file-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.file-label input { max-width: 220px; font-size: 0.8rem; }
.file-label.is-disabled { opacity: 0.5; cursor: not-allowed; }

/* Filters (secondary — not clone of tabs) */
.filter-row { display: flex; flex-wrap: wrap; gap: 4px; }
.filter {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.filter:hover { border-color: #aebcc6; color: var(--ink); }
.filter.active {
  background: var(--surface-2);
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

/* Split list / detail */
.split {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 12px;
  align-items: start;
}

.detail-pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
}
.empty-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  background: var(--surface-2);
}
.empty-pane .hint { margin: 0; }

.patient-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.detail-top .patient-title { margin-bottom: 0; flex: 1; min-width: 160px; }

.btn-send {
  appearance: none;
  border: 1px solid var(--brand);
  background: var(--surface);
  color: var(--brand);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-send:hover {
  background: var(--brand);
  color: #fff;
}
.btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-send:disabled:hover {
  background: var(--surface);
  color: var(--brand);
}
.btn-send-sm {
  padding: 5px 8px;
  font-size: 0.7rem;
}
.case-line { font-size: 0.84rem; color: var(--ink-soft); margin-bottom: 12px; }
.list-caption {
  padding: 12px 14px 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--brand);
}

/* Metrics */
.metrics {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 10px 18px;
  align-items: center;
}
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-k { font-size: 0.68rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-v { font-size: 0.95rem; font-weight: 700; color: var(--ink); }
.metric-bar {
  display: flex;
  height: 6px;
  background: var(--line-soft);
  border-radius: 3px;
  overflow: hidden;
  grid-column: 1 / -1;
}
.metric-bar i { display: block; height: 100%; }
.mb-safe { background: var(--safe); }
.mb-caution { background: #c49200; }
.mb-stop { background: var(--stop); }
.metric-legend {
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
  font-size: 0.72rem;
  font-weight: 600;
}
.metric-note {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0;
}

.st-na { color: var(--muted); font-weight: 500; }

.ectasia-kicker {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.ectasia-stage { color: var(--ink-soft); font-weight: 500; margin-left: 6px; }
.gate-note {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin: -6px 0 12px;
  padding-left: 2px;
}
.step-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.step-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.block-note {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-size: 0.72rem;
}
.cxl-row .verdict-matrix {
  grid-template-columns: minmax(120px, 180px);
}
.col-cxl { border-left: 1px solid var(--line); }

/* Tables */
.table-wrap { overflow: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.data-table th {
  text-align: left;
  padding: 9px 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.th-verdict {
  display: table-cell;
}
.th-verdict span {
  display: block;
  margin-bottom: 4px;
}
.verdict-filter {
  appearance: none;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236a7d8a'/%3E%3C/svg%3E") no-repeat right 8px center;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 22px 4px 8px;
  min-width: 9.5rem;
  cursor: pointer;
}
.verdict-filter:hover { border-color: var(--accent); }
.verdict-filter:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(18, 102, 92, 0.15);
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.data-table.tight td, .data-table.tight th { padding: 6px 10px; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: #eef3f5; }
.data-table tr.selected { background: #e4eef0; }
.col-focus { background: rgba(18, 102, 92, 0.06); }

/* Status — text weight, not pastel wallpaper */
.st-safe { color: var(--safe); font-weight: 700; }
.st-caution { color: var(--caution); font-weight: 650; }
.st-stop { color: var(--stop); font-weight: 700; }

/* Results */
.results-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-top: 8px;
}

.ectasia-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 4px;
  margin-bottom: 14px;
  background: var(--surface-2);
  font-size: 0.9rem;
}
.ectasia-row.st-safe { border-left-color: var(--safe); }
.ectasia-row.st-caution { border-left-color: var(--caution); }
.ectasia-row.st-stop { border-left-color: var(--stop); }
.ectasia-meta { margin-left: auto; font-size: 0.75rem; color: var(--muted); font-weight: 500; }

.block-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 12px 0 6px;
}

.verdict-matrix {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.vm-cell {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 8px;
  text-align: center;
  background: var(--surface);
}
.vm-proc {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.vm-val { font-size: 0.84rem; font-weight: 700; }
.vm-cell.st-safe .vm-val { color: var(--safe); }
.vm-cell.st-caution .vm-val { color: var(--caution); }
.vm-cell.st-stop .vm-val { color: var(--stop); }
.vm-cell.vm-focus {
  border-color: var(--safe);
  box-shadow: inset 0 0 0 1px var(--safe);
  background: #f2faf5;
}
.vm-click {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.vm-click:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
}
.checks.check-flash {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.meta-row span {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  border: 1px solid var(--line-soft);
  padding: 4px 8px;
  border-radius: 3px;
  background: var(--surface-2);
}

.checks {
  border: 1px solid var(--line);
  border-radius: 4px;
  margin: 6px 0;
  overflow: hidden;
}
.checks summary {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 650;
  background: var(--surface-2);
  list-style: none;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: baseline;
}
.checks summary::-webkit-details-marker { display: none; }
.checks[open] summary { border-bottom: 1px solid var(--line); }

/* Dark */
body.dark {
  --ink: #e6eef2;
  --ink-soft: #b4c2cb;
  --muted: #8494a0;
  --line: #2c3b44;
  --line-soft: #223038;
  --surface: #121c22;
  --surface-2: #0d151a;
  --bg: #0a1115;
  --brand: #d5e6ea;
  --accent: #3aa899;
  --safe: #45c07a;
  --caution: #e0b03a;
  --stop: #f07a70;
}
body.dark .data-table tr.clickable:hover { background: #18242c; }
body.dark .data-table tr.selected { background: #1c3034; }
body.dark .vm-cell.vm-focus { background: #14241c; }
body.dark .empty-pane { background: #0d151a; }
body.dark .btn-run:hover { background: #1a3a44; }

/* ── 4-Map workspace ── */
.fourmap { animation: fade 0.3s var(--ease); }

.fourmap-drop {
  appearance: none;
  width: 100%;
  border: 1px dashed var(--line);
  background: var(--surface);
  border-radius: 8px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.fourmap-drop:hover,
.fourmap-drop.is-drag {
  border-color: var(--accent);
  background: rgba(18, 102, 92, 0.05);
}
.fourmap-drop-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -0.02em;
}
.fourmap-drop-sub { font-size: 0.88rem; color: var(--muted); }

.fourmap-room {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.fourmap-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}

.fourmap-file {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fourmap-zoom-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.btn-quiet {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-quiet:hover { border-color: var(--accent); color: var(--accent-deep); }

.zoom-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}
.zoom-btn:hover { border-color: var(--accent); }
.zoom-pct {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.8em;
}

.fourmap-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 520px;
}

.fourmap-viewer {
  position: relative;
  background: #1a2228;
  min-height: 520px;
  height: min(68vh, 720px);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  outline: none;
}
.fourmap-viewer:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(18, 102, 92, 0.5);
}
.fourmap-viewer.is-panning { cursor: grabbing; }

.fourmap-viewer img {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
.fourmap-viewer img.is-animated {
  transition: transform 0.16s var(--ease);
}

.fourmap-side {
  border-left: 1px solid var(--line-soft);
  padding: 14px 14px 16px;
  background: var(--surface);
  overflow: auto;
  max-height: min(68vh, 720px);
}

.fourmap-side h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.fourmap-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.fourmap-fields .field label {
  font-size: 0.7rem;
}
.fourmap-fields .field input {
  padding: 7px 8px;
}

.fourmap-side .btn-run {
  width: 100%;
  margin-top: 12px;
}
.fourmap-side .hint { margin-top: 6px; }

.fourmap-ocr {
  margin-top: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.fourmap-ocr .btn-run { width: 100%; margin-top: 12px; }
.fourmap-ocr .fourmap-fields {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.fourmap-below {
  margin-top: 14px;
}
.fourmap-below:empty { margin-top: 0; }
#jpg-eval .results-shell {
  margin-top: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 700px) {
  .fourmap-ocr .fourmap-fields { grid-template-columns: 1fr 1fr; }
}

body.dark .fourmap-toolbar { background: #0d151a; }
body.dark .fourmap-viewer { background: #0a1014; }
body.dark .zoom-btn,
body.dark .btn-quiet { background: #121a20; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .detail-pane { position: static; max-height: none; }
  .verdict-matrix { grid-template-columns: repeat(3, 1fr); }
  .metrics { grid-template-columns: 1fr 1fr 1fr; }
  .fourmap-body { grid-template-columns: 1fr; }
  .fourmap-viewer { height: 48vh; min-height: 280px; }
  .fourmap-side {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
    max-height: none;
  }
  .fourmap-drop { min-height: 220px; }
}
@media (max-width: 700px) {
  .form-row-3, .form-row-4 { grid-template-columns: 1fr 1fr; }
  .verdict-matrix { grid-template-columns: 1fr 1fr; }
  main { padding: 16px; }
}
@media (max-width: 480px) {
  .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
}
