:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --danger: #ef4444;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --panel: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { font-size: 1.1rem; margin: 0; }

.tabs { display: flex; gap: 0.25rem; }

.tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab.active { background: var(--accent); color: white; }

.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
}

.view.hidden { display: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
}

.form { display: flex; flex-direction: column; gap: 0.6rem; }
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--text-muted); }
.form input, .form select, .form textarea {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.checkbox-row { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}
button.secondary { background: var(--border); color: var(--text); }
button.icon-danger { background: transparent; color: var(--danger); padding: 0.2rem 0.5rem; }

.list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.list .meta { color: var(--text-muted); font-size: 0.8rem; }
.swatch { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.4rem; }

.checklist { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.75rem; }
.checklist label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; color: var(--text); }

.chart-card { display: flex; flex-direction: column; min-height: 360px; }
#curve-canvas { width: 100%; height: 320px; flex: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; font-size: 0.85rem; }

.disclaimer {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.preset-picker {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.preset-picker select {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.dose-list-header { display: flex; align-items: center; justify-content: space-between; }
.dose-list-header h3 { margin: 0; }
.dose-list-header button { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.stats { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.75rem; font-size: 0.85rem; }
.stats .stat-row { display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--border); padding-top: 0.4rem; }
.stats .stat-name { display: flex; align-items: center; font-weight: 600; }
.stats .stat-values { color: var(--text-muted); text-align: right; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  max-width: 90vw;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 100;
}
.toast.hidden { display: none; }

/* Desktop / wide-viewport layout: persistent sidebar + always-visible chart */
@media (min-width: 900px) {
  .tabs { display: none; }
  .layout { flex-direction: row; align-items: flex-start; }
  .sidebar {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  .view { display: block !important; }
  .main-panel { flex: 1; position: sticky; top: 4.5rem; }
  #curve-canvas { height: 480px; }
}
