/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg:        #f8fafc;
  --bg2:       #ffffff;
  --bg3:       #f1f5f9;
  --border:    #e2e8f0;
  --accent:    #0284c7;
  --accent2:   #d97706;
  --danger:    #dc2626;
  --text:      #0f172a;
  --text-dim:  #64748b;
  --text-mid:  #475569;
  --cnn-color: #0284c7;
  --rf-color:  #d97706;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'DM Sans', sans-serif;
  --radius:    6px;
  --radius-lg: 12px;
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(248,250,252,.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: .75rem; }
.logo-icon { width: 44px; height: 22px; }
.logo-text {
  font-family: var(--font-mono);
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .04em;
}
.logo-accent { color: var(--accent); }

.nav { display: flex; gap: .25rem; }
.nav-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .08em;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color .2s, background .2s;
  text-transform: uppercase;
}
.nav-btn:hover  { color: var(--text);   background: var(--bg3); }
.nav-btn.active { color: var(--accent); background: rgba(2,132,199,.08); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tab { display: none; }
.tab.active { display: block; }

/* ── Container ───────────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 3rem 2rem 4rem;
}

/* ── Hero ────────────────────────────────────────────────────────────────── */
.hero    { margin-bottom: 2.5rem; }
.hero-sm { margin-bottom: 2rem; }
.hero-label {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--accent);
  letter-spacing: .15em;
  text-transform: uppercase;
  margin-bottom: .75rem;
}
.hero-title {
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.02em;
  margin-bottom: 1rem;
  color: var(--text);
}
.accent  { color: var(--accent); }
.hero-sub {
  max-width: 520px;
  color: var(--text-mid);
  font-size: .95rem;
  line-height: 1.7;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.card-label {
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .14em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ── Input tabs ──────────────────────────────────────────────────────────── */
.input-tabs { display: flex; gap: .25rem; }
.input-tab {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .06em;
  padding: .35rem .8rem;
  cursor: pointer;
  transition: all .2s;
}
.input-tab:hover  { color: var(--text);   border-color: var(--text-dim); }
.input-tab.active { color: var(--accent); border-color: var(--accent);   background: rgba(2,132,199,.06); }

/* ── Input panels ────────────────────────────────────────────────────────── */
.input-panel        { display: none; }
.input-panel.active { display: block; }

.field-label {
  display: block;
  font-size: .8rem;
  color: var(--text-dim);
  margin-bottom: .5rem;
  font-family: var(--font-mono);
}
.signal-textarea {
  width: 100%;
  height: 110px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .8rem;
  padding: .75rem 1rem;
  resize: vertical;
  transition: border-color .2s;
  outline: none;
}
.signal-textarea:focus { border-color: var(--accent); }
.sample-count {
  display: block;
  text-align: right;
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-dim);
  margin-top: .4rem;
}

/* ── Ground Truth ────────────────────────────────────────────────────────── */
.ground-truth-wrap {
  margin-top: 1.25rem;
}
.ground-truth-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
}
.gt-label-text {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.gt-select {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .82rem;
  cursor: pointer;
}
.gt-badge {
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 700;
  padding: .15rem .5rem;
  border-radius: 3px;
  background: rgba(2,132,199,.1);
  color: var(--accent);
  border: 1px solid rgba(2,132,199,.2);
  white-space: nowrap;
}
.gt-badge.gt-auto {
  background: rgba(5,150,105,.1);
  color: #059669;
  border-color: rgba(5,150,105,.25);
}

/* ── Drop zone ───────────────────────────────────────────────────────────── */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  text-align: center;
}
.drop-zone:hover, .drop-zone.over {
  border-color: var(--accent);
  background: rgba(2,132,199,.04);
}
.upload-icon { width: 32px; height: 32px; color: var(--text-dim); }
.drop-text   { color: var(--text-mid); font-size: .9rem; }
.drop-hint   { font-size: .78rem; color: var(--text-dim); font-family: var(--font-mono); }

/* ── Random panel ────────────────────────────────────────────────────────── */
.random-desc { color: var(--text-mid); font-size: .9rem; margin-bottom: 1rem; }

/* ── ECG preview canvas ──────────────────────────────────────────────────── */
.signal-preview {
  margin: 1.25rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f0f9ff;
}
.signal-preview canvas { display: block; width: 100%; height: 80px; }
.hidden { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .08em;
  padding: .65rem 1.4rem;
  transition: all .2s;
  text-transform: uppercase;
  white-space: nowrap;
}
.btn-primary {
  width: 100%;
  margin-top: 1.25rem;
  padding: .85rem;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: .82rem;
  letter-spacing: .1em;
}
.btn-primary:hover    { background: #0369a1; box-shadow: 0 4px 14px rgba(2,132,199,.3); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mid);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* ── Loader dots ─────────────────────────────────────────────────────────── */
.btn-loader { display: inline-flex; gap: 4px; align-items: center; }
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #ffffff;
  animation: pulse 1s infinite;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,80%,100%{opacity:.3} 40%{opacity:1} }

/* ── Results section ─────────────────────────────────────────────────────── */
.section-title {
  font-family: var(--font-mono);
  font-size: .75rem;
  letter-spacing: .14em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 1.25rem;
}
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 640px) { .results-grid { grid-template-columns: 1fr; } }

.result-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  animation: fadeUp .4s ease both;
}
@keyframes fadeUp { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:none} }

.model-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  padding: .2rem .6rem;
  border-radius: 3px;
  margin-bottom: 1rem;
  text-transform: uppercase;
}
.cnn-badge { background: rgba(2,132,199,.1);  color: var(--cnn-color); border: 1px solid rgba(2,132,199,.25); }
.rf-badge  { background: rgba(217,119,6,.1);  color: var(--rf-color);  border: 1px solid rgba(217,119,6,.25); }

.diagnosis-main {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
  margin-bottom: .75rem;
  min-height: 2rem;
}
.confidence-row { display: flex; justify-content: space-between; margin-bottom: .4rem; }
.conf-label { font-size: .78rem; color: var(--text-dim); }
.conf-value { font-family: var(--font-mono); font-size: .8rem; color: var(--text); }

.conf-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: .9rem;
  overflow: hidden;
}
.conf-bar { height: 100%; border-radius: 2px; width: 0%; transition: width .6s ease; }
#cnn-bar  { background: var(--cnn-color); }
#rf-bar   { background: var(--rf-color); }

.reliability-badge {
  font-size: .75rem;
  font-family: var(--font-mono);
  padding: .3rem .7rem;
  border-radius: 3px;
  margin-bottom: 1.1rem;
  display: inline-block;
}
.rel-high { background: rgba(2,132,199,.07);  color: var(--accent); border: 1px solid rgba(2,132,199,.2); }
.rel-low  { background: rgba(220,38,38,.07);  color: var(--danger); border: 1px solid rgba(220,38,38,.2); }

/* ── Ground truth result banner ──────────────────────────────────────────── */
.gt-result-banner {
  margin-top: 1rem;
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: .75rem;
  border: 1px solid rgba(5,150,105,.25);
  background: rgba(5,150,105,.06);
  color: #059669;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.gt-result-banner.hidden { display: none; }

/* ── Probability mini chart ───────────────────────────────────────────────── */
.prob-chart { display: flex; flex-direction: column; gap: .3rem; margin-top: .25rem; }
.prob-row   { display: flex; align-items: center; gap: .5rem; }
.prob-cls {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--text-dim);
  width: 62px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prob-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.prob-fill { height: 100%; border-radius: 2px; transition: width .5s ease; }
.prob-val {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--text-dim);
  width: 36px;
  text-align: right;
}

/* ── Agreement banner ─────────────────────────────────────────────────────── */
.agreement-banner {
  padding: .75rem 1.2rem;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .04em;
  border: 1px solid;
}
.agree    { background: rgba(2,132,199,.05);  border-color: rgba(2,132,199,.25);  color: var(--accent); }
.disagree { background: rgba(220,38,38,.05);  border-color: rgba(220,38,38,.25);  color: var(--danger); }

/* ── History ─────────────────────────────────────────────────────────────── */
.history-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.history-count {
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--text-dim);
}
.history-list { display: flex; flex-direction: column; gap: .75rem; }

.history-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.4rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem 1.5rem;
  align-items: start;
  animation: fadeUp .3s ease both;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  transition: border-color .2s, box-shadow .2s;
}
.history-item:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(2,132,199,.12); }

.hi-time {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--text-dim);
  grid-column: 1 / -1;
  margin-bottom: .15rem;
}
.hi-diag          { font-weight: 600; font-size: .95rem; }
.hi-diag .cnn-tag { color: var(--cnn-color); }
.hi-diag .rf-tag  { color: var(--rf-color); }
.hi-conf {
  font-family: var(--font-mono);
  font-size: .78rem;
  color: var(--text-mid);
  text-align: right;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: .8rem;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 2rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--text-dim);
  letter-spacing: .06em;
  background: var(--bg2);
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }