:root {
  --bg:             #f0f9ff;
  --card-bg:        #ffffff;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --heading:        #0369a1;
  --subheading:     #475569;
  --border:         #cbd5e1;
  --input-bg:       #ffffff;
  --focus-ring:     #0ea5e9;
  --btn-bg:         #0369a1;
  --btn-active:     #075985;
  --row-border:     #f1f5f9;
  --badge-ok-bg:    #dcfce7; --badge-ok-text:   #166534;
  --badge-low-bg:   #fee2e2; --badge-low-text:  #991b1b;
  --badge-high-bg:  #fef9c3; --badge-high-text: #854d0e;
  --error-bg:       #fee2e2; --error-text:      #991b1b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:             #0f172a;
    --card-bg:        #1e293b;
    --text:           #e2e8f0;
    --text-muted:     #94a3b8;
    --heading:        #38bdf8;
    --subheading:     #94a3b8;
    --border:         #334155;
    --input-bg:       #0f172a;
    --focus-ring:     #38bdf8;
    --btn-bg:         #0284c7;
    --btn-active:     #0369a1;
    --row-border:     #334155;
    --badge-ok-bg:    #14532d; --badge-ok-text:   #86efac;
    --badge-low-bg:   #7f1d1d; --badge-low-text:  #fca5a5;
    --badge-high-bg:  #713f12; --badge-high-text: #fde68a;
    --error-bg:       #7f1d1d; --error-text:      #fca5a5;
  }
}

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

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 1rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 1.25rem;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--subheading);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card {
  background: var(--card-bg);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.field input, .field select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  background: var(--input-bg);
  color: var(--text);
  -webkit-appearance: none;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--focus-ring);
}

button[type="submit"] {
  width: 100%;
  padding: 0.85rem;
  background: var(--btn-bg);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  margin-top: 0.25rem;
}

button[type="submit"]:active { background: var(--btn-active); }
button[type="submit"]:disabled { background: #94a3b8; cursor: default; }

#results { display: none; }
#dosing  { display: none; }
#history { display: none; }

.btn-secondary {
  width: 100%;
  padding: 0.85rem;
  background: transparent;
  color: var(--btn-bg);
  font-size: 1rem;
  font-weight: 600;
  border: 1.5px solid var(--btn-bg);
  border-radius: 0.5rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.btn-secondary:active { opacity: 0.7; }
.btn-secondary:disabled { opacity: 0.4; cursor: default; }

.btn-sm {
  padding: 0.6rem 0.85rem;
  background: var(--btn-bg);
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  width: 100%;
}
.btn-sm:active { background: var(--btn-active); }

.hist-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--row-border);
  gap: 0.5rem;
}
.hist-row:last-child { border-bottom: none; }
.hist-date { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.hist-vals { font-size: 0.85rem; text-align: right; }

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--row-border);
}
.result-row:last-child { border-bottom: none; }
.result-label { font-weight: 500; font-size: 0.95rem; }
.result-right { text-align: right; }
.result-value { font-size: 0.85rem; color: var(--text-muted); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-ok   { background: var(--badge-ok-bg);   color: var(--badge-ok-text); }
.badge-low  { background: var(--badge-low-bg);  color: var(--badge-low-text); }
.badge-high { background: var(--badge-high-bg); color: var(--badge-high-text); }

.error-msg {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

.chart-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chart-section {
  width: 100%;
}

.chart-param-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.hist-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.2rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.hist-row:hover .hist-delete { opacity: 1; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  padding: 0.6rem 1.2rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  z-index: 1000;
  animation: toast-in 0.2s ease;
}

.toast-error { background: var(--error-bg); color: var(--error-text); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(0.5rem); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.test-warning {
  background: var(--badge-high-bg);
  color: var(--badge-high-text);
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.attention-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.attention-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.attention-item {
  padding: 0.35rem 0.6rem;
  border-radius: 0.35rem;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.attention-item:last-child { margin-bottom: 0; }

.attention-low  { background: var(--badge-low-bg);  color: var(--badge-low-text); }
.attention-high { background: var(--badge-high-bg); color: var(--badge-high-text); }

@media (max-width: 380px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

.slam-banner { border-left: 4px solid var(--heading); }

.slam-target {
  font-size: 2rem;
  font-weight: 700;
  color: var(--heading);
}

.checklist { list-style: none; margin: 0.5rem 0 0.75rem; }
.checklist li { padding: 0.3rem 0; font-size: 0.95rem; }
.checklist li::before { content: "☐  "; }

.oclt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--row-border);
  font-size: 0.9rem;
}
.oclt-row:last-child { border-bottom: none; }

.btn-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.btn-row .btn-sm { width: auto; flex: 1; }
.btn-success {
  padding: 0.6rem 0.85rem;
  background: var(--badge-ok-bg);
  color: var(--badge-ok-text);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  flex: 1;
}
.btn-success:active { opacity: 0.7; }
