*, *::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-hover: #d4681c;
    --accent-dim: rgba(234, 116, 32, 0.08);
    --blue: #1c66a0;
    --blue-hover: #065293;
    --blue-dim: rgba(28, 102, 160, 0.08);
    --navy: #0d2751;
    --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.06), 0 0 1px rgba(13, 39, 81, 0.04);
    --radius: 10px;
    --radius-sm: 6px;
    --nav-bg: #0d2751;
    --nav-border: transparent;
    --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;
        --text: #e4e8ef;
        --text-muted: #7a8a9e;
        --text-dim: #3d4d63;
        --accent-dim: rgba(234, 116, 32, 0.12);
        --blue-dim: rgba(28, 102, 160, 0.15);
        --success-bg: rgba(39, 174, 96, 0.12);
        --danger-bg: rgba(231, 76, 60, 0.12);
        --border: #1a2436;
        --border-light: #223048;
        --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        --nav-bg: #0a0e18;
        --nav-border: #1a2436;
    }
}

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

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ===== Nav ===== */
nav {
    background: var(--nav-bg);
    padding: 0;
    margin-bottom: 32px;
    border-bottom: 1px solid var(--nav-border);
}

nav .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

nav .logo {
    color: #fff;
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    letter-spacing: 0.02em;
}

nav .logo:hover { text-decoration: none; }

nav .logo img {
    height: 30px;
    width: auto;
}

nav .nav-links {
    display: flex;
    align-items: center;
    gap: 2px;
}

nav .nav-links a {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.88rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease, background 0.15s ease;
    text-decoration: none;
}

nav .nav-links a:hover {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
}

nav .nav-links a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    font-weight: 600;
}

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

.card h2 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.25rem;
    margin-bottom: 16px;
    letter-spacing: 0.01em;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font-body);
    background: var(--bg-input);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-dim);
}

.form-group select {
    -webkit-appearance: none;
    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 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 12px center;
    padding-right: 32px;
}

@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: 16px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

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

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

.btn-primary:hover { background: var(--blue-hover); }

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

.btn-danger:hover { background: #c0392b; }

.btn-google {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 12px;
}

.btn-google:hover { background: var(--bg-raised); }

.btn-small {
    padding: 6px 14px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-small:hover { background: var(--bg-raised); }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
    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);
}

/* ===== Chart Controls ===== */
.chart-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    align-items: center;
}

.date-range,
.smoothing {
    display: inline-flex;
}

.date-range button,
.smoothing button {
    padding: 7px 16px;
    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.85rem;
    font-weight: 500;
    transition: all 0.15s ease;
    position: relative;
}

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

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

.date-range button:hover,
.smoothing button:hover {
    color: var(--text);
    z-index: 1;
}

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

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

/* ===== Charts ===== */
.chart-container {
    position: relative;
    margin-bottom: 24px;
}

.chart-container canvas {
    width: 100% !important;
}

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

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    text-align: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.5rem;
    margin-bottom: 24px;
}

.auth-logo {
    display: block;
    margin: 0 auto 24px;
    max-width: 220px;
    height: auto;
    border-radius: var(--radius);
}

@media (prefers-color-scheme: dark) {
    .auth-logo {
        background: #fff;
        padding: 16px 20px;
    }
}

.divider {
    text-align: center;
    margin: 18px 0;
    color: var(--text-dim);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    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; }

/* ===== Admin ===== */
.text-muted { color: var(--text-muted); }

.invite-link-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    margin: 8px 0;
    background: var(--bg-raised);
    color: var(--text);
}

.invite-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.invite-table th,
.invite-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.invite-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ===== Import ===== */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover,
.drop-zone-active {
    border-color: var(--blue);
    background: var(--blue-dim);
}

.import-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.import-table th,
.import-table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.import-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--blue);
    border-radius: 4px;
    transition: width 0.15s;
}

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

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

/* ===== Checkbox ===== */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--blue);
}

/* ===== Reports ===== */
.report-header {
    text-align: center;
    margin: 32px 0 8px;
}

.report-header h1 {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.report-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.report-dates {
    color: var(--text-dim);
    font-size: 0.88rem;
    margin-top: 2px;
}

.report-section-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-bottom: 8px;
    margin: 32px 0 16px;
    border-bottom: 2px solid var(--border);
}

.report-chart {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
}

.report-chart canvas {
    width: 100% !important;
}

.report-table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 0;
    margin-top: 16px;
    border: 1px solid var(--border-light);
    overflow-x: auto;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.report-table th,
.report-table td {
    text-align: left;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}

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

.report-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.82rem;
    background: var(--bg-raised);
}

/* ===== Print ===== */
@media print {
    nav,
    .report-config,
    .no-print {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #0d2751 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .container {
        max-width: 100%;
        padding: 0 12px;
    }

    .report-header {
        margin-top: 0;
    }

    .report-chart {
        break-inside: avoid;
        background: #fff !important;
        box-shadow: none;
        border: 1px solid #d2dbe6;
    }

    .report-section-title {
        break-after: avoid;
    }

    .report-table-wrapper {
        background: #fff !important;
        box-shadow: none;
        border: 1px solid #d2dbe6;
    }

    .report-table th {
        background: #edf0f5 !important;
        color: #5e7590 !important;
    }
}

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