/* Apple Health Inspired Clean Design System */
:root {
    --bg-app: #f2f2f7;
    --bg-card: #ffffff;
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --text-muted: #aeaeb2;
    --accent: #007aff;
    --accent-light: #e5f2ff;
    --success: #34c759;
    --warning: #ff9500;
    --danger: #ff3b30;
    --border-light: #e5e5ea;
    --card-radius: 22px;
    --btn-radius: 14px;
    --shadow-subtle: 0 4px 18px rgba(0, 0, 0, 0.035);
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom, 30px);
}

/* Offline Banner */
.offline-banner {
    background-color: #3a3a3c;
    color: #ffffff;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: center;
    padding: 8px 16px;
    position: sticky;
    top: 0;
    z-index: 999;
}

/* Container */
.app-container {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 18px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 22px;
}

.greeting {
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.sync-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-line {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.meta-label {
    font-weight: 400;
}

.meta-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Sync button */
.btn-sync {
    background-color: var(--bg-card);
    border: 1px solid var(--border-light);
    color: var(--accent);
    padding: 9px 15px;
    border-radius: var(--btn-radius);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    box-shadow: var(--shadow-subtle);
    transition: all 0.18s ease;
}

.btn-sync:hover {
    background-color: var(--accent-light);
}

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

.sync-icon.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Sync Feedback Banner */
.sync-feedback {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.84rem;
    font-weight: 500;
    margin-bottom: 18px;
    box-shadow: var(--shadow-subtle);
    text-align: center;
    transition: all 0.25s ease;
}

.sync-feedback.success {
    color: #15803d;
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.sync-feedback.warning {
    color: #b45309;
    background-color: #fffbeb;
    border: 1px solid #fde68a;
}

/* Period Selector */
.period-selector-wrapper {
    margin-bottom: 22px;
}

.period-selector {
    display: flex;
    gap: 6px;
    background-color: #e5e5ea;
    padding: 4px;
    border-radius: 14px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.period-selector::-webkit-scrollbar {
    display: none;
}

.period-btn {
    flex: 1;
    min-width: fit-content;
    white-space: nowrap;
    background: none;
    border: none;
    padding: 7px 12px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.18s ease;
}

.period-btn.active {
    background-color: #ffffff;
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.custom-range-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    background: var(--bg-card);
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: var(--shadow-subtle);
}

.custom-range-inputs input[type="date"] {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-primary);
    flex: 1;
}

/* Cards Grid */
.cards-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Metric Card */
.metric-card {
    background-color: var(--bg-card);
    border-radius: var(--card-radius);
    padding: 22px 20px 18px 20px;
    box-shadow: var(--shadow-subtle);
    border: 1px solid rgba(0, 0, 0, 0.02);
}

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

.card-tag {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.health-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.74rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 9999px;
    letter-spacing: -0.01em;
    text-transform: none;
    line-height: 1.3;
}

.health-badge.hidden {
    display: none;
}

.badge-normal  { background: rgba(52, 199, 89, 0.14); color: #1e7e34; }
.badge-low     { background: rgba(0, 122, 255, 0.12); color: #0056b3; }
.badge-warning { background: rgba(255, 149, 0, 0.14); color: #ad5700; }
.badge-high    { background: rgba(255, 59, 48, 0.12); color: #c62828; }

.card-value-group {
    margin-bottom: 18px;
}

.primary-number {
    font-size: 2.7rem;
    font-weight: 700;
    letter-spacing: -0.035em;
    color: var(--text-primary);
    line-height: 1.1;
}

.numbers-row {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

.secondary-number {
    font-size: 1.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: -0.02em;
}

.unit {
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-left: 2px;
}

.meta-label-discreet {
    font-size: 0.86rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.diff-text {
    font-size: 0.88rem;
    font-weight: 500;
    margin-top: 4px;
    color: var(--text-secondary);
}

.diff-up {
    color: var(--text-primary);
}

.diff-down {
    color: var(--text-primary);
}

.no-data-msg {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    padding: 10px 0;
}

/* Chart Container */
.chart-container {
    position: relative;
    width: 100%;
    height: 180px;
}

.card-footer-note {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 10px;
}

/* Footer */
.app-footer {
    margin-top: 36px;
    padding: 20px 0;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.footer-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: color 0.15s ease;
}

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

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

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

.copyright {
    font-size: 0.76rem;
    color: var(--text-muted);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: #ffffff;
    border-radius: var(--card-radius);
    padding: 26px 22px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.15);
    z-index: 1001;
}

.modal-content h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.modal-desc {
    font-size: 0.86rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

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

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

.form-group select,
.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-primary);
    background: #f9f9fb;
}

.form-group-checkbox {
    margin-bottom: 20px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

.btn-primary {
    background-color: var(--accent);
    color: #ffffff;
    border: none;
    padding: 10px 18px;
    border-radius: var(--btn-radius);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.25);
    transition: opacity 0.15s ease;
}

.btn-primary:hover {
    opacity: 0.92;
}

.btn-subtle {
    background: #e5e5ea;
    color: var(--text-primary);
    border: none;
    padding: 10px 16px;
    border-radius: var(--btn-radius);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
}

.btn-danger {
    background-color: var(--danger);
    color: #ffffff;
    border: none;
    padding: 10px 18px;
    border-radius: var(--btn-radius);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
}

/* LOGIN SCREEN STYLING */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background-color: #f2f2f7;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background-color: var(--bg-card);
    border-radius: 26px;
    padding: 44px 28px 36px 28px;
    box-shadow: var(--shadow-subtle);
    text-align: center;
}

.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 22px;
    background: var(--accent-light);
    color: var(--accent);
    margin-bottom: 22px;
}

.brand-title {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.brand-tagline {
    font-size: 1.05rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-bottom: 36px;
}

.login-actions .btn-primary {
    width: 100%;
    justify-content: center;
    padding: 14px 20px;
    font-size: 1.05rem;
    border-radius: 16px;
}

.alert-box {
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 0.88rem;
    margin-bottom: 24px;
    text-align: left;
}

.alert-box.error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-box.info {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.login-footer {
    margin-top: 36px;
    font-size: 0.76rem;
    color: var(--text-muted);
}

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