/* ==========================================================================
   Design System & Theme Variables
   ========================================================================== */

:root {
    /* Color Palette - HSL Tailored for Dark Mode (Default) */
    --hue-primary: 210; /* Electric Blue */
    --hue-success: 142; /* Vibrant Green */
    --hue-warning: 38;  /* Warm Amber */
    --hue-danger: 350;  /* Crimson Red */
    --hue-neutral: 222; /* Sleek Deep Slate */

    /* Dark Theme Colors */
    --bg-app: hsl(var(--hue-neutral), 25%, 8%);
    --bg-card: hsl(var(--hue-neutral), 22%, 13%);
    --bg-card-hover: hsl(var(--hue-neutral), 22%, 16%);
    --border-color: hsl(var(--hue-neutral), 20%, 20%);
    --border-color-glow: hsla(var(--hue-primary), 100%, 60%, 0.15);
    
    --text-primary: hsl(var(--hue-neutral), 20%, 96%);
    --text-secondary: hsl(var(--hue-neutral), 15%, 80%);
    --text-muted: hsl(var(--hue-neutral), 10%, 60%);
    
    --color-primary: hsl(var(--hue-primary), 100%, 60%);
    --color-primary-hover: hsl(var(--hue-primary), 100%, 66%);
    --color-primary-rgb: 0, 132, 255;
    
    --color-success: hsl(var(--hue-success), 70%, 45%);
    --color-success-bg: hsla(var(--hue-success), 70%, 45%, 0.1);
    
    --color-warning: hsl(var(--hue-warning), 90%, 50%);
    --color-warning-bg: hsla(var(--hue-warning), 90%, 50%, 0.1);
    
    --color-danger: hsl(var(--hue-danger), 80%, 55%);
    --color-danger-bg: hsla(var(--hue-danger), 80%, 55%, 0.15);

    /* Shadows & Effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 15px hsla(var(--hue-primary), 100%, 60%, 0.25);
    --glass-bg: rgba(23, 28, 41, 0.7);
    --glass-backdrop: blur(12px);

    /* Fonts & Radii */
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-circle: 50%;
    
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Light Theme Overrides */
html[data-theme="light"] {
    --bg-app: hsl(var(--hue-neutral), 30%, 96%);
    --bg-card: hsl(0, 0%, 100%);
    --bg-card-hover: hsl(var(--hue-neutral), 30%, 98%);
    --border-color: hsl(var(--hue-neutral), 20%, 88%);
    --border-color-glow: hsla(var(--hue-primary), 100%, 45%, 0.1);
    
    --text-primary: hsl(var(--hue-neutral), 25%, 15%);
    --text-secondary: hsl(var(--hue-neutral), 20%, 35%);
    --text-muted: hsl(var(--hue-neutral), 15%, 55%);
    
    --color-primary: hsl(var(--hue-primary), 95%, 48%);
    --color-primary-hover: hsl(var(--hue-primary), 95%, 40%);
    --color-primary-rgb: 0, 106, 224;
    
    --color-success: hsl(var(--hue-success), 75%, 35%);
    --color-success-bg: hsla(var(--hue-success), 75%, 35%, 0.08);
    
    --color-warning: hsl(var(--hue-warning), 85%, 42%);
    --color-warning-bg: hsla(var(--hue-warning), 85%, 42%, 0.08);
    
    --color-danger: hsl(var(--hue-danger), 80%, 48%);
    --color-danger-bg: hsla(var(--hue-danger), 80%, 48%, 0.08);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(23, 28, 41, 0.06);
    --shadow-lg: 0 16px 40px rgba(23, 28, 41, 0.1);
    --shadow-glow: 0 0 15px hsla(var(--hue-primary), 100%, 50%, 0.12);
    --glass-bg: rgba(255, 255, 255, 0.85);
}

/* ==========================================================================
   Resets & Base Styles
   ========================================================================== */

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

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color var(--transition-smooth);
    overflow-x: hidden;
}

/* ==========================================================================
   Layout Containers
   ========================================================================== */

.app-container {
    width: 100%;
    max-width: 1200px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 100vh;
}

/* Header Styling */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    background: linear-gradient(135deg, var(--color-primary), hsl(var(--hue-primary), 100%, 70%));
    color: white;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-glow);
    animation: pulseGlow 3s infinite alternate;
}

.header-logo h1 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

/* ==========================================================================
   Navigation Tabs
   ========================================================================== */

.app-nav {
    display: flex;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 6px;
    border-radius: var(--radius-md);
    gap: 6px;
    position: sticky;
    top: 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    backdrop-filter: var(--glass-backdrop);
}

.nav-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-smooth);
}

.nav-tab svg {
    transition: transform var(--transition-smooth);
}

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

.nav-tab:hover svg {
    transform: translateY(-1px);
}

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

.nav-tab.active svg {
    stroke: white;
}

/* ==========================================================================
   Main Content Area & Dashboard Grid
   ========================================================================== */

.app-main {
    flex: 1;
    position: relative;
}

.tab-panel {
    display: none;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity var(--transition-smooth), transform var(--transition-smooth);
}

.tab-panel.active-panel {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
}

/* ==========================================================================
   Cards Visual Styles
   ========================================================================== */

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-smooth), border-color var(--transition-smooth), box-shadow var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: transparent;
    transition: background var(--transition-smooth);
}

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

.card-calculator::before {
    background: linear-gradient(90deg, var(--color-primary), transparent);
}

.card-result::before {
    background: linear-gradient(90deg, var(--color-success), transparent);
}

.card-visuals::before {
    background: linear-gradient(90deg, var(--color-warning), transparent);
}

.card-header-simple {
    margin-bottom: 24px;
}

.card-header-simple h2 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.2px;
}

.card-header-simple p {
    font-size: 13px;
    color: var(--text-muted);
}

.full-width-tablet {
    grid-column: span 2;
}

/* ==========================================================================
   Form Controls
   ========================================================================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

input[type="number"],
input[type="text"] {
    width: 100%;
    background-color: hsl(var(--hue-neutral), 22%, 18%);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 14px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 500;
    outline: none;
    transition: all var(--transition-smooth);
}

html[data-theme="light"] input[type="number"],
html[data-theme="light"] input[type="text"] {
    background-color: hsl(var(--hue-neutral), 30%, 93%);
}

input[type="number"]:focus,
input[type="text"]:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px hsla(var(--hue-primary), 100%, 60%, 0.15);
    background-color: hsl(var(--hue-neutral), 22%, 20%);
}

html[data-theme="light"] input[type="number"]:focus,
html[data-theme="light"] input[type="text"]:focus {
    background-color: white;
}

/* Unit tags & Quick select buttons inside Inputs */
.input-wrapper input {
    padding-right: 70px;
}

.quick-value-btn {
    position: absolute;
    right: 8px;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-smooth);
}

html[data-theme="light"] .quick-value-btn {
    background-color: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

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

.input-icon-label {
    position: absolute;
    right: 20px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
}

/* Dual Inputs grouping for IOB Seed */
.dual-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.help-text {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.4;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: none;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 15px;
    padding: 14px 24px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-smooth);
    width: 100%;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background-color: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px hsla(var(--hue-primary), 100%, 60%, 0.35);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

html[data-theme="light"] .btn-secondary {
    background-color: rgba(0, 0, 0, 0.04);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Icon Buttons & Dropdowns */
.icon-btn, .text-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-smooth);
}

html[data-theme="light"] .icon-btn, 
html[data-theme="light"] .text-btn {
    background: white;
}

.icon-btn:hover, .text-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* ==========================================================================
   Calculations Results Styling
   ========================================================================== */

.card-result {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    background-color: var(--color-warning-bg);
    color: var(--color-warning);
    border: 1px solid rgba(var(--hue-warning), 90%, 50%, 0.15);
    text-transform: uppercase;
}

.result-display {
    text-align: center;
    background: linear-gradient(135deg, rgba(var(--color-primary-rgb), 0.04), rgba(var(--color-primary-rgb), 0.08));
    border: 1px dashed var(--border-color-glow);
    padding: 24px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    position: relative;
}

.result-number-container {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
}

#result-total-value {
    font-family: var(--font-heading);
    font-size: 52px;
    font-weight: 800;
    color: var(--color-primary);
    line-height: 1;
    animation: popIn var(--transition-bounce) forwards;
}

.result-unit {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-muted);
}

.result-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* Progress bars breakdown */
.dose-breakdown {
    margin-bottom: 24px;
}

.dose-breakdown h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.breakdown-item {
    margin-bottom: 14px;
}

.breakdown-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.breakdown-value {
    font-weight: 700;
    color: var(--text-primary);
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-circle);
    overflow: hidden;
}

html[data-theme="light"] .progress-bar-bg {
    background-color: rgba(0, 0, 0, 0.05);
}

.progress-bar {
    height: 100%;
    border-radius: var(--radius-circle);
    transition: width var(--transition-smooth);
}

.bar-correction {
    background-color: var(--color-primary);
}

.bar-meal {
    background-color: var(--color-success);
}

.bar-iob {
    background-color: var(--color-warning);
}

/* Alert Boxes */
.alert-box {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 13px;
    line-height: 1.5;
    align-items: flex-start;
}

.alert-info {
    background-color: rgba(0, 132, 255, 0.08);
    border: 1px solid rgba(0, 132, 255, 0.15);
    color: hsl(205, 100%, 75%);
}

html[data-theme="light"] .alert-info {
    background-color: rgba(0, 132, 255, 0.05);
    color: hsl(205, 100%, 35%);
}

.alert-danger-custom {
    background-color: var(--color-danger-bg);
    border: 1px solid rgba(var(--hue-danger), 80%, 55%, 0.2);
    color: var(--color-danger);
}

.alert-warning-custom {
    background-color: var(--color-warning-bg);
    border: 1px solid rgba(var(--hue-warning), 90%, 50%, 0.2);
    color: var(--color-warning);
}

.alert-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.text-warning-custom {
    color: var(--color-warning) !important;
}

/* ==========================================================================
   Visualizations & Charts
   ========================================================================== */

.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.chart-box {
    background-color: rgba(255, 255, 255, 0.015);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
}

.chart-box h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.canvas-wrapper {
    width: 100%;
    position: relative;
}

canvas {
    display: block;
    width: 100% !important;
    height: auto !important;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   History Tab & Statistics
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-bg-avg {
    background-color: rgba(0, 132, 255, 0.08);
    color: var(--color-primary);
}

.icon-tir {
    background-color: var(--color-success-bg);
    color: var(--color-success);
}

.icon-total-insulin {
    background-color: var(--color-warning-bg);
    color: var(--color-warning);
}

.icon-total-carbs {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    margin-top: 4px;
}

.text-small {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

/* History Logs */
.card-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.history-actions {
    display: flex;
    gap: 8px;
}

.btn-icon-only {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-smooth);
    padding: 0;
}

.btn-icon-only:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-danger:hover {
    background-color: var(--color-danger-bg);
    color: var(--color-danger);
    border-color: rgba(var(--hue-danger), 80%, 55%, 0.2);
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.history-table th {
    font-family: var(--font-heading);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 14px 16px;
    border-bottom: 2px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-secondary);
}

.history-table tr:hover td {
    background-color: rgba(255, 255, 255, 0.01);
}

.history-table td.empty-table {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-style: italic;
}

/* History row elements formatting */
.hist-bg-value {
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.bg-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-circle);
    display: inline-block;
}

.bg-dot-normal { background-color: var(--color-success); }
.bg-dot-high { background-color: var(--color-warning); }
.bg-dot-low { background-color: var(--color-danger); }

/* ==========================================================================
   Settings & About Grid
   ========================================================================== */

.settings-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
}

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

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

/* About / Warning styles */
.about-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.caution-banner {
    display: flex;
    gap: 16px;
    background-color: var(--color-danger-bg);
    border: 1px solid rgba(var(--hue-danger), 80%, 55%, 0.15);
    padding: 20px;
    border-radius: var(--radius-md);
    align-items: flex-start;
}

.caution-icon {
    color: var(--color-danger);
    flex-shrink: 0;
    margin-top: 2px;
}

.caution-text {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.caution-text strong {
    color: var(--color-danger);
}

.about-how-title {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: -10px;
}

.about-list {
    list-style-type: none;
}

.about-list li {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    position: relative;
    padding-left: 20px;
    margin-bottom: 12px;
}

.about-list li::before {
    content: "•";
    color: var(--color-primary);
    font-weight: bold;
    font-size: 20px;
    position: absolute;
    left: 4px;
    top: -3px;
}

/* ==========================================================================
   Language Switcher Dropdown
   ========================================================================== */

.language-dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-width: 140px;
    box-shadow: var(--shadow-md);
    z-index: 200;
    margin-top: 4px;
    overflow: hidden;
}

.dropdown-item {
    background: none;
    border: none;
    width: 100%;
    color: var(--text-secondary);
    padding: 10px 16px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--transition-smooth);
}

.dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.language-dropdown:hover .dropdown-content {
    display: block;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.app-footer {
    text-align: center;
    padding: 24px 0;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.app-footer p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================================================
   Animations & Transitions
   ========================================================================== */

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 10px hsla(var(--hue-primary), 100%, 60%, 0.2);
    }
    100% {
        box-shadow: 0 0 20px hsla(var(--hue-primary), 100%, 65%, 0.45);
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   Responsive Media Queries
   ========================================================================== */

@media (max-width: 900px) {
    .dashboard-grid, .settings-grid {
        grid-template-columns: 1fr;
    }
    
    .full-width-tablet {
        grid-column: span 1;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .charts-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    body {
        font-size: 14px;
    }

    .app-container {
        padding: 12px;
        gap: 16px;
    }

    .app-header {
        flex-direction: row;
        align-items: center;
    }

    .header-logo h1 {
        font-size: 20px;
    }

    .nav-tab span {
        display: none; /* Hide labels, show only icons on tiny screens */
    }

    .nav-tab {
        padding: 10px;
    }

    .card {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .dual-inputs {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .form-actions {
        flex-direction: column;
    }
}

/* ==========================================================================
   Carb Presets, Math Details & HbA1c Extra Styles
   ========================================================================== */

.carb-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.preset-btn {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-smooth);
}

html[data-theme="light"] .preset-btn {
    background-color: rgba(0, 0, 0, 0.03);
}

.preset-btn:hover {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
    transform: translateY(-1px);
}

.math-details {
    margin-top: 16px;
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    transition: all var(--transition-smooth);
}

html[data-theme="light"] .math-details {
    background-color: rgba(0, 0, 0, 0.01);
}

.math-details summary {
    font-family: var(--font-heading);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
    outline: none;
    user-select: none;
}

.math-details summary:hover {
    color: var(--text-primary);
}

.math-details-content {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}

.math-formula {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin: 6px 0;
    font-weight: bold;
    color: var(--color-primary);
    display: block;
    font-family: monospace;
    word-break: break-all;
}

html[data-theme="light"] .math-formula {
    background-color: rgba(0, 0, 0, 0.05);
}

.stat-subtext {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
}

.stat-subtext span {
    font-weight: 700;
    color: var(--color-primary);
}

