/* 
   ==========================================================================
   HEALTH TRACKER APP - DESIGN SYSTEM (style.css)
   Aesthetics: Premium Dark Glassmorphism, HSL tailors, iOS native feel
   ========================================================================== 
*/

:root {
    /* Color Palette - Default Dark Theme */
    --color-bg-base: #060814;
    --color-bg-surface: rgba(17, 24, 48, 0.6);
    --color-bg-glass: rgba(255, 255, 255, 0.03);
    --color-bg-glass-hover: rgba(255, 255, 255, 0.06);
    
    --color-border: rgba(255, 255, 255, 0.07);
    --color-border-hover: rgba(255, 255, 255, 0.15);
    --color-card-border: rgba(255, 255, 255, 0.07);
    
    --color-text-primary: #f8fafc;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;
    --color-shadow: rgba(0, 0, 0, 0.4);
    
    /* Category Colors */
    --color-sugar: #ff6b6b;
    --color-sugar-light: rgba(255, 107, 107, 0.15);
    
    --color-lipids: #ec4899;
    --color-lipids-light: rgba(236, 72, 153, 0.15);
    
    --color-kidney: #06b6d4;
    --color-kidney-light: rgba(6, 182, 212, 0.15);
    
    --color-liver: #f59e0b;
    --color-liver-light: rgba(245, 158, 11, 0.15);
    
    /* Status Colors */
    --color-normal: #10b981;
    --color-normal-light: rgba(16, 185, 129, 0.15);
    --color-warning: #f59e0b;
    --color-warning-light: rgba(245, 158, 11, 0.15);
    --color-danger: #ef4444;
    --color-danger-light: rgba(239, 68, 68, 0.15);
    
    /* Accent Gradient */
    --color-accent: #6366f1;
    --color-accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
    --color-accent-light: rgba(99, 102, 241, 0.15);
    
    /* Layout Constants */
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
    --border-radius-lg: 24px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-size-base: 16px;
}

/* Light Theme - High-Contrast Elder-Friendly Mode */
.light-theme {
    --color-bg-base: #f1f5f9;
    --color-bg-surface: #ffffff;
    --color-bg-glass: #ffffff;
    --color-bg-glass-hover: #f1f5f9;
    
    --color-border: #cbd5e1;
    --color-border-hover: #94a3b8;
    --color-card-border: #cbd5e1;
    
    --color-text-primary: #0f172a;
    --color-text-secondary: #334155;
    --color-text-muted: #475569;
    --color-shadow: rgba(15, 23, 42, 0.08);
    
    /* Category Colors - Darkened for Light Mode */
    --color-sugar: #dc2626;
    --color-sugar-light: rgba(220, 38, 38, 0.08);
    
    --color-lipids: #db2777;
    --color-lipids-light: rgba(219, 39, 119, 0.08);
    
    --color-kidney: #0891b2;
    --color-kidney-light: rgba(8, 145, 178, 0.08);
    
    --color-liver: #d97706;
    --color-liver-light: rgba(217, 119, 6, 0.08);
    
    /* Status Colors - Optimized for light background visibility */
    --color-normal: #047857;
    --color-normal-light: rgba(4, 120, 87, 0.12);
    --color-warning: #b45309;
    --color-warning-light: rgba(180, 83, 9, 0.12);
    --color-danger: #b91c1c;
    --color-danger-light: rgba(185, 28, 28, 0.12);
    
    /* Accent Gradient */
    --color-accent: #4f46e5;
    --color-accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #c026d3 100%);
    --color-accent-light: rgba(79, 70, 229, 0.12);
    
    --font-size-base: 17px;
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Disable touch blue outline on iOS */
}

body {
    background-color: var(--color-bg-base);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(217, 70, 239, 0.06) 0%, transparent 40%);
    color: var(--color-text-primary);
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    padding-top: max(20px, env(safe-area-inset-top)); /* iOS Safe Areas */
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    transition: background-color 0.3s, color 0.3s;
}

/* Light theme body gradient overrides */
.light-theme body {
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(79, 70, 229, 0.03) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(192, 38, 211, 0.03) 0%, transparent 40%);
}

.app-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Glassmorphism utility */
.glass {
    background: var(--color-bg-surface);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border: 1px solid var(--color-card-border);
    border-radius: var(--border-radius-md);
    box-shadow: 0 10px 30px var(--color-shadow);
}

/* Typography & Layout elements */
h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.02em;
}

h1 {
    font-size: 1.8rem;
    line-height: 1.2;
}

h2 {
    font-size: 1.4rem;
    color: var(--color-text-primary);
}

.subtitle {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.font-sm {
    font-size: 0.8rem;
}

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

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

.pulse-icon {
    width: 38px;
    height: 38px;
    color: var(--color-accent);
    background: var(--color-accent-light);
    padding: 8px;
    border-radius: var(--border-radius-sm);
    box-shadow: 0 0 15px var(--color-accent-light);
    animation: iconPulse 2s infinite ease-in-out;
}

@keyframes iconPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 10px var(--color-accent-light); }
    50% { transform: scale(1.05); box-shadow: 0 0 20px rgba(99, 102, 241, 0.4); }
}

/* Preferences Bar */
.preferences-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.pref-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.pref-label i {
    width: 16px;
    height: 16px;
}

.toggles-container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.unit-toggle-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.toggle-buttons {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 2px;
    border: 1px solid var(--color-border);
}

.toggle-btn {
    background: none;
    border: none;
    padding: 4px 10px;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.toggle-btn.active {
    background: var(--color-accent-gradient);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    min-height: 46px;
    padding: 10px 20px;
    border-radius: var(--border-radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    gap: 8px;
}

.btn-icon i {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--color-accent-gradient);
    color: white;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

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

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

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

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

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

.btn-sm i {
    width: 14px;
    height: 14px;
}

/* Dashboard Cards Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.metric-card {
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
}

.metric-card[data-category="sugar"]::before { background: var(--color-sugar); }
.metric-card[data-category="lipids"]::before { background: var(--color-lipids); }
.metric-card[data-category="kidney"]::before { background: var(--color-kidney); }
.metric-card[data-category="liver"]::before { background: var(--color-liver); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.1rem;
}

.card-title i {
    width: 20px;
    height: 20px;
}

.card-date {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* Card Colors */
.color-sugar { color: var(--color-sugar); }
.color-lipids { color: var(--color-lipids); }
.color-kidney { color: var(--color-kidney); }
.color-liver { color: var(--color-liver); }

.card-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
    margin-bottom: 16px;
}

.main-val-container {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.main-val {
    font-size: 2.2rem;
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.1;
}

.main-unit {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

/* Multi metrics body (lipids, kidney, liver) */
.multi-body, .kidney-body, .liver-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.sub-metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--color-border);
}

.sub-label {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.sub-val-wrapper {
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.sub-val {
    font-size: 1.1rem;
    font-family: var(--font-heading);
    font-weight: 700;
}

.sub-unit {
    color: var(--color-text-muted);
}

.highlight-kidney {
    background: var(--color-kidney-light);
    border-color: rgba(6, 182, 212, 0.3);
}

/* Combined BUN / Urea tile (one measurement shown in both units) */
.bun-urea-tile {
    grid-column: 1 / -1;
}

.bun-urea-lines {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bu-line {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.bu-name {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--color-kidney);
    min-width: 34px;
}

.bu-tag {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg-glass);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    padding: 1px 6px;
    line-height: 1.4;
}

/* Card truncation: hide overflow tiles, show a "…" affordance */
.sub-metric.tile-hidden {
    display: none;
}

.sub-metric-more {
    grid-column: 1 / -1;
    align-items: center;
    justify-content: center;
    flex-direction: row;
    padding: 2px 10px;
    cursor: pointer;
}

.sub-metric-more .more-dots {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--color-text-muted);
    line-height: 1;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.ref-range {
    color: var(--color-text-muted);
}

/* Single-item footers (no unit toggle) push their content to the right */
.card-footer-end {
    justify-content: flex-end;
}

/* Compact unit toggle mounted inside a dashboard card footer */
.card-unit-toggle .toggle-btn {
    padding: 3px 8px;
    font-size: 0.7rem;
}

/* Status Badges (icon-only indicator next to the card title) */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    border-radius: 100px;
    width: fit-content;
    flex-shrink: 0;
}

.badge.status-normal {
    background: var(--color-normal-light);
    color: var(--color-normal);
}

.badge.status-warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.badge.status-danger {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

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

/* Charts Section */
.charts-section {
    padding: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.chart-tab-container {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    padding: 4px;
    border: 1px solid var(--color-border);
}

.chart-tab-btn {
    background: none;
    border: none;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.chart-tab-btn.active {
    background: var(--color-bg-glass-hover);
    color: var(--color-text-primary);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
}

.chart-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.subtabs-container {
    display: block;
}

.subtab-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.subtab-btn {
    background: var(--color-bg-glass);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.subtab-btn.active {
    background: var(--color-accent-light);
    border-color: var(--color-accent);
    color: var(--color-text-primary);
}

/* Unit suffix shown inside each metric badge */
.subtab-unit {
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.6;
    margin-left: 4px;
}

/* Collapsed toggle button — hidden on desktop, shown on mobile (see media query) */
.subtab-toggle {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--color-bg-glass);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 12px 14px;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
}

.subtab-toggle-unit {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-left: 4px;
}

.subtab-toggle-arrow {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.subtabs-container.open .subtab-toggle-arrow {
    transform: rotate(180deg);
}

.chart-filter-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    padding: 10px 16px;
    gap: 16px;
    flex-wrap: wrap;
}

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

.filter-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.quick-range-container {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 2px;
    border: 1px solid var(--color-border);
}

.quick-range-btn {
    background: none;
    border: none;
    padding: 4px 10px;
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.quick-range-btn.active {
    background: var(--color-accent-gradient);
    color: white;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.date-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-date-input {
    width: 130px !important;
    height: 28px !important;
    padding: 2px 8px !important;
    font-size: 0.8rem !important;
    background: rgba(0, 0, 0, 0.3) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: 4px !important;
}

.date-separator {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.chart-canvas-wrapper {
    position: relative;
    width: 100%;
    height: 320px;
}

.hide {
    display: none !important;
}

/* History Section */
.history-section {
    padding: 24px;
}

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

/* Collapsible history header */
.history-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    color: inherit;
    min-height: 0;
}

.history-toggle h2 {
    margin: 0;
}

.history-chevron {
    width: 20px;
    height: 20px;
    color: var(--color-text-secondary);
    transition: transform 0.2s ease;
}

.history-section:not(.collapsed) .history-chevron {
    transform: rotate(90deg);
}

.history-section.collapsed .section-header {
    margin-bottom: 0;
}

.history-section.collapsed .history-body {
    display: none;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin-top: 16px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border);
    background: rgba(0, 0, 0, 0.15);
}

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

.history-table th, .history-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
}

.history-table th {
    background: rgba(0, 0, 0, 0.3);
    color: var(--color-text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.history-table tbody tr {
    transition: var(--transition-smooth);
}

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

.history-table tbody tr:last-child td {
    border-bottom: none;
}

.actions-col {
    text-align: right;
    width: 100px;
}

.row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.action-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition-smooth);
}

.action-btn:hover {
    background: var(--color-bg-glass);
}

.action-btn-edit:hover {
    color: var(--color-accent);
}

.action-btn-delete:hover {
    color: var(--color-danger);
}

.action-btn i {
    width: 16px;
    height: 16px;
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 7, 20, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 16px;
    transition: var(--transition-smooth);
    opacity: 1;
}

.modal-overlay.hide {
    display: none;
    opacity: 0;
}

.modal-card {
    width: 100%;
    max-width: 520px;
    background: #0f132a;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
    padding: 24px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

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

.modal-close-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
}

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

#reading-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    padding-right: 4px;
}

/* Modal Form Tabs */
.form-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 2px;
    border: 1px solid var(--color-border);
}

.form-tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--color-text-secondary);
    padding: 8px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-smooth);
    text-align: center;
}

.form-tab-btn.active {
    background: var(--color-accent);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* Form Sheets */
.form-sheets {
    margin-top: 4px;
}

.form-sheet {
    display: none;
    flex-direction: column;
    gap: 16px;
}

.form-sheet.active {
    display: flex;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* Date Row specific */
.date-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0,0,0,0.15);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border);
}

.date-row label {
    font-size: 0.9rem;
    font-weight: 600;
}

/* Input design - MOBILE FRIENDLY (Min 16px font-size to prevent iOS auto-zoom) */
input[type="number"],
input[type="date"],
select {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--color-text-primary);
    font-family: var(--font-body);
    font-size: 16px; /* CRITICAL: Prevents iOS keyboard zoom-in */
    outline: none;
    transition: var(--transition-smooth);
}

input[type="number"]:focus,
input[type="date"]:focus,
select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.25);
    background: rgba(0, 0, 0, 0.45);
}

input::placeholder {
    color: var(--color-text-muted);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.input-header label {
    font-weight: 500;
}

.select-unit {
    width: auto;
    padding: 4px 24px 4px 8px;
    font-size: 0.8rem;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.4);
    height: 28px;
}

.sheet-info-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    justify-content: flex-end;
}

.sheet-info-bar select {
    width: auto;
    height: 28px;
    padding: 4px 24px 4px 8px;
}

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

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

.mb-lg { margin-bottom: 20px; }
.mt-sm { margin-top: 12px; }
.mt-md { margin-top: 16px; }

/* Highlighted Kidney Group (BUN/Urea) */
.highlighted-input-group {
    background: rgba(6, 182, 212, 0.05);
    border: 1px solid rgba(6, 182, 212, 0.2);
    border-radius: var(--border-radius-sm);
    padding: 10px;
}

.highlighted-input-group label {
    color: var(--color-kidney);
    font-weight: 600;
}

.highlighted-input-group input {
    border-color: rgba(6, 182, 212, 0.2);
}

.highlighted-input-group input:focus {
    border-color: var(--color-kidney);
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.25);
}

.conversion-alert {
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--color-accent-light);
    border-radius: var(--border-radius-sm);
    padding: 10px 12px;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    border-left: 3px solid var(--color-accent);
}

.conversion-alert i {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.upcr-hint {
    margin-top: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-align: center;
}

.upcr-hint strong {
    font-family: var(--font-heading);
    color: var(--color-accent);
    font-size: 0.95rem;
}

/* Light theme: modal / add form (the defaults above are tuned for dark mode) */
.light-theme .modal-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-card-border);
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
}

.light-theme .form-tabs,
.light-theme .date-row {
    background: var(--color-bg-base);
}

.light-theme input[type="number"],
.light-theme input[type="date"],
.light-theme select,
.light-theme .select-unit {
    background: var(--color-bg-base);
    background-color: var(--color-bg-base);
}

.light-theme input[type="number"]:focus,
.light-theme input[type="date"]:focus,
.light-theme select:focus {
    background: var(--color-bg-surface);
}

/* Chart insight panel ("explain the numbers") */
.chart-insight {
    margin-top: 14px;
}
.insight-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.insight-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
}
body.light-theme .insight-block {
    background: rgba(15, 23, 42, 0.03);
}
/* Unit switcher embedded in the chart insight badge */
.insight-unit-block {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.insight-unit-block .insight-k {
    margin: 0;
}
.insight-k {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    font-weight: 600;
}
.insight-v {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 700;
}
.insight-v.range { color: var(--color-text-secondary); }
.insight-v.normal { color: var(--color-normal); }
.insight-v.warning { color: var(--color-warning); }
.insight-v.danger { color: var(--color-danger); }
.insight-unit {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}
.insight-sub {
    font-size: 0.72rem;
    color: var(--color-text-muted);
}
.insight-badge {
    align-self: flex-start;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.insight-badge.normal { background: var(--color-normal-bg, rgba(16,185,129,0.15)); color: var(--color-normal); }
.insight-badge.warning { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.insight-badge.danger { background: rgba(239, 68, 68, 0.15); color: var(--color-danger); }
.insight-badge.nodata { background: rgba(100, 116, 139, 0.15); color: var(--color-text-muted); }
.insight-trend {
    font-size: 0.92rem;
    font-weight: 600;
}
.insight-trend.worse { color: var(--color-danger); }
.insight-trend.better { color: var(--color-normal); }
.insight-trend.stable,
.insight-trend.neutral { color: var(--color-text-muted); }
.insight-delta {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--color-text-muted);
}
.insight-empty {
    padding: 14px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--border-radius-sm);
}
@media (max-width: 640px) {
    .insight-row { grid-template-columns: 1fr 1fr; }
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    margin-top: auto;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--color-border-hover);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    padding: 12px 24px;
    border-radius: 100px;
    color: var(--color-text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 2000;
    transition: opacity 0.3s, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 1;
    pointer-events: none;
    white-space: nowrap;
}

.toast.hide {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
}

/* Footer Styling */
.app-footer {
    text-align: center;
    padding: 16px 0;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    margin-top: 24px;
}

.profile-input-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.15);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px dashed rgba(255, 255, 255, 0.15);
}

.profile-input-group.hide {
    display: none !important;
}

/* Visibility classes */
.hide-desktop {
    display: none !important;
}

.hide-mobile {
    display: block; /* fallback */
}

/* Mobile Log Card Sizing & Glassmorphism Styles */
.history-cards-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.history-card {
    background: rgba(15, 19, 42, 0.4);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 4px 15px var(--color-shadow);
    transition: var(--transition-smooth);
}

.light-theme .history-card {
    background: #ffffff;
    border-color: var(--color-border);
}

.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 10px;
}

.history-card-date {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--color-text-primary);
}

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

.history-card-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-card-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--color-border);
}

.light-theme .history-card-section {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.history-card-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.history-card-section-title i {
    width: 14px;
    height: 14px;
}

.history-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    font-size: 0.9rem;
}

.history-card-grid div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-card-grid span.label-sub {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.history-card-grid span.val-sub {
    font-weight: 700;
}

.history-card-grid span.normal { color: var(--color-normal); }
.history-card-grid span.warning { color: var(--color-warning); }
.history-card-grid span.danger { color: var(--color-danger); }

/* Theme toggle adjustments */
.theme-toggle-group {
    display: flex;
    align-items: center;
}

/* Light mode specific badge adjustments for visual accessibility */
.light-theme .badge {
    border-width: 1px;
    border-style: solid;
}
.light-theme .badge.status-normal { border-color: rgba(4, 120, 87, 0.3); }
.light-theme .badge.status-warning { border-color: rgba(180, 83, 9, 0.3); }
.light-theme .badge.status-danger { border-color: rgba(185, 28, 28, 0.3); }

/* Badge icon alignment */
.badge i {
    margin: 0;
    width: 14px;
    height: 14px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .app-wrapper {
        padding: 16px 12px;
        gap: 16px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .app-header {
        align-items: center;
    }
    
    .preferences-bar {
        padding: 12px 14px;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .toggles-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .unit-toggle-group {
        justify-content: space-between;
    }
    
    /* Mobile: hide the at-a-glance dashboard cards (history + charts suffice) */
    .dashboard-grid {
        display: none;
    }

    .charts-section {
        padding: 16px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .chart-tab-container {
        overflow-x: auto;
        white-space: nowrap;
        display: inline-flex;
    }
    
    .chart-tab-btn {
        flex: 1 0 auto;
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .chart-canvas-wrapper {
        height: 240px;
    }
    
    .history-section {
        padding: 16px;
    }
    
    .history-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .modal-card {
        padding: 16px;
        border-radius: var(--border-radius-md);
    }
    
    .input-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .chart-filter-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        gap: 12px;
    }
    
    .filter-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        width: 100%;
    }
    
    .quick-range-container {
        width: 100%;
        display: flex;
    }
    
    .quick-range-btn {
        flex: 1;
        text-align: center;
        padding: 6px 4px;
        font-size: 0.75rem;
    }

    /* Collapse the chart metric badges into a toggle button on mobile */
    .subtab-toggle {
        display: flex;
    }

    .subtab-badges {
        display: none;
    }

    .subtabs-container.open .subtab-badges {
        display: flex;
        margin-top: 8px;
        padding: 10px;
        background: rgba(0, 0, 0, 0.15);
        border: 1px solid var(--color-border);
        border-radius: 10px;
    }

    .subtabs-container.open .subtab-btn {
        flex: 1 1 auto;
    }

    .hide-mobile {
        display: none !important;
    }

    .hide-desktop {
        display: block !important;
    }
    
    .history-cards-container {
        display: flex !important;
    }
}

/* ===== Clickable dashboard cards + per-category detail table ===== */
.metric-card { cursor: pointer; }
.metric-card:hover {
    border-color: var(--color-border-hover);
    background: var(--color-bg-glass-hover);
}
.card-detail-hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-accent);
}
.card-detail-hint i { width: 13px; height: 13px; }

.detail-modal-card { max-width: 940px; }

.detail-table-container {
    overflow: auto;
    max-height: 70vh;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    -webkit-overflow-scrolling: touch;
}
.detail-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 0.85rem;
    white-space: nowrap;
}
.detail-table th,
.detail-table td {
    padding: 9px 14px;
    text-align: right;
    border-bottom: 1px solid var(--color-border);
    font-variant-numeric: tabular-nums;
}
.detail-table thead th {
    position: sticky;
    top: 0;
    background: #0f132a;
    z-index: 2;
    font-family: var(--font-heading);
    vertical-align: bottom;
}
.detail-table .dt-date {
    position: sticky;
    left: 0;
    background: #0f132a;
    text-align: left;
    font-weight: 600;
    z-index: 1;
}
.detail-table thead th.dt-date { z-index: 3; }
.detail-table td { color: var(--color-text-secondary); }
.detail-table td.normal { color: var(--color-normal); }
.detail-table td.warning { color: var(--color-warning); font-weight: 600; }
.detail-table td.danger { color: var(--color-danger); font-weight: 700; }
.detail-table td.dt-empty { color: var(--color-text-muted); }
.detail-table tbody tr:hover td { background: rgba(255, 255, 255, 0.04); }
.detail-table tbody tr:hover th.dt-date { background: #161b38; }
.dt-h-label { display: block; font-size: 0.74rem; color: var(--color-text-primary); }
.dt-h-unit { display: block; font-size: 0.62rem; color: var(--color-text-muted); font-weight: 500; }
.detail-empty {
    padding: 28px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Light theme: the sticky header/date backgrounds above are hardcoded dark navy,
   which hides the (now dark) label text. Flip them to light surfaces. */
.light-theme .detail-table thead th {
    background: var(--color-bg-base);
}
.light-theme .detail-table tbody .dt-date {
    background: var(--color-bg-surface);
}
.light-theme .detail-table tbody tr:hover td {
    background: rgba(15, 23, 42, 0.04);
}
.light-theme .detail-table tbody tr:hover th.dt-date {
    background: #e2e8f0;
}
