/* ═══════════════════════════════════════════════════════════════
   NeuroTrace AI — Medical-Grade UI Stylesheet
   Research-based Tremor & Parkinson's Diagnostic System
═══════════════════════════════════════════════════════════════ */

:root {
  --primary:       #1a3a6b;
  --primary-light: #2a5298;
  --accent:        #0ea5e9;
  --healthy:       #10b981;
  --et-color:      #f59e0b;
  --pd-color:      #ef4444;
  --bg:            #f0f4f8;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --shadow:        0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.12);
  --radius:        12px;
  --radius-sm:     8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ─── HEADER ─────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 0 24px;
  height: 70px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 20px rgba(26,58,107,0.4);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-icon {
  font-size: 32px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.brand-text h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-text span {
  font-size: 11px;
  opacity: 0.75;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pulse-dot.training {
  background: #fbbf24;
  animation: pulse 1.2s ease-in-out infinite;
}

.pulse-dot.ready {
  background: #10b981;
  animation: none;
}

.pulse-dot.error {
  background: #ef4444;
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

/* ─── MAIN ────────────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

/* ─── PANELS ──────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 32px;
  margin-bottom: 24px;
}

.center-panel {
  max-width: 640px;
  margin: 0 auto 24px;
  text-align: center;
}

.panel-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
}

.panel-sub {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}

/* ─── PROGRESS BAR ────────────────────────────────────────── */
.progress-track {
  background: #e2e8f0;
  border-radius: 8px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary-light));
  border-radius: 8px;
  transition: width 0.4s ease;
}

.progress-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.training-log {
  text-align: left;
  background: #0f172a;
  color: #94a3b8;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  min-height: 80px;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.8;
}

.training-log .log-ok   { color: #10b981; }
.training-log .log-info { color: #60a5fa; }
.training-log .log-warn { color: #fbbf24; }

/* ─── FORM ────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
  text-align: left;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.12);
}

/* ─── BUTTONS ─────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(42,82,152,0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(42,82,152,0.45);
}

.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--primary-light);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-ghost:hover {
  background: #f1f5f9;
  border-color: var(--accent);
}

/* ─── TASK NAVIGATION ─────────────────────────────────────── */
.task-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.task-step {
  flex: 1;
  min-width: 80px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 2px solid var(--border);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
  cursor: default;
}

.task-step.active {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--primary-light);
}

.task-step.done {
  border-color: var(--healthy);
  background: #ecfdf5;
  color: var(--healthy);
}

.task-step .step-icon { font-size: 18px; display: block; margin-bottom: 4px; }
.task-step .step-name { display: block; }

/* ─── DRAWING CARD ────────────────────────────────────────── */
.draw-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.draw-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.task-badge {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.task-meta h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.task-meta p {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 480px;
}

.draw-controls {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  align-items: center;
}

/* ─── CANVAS ──────────────────────────────────────────────── */
.canvas-wrap {
  position: relative;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  touch-action: none;
  user-select: none;
}

#templateCanvas,
#drawingCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#templateCanvas { z-index: 1; }
#drawingCanvas  { z-index: 2; cursor: crosshair; }

.canvas-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 13px;
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.4s;
  white-space: nowrap;
}

.canvas-hint.hidden { opacity: 0; }

/* ─── LIVE STATS ──────────────────────────────────────────── */
.live-stats {
  display: flex;
  gap: 0;
  border-top: 1px solid var(--border);
}

.stat {
  flex: 1;
  padding: 12px 16px;
  text-align: center;
  border-right: 1px solid var(--border);
}

.stat:last-child { border-right: none; }

.stat-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.stat-val {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

/* ─── RESULTS ─────────────────────────────────────────────── */
.results-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.results-topbar h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

/* ─── DIAGNOSIS CARD ──────────────────────────────────────── */
.diagnosis-card {
  display: flex;
  gap: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  margin-bottom: 20px;
  border-left: 6px solid var(--border);
  transition: border-color 0.4s;
  align-items: flex-start;
  flex-wrap: wrap;
}

.diagnosis-card.healthy { border-left-color: var(--healthy); }
.diagnosis-card.et      { border-left-color: var(--et-color); }
.diagnosis-card.pd      { border-left-color: var(--pd-color); }

.dx-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 100px;
}

.dx-icon { font-size: 56px; line-height: 1; }

.dx-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 12px;
  border-radius: 20px;
  background: #f1f5f9;
  color: var(--text-muted);
}

.dx-label.healthy { background: #ecfdf5; color: var(--healthy); }
.dx-label.et      { background: #fffbeb; color: var(--et-color); }
.dx-label.pd      { background: #fef2f2; color: var(--pd-color); }

.dx-right { flex: 1; min-width: 260px; }

.dx-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.dx-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.severity-section { margin-top: 8px; }

.severity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.severity-score {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
}

.severity-track {
  background: #e2e8f0;
  border-radius: 8px;
  height: 12px;
  overflow: hidden;
  margin-bottom: 6px;
}

.severity-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
  transition: width 1s ease;
}

.severity-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── CONFIDENCE ──────────────────────────────────────────── */
.confidence-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.conf-item {
  flex: 1;
  min-width: 160px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 16px;
  border: 1.5px solid var(--border);
}

.conf-item.winner { border-color: var(--accent); background: #eff6ff; }

.conf-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.conf-pct {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 8px;
}

.conf-bar-track {
  background: #e2e8f0;
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.conf-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease;
}

.conf-bar-fill.healthy { background: var(--healthy); }
.conf-bar-fill.et      { background: var(--et-color); }
.conf-bar-fill.pd      { background: var(--pd-color); }

/* ─── CARDS ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.chart-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -10px;
  margin-bottom: 16px;
}

/* ─── CHARTS ROW ──────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.chart-card { margin-bottom: 0; }

/* ─── FEATURES GRID ───────────────────────────────────────── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.feat-item {
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1px solid var(--border);
}

.feat-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}

.feat-val {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.feat-bar-track {
  background: #e2e8f0;
  border-radius: 3px;
  height: 4px;
  margin-top: 6px;
  overflow: hidden;
}

.feat-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.6s ease;
}

.feat-bar-fill.high   { background: var(--pd-color); }
.feat-bar-fill.medium { background: var(--et-color); }
.feat-bar-fill.low    { background: var(--healthy); }

/* ─── ENSEMBLE GRID ───────────────────────────────────────── */
.ensemble-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.model-item {
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 16px;
  border: 1.5px solid var(--border);
}

.model-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.model-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

.model-pred {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.model-pred-label { font-weight: 600; }
.model-pred-conf  { color: var(--text-muted); }

/* ─── CITATIONS ───────────────────────────────────────────── */
.citations-card {}

.citation-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.6;
}

.citation-item:last-child { border-bottom: none; }

.citation-num {
  display: inline-block;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  margin-right: 8px;
}

.citation-title { font-weight: 600; color: var(--primary); }
.citation-meta  { color: var(--text-muted); }

/* ─── DISCLAIMER ──────────────────────────────────────────── */
.disclaimer {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ─── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 700px) {
  header { padding: 0 16px; }
  main   { padding: 20px 12px 40px; }

  .panel { padding: 28px 20px; }

  .form-grid { grid-template-columns: 1fr; }

  .draw-header { flex-direction: column; }
  .draw-controls { width: 100%; justify-content: flex-end; }

  .charts-row { grid-template-columns: 1fr; }

  .diagnosis-card { flex-direction: column; }

  .confidence-row { flex-direction: column; }

  .task-nav { gap: 4px; }
  .task-step { min-width: 60px; font-size: 10px; padding: 8px 4px; }
  .task-step .step-icon { font-size: 14px; }

  .live-stats { flex-wrap: wrap; }
  .stat { min-width: 50%; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ─── SCROLLBAR ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── ANIMATIONS ──────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.4s ease forwards; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.slide-up { animation: slideUp 0.5s ease forwards; }