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

/* ===== Light Theme (Default) ===== */
:root {
    color-scheme: light dark;

    --bg: #f3f5f9;
    --bg-card: #ffffff;
    --bg-raised: #edf0f5;
    --bg-input: #ffffff;
    --accent: #ea7420;
    --accent-bright: #f08830;
    --accent-dim: rgba(234, 116, 32, 0.08);
    --accent-border: rgba(234, 116, 32, 0.2);
    --blue: #1c66a0;
    --blue-dim: rgba(28, 102, 160, 0.08);
    --text: #0d2751;
    --text-muted: #5e7590;
    --text-dim: #8c9db3;
    --success: #27ae60;
    --success-bg: rgba(39, 174, 96, 0.08);
    --danger: #e74c3c;
    --danger-bg: rgba(231, 76, 60, 0.08);
    --border: #d2dbe6;
    --border-light: #e4eaf0;
    --card-shadow: 0 1px 3px rgba(13, 39, 81, 0.05);
    --nav-backdrop: rgba(255, 255, 255, 0.88);
    --radius: 12px;
    --radius-sm: 8px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 64px;
    --font-display: 'Rajdhani', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

/* ===== Dark Theme ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #080c14;
        --bg-card: #0e1520;
        --bg-raised: #152030;
        --bg-input: #0b1018;
        --accent-dim: rgba(234, 116, 32, 0.12);
        --accent-border: rgba(234, 116, 32, 0.25);
        --blue-dim: rgba(28, 102, 160, 0.15);
        --text: #e4e8ef;
        --text-muted: #7a8a9e;
        --text-dim: #3d4d63;
        --success-bg: rgba(39, 174, 96, 0.12);
        --danger-bg: rgba(231, 76, 60, 0.12);
        --border: #1a2436;
        --border-light: #223048;
        --card-shadow: none;
        --nav-backdrop: rgba(14, 21, 32, 0.88);
    }
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App container */
#app {
    padding: 20px 16px;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    min-height: 100%;
}

#app.view-enter {
    animation: fadeIn 0.25s ease;
}

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

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--nav-backdrop);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 6px 0;
    padding-bottom: calc(6px + var(--safe-bottom));
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    min-width: 64px;
    min-height: 44px;
    justify-content: center;
    gap: 3px;
    transition: color 0.2s ease;
    position: relative;
}

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

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

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.nav-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
    box-shadow: var(--card-shadow);
}

/* ===== Typography ===== */
h2 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.35rem;
    letter-spacing: 0.02em;
    margin-bottom: 16px;
    color: var(--text);
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.form-group input:not([type="checkbox"]),
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: var(--font-body);
    background: var(--bg-input);
    color: var(--text);
    min-height: 48px;
    -webkit-appearance: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:not([type="checkbox"]):focus,
.form-group select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-dim);
}

.form-group input::placeholder {
    color: var(--text-dim);
}

.form-group select {
    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 d='M3 5l3 3 3-3' fill='none' stroke='%235e7590' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

@media (prefers-color-scheme: dark) {
    .form-group select {
        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 d='M3 5l3 3 3-3' fill='none' stroke='%237a8a9e' stroke-width='1.5'/%3E%3C/svg%3E");
    }
}

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

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

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    touch-action: manipulation;
    transition: background 0.15s ease, transform 0.1s ease;
    letter-spacing: 0.02em;
}

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

.btn-block {
    display: flex;
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:active {
    background: var(--accent-bright);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.15);
}

.btn-danger:active {
    background: rgba(231, 76, 60, 0.15);
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 0.88rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(231, 76, 60, 0.12);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: rgba(39, 174, 96, 0.12);
}

/* ===== Auth / Login ===== */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 85vh;
    position: relative;
}

.auth-wrapper::before {
    content: '';
    position: fixed;
    top: -20%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 50%;
    background: transparent;
    pointer-events: none;
}

@media (prefers-color-scheme: dark) {
    .auth-wrapper::before {
        background: radial-gradient(ellipse, rgba(234, 116, 32, 0.07) 0%, transparent 70%);
    }
}

.auth-card {
    width: 100%;
    max-width: 380px;
    position: relative;
}

.auth-card h1 {
    text-align: center;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--accent-bright), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    margin-bottom: 28px;
}

.divider {
    text-align: center;
    margin: 20px 0;
    color: var(--text-dim);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    position: relative;
}

.divider::before,
.divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 38%;
    height: 1px;
    background: var(--border);
}

.divider::before { left: 0; }
.divider::after { right: 0; }

.g_id_signin {
    display: flex;
    justify-content: center;
}

/* ===== Dashboard — Stat Cards ===== */
.section-label {
    font-family: var(--font-display);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 10px;
}

.stat-cards {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin-bottom: 20px;
}

.stat-cards::-webkit-scrollbar { display: none; }

.stat-card {
    flex: 0 0 auto;
    min-width: 100px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    border: 1px solid var(--border-light);
    box-shadow: var(--card-shadow);
    scroll-snap-align: start;
    opacity: 0;
    animation: slideUp 0.35s ease forwards;
}

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

.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.06s; }
.stat-card:nth-child(4) { animation-delay: 0.09s; }
.stat-card:nth-child(5) { animation-delay: 0.12s; }
.stat-card:nth-child(6) { animation-delay: 0.15s; }

.stat-value {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.stat-delta {
    font-size: 0.72rem;
    font-weight: 600;
    margin-top: 6px;
    color: var(--text-dim);
}

.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-delta.up.inverted { color: var(--danger); }
.stat-delta.down.inverted { color: var(--success); }

/* ===== Date Range & Smoothing Controls ===== */
.date-range {
    display: flex;
    margin-bottom: 8px;
}

.smooth-range {
    display: flex;
    margin-bottom: 16px;
}

.date-range button,
.smooth-range button {
    flex: 1;
    padding: 8px 0;
    border: 1px solid var(--border);
    margin-left: -1px;
    border-radius: 0;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 500;
    min-height: 40px;
    touch-action: manipulation;
    transition: all 0.15s ease;
    position: relative;
}

.date-range button:first-child,
.smooth-range button:first-child {
    margin-left: 0;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.date-range button:last-child,
.smooth-range button:last-child {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.date-range button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
    z-index: 1;
}

.smooth-range button.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
    font-weight: 600;
    z-index: 1;
}

/* ===== Chart Carousel ===== */
.chart-carousel {
    position: relative;
}

.chart-slides {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 12px;
}

.chart-slides::-webkit-scrollbar { display: none; }

.chart-slide {
    flex: 0 0 100%;
    scroll-snap-align: start;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--card-shadow);
    padding: 16px 12px 12px;
}

.chart-slide canvas {
    width: 100% !important;
    height: 250px !important;
}

.chart-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 0 4px;
}

.chart-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    border: none;
    padding: 0;
    cursor: pointer;
    transition: all 0.25s ease;
    touch-action: manipulation;
}

.chart-dot.active {
    background: var(--accent);
    width: 20px;
    border-radius: 3px;
}

.chart-title {
    text-align: center;
    font-family: var(--font-display);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

/* ===== Blood Pressure Readings ===== */
.bp-reading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

.bp-reading-row:last-child {
    border-bottom: none;
}

.bp-reading-row .btn-bp-delete {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.8rem;
}

/* ===== Checkbox ===== */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 0.88rem;
    cursor: pointer;
    color: var(--text);
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: auto;
    margin: 0;
    accent-color: var(--accent);
    border-radius: 4px;
}

/* ===== View Containers ===== */
.view-entry,
.view-profile {
    max-width: 500px;
    margin: 0 auto;
}

/* ===== Loading Skeleton ===== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 0%, var(--bg-raised) 50%, var(--bg-card) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

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

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    color: var(--text-dim);
    font-size: 0.88rem;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
