:root {
  --bg-main: #0b0f19;
  --bg-card: #151d30;
  --bg-card-hover: #1c2742;
  --bg-input: #101726;
  --border-color: #24324f;
  --border-focus: #38bdf8;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  
  --emerald: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.15);
  
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.15);
  
  --rose: #f43f5e;
  --rose-bg: rgba(244, 63, 94, 0.15);
  
  --purple: #a855f7;
  --purple-bg: rgba(168, 85, 247, 0.15);
  
  --cyan: #06b6d4;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-icon {
  width: 32px;
  height: 32px;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #38bdf8, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.role-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.role-son {
  background: var(--cyan);
  color: #082f49;
}

.role-parent {
  background: var(--purple);
  color: #3b0764;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  flex: 1;
  text-align: center;
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.nav-tab.active {
  color: #38bdf8;
  border-bottom-color: #38bdf8;
  background: rgba(56, 189, 248, 0.05);
}

/* Main Container */
.main-container {
  flex: 1;
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* Card Styles */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-text, .input-select, .input-time, .input-date {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-text:focus, .input-select:focus, .input-time:focus, .input-date:focus {
  border-color: var(--border-focus);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-primary {
  background: #0284c7;
  color: #ffffff;
}

.btn-primary:hover {
  background: #0369a1;
}

.btn-emerald {
  background: #059669;
  color: #ffffff;
}

.btn-emerald:hover {
  background: #047857;
}

.btn-secondary {
  background: #1e293b;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: #334155;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  min-height: 32px;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Search Container & Autocomplete */
.search-container {
  position: relative;
  margin-bottom: 16px;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  max-height: 250px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow);
}

.autocomplete-item {
  padding: 12px 16px;
  border-bottom: 1px solid #334155;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.autocomplete-item:hover {
  background: #2b3a55;
}

/* Safe Dose Display Card (Son & Parent) */
.hero-dose-card {
  text-align: center;
  background: linear-gradient(180deg, #16243b 0%, #101a2d 100%);
  border: 2px solid #0284c7;
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  margin-bottom: 20px;
}

.hero-dose-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.hero-dose-number {
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
  color: #ffffff;
  margin: 8px 0;
}

.hero-dose-unit {
  font-size: 1.5rem;
  font-weight: 700;
  color: #38bdf8;
  margin-left: 4px;
}

.formula-tag {
  display: inline-block;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.stat-box {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: var(--radius-md);
  text-align: center;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Warnings Box */
.warning-box {
  background: rgba(245, 158, 11, 0.1);
  border-left: 4px solid var(--amber);
  padding: 12px 14px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 14px 0;
  font-size: 0.85rem;
  color: #fde68a;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

/* Interactive Timeline Chart Containers */
.timeline-wrapper {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
}

.chart-header {
  padding: 10px 14px;
  background: #172033;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.scrubber-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d1424;
  padding: 8px 14px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
}

.chart-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  background: #090d16;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: #334155 #0f172a;
}

.chart-scroll-wrapper::-webkit-scrollbar {
  height: 8px;
}

.chart-scroll-wrapper::-webkit-scrollbar-track {
  background: #0f172a;
}

.chart-scroll-wrapper::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

.chart-canvas-container {
  height: 350px;
  position: relative;
  cursor: crosshair;
  min-width: 100%;
}

canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Dose Chips */
.dose-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.dose-chip-bolus {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.dose-chip-smb {
  background: rgba(192, 132, 252, 0.18);
  color: #c084fc;
  border: 1px solid rgba(192, 132, 252, 0.35);
}

/* Chart Legend */
.chart-legend {
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  background: #172033;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

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

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* Meal Window Control Bar */
.window-control-bar {
  background: #162035;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}

.window-stats-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f172a;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 12px;
}

.window-stat-item {
  display: flex;
  flex-direction: column;
}

.window-stat-title {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.window-stat-val {
  font-size: 1.15rem;
  font-weight: 700;
}

.stepper-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.stepper-label {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 80px;
  color: var(--text-secondary);
}

/* Modal / Drawer */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  max-height: 90vh;
  overflow-y: auto;
}

/* Episode Curve Viewer / Carousel */
.episode-viewer {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: 14px;
}

.episode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.episode-chart-container {
  width: 100%;
  height: 220px;
  position: relative;
  background: #0f172a;
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* Responsive tweaks */
@media (max-width: 600px) {
  .brand-title {
    font-size: 1.1rem;
  }
  .hero-dose-number {
    font-size: 2.8rem;
  }
  .chart-canvas-container {
    height: 230px;
  }
  .window-stats-badge {
    flex-direction: column;
    align-items: flex-start;
  }
}
