:root {
  --bg: #0f1720;
  --bg-soft: #16202b;
  --panel: #1b2632;
  --panel-2: #212e3d;
  --line: #2c3a4a;
  --text: #e6edf3;
  --muted: #8a97a6;
  --accent: #4f9cff;
  --accent-2: #6ab0ff;
  --ok: #43c08d;
  --warn: #f0a33a;
  --err: #e5645e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0,0,0,.28);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mt { margin-top: 18px; }

/* -------- GATE -------- */
.gate {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(79,156,255,.18), transparent 60%),
    var(--bg);
}
.gate-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 36px 32px;
  width: 340px;
  text-align: center;
  box-shadow: var(--shadow);
}
.gate-logo {
  font-size: 40px;
  color: var(--accent);
  margin-bottom: 8px;
}
.gate-card h1 {
  font-size: 18px;
  margin: 0 0 6px;
  font-weight: 600;
}
.gate-card p { margin: 0 0 20px; font-size: 13px; }
.gate-card input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-error {
  color: var(--err);
  font-size: 13px;
  min-height: 18px;
  margin-top: 10px;
}

/* -------- TOPBAR -------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7ab6ff);
  color: #0b1220;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 700;
}
.brand-title { font-weight: 600; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* -------- LAYOUT -------- */
.layout {
  display: grid;
  grid-template-columns: 280px minmax(340px, 1fr) minmax(380px, 1.1fr);
  gap: 16px;
  padding: 16px 24px 24px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  overflow: auto;
  min-height: 0;
}
.panel-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}

/* -------- FORM -------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg-soft);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.seg {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: all .15s;
}
.seg:hover { color: var(--text); }
.seg.active {
  background: var(--accent);
  color: #07111f;
  font-weight: 600;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 18px 0;
}

.symptoms-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.symptoms-head .panel-title { margin: 0; }
.link-btn {
  background: none; border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font);
}
.link-btn:hover { text-decoration: underline; }

.symptoms { display: flex; flex-direction: column; gap: 14px; }
.sym-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent-2);
  margin-bottom: 6px;
  font-weight: 600;
}
.sym-list { display: flex; flex-direction: column; gap: 4px; }
.sym {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background .12s;
  user-select: none;
}
.sym:hover { background: var(--panel-2); }
.sym input { display: none; }
.sym .box {
  width: 16px; height: 16px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: all .12s;
}
.sym input:checked + .box {
  background: var(--accent);
  border-color: var(--accent);
}
.sym input:checked + .box::after {
  content: "✓";
  color: #07111f;
  font-size: 12px;
  font-weight: 700;
}
.sym input:checked ~ .label { color: var(--text); font-weight: 500; }

/* -------- TEXTAREA -------- */
textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: vertical;
  outline: none;
  min-height: 100px;
}
textarea:focus { border-color: var(--accent); }

/* -------- BUTTONS -------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07111f;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(79,156,255,.35); }
.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn-icon { font-size: 14px; }

.actions {
  display: flex; align-items: center; gap: 14px;
  margin-top: 12px;
}
.status { font-size: 13px; }

/* -------- RESULTS -------- */
.results {
  display: flex; flex-direction: column; gap: 8px;
}
.icd-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: all .15s;
}
.icd-card:hover {
  border-color: var(--accent);
  border-left-color: var(--accent);
  transform: translateX(2px);
}
.icd-card.selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background: linear-gradient(90deg, rgba(79,156,255,.14), transparent);
}
.icd-card[data-conf="high"] { border-left-color: var(--ok); }
.icd-card[data-conf="medium"] { border-left-color: var(--warn); }
.icd-card[data-conf="low"] { border-left-color: var(--err); }

.icd-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px;
}
.icd-code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
  letter-spacing: .02em;
}
.icd-name { font-weight: 500; font-size: 14px; flex: 1; }
.icd-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
.icd-badge[data-conf="high"] { background: rgba(67,192,141,.15); color: var(--ok); }
.icd-badge[data-conf="medium"] { background: rgba(240,163,58,.15); color: var(--warn); }
.icd-badge[data-conf="low"] { background: rgba(229,100,94,.15); color: var(--err); }

.icd-why {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* -------- RIGHT PANEL -------- */
.kr-header {
  background: var(--bg-soft);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.kr-header strong { color: var(--text); }
.kr-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(79,156,255,.15);
  color: var(--accent-2);
  margin-left: 6px;
  font-weight: 600;
}

.services {
  display: flex; flex-direction: column; gap: 8px;
}
.svc-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.svc-top { display: flex; align-items: baseline; gap: 10px; }
.svc-code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}
.svc-name { font-size: 13.5px; font-weight: 500; }
.svc-why {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* -------- EMPTY / LOADER -------- */
.empty-state {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 40px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}

.loader {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }