:root {
  --bg: #e8eef2;
  --bg-deep: #d5e0e8;
  --panel: #f7fafc;
  --ink: #15202b;
  --muted: #5b6b78;
  --line: #c5d2dc;
  --accent: #0d7c74;
  --accent-soft: #d4efec;
  --danger: #b42318;
  --shadow: 0 18px 40px rgba(21, 32, 43, 0.08);
  --radius: 16px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --display: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 50% at 0% 0%, #c8dde8 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 100% 100%, #c5e4df 0%, transparent 50%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(247, 250, 252, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, var(--accent), #1aa39a 55%, #7ec8c2);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }

.patient-form label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; margin-top: 12px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.danger-ghost { background: transparent; color: var(--danger); border: 1px solid #f0b8b4; }
.btn.primary:hover:not(:disabled),
.btn.secondary:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); transition: .15s ease; }

.patient-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; flex: 1; }
.patient-item {
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.patient-item:hover { background: #fff; border-color: var(--line); }
.patient-item.active { background: #fff; border-color: var(--accent); box-shadow: var(--shadow); }
.patient-item strong { display: block; }
.patient-item span { color: var(--muted); font-size: 12px; }

.main { padding: 28px 28px 40px; min-width: 0; }
.empty-view {
  max-width: 520px;
  margin: 12vh auto 0;
  text-align: center;
}
.empty-view h1 {
  font-family: var(--display);
  font-size: clamp(32px, 5vw, 48px);
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}
.empty-view p { color: var(--muted); line-height: 1.55; }

.patient-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.patient-header h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); margin: 6px 0 0; }
.header-actions { display: flex; gap: 8px; }

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1.4fr) minmax(240px, .9fr);
  gap: 14px;
  align-items: start;
}

.panel {
  background: rgba(247, 250, 252, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; font-size: 15px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }

.study-list { display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow: auto; }
.study-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}
.study-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.study-item img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: #dfe8ee;
}
.study-item strong { display: block; margin-top: 6px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-item span { color: var(--muted); font-size: 11px; }

.canvas-wrap {
  position: relative;
  background:
    linear-gradient(45deg, #dfe8ee 25%, transparent 25%) -10px 0 / 20px 20px,
    linear-gradient(-45deg, #dfe8ee 25%, transparent 25%) -10px 0 / 20px 20px,
    #eef3f6;
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow: auto;
  max-height: 62vh;
  min-height: 280px;
}
#study-canvas {
  display: block;
  max-width: 100%;
  cursor: crosshair;
}
.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  pointer-events: none;
}
.canvas-empty[hidden] {
  display: none;
}

.analyze-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.status {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.status.error { color: var(--danger); }
.status.ok { color: var(--accent); }

.results-list { display: flex; flex-direction: column; gap: 8px; max-height: 28vh; overflow: auto; }
.result-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.result-item.active { border-color: var(--accent); }
.result-item strong { display: block; font-size: 13px; }
.result-item span { color: var(--muted); font-size: 11px; }
.result-detail { margin-top: 12px; }
.result-detail img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #111;
}
.result-detail pre {
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: #132028;
  color: #d7ebe7;
  font-size: 11px;
  overflow: auto;
  max-height: 220px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  width: min(420px, calc(100% - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(21, 32, 43, 0.35); }
dialog h3 { margin: 0 0 12px; font-family: var(--display); }
dialog label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 600; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .study-list { max-height: none; flex-direction: row; overflow-x: auto; }
  .study-item { min-width: 140px; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .patient-header { flex-direction: column; }
}
