/* ═══════════════════════════════════════════════════════
   TCI Simulator — Dark Medical Theme
   SPDX-License-Identifier: GPL-3.0-only
   Copyright (C) 2026 TCI Simulator contributors
   ═══════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(30, 41, 59, 0.9);
  --bg-glass: rgba(15, 23, 42, 0.7);
  --bg-input: rgba(30, 41, 59, 0.6);
  --bg-input-focus: rgba(51, 65, 85, 0.8);

  --border-subtle: rgba(71, 85, 105, 0.3);
  --border-medium: rgba(100, 116, 139, 0.4);
  --border-active: rgba(59, 130, 246, 0.5);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #e2e8f0;

  --propofol-primary: #3b82f6;
  --propofol-light: #60a5fa;
  --propofol-dark: #1e40af;
  --propofol-glow: rgba(59, 130, 246, 0.15);
  --propofol-gradient: linear-gradient(135deg, #3b82f6, #1e40af);

  --remi-primary: #f59e0b;
  --remi-light: #fbbf24;
  --remi-dark: #d97706;
  --remi-glow: rgba(245, 158, 11, 0.15);
  --remi-gradient: linear-gradient(135deg, #f59e0b, #d97706);

  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.15);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.15);
  --warning: #f59e0b;

  --cp-color: #3b82f6;
  --ce-color: #fbbf24;
  --target-color: #10b981;
  --infusion-color: #8b5cf6;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow-blue: 0 0 20px rgba(59, 130, 246, 0.15);
  --shadow-glow-amber: 0 0 20px rgba(245, 158, 11, 0.15);

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;

  --font-sans: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

  --drug-primary: var(--propofol-primary);
  --drug-light: var(--propofol-light);
  --drug-dark: var(--propofol-dark);
  --drug-glow: var(--propofol-glow);
  --drug-gradient: var(--propofol-gradient);
}

body.drug-remifentanil {
  --drug-primary: var(--remi-primary);
  --drug-light: var(--remi-light);
  --drug-dark: var(--remi-dark);
  --drug-glow: var(--remi-glow);
  --drug-gradient: var(--remi-gradient);
}

/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Background gradient effect */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(245, 158, 11, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
}

.mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* ── Glass Card ── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: var(--border-medium);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-header h3 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.card-header .icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
  min-height: 40px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--drug-gradient);
  color: white;
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-input-focus);
  border-color: var(--border-medium);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
}

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-icon {
  width: 36px; height: 36px;
  padding: 0; border-radius: var(--radius-sm);
}
.btn-icon.lg { width: 44px; height: 44px; border-radius: var(--radius-md); }

/* ── Inputs ── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.input-field {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  outline: none;
  min-height: 42px;
}

.input-field:focus {
  background: var(--bg-input-focus);
  border-color: var(--drug-primary);
  box-shadow: 0 0 0 3px var(--drug-glow);
}

.input-field::placeholder {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: 400;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

select.input-field {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

select.input-field option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.native-select-hidden {
  position: absolute;
  width: 1px !important;
  height: 1px !important;
  opacity: 0;
  pointer-events: none;
}

.custom-select {
  position: relative;
  width: 100%;
}

.custom-select-trigger {
  width: 100%;
  min-height: 44px;
  padding: 11px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.custom-select-trigger:hover,
.custom-select.open .custom-select-trigger {
  border-color: var(--drug-primary);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--drug-glow);
}

.custom-select-caret {
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--transition-fast);
}

.custom-select.open .custom-select-caret {
  transform: translateY(2px) rotate(225deg);
}

.custom-select-menu {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: 0;
  z-index: 80;
  display: none;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.98);
  box-shadow: var(--shadow-lg);
}

.custom-select.open .custom-select-menu {
  display: grid;
  gap: 3px;
}

.custom-select-option {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.custom-select-option:hover,
.custom-select-option.active {
  background: var(--drug-glow);
  color: var(--text-primary);
}

/* ── Setup Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: min(520px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 4px;
  background: var(--drug-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.modal-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.language-toggle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: rgba(15, 23, 42, 0.72);
}

.language-option {
  min-width: 36px;
  height: 28px;
  padding: 0 9px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.language-option:hover {
  color: var(--text-primary);
}

.language-option.active {
  background: var(--drug-primary);
  color: white;
  box-shadow: 0 0 14px var(--drug-glow);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

.form-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 0;
}

.setup-mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.62);
}

.setup-mode-tab {
  min-width: 0;
  min-height: 66px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.setup-mode-tab strong,
.setup-mode-tab span {
  display: block;
}

.setup-mode-tab strong {
  margin-bottom: 3px;
  color: var(--text-accent);
  font-size: 0.82rem;
  font-weight: 850;
}

.setup-mode-tab span {
  color: var(--text-muted);
  font-size: 0.66rem;
  line-height: 1.25;
}

.setup-mode-tab:hover {
  border-color: var(--border-medium);
  background: rgba(30, 41, 59, 0.45);
}

.setup-mode-tab.active {
  border-color: var(--drug-primary);
  background: var(--drug-glow);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
}

.setup-mode-tab.active strong {
  color: var(--text-primary);
}

.setup-mode-tab.active span {
  color: var(--text-secondary);
}

body.setup-mode-bolus .tci-setup-option {
  display: none !important;
}

/* ── Drug Selector Tabs ── */
.drug-tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
}

.drug-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.drug-tab.active {
  background: var(--drug-gradient);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.drug-tab:not(.active):hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
}

.setup-safety-notice {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
  align-items: center;
  padding: 11px 13px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(30, 41, 59, 0.42);
  box-shadow: inset 3px 0 0 var(--drug-primary);
}

.setup-safety-notice > strong {
  color: var(--text-accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
}

.setup-safety-notice > p {
  color: var(--text-secondary);
  font-size: 0.68rem;
  line-height: 1.35;
}

.legal-links,
.legal-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
}

.legal-links {
  grid-column: 1;
  grid-row: auto;
  justify-content: flex-start;
  margin-top: 5px;
}

.legal-links a,
.legal-footer a {
  color: var(--drug-light);
  font-size: 0.7rem;
  text-decoration: none;
}

.legal-links a:hover,
.legal-footer a:hover {
  text-decoration: underline;
}

.setup-feedback-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.feedback-entry-btn {
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(30, 41, 59, 0.5);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 750;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.feedback-entry-btn:hover {
  border-color: var(--drug-primary);
  color: var(--text-primary);
  background: var(--drug-glow);
}

.feedback-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.feedback-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.modal-close-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text-secondary);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--text-primary);
  border-color: var(--drug-primary);
}

.feedback-form {
  display: grid;
  gap: 14px;
}

.feedback-textarea {
  min-height: 150px;
  resize: vertical;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.feedback-status {
  min-height: 18px;
  color: var(--success);
  font-size: 0.78rem;
  font-weight: 700;
}

/* ── Simulation Layout ── */
#app-simulation {
  display: none;
  height: 100vh;
  height: 100dvh;
  position: relative;
  z-index: 1;
}

#app-simulation.active {
  display: flex;
  flex-direction: column;
}

#app-bolus-pk {
  display: none;
  height: 100vh;
  height: 100dvh;
  position: relative;
  z-index: 1;
}

#app-bolus-pk.active {
  display: flex;
  flex-direction: column;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 10;
  min-height: 56px;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-context-picker {
  position: relative;
  flex: 0 0 auto;
}

.context-pill {
  min-height: 30px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
}

.drug-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.drug-badge.propofol {
  background: var(--propofol-glow);
  color: var(--propofol-light);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.drug-badge.remifentanil {
  background: var(--remi-glow);
  color: var(--remi-light);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.bolus-mode-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border: 1px solid rgba(16, 185, 129, 0.28);
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
  font-size: 0.78rem;
  font-weight: 850;
}

.context-pill-caret {
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  opacity: 0.68;
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--transition-fast);
}

.top-context-picker.open .context-pill-caret {
  transform: translateY(2px) rotate(225deg);
}

.top-context-menu {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  z-index: 90;
  display: grid;
  gap: 3px;
  min-width: 154px;
  padding: 6px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.99);
  box-shadow: var(--shadow-lg);
}

.top-context-menu[hidden] {
  display: none;
}

.top-context-option {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 750;
  text-align: left;
  cursor: pointer;
}

.top-context-option:hover,
.top-context-option.active {
  background: var(--drug-glow);
  color: var(--text-primary);
}

.patient-info-bar {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.patient-info-bar span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.top-bar-right {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: max-content;
}

/* Main content */
.sim-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

.boluspk-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 0.28fr) minmax(0, 1fr);
  overflow: hidden;
}

.boluspk-control-panel {
  min-width: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1px solid var(--border-subtle);
  background: rgba(17, 24, 39, 0.5);
  overflow-y: auto;
}

.boluspk-drug-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.boluspk-drug-tab {
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(30, 41, 59, 0.45);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.boluspk-drug-tab:hover {
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.boluspk-drug-tab.active {
  border-color: var(--drug-primary);
  background: var(--drug-glow);
  color: var(--text-primary);
}

.boluspk-dose-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.46);
}

.boluspk-dose-field {
  display: grid;
  gap: 6px;
}

.boluspk-dose-field label {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.boluspk-dose-field .toolbar-dose-field {
  width: 100%;
}

.boluspk-dose-field .input-field {
  flex: 1 1 auto;
  width: 100%;
  text-align: left;
}

.boluspk-note {
  margin-top: 0;
}

.boluspk-chart-area {
  min-width: 0;
}

/* Left Panel */
.control-panel {
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-right: 1px solid var(--border-subtle);
  background: rgba(17, 24, 39, 0.5);
}

.control-section {
  padding: 9px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.42);
}

/* Concentration Display */
.conc-display {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.conc-box {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  text-align: center;
  transition: all var(--transition-fast);
}

.conc-box .label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.conc-box .value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}

.conc-box .unit {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.conc-box.cp .value { color: var(--cp-color); }
.conc-box.ce .value { color: var(--ce-color); }
.conc-box.target .value { color: var(--target-color); }
.conc-box.rate .value { color: var(--infusion-color); }

.conc-box.cp { border-color: rgba(59, 130, 246, 0.2); }
.conc-box.ce { border-color: rgba(251, 191, 36, 0.2); }

.dose-control-section {
  padding: 8px;
}

.dose-control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr));
  gap: 8px;
}

.dose-control {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto;
  grid-template-columns: minmax(112px, 1fr) minmax(108px, 0.82fr);
  grid-template-areas:
    "header header"
    "field action";
  gap: 7px 8px;
  padding: 9px;
  border: 1px solid rgba(71, 85, 105, 0.24);
  border-radius: var(--radius-sm);
  background: rgba(30, 41, 59, 0.34);
  align-items: end;
}

.target-mode-row {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.target-mode-row .section-label {
  padding-top: 0;
  white-space: nowrap;
}

.bolus-control > .section-label {
  grid-area: header;
  align-self: center;
}

.target-mode-select {
  flex: 0 1 160px;
  min-width: 0;
  min-height: 32px;
  padding: 5px 28px 5px 10px;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
}

.target-mode-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dose-input-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  grid-area: field;
  min-height: 40px;
  padding: 0 4px;
}

.dose-input-row .input-field {
  flex: 0 0 clamp(66px, 38%, 88px);
  min-width: 0;
  min-height: 40px;
  padding: 7px 9px;
  font-size: 1rem;
  text-align: center;
}

.dose-unit {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.1;
  white-space: nowrap;
}

.dose-action-btn {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  font-size: 0.86rem;
  line-height: 1.1;
  grid-area: action;
  align-self: stretch;
}

.target-preview {
  margin-top: 6px;
  border: 1px solid rgba(71, 85, 105, 0.34);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(30, 41, 59, 0.58), rgba(15, 23, 42, 0.72)),
    var(--bg-card);
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.035);
  overflow: hidden;
}

.target-preview[hidden] {
  display: none;
}

.target-preview summary::-webkit-details-marker {
  display: none;
}

.preview-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 30px 6px 10px;
  position: relative;
  cursor: pointer;
  list-style: none;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.68rem;
  line-height: 1.25;
  color: var(--text-secondary);
  user-select: none;
}

.preview-toggle::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-65%) rotate(45deg);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.target-preview[open] .preview-toggle::after {
  transform: translateY(-35%) rotate(225deg);
  border-color: var(--drug-light);
}

.preview-title {
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--drug-light);
}

.preview-lead {
  color: var(--text-secondary);
}

.preview-target-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: rgba(59, 130, 246, 0.14);
  border: 1px solid rgba(59, 130, 246, 0.24);
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--text-primary);
}

.preview-body {
  padding: 0 10px 8px;
}

.preview-summary {
  padding: 6px 0 4px;
  font-size: 0.74rem;
  line-height: 1.25;
  font-weight: 700;
  color: var(--text-accent);
}

.preview-steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 168px;
  overflow-y: auto;
  padding-top: 4px;
}

.preview-step {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
}

.preview-time-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  min-width: 72px;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(148, 163, 184, 0.13);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  line-height: 1.15;
  white-space: nowrap;
  color: var(--text-secondary);
}

.preview-step strong {
  display: block;
  font-size: 0.76rem;
  line-height: 1.2;
  font-weight: 700;
  color: var(--text-primary);
}

.preview-step-bolus strong {
  font-weight: 900;
}

.preview-step-bolus small {
  font-weight: 800;
  color: var(--text-secondary);
}

.preview-step small {
  display: block;
  margin-top: 2px;
  font-size: 0.66rem;
  color: var(--text-muted);
}

/* Speed Controls */
.speed-controls {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.speed-btn {
  flex: 1;
  min-width: 42px;
  padding: 6px 4px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.speed-btn:hover {
  background: var(--bg-input-focus);
  color: var(--text-primary);
}

.speed-btn.active {
  background: var(--drug-primary);
  color: white;
  border-color: var(--drug-primary);
}

/* Time jump buttons */
.time-jump-controls {
  display: flex;
  gap: 4px;
}

.time-jump-btn {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.time-jump-btn:hover {
  background: var(--bg-input-focus);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

/* History Log */
.history-log {
  flex: 1;
  overflow-y: auto;
  max-height: 220px;
  padding-right: 4px;
}

.history-log::-webkit-scrollbar {
  width: 4px;
}

.history-log::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

.history-entry {
  display: flex;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-left: 2px solid var(--border-subtle);
  margin-bottom: 4px;
  animation: fadeSlideIn 0.3s ease;
}

.history-entry .time {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 55px;
}

.history-entry.target {
  border-left-color: var(--target-color);
}

.history-entry.bolus {
  border-left-color: var(--infusion-color);
}

.history-entry.pause {
  border-left-color: var(--danger);
}

.history-entry.rate-change {
  border-left-color: var(--cp-color);
}

.infusion-log-panel {
  margin: 0;
  border: 1px solid var(--border-subtle);
  border-left: none;
  border-right: none;
  border-bottom: none;
  border-radius: 0;
  background: rgba(15, 23, 42, 0.72);
  overflow: hidden;
}

.infusion-log-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.infusion-log-panel summary::-webkit-details-marker {
  display: none;
}

.infusion-log-panel summary::before {
  content: '+';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  color: var(--drug-light);
  margin-right: 2px;
}

.infusion-log-panel[open] summary::before {
  content: '−';
}

.infusion-log-panel summary span {
  flex: 1;
}

.infusion-log-panel summary small {
  color: var(--text-muted);
  font-size: 0.68rem;
  letter-spacing: 0;
  text-transform: none;
}

.infusion-log-panel .history-log {
  max-height: 180px;
  padding: 0 12px 12px;
}

.legal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
  padding: 7px 12px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(10, 14, 26, 0.96);
  color: var(--text-muted);
  font-size: 0.66rem;
  line-height: 1.35;
}

.legal-footer-links {
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Chart Area */
.chart-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overflow-x: visible;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 0 10px;
}

.toolbar-target-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 440px;
}

.toolbar-target-control.attention-pulse {
  animation: target-attention 900ms ease;
}

.target-mode-picker {
  position: relative;
  flex: 0 1 172px;
  min-width: 130px;
  z-index: 8;
}

.target-mode-trigger {
  width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(30, 41, 59, 0.72);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.target-mode-trigger:hover,
.target-mode-picker.open .target-mode-trigger {
  border-color: var(--drug-primary);
  box-shadow: 0 0 0 2px var(--drug-glow);
}

.target-mode-caret {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--transition-fast);
}

.target-mode-picker.open .target-mode-caret {
  transform: translateY(2px) rotate(225deg);
}

.target-mode-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: 100%;
  padding: 5px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.98);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.target-mode-option {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 750;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.target-mode-option:hover,
.target-mode-option.active {
  background: rgba(59, 130, 246, 0.16);
  color: var(--text-primary);
}

.toolbar-dose-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 116px;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.72);
}

.toolbar-dose-field .input-field {
  flex: 0 0 70px;
  width: 70px;
  min-height: 30px;
  padding: 2px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 0.9rem;
  text-align: center;
}

.toolbar-dose-field .input-field:focus {
  box-shadow: none;
}

.toolbar-target-control .dose-action-btn {
  grid-area: auto;
  flex: 0 0 auto;
  width: auto;
  min-width: 140px;
  min-height: 36px;
  padding: 8px 14px;
  align-self: auto;
  font-size: 0.82rem;
}

.scale-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: rgba(30, 41, 59, 0.58);
  color: var(--text-muted);
}

.scale-stepper > span {
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.scale-stepper strong {
  min-width: 58px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-primary);
}

.scale-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.scale-btn:hover {
  border-color: var(--drug-primary);
  color: white;
  background: var(--drug-primary);
}

.chart-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chart-toolbar small {
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.chart-scale-input {
  width: 58px;
  min-height: 30px;
  padding: 4px 8px;
  font-size: 0.78rem;
  text-align: center;
}

.chart-container {
  position: relative;
  flex: 0 1 clamp(300px, 50dvh, 540px);
  min-height: 280px;
  max-height: 540px;
  margin: 0 12px 28px 48px;
  overflow: visible;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

.boluspk-chart-container {
  flex-basis: clamp(320px, 52dvh, 560px);
}

.axis-scale-controls {
  position: absolute;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  pointer-events: none;
}

.y-scale-controls {
  left: -24px;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  flex-direction: row;
  transform-origin: center;
}

.x-scale-controls {
  left: 50%;
  bottom: -16px;
  transform: translateX(-50%);
  flex-direction: row;
}

.axis-title-text {
  margin-right: 18px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.axis-scale-value {
  margin-left: 4px;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 800;
  color: var(--text-muted);
  white-space: nowrap;
}

.axis-scale-btn {
  pointer-events: auto;
  width: 17px;
  height: 17px;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.9);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.axis-scale-btn:hover {
  border-color: var(--drug-primary);
  color: white;
  background: var(--drug-primary);
}

.axis-scale-btn:active {
  transform: scale(0.92);
}

.scale-readout {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.bis-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  min-width: 70px;
  padding: 8px 10px;
  border: 1px solid rgba(71, 85, 105, 0.36);
  border-radius: var(--radius-sm);
  background: rgba(10, 14, 26, 0.68);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-sm);
  text-align: center;
  pointer-events: none;
}

.bis-badge span {
  display: block;
  margin-bottom: 3px;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.bis-badge strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-primary);
}

.chart-hover-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 116px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.96);
  color: var(--text-secondary);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transform: none;
  transition: opacity 80ms ease;
}

.chart-hover-tooltip.visible {
  opacity: 1;
}

.chart-hover-tooltip strong,
.chart-hover-tooltip span,
.chart-hover-tooltip small {
  display: block;
}

.chart-hover-tooltip strong {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-primary);
}

.chart-hover-tooltip span {
  margin-top: 2px;
  font-size: 0.72rem;
}

.chart-hover-tooltip small {
  margin-top: 2px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.mini-dashboard {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  padding-top: 8px;
}

.boluspk-dashboard {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.mini-dashboard > div {
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.dashboard-bolus-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dashboard-bolus-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.dashboard-bolus-field {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 28px;
  padding: 0 7px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.72);
}

.dashboard-bolus-field .input-field {
  flex: 1 1 48px;
  min-width: 42px;
  min-height: 24px;
  padding: 2px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 0.88rem;
  text-align: center;
}

.dashboard-bolus-field .input-field:focus {
  box-shadow: none;
}

.dashboard-bolus-field small {
  flex: 0 0 auto;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

.dashboard-bolus-btn {
  flex: 0 0 74px;
  min-height: 28px;
  padding: 4px 9px;
  font-size: 0.78rem;
}

.mini-dashboard span,
.mini-dashboard small {
  display: block;
  overflow-wrap: anywhere;
}

.dose-rate-heading {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  margin-bottom: 4px !important;
}

.dose-rate-heading > span {
  margin-bottom: 0;
}

.dash-unit-toggle {
  flex: 0 0 auto;
  min-width: 34px;
  min-height: 20px;
  padding: 2px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: rgba(15, 23, 42, 0.88);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.54rem;
  font-weight: 800;
  text-transform: uppercase;
  outline: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.dash-unit-toggle:hover {
  border-color: var(--drug-primary);
  color: var(--text-primary);
}

.wake-card {
  display: flex;
  flex-direction: column;
}

.wake-threshold-control {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  min-width: 0;
  color: var(--text-muted);
}

.wake-threshold-control span,
.wake-threshold-control small {
  margin: 0;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}

.wake-threshold-control input {
  width: 42px;
  min-width: 0;
  min-height: 22px;
  padding: 2px 5px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.82);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
  outline: none;
}

.wake-threshold-control input:focus {
  border-color: var(--drug-primary);
  box-shadow: 0 0 0 2px var(--drug-glow);
}

.mini-dashboard span {
  margin-bottom: 4px;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.mini-dashboard strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.2;
  color: var(--text-primary);
}

.mini-dashboard small {
  margin-top: 2px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Time Scrubber */
.time-scrubber {
  padding: 6px 16px calc(5px + env(safe-area-inset-bottom));
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
}

.time-scrubber-inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: center;
}

.transport-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.time-track-row {
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.time-scrubber .play-pause-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  font-size: 0.9rem;
}

.transport-btn {
  flex: 0 0 auto;
  min-width: 34px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: rgba(30, 41, 59, 0.64);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.transport-btn:hover,
.transport-btn.active {
  border-color: var(--drug-primary);
  background: var(--drug-primary);
  color: white;
  box-shadow: 0 0 14px var(--drug-glow);
}

.transport-btn:disabled,
.time-slider:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

.transport-btn:disabled:hover {
  border-color: var(--border-subtle);
  background: rgba(30, 41, 59, 0.64);
  color: var(--text-secondary);
}

.time-scrubber.timeline-locked .time-track-row {
  opacity: 0.66;
}

.time-scrubber.timeline-locked .play-pause-btn {
  border-style: dashed;
}

.quick-speed-btn.active {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.18);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.2);
}

.quick-speed-btn {
  min-width: 44px;
}

.step-backward-btn,
.step-forward-btn {
  min-width: 54px;
}

.time-display {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 75px;
  text-align: center;
}

.time-slider {
  width: 100%;
  min-width: 90px;
  margin-left: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 4px;
  background: var(--bg-input);
  outline: none;
  cursor: pointer;
}

.speed-select {
  flex: 0 0 78px;
  min-height: 36px;
  padding: 6px 30px 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--drug-primary);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 8px var(--drug-glow);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.time-slider::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

.time-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--drug-primary);
  border: 2px solid var(--bg-primary);
  cursor: pointer;
}

/* Status bar info */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-items {
  display: flex;
  gap: 20px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-item .dot.paused {
  background: var(--warning);
  animation: none;
}

.status-item .dot.stopped {
  background: var(--danger);
  animation: none;
}

/* ── Bolus rate selector ── */
.bolus-rate-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bolus-rate-selector label {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.bolus-rate-selector select {
  padding: 4px 28px 4px 8px;
  font-size: 0.8rem;
}

/* ── Targeting mode pills ── */
.mode-pills {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.mode-pill {
  flex: 1;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-pill.active {
  background: var(--drug-primary);
  color: white;
}

.mode-pill:not(.active):hover {
  color: var(--text-secondary);
}

/* ── Play/Pause button ── */
.play-pause-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--drug-primary);
  background: var(--drug-glow);
  color: var(--drug-primary);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.play-pause-btn:hover {
  background: var(--drug-primary);
  color: white;
  box-shadow: 0 0 20px var(--drug-glow);
}

.play-pause-btn.running {
  border-color: var(--success);
  color: var(--success);
  background: var(--success-glow);
  animation: pulse-ring 2s ease-in-out infinite;
}

.play-pause-btn.running:hover {
  background: var(--success);
  color: white;
}

/* ── Animations ── */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.3); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes target-attention {
  0% { filter: none; }
  25% { filter: drop-shadow(0 0 14px var(--drug-primary)); }
  100% { filter: none; }
}

@keyframes value-flash {
  0% { color: white; }
  100% { color: inherit; }
}

.value-updated {
  animation: value-flash 0.5s ease;
}

/* ── Sim controls row ── */
.sim-control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sim-control-row .play-pause-btn {
  flex-shrink: 0;
}

.elapsed-time {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.sim-speed-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--drug-glow);
  color: var(--drug-light);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* ── Volume infused ── */
.volume-display {
  text-align: center;
  padding: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.volume-display .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.volume-display .value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-accent);
}

/* ── Section dividers in control panel ── */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding-top: 4px;
}

/* ── Scrollbar styling ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-medium);
}

/* ── Responsive ── */
@media (max-width: 900px) {
  input,
  select,
  textarea,
  .input-field,
  .toolbar-dose-field .input-field,
  .dashboard-bolus-field .input-field,
  .wake-threshold-control input {
    font-size: 16px !important;
  }

  body {
    overflow-y: auto;
  }

  #app-simulation {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: flex-start;
    gap: 10px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .top-bar-left {
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
  }

  .drug-badge {
    max-width: 100%;
    white-space: normal;
    line-height: 1.2;
  }

  .top-bar-right {
    margin-left: 0;
    justify-self: end;
    flex-wrap: nowrap;
  }

  .sim-body {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  #app-bolus-pk {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .boluspk-body {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .boluspk-control-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px;
    overflow: visible;
  }

  .boluspk-drug-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .boluspk-drug-tab {
    min-height: 38px;
    padding: 8px 8px;
    font-size: 0.72rem;
    text-align: center;
  }

  .boluspk-dose-card {
    grid-template-columns: minmax(0, 1fr) minmax(112px, 0.46fr);
    align-items: end;
  }

  .control-panel {
    grid-row: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    max-height: none;
    overflow-y: visible;
    padding: 12px;
  }

  .chart-area {
    min-height: 0;
    padding: 10px 12px 14px;
    overflow: visible;
  }

  .chart-toolbar {
    align-items: stretch;
  }

  .toolbar-target-control {
    flex: 1 1 100%;
  }

  .chart-legend {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
  }

  .chart-container {
    flex-basis: clamp(280px, 46dvh, 430px);
    min-height: 290px;
    max-height: 430px;
    margin: 0 8px 28px 46px;
  }

  .y-scale-controls {
    left: -24px;
    top: 50%;
  }

  .x-scale-controls {
    left: 50%;
    bottom: -18px;
  }

  .mini-dashboard {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .boluspk-dashboard {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .infusion-log-panel {
    margin: 0;
  }

  .time-scrubber {
    position: static;
    z-index: 20;
    background: rgba(17, 24, 39, 0.98);
    padding: 6px 10px calc(5px + env(safe-area-inset-bottom));
  }

  .time-scrubber-inner {
    gap: 6px;
  }

  .transport-controls {
    gap: 5px;
  }

  .time-track-row {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 6px;
  }

  .time-scrubber .play-pause-btn {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .time-display {
    min-width: 66px;
    font-size: 0.75rem;
  }

  .transport-btn {
    height: 28px;
    min-width: 40px;
    padding-inline: 7px;
    font-size: 0.64rem;
  }

  .step-backward-btn,
  .step-forward-btn {
    min-width: 52px;
  }

  .time-slider {
    min-width: 0;
  }

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

  .patient-info-bar {
    display: none;
  }
}

@media (max-width: 520px) {
  .modal-content {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    padding: calc(20px + env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom));
  }

  .top-bar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .top-bar-right {
    width: 100%;
    justify-self: stretch;
    justify-content: flex-end;
  }

  .setup-feedback-actions {
    grid-template-columns: 1fr;
  }

  .setup-mode-tabs {
    grid-template-columns: 1fr;
  }

  .setup-mode-tab {
    min-height: 54px;
  }

  .top-context-menu {
    max-width: calc(100vw - 24px);
  }

  .legal-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .legal-footer-links {
    justify-content: flex-start;
  }

  .feedback-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .feedback-actions .btn {
    width: 100%;
  }

  .conc-box {
    padding: 10px 8px;
  }

  .conc-box .value {
    font-size: 1.35rem;
  }

  .dose-control-section {
    padding: 7px;
  }

  .dose-control-grid {
    gap: 6px;
  }

  .dose-control {
    padding: 7px;
    grid-template-columns: minmax(0, 1fr) minmax(92px, 0.78fr);
  }

  .dose-input-row .input-field {
    flex-basis: 62px;
    min-width: 0;
    font-size: 0.9rem;
  }

  .target-mode-row {
    align-items: stretch;
    flex-direction: column;
  }

  .dose-action-btn,
  .infusion-toggle {
    min-height: 40px;
  }

  .chart-toolbar {
    gap: 6px;
  }

  .toolbar-target-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(112px, 0.76fr);
    grid-template-areas:
      "mode mode"
      "target action";
    align-items: stretch;
    gap: 7px;
  }

  .target-mode-picker {
    grid-area: mode;
    width: 100%;
    min-width: 0;
  }

  .toolbar-dose-field {
    grid-area: target;
    width: 100%;
    min-width: 0;
  }

  .toolbar-dose-field .input-field {
    flex: 1 1 auto;
    width: 100%;
  }

  .toolbar-target-control .dose-action-btn {
    grid-area: action;
    width: 100%;
    min-width: 0;
  }

  .scale-stepper {
    flex: 1 1 150px;
  }

  .scale-stepper strong {
    min-width: 52px;
    font-size: 0.72rem;
  }

  .axis-scale-btn {
    width: 18px;
    height: 18px;
  }

  .mini-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .boluspk-drug-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .boluspk-dose-card {
    grid-template-columns: 1fr;
  }

  .boluspk-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .preview-step {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 6px;
  }

  .preview-time-pill {
    width: 72px;
    min-width: 72px;
    padding-inline: 6px;
  }

  .speed-btn,
  .time-jump-btn,
  .mode-pill {
    min-height: 38px;
  }

  .history-log {
    max-height: 150px;
  }
}

@media (max-width: 380px) {
  .toolbar-target-control {
    grid-template-columns: 1fr;
    grid-template-areas:
      "mode"
      "target"
      "action";
  }

  .chart-legend {
    justify-content: flex-start;
  }

  .target-mode-trigger,
  .toolbar-dose-field,
  .toolbar-target-control .dose-action-btn {
    min-height: 38px;
  }

  .mini-dashboard {
    grid-template-columns: 1fr;
  }

  .boluspk-dashboard {
    grid-template-columns: 1fr;
  }

  .dashboard-bolus-row {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-bolus-btn {
    flex-basis: auto;
    width: 100%;
  }

  .dose-control {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "field"
      "action";
  }

  .dose-input-row {
    justify-content: flex-start;
  }

  .dose-input-row .input-field {
    flex-basis: 70px;
  }
}

/* ── Tooltip ── */
.tooltip-custom {
  position: relative;
}

.tooltip-custom::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  pointer-events: none;
  z-index: 100;
}

.tooltip-custom:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Sim not started state */
.sim-not-started {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

.sim-not-started .icon-large {
  font-size: 3rem;
  opacity: 0.3;
}

/* Model info tag */
.model-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  color: var(--text-muted);
  padding: 4px 11px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.model-tag:hover,
.top-context-picker.open .model-tag {
  color: var(--text-primary);
  border-color: var(--drug-primary);
  background: var(--drug-glow);
}

/* New Sim button */
.btn-new-sim {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.btn-new-sim:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-glow);
}

.top-bar-right .btn-new-sim {
  width: 100%;
  min-width: 112px;
}

.btn-quick-reset:hover {
  border-color: var(--drug-primary);
  color: var(--drug-primary);
  background: var(--drug-glow);
}

/* Chart legend custom */
.chart-legend {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
  flex: 0 1 auto;
  margin-left: auto;
  padding: 0;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

.legend-swatch.cp { background: var(--cp-color); }
.legend-swatch.ce { background: var(--ce-color); }
.legend-swatch.target { background: var(--target-color); height: 2px; border: 1px dashed var(--target-color); }

.compare-toggle {
  min-height: 26px;
  padding: 4px 10px;
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: var(--radius-full);
  background: rgba(30, 41, 59, 0.58);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.compare-toggle:hover,
.compare-toggle.active {
  border-color: var(--drug-primary);
  background: rgba(59, 130, 246, 0.16);
  color: var(--text-primary);
}
