    /* ===== RESET & BASE ===== */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg-primary: #0a0e1a;
      --bg-secondary: #111827;
      --bg-card: rgba(17, 24, 39, 0.7);
      --bg-card-hover: rgba(30, 41, 59, 0.8);
      --bg-glass: rgba(255, 255, 255, 0.03);
      --border-glass: rgba(255, 255, 255, 0.08);
      --border-accent: rgba(99, 102, 241, 0.3);

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

      --accent-indigo: #818cf8;
      --accent-violet: #a78bfa;
      --accent-emerald: #34d399;
      --accent-amber: #fbbf24;
      --accent-rose: #fb7185;
      --accent-cyan: #22d3ee;
      --accent-orange: #fb923c;

      --gradient-hero: linear-gradient(135deg, #818cf8 0%, #a78bfa 50%, #f0abfc 100%);
      --gradient-danger: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
      --gradient-safe: linear-gradient(135deg, #10b981 0%, #34d399 100%);
      --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
      --gradient-glass: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.01) 100%);

      --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
      --shadow-md: 0 4px 14px rgba(0,0,0,0.4);
      --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
      --shadow-glow-indigo: 0 0 30px rgba(129, 140, 248, 0.15);
      --shadow-glow-emerald: 0 0 30px rgba(52, 211, 153, 0.15);
      --shadow-glow-rose: 0 0 30px rgba(251, 113, 133, 0.2);

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

      --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
      --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
      --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
    }

    html { scroll-behavior: smooth; }

    body {
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
      background: var(--bg-primary);
      color: var(--text-primary);
      min-height: 100vh;
      line-height: 1.6;
      overflow-x: hidden;
    }

    /* ===== AMBIENT BACKGROUND ===== */
    body::before {
      content: '';
      position: fixed;
      top: -50%;
      left: -50%;
      width: 200%;
      height: 200%;
      background:
        radial-gradient(ellipse at 20% 50%, rgba(129, 140, 248, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(167, 139, 250, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(52, 211, 153, 0.04) 0%, transparent 50%);
      z-index: 0;
      pointer-events: none;
      animation: ambientShift 20s ease-in-out infinite alternate;
    }

    @keyframes ambientShift {
      0% { transform: translate(0, 0) rotate(0deg); }
      100% { transform: translate(-2%, -1%) rotate(1deg); }
    }

    /* ===== SCROLLBAR ===== */
    ::-webkit-scrollbar { width: 6px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: rgba(129, 140, 248, 0.3); border-radius: 3px; }
    ::-webkit-scrollbar-thumb:hover { background: rgba(129, 140, 248, 0.5); }

    /* ===== LAYOUT ===== */
    .app-container {
      position: relative;
      z-index: 1;
      max-width: 1200px;
      margin: 0 auto;
      padding: 20px 24px 60px;
    }

    /* ===== HEADER ===== */
    .app-header {
      text-align: center;
      padding: 40px 0 24px;
      position: relative;
    }

    .app-header .logo-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 56px;
      height: 56px;
      background: var(--gradient-hero);
      border-radius: var(--radius-lg);
      font-size: 26px;
      margin-bottom: 16px;
      box-shadow: 0 8px 32px rgba(129, 140, 248, 0.3);
      animation: logoPulse 3s ease-in-out infinite;
    }

    @keyframes logoPulse {
      0%, 100% { transform: scale(1); box-shadow: 0 8px 32px rgba(129, 140, 248, 0.3); }
      50% { transform: scale(1.05); box-shadow: 0 12px 40px rgba(129, 140, 248, 0.4); }
    }

    .app-header h1 {
      font-size: 2rem;
      font-weight: 800;
      background: var(--gradient-hero);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      letter-spacing: -0.5px;
    }

    .app-header .subtitle {
      color: var(--text-secondary);
      font-size: 0.9rem;
      margin-top: 6px;
      font-weight: 400;
    }

    .current-date {
      display: inline-block;
      margin-top: 12px;
      padding: 6px 16px;
      background: var(--bg-glass);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-full);
      font-size: 0.8rem;
      color: var(--text-muted);
      font-weight: 500;
    }

    /* ===== AUTHENTICATION OVERLAY ===== */
    .auth-overlay {
      position: fixed;
      inset: 0;
      background: rgba(10, 14, 26, 0.96);
      backdrop-filter: blur(15px);
      z-index: 1000;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
      transition: opacity 0.4s ease;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }
    .auth-overlay.hidden {
      opacity: 0;
      pointer-events: none;
    }
    .auth-card, .auth-box {
      background: var(--bg-card);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-xl);
      padding: 35px;
      width: 100%;
      max-width: 420px;
      max-height: 90vh;
      overflow-y: auto;
      text-align: center;
      box-shadow: var(--shadow-lg);
      -webkit-overflow-scrolling: touch;
    }
    .auth-card h2 {
      margin-top: 15px;
      font-size: 1.6rem;
      font-weight: 800;
      background: var(--gradient-hero);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    .auth-card p {
      color: var(--text-secondary);
      font-size: 0.85rem;
      margin-bottom: 25px;
    }
    .auth-toggle {
      margin-top: 20px;
      font-size: 0.82rem;
      color: var(--text-muted);
    }
    .auth-toggle a {
      color: var(--accent-indigo);
      text-decoration: none;
      font-weight: 600;
      margin-left: 5px;
    }
    .auth-toggle a:hover {
      text-decoration: underline;
    }
    .user-banner {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 12px;
      margin-top: 14px;
      font-size: 0.82rem;
      color: var(--text-secondary);
    }

    /* ===== NAVIGATION TABS ===== */
    .nav-tabs {
      display: flex;
      gap: 6px;
      padding: 6px;
      background: var(--bg-card);
      backdrop-filter: blur(20px);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-xl);
      margin-bottom: 28px;
      overflow-x: auto;
      scrollbar-width: none;
      -ms-overflow-style: none;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }

    .nav-tab {
      flex: 1;
      min-width: 120px;
      padding: 12px 16px;
      border: none;
      background: transparent;
      color: var(--text-muted);
      font-family: inherit;
      font-size: 0.8rem;
      font-weight: 600;
      border-radius: var(--radius-lg);
      cursor: pointer;
      transition: all var(--transition-base);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      white-space: nowrap;
      position: relative;
    }

    .nav-tab:hover {
      color: var(--text-secondary);
      background: rgba(255,255,255,0.03);
    }

    .nav-tab.active {
      background: rgba(129, 140, 248, 0.12);
      color: var(--accent-indigo);
      box-shadow: var(--shadow-glow-indigo);
    }

    .nav-tab .tab-icon { font-size: 1.1rem; }

    /* ===== TAB SECTIONS ===== */
    .tab-section {
      display: none;
      animation: fadeIn 0.3s ease;
    }

    .tab-section.active { display: block; }

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

    /* ===== CARD ===== */
    .card {
      background: var(--bg-card);
      backdrop-filter: blur(20px);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-xl);
      padding: 28px;
      margin-bottom: 20px;
      transition: all var(--transition-base);
      position: relative;
      overflow: hidden;
    }

    .card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 1px;
      background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    }

    .card:hover {
      border-color: var(--border-accent);
      box-shadow: var(--shadow-glow-indigo);
    }

    .card-header {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 20px;
    }

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

    .card-header h2 {
      font-size: 1.1rem;
      font-weight: 700;
      letter-spacing: -0.3px;
    }

    .card-header p {
      font-size: 0.78rem;
      color: var(--text-muted);
      margin-top: 2px;
    }

    /* ===== GLUCOSE ALERT PANEL ===== */
    .glucose-display {
      text-align: center;
      padding: 32px 20px;
      border-radius: var(--radius-lg);
      margin-bottom: 24px;
      position: relative;
      transition: all var(--transition-slow);
    }

    .glucose-display.crisis {
      background: linear-gradient(135deg, rgba(239, 68, 68, 0.12) 0%, rgba(249, 115, 22, 0.08) 100%);
      border: 1px solid rgba(239, 68, 68, 0.25);
      animation: crisisFlash 1.5s ease-in-out infinite;
    }

    @keyframes crisisFlash {
      0%, 100% { border-color: rgba(239, 68, 68, 0.25); box-shadow: 0 0 20px rgba(239, 68, 68, 0.1); }
      50% { border-color: rgba(249, 115, 22, 0.5); box-shadow: 0 0 40px rgba(239, 68, 68, 0.2); }
    }

    .glucose-display.warning {
      background: linear-gradient(135deg, rgba(245, 158, 11, 0.1) 0%, rgba(251, 191, 36, 0.05) 100%);
      border: 1px solid rgba(245, 158, 11, 0.2);
    }

    .glucose-display.safe {
      background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(52, 211, 153, 0.05) 100%);
      border: 1px solid rgba(16, 185, 129, 0.2);
    }

    .glucose-display.optimal {
      background: linear-gradient(135deg, rgba(34, 211, 238, 0.1) 0%, rgba(129, 140, 248, 0.05) 100%);
      border: 1px solid rgba(34, 211, 238, 0.2);
    }

    .glucose-display.idle {
      background: var(--bg-glass);
      border: 1px solid var(--border-glass);
    }

    .glucose-value {
      font-size: 4rem;
      font-weight: 900;
      line-height: 1;
      margin-bottom: 4px;
      letter-spacing: -2px;
      transition: color var(--transition-base);
    }

    .glucose-value.crisis { color: #ef4444; }
    .glucose-value.warning { color: #fbbf24; }
    .glucose-value.safe { color: #34d399; }
    .glucose-value.optimal { color: #22d3ee; }
    .glucose-value.idle { color: var(--text-muted); }

    .glucose-unit {
      font-size: 0.85rem;
      color: var(--text-muted);
      font-weight: 500;
    }

    .glucose-status {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      margin-top: 12px;
      padding: 6px 16px;
      border-radius: var(--radius-full);
      font-size: 0.8rem;
      font-weight: 600;
    }

    .glucose-status.crisis {
      background: rgba(239, 68, 68, 0.15);
      color: #fca5a5;
    }

    .glucose-status.warning {
      background: rgba(245, 158, 11, 0.15);
      color: #fde68a;
    }

    .glucose-status.safe {
      background: rgba(16, 185, 129, 0.15);
      color: #6ee7b7;
    }

    .glucose-status.optimal {
      background: rgba(34, 211, 238, 0.15);
      color: #67e8f9;
    }

    .glucose-status.idle {
      background: var(--bg-glass);
      color: var(--text-muted);
    }

    .status-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      display: inline-block;
    }

    .status-dot.crisis { background: #ef4444; animation: dotPulse 1s infinite; }
    .status-dot.warning { background: #fbbf24; }
    .status-dot.safe { background: #34d399; }
    .status-dot.optimal { background: #22d3ee; }
    .status-dot.idle { background: var(--text-muted); }

    @keyframes dotPulse {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.3; }
    }

    .glucose-input-row {
      display: flex;
      gap: 12px;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
    }

    .glucose-input-row input {
      width: 180px;
      padding: 14px 20px;
      background: rgba(255,255,255,0.05);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-md);
      color: var(--text-primary);
      font-family: inherit;
      font-size: 1.1rem;
      font-weight: 600;
      text-align: center;
      outline: none;
      transition: all var(--transition-base);
    }

    .glucose-input-row input:focus {
      border-color: var(--accent-indigo);
      box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
    }

    /* ===== ALERT RECOMMENDATIONS ===== */
    .alert-recs {
      margin-top: 20px;
      display: none;
    }

    .alert-recs.show { display: block; animation: fadeIn 0.4s ease; }

    .alert-rec-item {
      display: flex;
      align-items: flex-start;
      gap: 12px;
      padding: 14px 18px;
      background: rgba(239, 68, 68, 0.06);
      border: 1px solid rgba(239, 68, 68, 0.12);
      border-radius: var(--radius-md);
      margin-bottom: 8px;
      font-size: 0.85rem;
      color: var(--text-secondary);
      line-height: 1.5;
    }

    .alert-rec-item .rec-icon {
      font-size: 1.2rem;
      flex-shrink: 0;
      margin-top: 1px;
    }

    /* ===== GAUGE RING ===== */
    .gauge-container {
      display: flex;
      justify-content: center;
      margin-bottom: 8px;
    }

    .gauge-svg {
      transform: rotate(-90deg);
    }

    .gauge-track {
      fill: none;
      stroke: rgba(255,255,255,0.05);
      stroke-width: 8;
    }

    .gauge-fill {
      fill: none;
      stroke-width: 8;
      stroke-linecap: round;
      transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.4s ease;
    }

    /* ===== BUTTONS ===== */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 12px 24px;
      border: none;
      border-radius: var(--radius-md);
      font-family: inherit;
      font-size: 0.85rem;
      font-weight: 600;
      cursor: pointer;
      transition: all var(--transition-base);
      position: relative;
      overflow: hidden;
    }

    .btn::after {
      content: '';
      position: absolute;
      inset: 0;
      background: rgba(255,255,255,0);
      transition: background var(--transition-fast);
    }

    .btn:hover::after { background: rgba(255,255,255,0.05); }
    .btn:active { transform: scale(0.97); }

    .btn-primary {
      background: var(--gradient-hero);
      color: white;
      box-shadow: 0 4px 16px rgba(129, 140, 248, 0.3);
    }
    .btn-primary:hover { box-shadow: 0 6px 24px rgba(129, 140, 248, 0.4); }

    .btn-success {
      background: var(--gradient-safe);
      color: #064e3b;
      box-shadow: 0 4px 16px rgba(52, 211, 153, 0.3);
    }

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

    .btn-ghost {
      background: rgba(255,255,255,0.05);
      color: var(--text-secondary);
      border: 1px solid var(--border-glass);
    }
    .btn-ghost:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }

    .btn-sm {
      padding: 8px 16px;
      font-size: 0.78rem;
    }

    /* ===== FORM ELEMENTS ===== */
    .form-group {
      margin-bottom: 16px;
      text-align: left;
    }

    .form-label {
      display: block;
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--text-secondary);
      margin-bottom: 6px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .form-input, .form-select {
      width: 100%;
      padding: 12px 16px;
      background: rgba(255,255,255,0.04);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-md);
      color: var(--text-primary);
      font-family: inherit;
      font-size: 0.9rem;
      outline: none;
      transition: all var(--transition-base);
    }

    .form-input:focus, .form-select:focus {
      border-color: var(--accent-indigo);
      box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12);
    }

    .form-select {
      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 fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 14px center;
      padding-right: 36px;
      cursor: pointer;
    }

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

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

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

    .radio-pill {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .radio-pill input[type="radio"] {
      display: none;
    }

    .radio-pill label {
      padding: 8px 18px;
      background: rgba(255,255,255,0.04);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-full);
      font-size: 0.8rem;
      font-weight: 500;
      color: var(--text-muted);
      cursor: pointer;
      transition: all var(--transition-base);
    }

    .radio-pill input[type="radio"]:checked + label {
      background: rgba(129, 140, 248, 0.12);
      border-color: rgba(129, 140, 248, 0.3);
      color: var(--accent-indigo);
    }

    /* ===== METRICS TABLE ===== */
    .metrics-table-wrap {
      overflow-x: auto;
      border-radius: var(--radius-md);
      border: 1px solid var(--border-glass);
    }

    .metrics-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.82rem;
    }

    .metrics-table thead th {
      padding: 12px 16px;
      background: rgba(255,255,255,0.03);
      color: var(--text-muted);
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      font-size: 0.72rem;
      text-align: left;
      border-bottom: 1px solid var(--border-glass);
    }

    .metrics-table tbody td {
      padding: 12px 16px;
      border-bottom: 1px solid rgba(255,255,255,0.03);
      color: var(--text-secondary);
    }

    .metrics-table tbody tr:hover {
      background: rgba(255,255,255,0.02);
    }

    .glucose-badge {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 3px 10px;
      border-radius: var(--radius-full);
      font-weight: 600;
      font-size: 0.78rem;
    }

    .glucose-badge.crisis { background: rgba(239,68,68,0.12); color: #fca5a5; }
    .glucose-badge.warning { background: rgba(245,158,11,0.12); color: #fde68a; }
    .glucose-badge.safe { background: rgba(16,185,129,0.12); color: #6ee7b7; }
    .glucose-badge.optimal { background: rgba(34,211,238,0.12); color: #67e8f9; }

    .avg-display {
      display: flex;
      gap: 16px;
      margin-bottom: 20px;
      flex-wrap: wrap;
    }

    .avg-card {
      flex: 1;
      min-width: 140px;
      padding: 18px;
      background: var(--bg-glass);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-md);
      text-align: center;
    }

    .avg-card .avg-label {
      font-size: 0.7rem;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.5px;
      font-weight: 600;
      margin-bottom: 4px;
    }

    .avg-card .avg-value {
      font-size: 1.8rem;
      font-weight: 800;
      letter-spacing: -1px;
    }

    .delete-btn {
      background: none;
      border: none;
      color: var(--text-muted);
      cursor: pointer;
      font-size: 1rem;
      padding: 4px;
      border-radius: 4px;
      transition: all var(--transition-fast);
    }
    .delete-btn:hover { color: var(--accent-rose); background: rgba(251,113,133,0.1); }

    /* ===== FASTING TIMER ===== */
    .fasting-timer-display {
      text-align: center;
      padding: 40px 20px;
      position: relative;
    }

    .timer-ring-container {
      position: relative;
      display: inline-block;
      margin-bottom: 24px;
    }

    .timer-ring-container .timer-text-overlay {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
    }

    .timer-value {
      font-size: 2.5rem;
      font-weight: 800;
      color: var(--text-primary);
      letter-spacing: -1px;
      font-variant-numeric: tabular-nums;
    }

    .timer-label-small {
      font-size: 0.75rem;
      color: var(--text-muted);
      font-weight: 500;
    }

    .fasting-protocol-select {
      display: flex;
      gap: 8px;
      justify-content: center;
      margin-bottom: 24px;
      flex-wrap: wrap;
    }

    .protocol-btn {
      padding: 10px 20px;
      background: rgba(255,255,255,0.04);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-full);
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--text-muted);
      cursor: pointer;
      transition: all var(--transition-base);
    }

    .protocol-btn.active {
      background: rgba(129, 140, 248, 0.15);
      border-color: rgba(129, 140, 248, 0.4);
      color: var(--accent-indigo);
    }

    /* ===== ALARMS CARD ===== */
    .alarms-list {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .alarm-card {
      background: var(--bg-glass);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-lg);
      padding: 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      transition: all var(--transition-base);
    }

    .alarm-card.active-alarm {
      border-color: rgba(129, 140, 248, 0.3);
      background: rgba(129, 140, 248, 0.03);
    }

    .alarm-card.ringing {
      animation: alarmRinging 0.5s infinite alternate;
    }

    @keyframes alarmRinging {
      0% { border-color: rgba(251, 113, 133, 0.3); background: rgba(251, 113, 133, 0.05); }
      100% { border-color: rgba(251, 113, 133, 0.8); background: rgba(251, 113, 133, 0.2); }
    }

    .alarm-info-side {
      display: flex;
      align-items: center;
      gap: 14px;
    }

    .alarm-icon-box {
      font-size: 1.5rem;
    }

    .alarm-title-small {
      font-size: 0.9rem;
      font-weight: 700;
    }

    .alarm-desc-small {
      font-size: 0.75rem;
      color: var(--text-muted);
    }

    .alarm-timer-side {
      text-align: right;
    }

    .alarm-timer-value {
      font-size: 1.3rem;
      font-weight: 800;
      font-variant-numeric: tabular-nums;
      color: var(--text-muted);
    }

    /* ===== HABITS CHECKLIST ===== */
    .habits-progress-wrap {
      margin-bottom: 24px;
    }

    .habits-progress-bar {
      height: 6px;
      background: rgba(255,255,255,0.05);
      border-radius: var(--radius-full);
      overflow: hidden;
      margin-top: 8px;
    }

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

    .habits-list {
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .habit-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      background: var(--bg-glass);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-lg);
      cursor: pointer;
      transition: all var(--transition-base);
      user-select: none;
    }

    .habit-item:hover {
      border-color: rgba(129, 140, 248, 0.2);
      background: rgba(255,255,255,0.05);
    }

    .habit-item.completed {
      background: rgba(52, 211, 153, 0.04);
      border-color: rgba(52, 211, 153, 0.15);
    }

    .habit-content-side {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .habit-checkbox {
      width: 22px;
      height: 22px;
      border: 2px solid var(--border-glass);
      border-radius: var(--radius-sm);
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--accent-emerald);
      font-weight: 700;
      font-size: 0.8rem;
      transition: all var(--transition-fast);
    }

    .habit-item.completed .habit-checkbox {
      border-color: var(--accent-emerald);
      background: rgba(52, 211, 153, 0.1);
    }

    .habit-text {
      font-size: 0.85rem;
      font-weight: 600;
      color: var(--text-secondary);
      transition: all var(--transition-fast);
    }

    .habit-item.completed .habit-text {
      color: var(--text-muted);
      text-decoration: line-through;
    }

    .habit-badge {
      font-size: 0.7rem;
      font-weight: 700;
      padding: 4px 10px;
      border-radius: var(--radius-full);
      background: rgba(255,255,255,0.04);
      color: var(--text-muted);
    }
    .habit-item.completed .habit-badge {
      background: rgba(52, 211, 153, 0.1);
      color: var(--accent-emerald);
    }

    /* ===== CHART LAYOUT ===== */
    .chart-container {
      height: 160px;
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      padding: 20px 10px 10px;
      border-bottom: 1px solid var(--border-glass);
      gap: 8px;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    .chart-bar-wrap {
      flex: 0 0 auto;
      min-width: 44px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 6px;
    }

    .chart-bar {
      width: 100%;
      max-width: 40px;
      min-width: 28px;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
      background: var(--accent-indigo);
      transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .chart-bar-value {
      font-size: 0.7rem;
      font-weight: 700;
      color: var(--text-primary);
    }

    .chart-bar-label {
      font-size: 0.65rem;
      color: var(--text-muted);
      text-align: center;
      white-space: nowrap;
    }

    /* ===== MEALS GALLERY ===== */
    .meals-gallery {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 16px;
      margin-top: 15px;
    }
    .meal-card {
      background: var(--bg-glass);
      border: 1px solid var(--border-glass);
      border-radius: var(--radius-lg);
      overflow: hidden;
      display: flex;
      flex-direction: column;
      transition: all var(--transition-base);
    }
    .meal-card:hover {
      border-color: var(--border-accent);
      transform: translateY(-2px);
    }
    .meal-img {
      width: 100%;
      height: 180px;
      object-fit: cover;
      background: #111827;
    }
    .meal-info {
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      flex-grow: 1;
    }
    .meal-date {
      font-size: 0.72rem;
      color: var(--text-muted);
      font-weight: 500;
    }
    .meal-title {
      font-size: 0.9rem;
      font-weight: 700;
      color: var(--text-primary);
    }
    .meal-macros {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 6px;
      background: rgba(255, 255, 255, 0.02);
      padding: 8px;
      border-radius: var(--radius-sm);
      text-align: center;
      font-size: 0.75rem;
    }
    .macro-val {
      font-weight: 700;
      color: var(--text-primary);
    }
    .macro-label {
      font-size: 0.65rem;
      color: var(--text-muted);
    }
    .meal-impact {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      font-size: 0.72rem;
      font-weight: 600;
      padding: 4px 10px;
      border-radius: var(--radius-full);
      width: fit-content;
    }
    .meal-impact.bajo { background: rgba(16, 185, 129, 0.12); color: #34d399; }
    .meal-impact.moderado { background: rgba(245, 158, 11, 0.12); color: #fbbf24; }
    .meal-impact.alto { background: rgba(239, 68, 68, 0.12); color: #fb7185; }
    .meal-rec {
      font-size: 0.78rem;
      color: var(--text-secondary);
      line-height: 1.4;
      border-left: 2px solid var(--accent-indigo);
      padding-left: 8px;
      margin-top: 4px;
      text-align: left;
    }

    /* ===== AI CHAT CONTAINER ===== */
    .chat-messages {
      flex-grow: 1;
      overflow-y: auto;
      padding: 10px;
      background: rgba(0, 0, 0, 0.2);
      border-radius: var(--radius-lg);
      border: 1px solid var(--border-glass);
      display: flex;
      flex-direction: column;
      gap: 12px;
      margin-bottom: 15px;
    }
    .chat-msg {
      max-width: 80%;
      padding: 12px 16px;
      border-radius: var(--radius-lg);
      font-size: 0.85rem;
      line-height: 1.5;
      word-break: break-word;
      text-align: left;
    }
    .chat-msg.bot {
      background: var(--bg-glass);
      color: var(--text-primary);
      border: 1px solid var(--border-glass);
      align-self: flex-start;
      border-bottom-left-radius: 4px;
    }
    .chat-msg.user {
      background: var(--gradient-hero);
      color: white;
      align-self: flex-end;
      border-bottom-right-radius: 4px;
      box-shadow: 0 4px 12px rgba(129, 140, 248, 0.2);
    }
    .chat-input-row {
      display: flex;
      gap: 10px;
      flex-shrink: 0;
    }
    .chat-input-row input {
      flex-grow: 1;
    }

    /* ===== TOAST NOTIFICATION ===== */
    .toast-container {
      position: fixed;
      bottom: 24px;
      right: 24px;
      z-index: 1100;
      display: flex;
      flex-direction: column;
      gap: 10px;
      pointer-events: none;
    }

    .toast {
      pointer-events: auto;
      display: flex;
      align-items: center;
      gap: 12px;
      background: var(--bg-card);
      backdrop-filter: blur(20px);
      border: 1px solid var(--border-glass);
      padding: 14px 20px;
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-md);
      color: var(--text-primary);
      font-size: 0.85rem;
      min-width: 280px;
      max-width: 380px;
      animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
      cursor: pointer;
    }

    @keyframes toastIn {
      from { transform: translateY(20px) scale(0.9); opacity: 0; }
      to { transform: translateY(0) scale(1); opacity: 1; }
    }

    .toast.success { border-color: rgba(52, 211, 153, 0.3); }
    .toast.warning { border-color: rgba(251, 191, 36, 0.3); }
    .toast.danger { border-color: rgba(251, 113, 133, 0.4); }

    .toast-icon { font-size: 1.1rem; }
    .toast-msg { font-weight: 500; }

    .hidden { display: none !important; }

    /* ===== RESPONSIVE ===== */
    @media (max-width: 768px) {
      .form-row { grid-template-columns: 1fr; }
      .app-header { padding: 24px 0 16px; }
      .app-header h1 { font-size: 1.6rem; }
      .nav-tabs { border-radius: var(--radius-lg); }
      .nav-tab { min-width: 90px; padding: 10px 12px; font-size: 0.72rem; }
      .card { padding: 20px; }
    }

/* ===== BOTTOM NAVIGATION (MOBILE-FIRST) ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-glass);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
  backdrop-filter: blur(20px);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 0;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition-fast);
  position: relative;
}

.bottom-nav-item.active {
  color: var(--accent-indigo);
}

.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--accent-indigo);
  border-radius: 0 0 3px 3px;
}

.bottom-nav-item .nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

/* ===== BOTTOM SHEET (MORE DRAWER) ===== */
.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

.bottom-sheet.open {
  pointer-events: auto;
}

.bottom-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background 0.3s ease;
}

.bottom-sheet.open .bottom-sheet-backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.bottom-sheet-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
}

.bottom-sheet.open .bottom-sheet-panel {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 32px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  margin: 0 auto 16px;
  opacity: 0.5;
}

.bottom-sheet-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  text-align: center;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.sheet-item:hover, .sheet-item:active {
  background: rgba(129, 140, 248, 0.08);
  color: var(--text-primary);
}

.sheet-item .sheet-icon {
  font-size: 1.3rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

/* ===== SUB-NAVIGATION PILLS ===== */
.sub-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--bg-glass);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-glass);
}

.sub-nav-pill {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}

.sub-nav-pill.active {
  background: rgba(129, 140, 248, 0.15);
  color: var(--accent-indigo);
}

/* Content padding for bottom nav */
.content-padding-bottom {
  padding-bottom: 84px;
}

/* Hide top nav on mobile, show on large screens */
@media (max-width: 899px) {
  .nav-tabs {
    display: none;
  }
}

@media (min-width: 900px) {
  .bottom-nav {
    display: none;
  }
  
  .content-padding-bottom {
    padding-bottom: 0;
  }
}

/* ===== TOAST POSITION (mobile: bottom-center) ===== */
@media (max-width: 600px) {
  .toast-container {
    top: auto;
    bottom: 80px;
    left: 16px;
    right: 16px;
  }
}

/* ===== PHASE 3: MOBILE-FIRST OVERRIDES ===== */

/* Touch targets: minimum 44px (Apple) / 48px (Material) */
.btn {
  padding: 14px 24px;
  min-height: 48px;
}

.btn-sm {
  padding: 10px 18px;
  min-height: 44px;
}

.form-input, .form-select {
  padding: 14px 16px;
  min-height: 48px;
  font-size: 1rem; /* 16px — prevents iOS zoom on focus */
}

.radio-pill label {
  padding: 10px 20px;
  min-height: 44px;
}

.delete-btn {
  width: 44px;
  height: 44px;
  padding: 8px;
}

.protocol-btn {
  padding: 12px 22px;
  min-height: 44px;
}

.habit-item {
  min-height: 52px;
  padding: 14px 18px;
}

.habit-checkbox {
  width: 28px;
  height: 28px;
  min-width: 28px;
}

.alarm-card {
  min-height: 72px;
}

.nav-tab {
  min-width: 90px;
  padding: 14px 12px;
  min-height: 44px;
}

/* Glucose value: scale with viewport */
.glucose-value {
  font-size: clamp(2.5rem, 10vw, 4rem);
}

/* Chart labels: readable at small sizes */
.chart-bar-value {
  font-size: 0.75rem;
}

.chart-bar-label {
  font-size: 0.65rem;
}

/* Safe areas for notched/rounded displays */
.app-container {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* Landscape orientation handling */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header {
    display: none;
  }
  
  .bottom-nav {
    height: 48px;
  }
  
  .content-padding-bottom {
    padding-bottom: 64px;
  }
  
  .card {
    padding: 14px;
    margin-bottom: 10px;
  }
  
  .glucose-value {
    font-size: 2rem;
  }
  
  .app-container {
    padding-top: 8px;
  }
}

/* Tablet breakpoint (600px+) */
@media (min-width: 600px) {
  .app-container {
    padding: 20px 24px 84px;
    max-width: 600px;
    margin: 0 auto;
  }
  
  .app-header h1 {
    font-size: 1.8rem;
  }
  
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
  
  .card {
    padding: 24px;
  }
}

/* Desktop breakpoint (900px+) */
@media (min-width: 900px) {
  .app-container {
    max-width: 900px;
  }
  
  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
  
  .content-padding-bottom {
    padding-bottom: 84px;
  }
}

/* Touch optimization */
.tab-section, .bottom-nav-item, .nav-tab, .btn, .sheet-item {
  touch-action: manipulation;
}

/* Prevent pull-to-refresh on main content */
.app-container {
  overscroll-behavior: contain;
}

/* Smooth scrolling for chat containers */
#chatMessages {
  -webkit-overflow-scrolling: touch;
}

/* ===== PHASE 4: DUAL THEME (LIGHT MODE) ===== */
/* Dark theme is the default in :root. Light mode overrides below. */

[data-theme="light"] {
  --bg-primary: #f0fdfa;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(240, 253, 250, 0.9);
  --bg-glass: rgba(0, 0, 0, 0.03);
  --border-glass: rgba(0, 0, 0, 0.08);
  --border-accent: rgba(8, 145, 178, 0.3);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-indigo: #0891B2;
  --accent-violet: #0e7490;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-cyan: #0891b2;
  --accent-orange: #ea580c;

  --gradient-hero: linear-gradient(135deg, #0891B2 0%, #0e7490 50%, #06b6d4 100%);
  --gradient-danger: linear-gradient(135deg, #dc2626 0%, #ea580c 100%);
  --gradient-safe: linear-gradient(135deg, #059669 0%, #10b981 100%);
  --gradient-warning: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
  --gradient-glass: linear-gradient(135deg, rgba(0,0,0,0.02) 0%, rgba(0,0,0,0.01) 100%);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
  --shadow-glow-indigo: 0 0 30px rgba(8, 145, 178, 0.15);
  --shadow-glow-emerald: 0 0 30px rgba(5, 150, 105, 0.15);
  --shadow-glow-rose: 0 0 30px rgba(225, 29, 72, 0.15);
}

/* Smooth theme transitions */
*, *::before, *::after {
  transition: background-color 0.3s ease,
              color 0.3s ease,
              border-color 0.3s ease,
              box-shadow 0.3s ease;
}

/* ===== CONFIRM MODAL ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.7);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.3s ease;
}

.confirm-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.confirm-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
}

.confirm-message {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 24px;
  font-weight: 500;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 100px;
}

/* ===== LOADING SKELETONS ===== */
.skeleton {
  background: linear-gradient(90deg,
    var(--bg-card) 25%,
    var(--bg-card-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 14px; width: 60%; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 40%; margin-bottom: 12px; }
.skeleton-card { height: 120px; width: 100%; border-radius: var(--radius-md); }
.skeleton-circle { border-radius: 50%; }

/* ===== NETWORK INDICATOR ===== */
.network-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--accent-amber);
  color: #0f172a;
  text-align: center;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 9999;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.network-indicator.show {
  transform: translateY(0);
}

.network-indicator.hidden {
  display: none;
}

/* ===== DETAILS/SUMMARY (COLLAPSIBLE CARDS) ===== */
details.card {
  cursor: default;
}

details.card summary {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

details.card summary::marker {
  display: none;
  content: '';
}

details.card[open] summary {
  margin-bottom: 0;
}
