/* ============================================================
   DiaLife Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* === CSS Custom Properties === */
:root {
  /* Colors */
  --primary: #2563EB;
  --primary-light: #3B82F6;
  --primary-dark: #1D4ED8;
  --primary-50: #EFF6FF;
  --primary-100: #DBEAFE;

  --secondary: #10B981;
  --secondary-light: #34D399;
  --secondary-dark: #059669;
  --secondary-50: #ECFDF5;

  --success: #22C55E;
  --success-light: #4ADE80;
  --success-bg: #F0FDF4;

  --warning: #F59E0B;
  --warning-light: #FCD34D;
  --warning-bg: #FFFBEB;

  --danger: #EF4444;
  --danger-light: #F87171;
  --danger-bg: #FEF2F2;
  --danger-dark: #DC2626;

  --hypo-color: #7C3AED;
  --hypo-bg: #F5F3FF;

  /* Neutrals */
  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --border: #E2E8F0;
  --border-light: #F1F5F9;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #94A3B8;
  --text-inverse: #FFFFFF;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  --shadow-colored: 0 8px 24px rgba(37,99,235,0.18);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Spacing */
  --nav-height: 72px;
  --header-height: 60px;

  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dark Mode */
[data-theme="dark"] {
  --bg: #0F172A;
  --bg-card: #1E293B;
  --bg-subtle: #162032;
  --border: #334155;
  --border-light: #1E293B;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-tertiary: #475569;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
  --primary-50: rgba(37,99,235,0.1);
  --primary-100: rgba(37,99,235,0.15);
  --secondary-50: rgba(16,185,129,0.1);
  --success-bg: rgba(34,197,94,0.1);
  --warning-bg: rgba(245,158,11,0.1);
  --danger-bg: rgba(239,68,68,0.1);
  --hypo-bg: rgba(124,58,237,0.1);
}

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

/* Desktop centering wrapper */
@media (min-width: 430px) {
  body {
    background: linear-gradient(135deg, #EFF6FF 0%, #F0FDF4 100%);
  }
  #app {
    box-shadow: 0 0 60px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.06);
    border-radius: 36px;
    margin-top: 20px;
    margin-bottom: 20px;
    min-height: calc(100vh - 40px);
    overflow: hidden;
  }
  .bottom-nav {
    border-radius: 0 0 36px 36px;
  }
}

/* === Screen Container === */
.screens {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  min-height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.screen.active { display: flex; }

/* === Page Header === */
.page-header {
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
  border-bottom: 1px solid var(--border-light);
}

.page-header h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.page-header p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ============================================================
   BOTTOM NAVIGATION
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: var(--nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  z-index: 200;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: transparent;
  flex: 1;
  color: var(--text-tertiary);
  -webkit-tap-highlight-color: transparent;
  min-width: 44px;
}

.nav-item:active { transform: scale(0.92); }

.nav-item svg {
  width: 24px;
  height: 24px;
  transition: var(--transition);
}

.nav-item span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: var(--transition);
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active .nav-icon-wrap {
  background: var(--primary-100);
  border-radius: 12px;
  padding: 4px 10px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.card-sm { padding: 14px; border-radius: var(--radius-lg); }
.card-lg { padding: 22px; border-radius: var(--radius-2xl); }

/* ============================================================
   GLUCOSE STATUS COLORS
   ============================================================ */
.glucose-normal { color: var(--success); }
.glucose-high { color: var(--warning); }
.glucose-critical { color: var(--danger); }
.glucose-hypo { color: var(--hypo-color); }

.badge-normal { background: var(--success-bg); color: var(--success); }
.badge-high { background: var(--warning-bg); color: var(--warning); }
.badge-critical { background: var(--danger-bg); color: var(--danger); }
.badge-hypo { background: var(--hypo-bg); color: var(--hypo-color); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px rgba(37,99,235,0.3);
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 6px 20px rgba(37,99,235,0.4); }

.btn-secondary {
  background: var(--secondary);
  color: white;
  box-shadow: 0 4px 14px rgba(16,185,129,0.3);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

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

.btn-danger {
  background: var(--danger);
  color: white;
  box-shadow: 0 4px 14px rgba(239,68,68,0.3);
}

.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: var(--radius-md); }
.btn-lg { padding: 16px 28px; font-size: 16px; border-radius: var(--radius-xl); }
.btn-full { width: 100%; }
.btn-icon { padding: 10px; border-radius: var(--radius-full); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

.form-input {
  background: var(--bg-subtle);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
  width: 100%;
}

.form-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ============================================================
   SCROLL STYLES
   ============================================================ */
.screen::-webkit-scrollbar { width: 0; }
.horizontal-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.horizontal-scroll::-webkit-scrollbar { display: none; }

/* ============================================================
   SECTION HEADERS
   ============================================================ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.section-action {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font);
}

/* ============================================================
   HOME / DASHBOARD
   ============================================================ */
#screen-home {
  padding-bottom: calc(var(--nav-height) + 20px);
}

/* === Hero Glucose Card === */
.hero-card {
  background: linear-gradient(135deg, var(--primary) 0%, #1D4ED8 60%, #7C3AED 100%);
  border-radius: var(--radius-2xl);
  padding: 28px 24px;
  color: white !important;
  position: relative;
  overflow: hidden;
  margin: 16px 16px 0;
  box-shadow: 0 12px 40px rgba(37,99,235,0.35);
  min-height: 220px;
}

.hero-card::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 180px;
  height: 180px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
}

.hero-card::after {
  content: '';
  position: absolute;
  bottom: -30px;
  left: -20px;
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.04);
  border-radius: 50%;
}

.hero-label {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.8;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: white;
}

.hero-glucose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
}

.hero-value {
  font-size: 72px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -3px;
  color: white;
}

.hero-unit {
  font-size: 16px;
  font-weight: 500;
  opacity: 0.7;
  padding-bottom: 12px;
  color: white;
}

.hero-trend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
}

.trend-arrow {
  font-size: 20px;
  font-weight: 700;
}

.trend-label {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
  color: white;
}

.hero-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(10px);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.hero-status-dot {
  width: 8px;
  height: 8px;
  background: #22C55E;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(34,197,94,0.4);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 2px rgba(34,197,94,0.4); }
  50% { box-shadow: 0 0 0 5px rgba(34,197,94,0.15); }
}

.hero-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.15);
}

.hero-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hero-meta-label { font-size: 11px; opacity: 0.65; font-weight: 500; color: white; }
.hero-meta-value { font-size: 14px; font-weight: 700; color: white; }

/* === Quick Actions === */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 16px;
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  transition: var(--transition-spring);
}

.quick-action:active { transform: scale(0.88); }

.quick-action-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: var(--transition);
}

.quick-action span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.3;
}

.qa-glucose { background: var(--primary-100); }
.qa-insulin { background: var(--secondary-50); }
.qa-food { background: var(--warning-bg); }
.qa-emergency { background: var(--danger-bg); }

/* === Summary Row === */
.summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 16px;
}

.summary-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 14px 12px;
  text-align: center;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-xs);
}

.summary-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -1px;
}

.summary-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 3px;
}

/* === Section Padding === */
.section-pad {
  padding: 16px 16px 0;
}

/* === Health Score Card === */
.health-score-card {
  background: linear-gradient(135deg, #10B981, #059669);
  border-radius: var(--radius-xl);
  padding: 20px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 24px rgba(16,185,129,0.25);
}

.health-score-left { flex: 1; }
.health-score-title { font-size: 13px; font-weight: 600; opacity: 0.85; margin-bottom: 6px; }

.score-ring {
  width: 72px;
  height: 72px;
  position: relative;
}

.score-ring svg { transform: rotate(-90deg); }
.score-ring .score-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  font-weight: 900;
  color: white;
}

/* === Mini Sparkline === */
.sparkline-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 18px;
  border: 1px solid var(--border-light);
}

.sparkline-wrap { height: 80px; position: relative; }

/* === Insulin Reminder Card === */
.reminder-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 16px;
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.reminder-card:active { transform: scale(0.98); }

.reminder-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.reminder-content { flex: 1; }
.reminder-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.reminder-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* === Medication Progress === */
.med-progress-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.med-info { flex: 1; }
.med-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.med-dose { font-size: 12px; color: var(--text-secondary); }

.progress-bar-wrap {
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  margin-top: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.med-check {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  cursor: pointer;
  transition: var(--transition-spring);
}

.med-check:active { transform: scale(0.85); }
.med-check.done { background: var(--success-bg); }
.med-check.pending { background: var(--bg-subtle); }

/* === HbA1c Card === */
.hba1c-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 18px;
  border: 1px solid var(--border-light);
}

.hba1c-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hba1c-value {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -2px;
  color: var(--primary);
}

.hba1c-unit { font-size: 16px; font-weight: 500; color: var(--text-secondary); }
.hba1c-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ============================================================
   GLUCOSE SCREEN
   ============================================================ */
#screen-glucose {
  padding-bottom: calc(var(--nav-height) + 20px);
}

.glucose-range-bar {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 16px;
  border: 1px solid var(--border-light);
}

.range-bar-track {
  height: 12px;
  border-radius: var(--radius-full);
  background: linear-gradient(to right,
    #7C3AED 0%, #7C3AED 15%,
    #22C55E 15%, #22C55E 65%,
    #F59E0B 65%, #F59E0B 80%,
    #EF4444 80%
  );
  position: relative;
  margin: 12px 0;
}

.range-bar-indicator {
  position: absolute;
  top: -3px;
  width: 18px;
  height: 18px;
  background: white;
  border: 3px solid var(--primary);
  border-radius: 50%;
  transform: translateX(-50%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: left 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: 600;
}

/* === Chart Container === */
.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 18px;
  border: 1px solid var(--border-light);
}

.chart-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
}

.chart-tab {
  flex: 1;
  padding: 7px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: var(--transition);
}

.chart-tab.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

canvas.chart { width: 100%; display: block; }

/* === Log Glucose Form === */
.log-form {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 20px;
  border: 1px solid var(--border-light);
}

.glucose-time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.glucose-time-item {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}

.glucose-time-item.selected {
  border-color: var(--primary);
  background: var(--primary-50);
}

.glucose-time-item label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}

.glucose-time-item input {
  background: transparent;
  border: none;
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  width: 100%;
  font-family: var(--font);
  outline: none;
}

.glucose-time-item input::placeholder { color: var(--text-tertiary); font-weight: 400; font-size: 16px; }

/* === History List === */
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.history-item:last-child { border-bottom: none; }

.history-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.history-info { flex: 1; }
.history-type { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.history-time { font-size: 11px; color: var(--text-tertiary); margin-top: 1px; }

.history-value {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

/* ============================================================
   INSULIN SCREEN
   ============================================================ */
#screen-insulin {
  padding-bottom: calc(var(--nav-height) + 20px);
}

/* === Body Map === */
.body-map-container {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 20px;
  border: 1px solid var(--border-light);
}

.body-map-svg-wrap {
  display: flex;
  justify-content: center;
  position: relative;
  height: 220px;
}

.body-map-svg-wrap svg { height: 220px; width: auto; }

.injection-site {
  cursor: pointer;
  transition: var(--transition);
}

.injection-site circle {
  fill: var(--bg-subtle);
  stroke: var(--border);
  stroke-width: 2;
  transition: var(--transition);
}

.injection-site.active circle { fill: var(--primary); stroke: var(--primary-dark); }
.injection-site.recent circle { fill: var(--warning-light); stroke: var(--warning); }
.injection-site text { font-size: 8px; fill: var(--text-secondary); text-anchor: middle; pointer-events: none; }
.injection-site.active text { fill: white; }

.body-map-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 14px;
}

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

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* === Insulin Type Selector === */
.insulin-type-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.insulin-type-tab {
  white-space: nowrap;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font);
  transition: var(--transition);
}

.insulin-type-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* === Dose Slider === */
.dose-slider-wrap {
  text-align: center;
  padding: 10px 0;
}

.dose-display {
  font-size: 48px;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -2px;
}

.dose-unit { font-size: 16px; font-weight: 500; color: var(--text-secondary); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  outline: none;
  margin: 16px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(37,99,235,0.4);
  transition: var(--transition-spring);
}

input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.3); }

/* ============================================================
   INSIGHTS SCREEN
   ============================================================ */
#screen-insights {
  padding-bottom: calc(var(--nav-height) + 20px);
}

/* === Time in Range === */
.tir-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 20px;
  border: 1px solid var(--border-light);
}

.tir-chart-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
}

.tir-donut { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.tir-donut .center-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.tir-donut .center-pct { font-size: 26px; font-weight: 900; color: var(--success); letter-spacing: -1px; }
.tir-donut .center-label { font-size: 10px; color: var(--text-tertiary); font-weight: 600; }

.tir-legend { flex: 1; }
.tir-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tir-legend-left { display: flex; align-items: center; gap: 8px; }
.tir-legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.tir-legend-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.tir-legend-pct { font-size: 13px; font-weight: 700; color: var(--text-primary); }

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--border-light);
}

.stat-icon { font-size: 22px; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 900; letter-spacing: -1px; color: var(--text-primary); }
.stat-label { font-size: 11px; color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 2px; }
.stat-trend { font-size: 11px; font-weight: 600; margin-top: 4px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* === AI Pattern Cards === */
.pattern-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--border-light);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.pattern-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.pattern-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.pattern-content { flex: 1; }
.pattern-title { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; }
.pattern-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }
.pattern-time { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }

/* === DiaCoach Chat === */
.diacoach-header {
  background: linear-gradient(135deg, #2563EB, #7C3AED);
  border-radius: var(--radius-xl);
  padding: 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.coach-avatar {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}

.coach-name { font-size: 18px; font-weight: 800; }
.coach-status { font-size: 12px; opacity: 0.8; margin-top: 2px; }
.coach-online { color: #4ADE80; }

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px 0;
}

.chat-messages::-webkit-scrollbar { width: 0; }

.chat-bubble {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.5;
}

.chat-bubble.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-bubble.coach {
  background: var(--bg-card);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-light);
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg-subtle);
  border: 2px solid transparent;
  border-radius: var(--radius-xl);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 100px;
  transition: var(--transition);
}

.chat-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--primary);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-spring);
  font-size: 18px;
}

.chat-send-btn:active { transform: scale(0.88); }

.chat-suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chat-suggestion {
  padding: 6px 12px;
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  cursor: pointer;
  font-family: var(--font);
  transition: var(--transition);
}

.chat-suggestion:hover { background: var(--primary); color: white; }

/* === Typing indicator === */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  border: 1px solid var(--border-light);
  max-width: 80px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   PROFILE SCREEN
   ============================================================ */
#screen-profile {
  padding-bottom: calc(var(--nav-height) + 20px);
}

/* === Profile Hero === */
.profile-hero {
  background: linear-gradient(135deg, var(--primary) 0%, #7C3AED 100%);
  padding: 30px 20px 24px;
  text-align: center;
  color: white;
  position: relative;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.2);
  border: 3px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin: 0 auto 14px;
  position: relative;
}

.profile-edit-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 28px;
  height: 28px;
  background: var(--secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}

.profile-name { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.profile-sub { font-size: 13px; opacity: 0.8; }

.profile-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.15);
}

.profile-stat { text-align: center; }
.profile-stat-value { font-size: 18px; font-weight: 800; }
.profile-stat-label { font-size: 11px; opacity: 0.7; font-weight: 500; margin-top: 2px; }

/* === Settings List === */
.settings-list {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.settings-item:last-child { border-bottom: none; }
.settings-item:active { background: var(--bg-subtle); }

.settings-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.settings-text { flex: 1; }
.settings-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.settings-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

.settings-chevron {
  color: var(--text-tertiary);
  font-size: 18px;
}

/* === Toggle Switch === */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
}

.toggle input:checked + .toggle-track { background: var(--primary); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  transition: var(--transition-spring);
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(22px); }

/* ============================================================
   EMERGENCY OVERLAY
   ============================================================ */
.emergency-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

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

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.emergency-card {
  background: var(--bg-card);
  border-radius: var(--radius-2xl);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.emergency-icon {
  font-size: 56px;
  margin-bottom: 12px;
  animation: emergencyPulse 1.5s infinite;
}

@keyframes emergencyPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.emergency-title {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.emergency-subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }

.emergency-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  margin-bottom: 20px;
}

.emergency-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-text { font-size: 13px; font-weight: 500; color: var(--text-primary); line-height: 1.4; }

/* === Timer === */
.emergency-timer {
  font-size: 40px;
  font-weight: 900;
  color: var(--danger);
  letter-spacing: -2px;
  margin: 12px 0;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

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

.modal-sheet {
  background: var(--bg-card);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 430px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  margin: 0 auto 20px;
}

.modal-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 16px;
}

/* ============================================================
   FOOD DATABASE MODAL
   ============================================================ */
.food-category-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
}

.food-cat-chip {
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: var(--transition);
  font-family: var(--font);
}

.food-cat-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.food-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.food-emoji { font-size: 28px; }
.food-info { flex: 1; }
.food-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.food-carbs { font-size: 12px; color: var(--text-secondary); }
.food-add-btn { font-size: 20px; cursor: pointer; color: var(--primary); }

/* ============================================================
   INVENTORY CARDS
   ============================================================ */
.inventory-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}

.inventory-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.inventory-info { flex: 1; }
.inventory-name { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.inventory-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.inventory-stock { text-align: right; }
.stock-value { font-size: 18px; font-weight: 800; color: var(--text-primary); }
.stock-label { font-size: 11px; color: var(--text-tertiary); }
.stock-low { color: var(--danger); }

/* === Expiry bar === */
.expiry-bar {
  height: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  margin-top: 6px;
  overflow: hidden;
}

.expiry-fill { height: 100%; border-radius: var(--radius-full); }

/* ============================================================
   HEALTH RECORDS
   ============================================================ */
.record-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
}

.record-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: var(--primary-50);
  flex-shrink: 0;
}

.record-info { flex: 1; }
.record-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.record-meta { font-size: 12px; color: var(--text-secondary); }

/* ============================================================
   JOURNEY TIMELINE
   ============================================================ */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, var(--primary), var(--secondary), var(--warning));
  border-radius: var(--radius-full);
}

.timeline-item {
  position: relative;
  margin-bottom: 20px;
}

.timeline-dot {
  position: absolute;
  left: -21px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 2px var(--primary);
}

.timeline-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  border: 1px solid var(--border-light);
}

.timeline-date { font-size: 11px; color: var(--text-tertiary); font-weight: 600; margin-bottom: 4px; }
.timeline-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.timeline-desc { font-size: 12px; color: var(--text-secondary); margin-top: 3px; line-height: 1.5; }
.timeline-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
}

/* ============================================================
   ONBOARDING SCREEN
   ============================================================ */
#onboarding {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg);
  overflow-y: auto;
}

#onboarding.show { display: flex; flex-direction: column; }

.onboarding-slide {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 100vh;
  padding: 40px 28px;
}

.onboarding-slide.active { display: flex; }

.onboarding-emoji {
  font-size: 80px;
  margin-bottom: 24px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.onboarding-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--text-primary);
  letter-spacing: -1px;
  line-height: 1.2;
  margin-bottom: 14px;
}

.onboarding-desc {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 320px;
}

.onboarding-dots {
  display: flex;
  gap: 8px;
  margin: 32px 0;
}

.onboarding-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: var(--transition-spring);
}

.onboarding-dot.active {
  background: var(--primary);
  width: 24px;
  border-radius: var(--radius-full);
}

/* ============================================================
   NOTIFICATIONS TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 398px;
  pointer-events: none;
}

.toast {
  background: var(--text-primary);
  color: var(--text-inverse);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: all;
}

.toast.success { background: var(--success); }
.toast.warning { background: var(--warning); }
.toast.danger { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ============================================================
   FAB
   ============================================================ */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  right: calc(50% - 215px + 16px);
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: white;
  border: none;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-colored);
  z-index: 100;
  transition: var(--transition-spring);
}

.fab:active { transform: scale(0.9); }

/* ============================================================
   LOADING SKELETON
   ============================================================ */
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border-light) 50%, var(--bg-subtle) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4 { gap: 4px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-14 { gap: 14px; }
.gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-sm { font-size: 12px; }
.text-md { font-size: 14px; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 900; }
.text-secondary { color: var(--text-secondary); }
.text-primary-color { color: var(--primary); }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.hidden { display: none !important; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
.animate-fade-in {
  animation: fadeIn 0.3s ease forwards;
}

.animate-slide-up {
  animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.scale-on-press {
  cursor: pointer;
  transition: var(--transition-spring);
}

.scale-on-press:active { transform: scale(0.95); }

/* ============================================================
   HEMA REDESIGN — GAMIFICATION & USER-FRIENDLY COMPONENTS
   ============================================================ */

/* === Warm accent color for Hema's theme === */
:root {
  --warm: #F97316;
  --warm-light: #FDBA74;
  --warm-bg: #FFF7ED;
  --streak-orange: #EA580C;
  --hba1c-purple: #7C3AED;
}

/* ============================================================
   AFFIRMATION CARD
   ============================================================ */
.affirmation-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  margin: 12px 16px 0;
  color: white;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(102,126,234,0.3);
}

.affirmation-card::before {
  content: '💙';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 48px;
  opacity: 0.15;
}

.affirmation-day {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 6px;
}

.affirmation-text {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  max-width: 85%;
}

/* ============================================================
   STREAK CARD
   ============================================================ */
.streak-card {
  background: linear-gradient(135deg, #EA580C 0%, #F97316 50%, #FB923C 100%);
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  margin: 12px 16px 0;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 28px rgba(234,88,12,0.35);
  position: relative;
  overflow: hidden;
}

.streak-card::after {
  content: '';
  position: absolute;
  top: -20px;
  right: -20px;
  width: 100px;
  height: 100px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.streak-left { flex: 1; }

.streak-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 4px;
}

.streak-count {
  font-size: 48px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -2px;
}

.streak-unit {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 2px;
}

.streak-fire {
  font-size: 56px;
  animation: fireFlicker 1.8s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(255,200,50,0.6));
}

@keyframes fireFlicker {
  0%, 100% { transform: scale(1) rotate(-3deg); }
  50%       { transform: scale(1.08) rotate(3deg); }
}

.streak-mini-stats {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}

.streak-mini-stat {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 600;
}

.streak-mini-stat span {
  font-weight: 800;
  font-size: 13px;
}

/* ============================================================
   INSULIN REMINDER HERO CARD
   ============================================================ */
.insulin-reminder-hero {
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  margin: 12px 16px 0;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.insulin-reminder-hero.due {
  background: linear-gradient(135deg, #1D4ED8 0%, #2563EB 100%);
  box-shadow: 0 8px 28px rgba(37,99,235,0.35);
  color: white;
}

.insulin-reminder-hero.overdue {
  background: linear-gradient(135deg, #DC2626 0%, #EF4444 100%);
  box-shadow: 0 8px 28px rgba(239,68,68,0.4);
  color: white;
  animation: overdueShake 0.5s ease;
}

.insulin-reminder-hero.all-done {
  background: linear-gradient(135deg, #059669 0%, #10B981 100%);
  box-shadow: 0 8px 24px rgba(16,185,129,0.3);
  color: white;
}

@keyframes overdueShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-4px); }
  40%       { transform: translateX(4px); }
  60%       { transform: translateX(-3px); }
  80%       { transform: translateX(3px); }
}

.insulin-reminder-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.insulin-reminder-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 4px;
}

.insulin-reminder-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.insulin-reminder-dose {
  font-size: 13px;
  opacity: 0.85;
  font-weight: 500;
  margin-top: 2px;
}

.insulin-pulse-ring {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  position: relative;
  flex-shrink: 0;
}

.insulin-pulse-ring.pulsing::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  animation: pulseRing 1.5s ease-out infinite;
}

.insulin-pulse-ring.pulsing::after {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  animation: pulseRing 1.5s ease-out infinite 0.3s;
}

@keyframes pulseRing {
  0%   { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.btn-take-insulin {
  width: 100%;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: var(--radius-lg);
  color: white;
  font-size: 15px;
  font-weight: 700;
  padding: 14px 20px;
  cursor: pointer;
  font-family: var(--font);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
}

.btn-take-insulin:hover {
  background: rgba(255,255,255,0.35);
  transform: translateY(-1px);
}

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

.btn-snooze {
  width: 100%;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  font-family: var(--font);
  text-align: center;
  margin-top: 4px;
}

.insulin-next-up {
  font-size: 11px;
  opacity: 0.75;
  margin-top: 8px;
  font-weight: 500;
}

/* ============================================================
   HbA1c COUNTDOWN CARD
   ============================================================ */
.hba1c-countdown-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  border: 2px solid #EDE9FE;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.hba1c-countdown-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #7C3AED, #A855F7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(124,58,237,0.3);
}

.hba1c-countdown-info { flex: 1; }

.hba1c-countdown-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.hba1c-countdown-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.hba1c-days {
  font-size: 28px;
  font-weight: 900;
  color: var(--hba1c-purple);
  letter-spacing: -1px;
  line-height: 1;
}

.hba1c-days-label {
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

[data-theme="dark"] .hba1c-countdown-card {
  border-color: rgba(124,58,237,0.2);
}

/* ============================================================
   ACHIEVEMENT BADGES
   ============================================================ */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.badge-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.badge-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  position: relative;
  transition: var(--transition-spring);
}

.badge-icon-wrap.earned {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  box-shadow: 0 4px 12px rgba(245,158,11,0.3);
}

.badge-icon-wrap.locked {
  background: var(--bg-subtle);
  filter: grayscale(1);
  opacity: 0.5;
}

.badge-icon-wrap.earned::after {
  content: '✓';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: var(--success);
  border-radius: 50%;
  font-size: 10px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--bg-card);
}

.badge-title {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* ============================================================
   FOOD PATTERN SECTION
   ============================================================ */
.food-pattern-day {
  background: var(--bg-subtle);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 10px;
}

.food-pattern-day-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.food-pattern-meal {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.food-pattern-meal:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.food-pattern-meal-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 64px;
  padding-top: 2px;
  text-transform: uppercase;
}

.food-pattern-meal-foods {
  font-size: 12px;
  color: var(--text-primary);
  flex: 1;
  line-height: 1.4;
}

.food-pattern-meal-carbs {
  font-size: 12px;
  font-weight: 700;
  color: var(--warning);
  flex-shrink: 0;
}

.food-pattern-insight-card {
  background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
  border: 2px solid #FED7AA;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-top: 10px;
}

.food-pattern-insight-title {
  font-size: 12px;
  font-weight: 700;
  color: #EA580C;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.food-pattern-insight-text {
  font-size: 12px;
  color: #7C2D12;
  line-height: 1.5;
}

/* ============================================================
   VETERAN HERO (Profile)
   ============================================================ */
.veteran-banner {
  background: linear-gradient(135deg, #F59E0B, #D97706);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(245,158,11,0.3);
}

.veteran-banner-icon { font-size: 32px; }

.veteran-banner-text { color: white; }

.veteran-banner-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}

.veteran-banner-sub {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

/* ============================================================
   QUICK ACTION — LARGER, MORE FRIENDLY
   ============================================================ */
.quick-action-icon {
  width: 60px !important;
  height: 60px !important;
  font-size: 26px !important;
  border-radius: 18px !important;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-spring) !important;
}

.quick-action:active .quick-action-icon {
  transform: scale(0.88);
}

.quick-action span {
  font-size: 11px !important;
  font-weight: 700 !important;
}

/* ============================================================
   WEEKLY SCORE CARD
   ============================================================ */
.weekly-score-card {
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 24px rgba(16,185,129,0.3);
}

.weekly-score-grade {
  font-size: 56px;
  font-weight: 900;
  letter-spacing: -3px;
  line-height: 1;
}

.weekly-score-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 4px;
}

.weekly-score-desc {
  font-size: 13px;
  opacity: 0.9;
  font-weight: 500;
  margin-top: 2px;
}

/* ============================================================
   INSULIN SCHEDULE LIST
   ============================================================ */
.insulin-schedule-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
}

.insulin-schedule-item:last-child { border-bottom: none; }

.insulin-schedule-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: var(--transition);
}

.insulin-schedule-dot.done { background: var(--success); }
.insulin-schedule-dot.pending { background: var(--border); border: 2px solid var(--border); }
.insulin-schedule-dot.due { background: var(--primary); animation: pulse-dot 1.5s infinite; }
.insulin-schedule-dot.overdue { background: var(--danger); animation: pulse-dot 1s infinite; }

.insulin-schedule-info { flex: 1; }

.insulin-schedule-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.insulin-schedule-time {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.insulin-schedule-action {
  background: var(--primary-50);
  color: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  font-family: var(--font);
  min-height: 36px;
  transition: var(--transition);
}

.insulin-schedule-action:active { transform: scale(0.94); }
.insulin-schedule-action.done-btn { background: var(--success-bg); color: var(--success); }

/* === Printable Report Styles === */
.print-only-container {
  display: none;
}

@media print {
  body {
    background: white !important;
    color: black !important;
  }
  #app {
    display: none !important;
  }
  .print-only-container {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: white;
    color: black;
    padding: 0;
    box-shadow: none;
  }
  
  @page {
    size: A4;
    margin: 15mm;
  }
}
