/* ================================================================
   whoof dashboard — design system v2
   Inspired by WHOOP's signature dark + vibrant ring aesthetic.
   ================================================================ */

:root {
    /* ─── Surfaces ─────────────────────────────────── */
    --bg: #050508; /* true-black canvas */
    --surface-1: #0d0d12; /* primary card */
    --surface-2: #131318; /* nested / elevated */
    --surface-3: #1a1a22; /* hover / inputs */
    --surface-glow: #20202b;
    --border: rgba(255, 255, 255, 0.06);
    --border-hi: rgba(255, 255, 255, 0.12);
    --hairline: rgba(255, 255, 255, 0.04);

    /* ─── Text ─────────────────────────────────────── */
    --text: #ffffff;
    --text-2: #e2e2e8;
    --text-muted: #8b8b95;
    --text-faint: #51515b;

    /* ─── Metric palette (Whoop-faithful) ──────────── */
    --recovery: #16ec06;
    --recovery-2: #0aa803;
    --recovery-glow: rgba(22, 236, 6, 0.35);

    --strain: #9b5de5;
    --strain-2: #7b3fc4;
    --strain-glow: rgba(155, 93, 229, 0.35);

    --sleep: #c77dff;
    --sleep-2: #9b4dca;
    --sleep-glow: rgba(199, 125, 255, 0.32);

    --warn: #ffb020;
    --bad: #ff4757;
    --good: var(--recovery);
    --mid: var(--warn);

    /* legacy aliases */
    --rec-good: var(--recovery);
    --rec-mid: var(--warn);
    --rec-bad: var(--bad);
    --fg: var(--text);
    --fg-2: var(--text-2);
    --fg2: var(--text-2);
    --muted: var(--text-muted);
    --card-bg: var(--surface-1);
    --card-bg2: var(--surface-2);

    /* Stage colors */
    --stage-wake: #ff4757;
    --stage-light: #03b5f3;
    --stage-deep: #2547d4;
    --stage-rem: #b95cff;

    /* Zones */
    --zone-1: #1e88e5;
    --zone-2: #00bcd4;
    --zone-3: #16ec06;
    --zone-4: #ffb020;
    --zone-5: #ff4757;

    /* ─── Typography ───────────────────────────────── */
    --font:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
        sans-serif;
    --font-display:
        "Manrope", "Inter", -apple-system, BlinkMacSystemFont, system-ui,
        sans-serif;
    --font-mono:
        ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, monospace;

    /* ─── Geometry ─────────────────────────────────── */
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius: 18px;
    --radius-lg: 28px;
    --gutter: 20px;
    --sidebar-w: 240px;
    --topbar-h: 64px;

    /* iOS safe areas (notch / Dynamic Island / home indicator) */
    --sa-top: env(safe-area-inset-top, 0px);
    --sa-bottom: env(safe-area-inset-bottom, 0px);
    --sa-left: env(safe-area-inset-left, 0px);
    --sa-right: env(safe-area-inset-right, 0px);
}

/* ───────────────────────────────────────────────── */
/* Reset & base                                       */
/* ───────────────────────────────────────────────── */

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

html {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    font-feature-settings: "ss01", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    background:
        radial-gradient(
            1200px 600px at 80% -10%,
            rgba(3, 181, 243, 0.06),
            transparent 60%
        ),
        radial-gradient(
            900px 500px at -10% 110%,
            rgba(22, 236, 6, 0.04),
            transparent 60%
        ),
        var(--bg);
}

::selection {
    background: var(--strain);
    color: white;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 999px;
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--surface-glow);
}

/* Typography utilities */
h1,
h2,
h3,
h4 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
    color: var(--text);
}
h1 {
    font-size: 32px;
    line-height: 1.1;
}
h2 {
    font-size: 20px;
    line-height: 1.2;
}
h3 {
    font-size: 16px;
    line-height: 1.3;
    font-weight: 600;
}
p {
    margin: 0;
}

/* Pill labels (eyebrows) */
.eyebrow,
.card-eyebrow {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ───────────────────────────────────────────────── */
/* Sidebar                                            */
/* ───────────────────────────────────────────────── */

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: linear-gradient(180deg, #0a0a0e 0%, #07070a 100%);
    border-right: 1px solid var(--hairline);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    z-index: var(--z-nav);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 18px 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--hairline);
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}
.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: conic-gradient(
        from 180deg,
        var(--strain),
        var(--sleep),
        #6a0dad,
        var(--strain)
    );
    position: relative;
    flex: 0 0 28px;
}
.brand-mark::after {
    content: "";
    position: absolute;
    inset: 6px;
    background: var(--surface-1);
    border-radius: 4px;
}
.brand .brand-accent {
    background: linear-gradient(135deg, var(--strain), var(--sleep));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* Tabs in sidebar */
.tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0;
}
.tab {
    appearance: none;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--text-muted);
    text-align: left;
    padding: 10px 12px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: -0.005em;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition:
        background 120ms,
        color 120ms,
        border-color 120ms;
}
.tab:hover {
    background: var(--surface-2);
    color: var(--text);
}
.tab.active {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
    box-shadow: inset 0 1px 0 var(--hairline);
}
.tab-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    flex-shrink: 0;
}
.tab-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

/* Device dock — collapsed by default-ish */
#mvp-panel {
    margin-top: auto;
    padding: 14px;
    border-radius: 16px;
    background: linear-gradient(
        180deg,
        var(--surface-1) 0%,
        var(--surface-2) 100%
    );
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 12px;
}
#mvp-panel strong {
    font-weight: 700;
}
#mvp-panel button {
    appearance: none;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-hi);
    border-radius: 8px;
    padding: 6px 10px;
    font: 600 11px/1 var(--font);
    letter-spacing: 0.02em;
    cursor: pointer;
    transition:
        background 120ms,
        border-color 120ms;
}
#mvp-panel button:hover {
    background: var(--surface-glow);
    border-color: rgba(255, 255, 255, 0.18);
}
#mvp-panel button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
#mvp-connect {
    background: linear-gradient(
        180deg,
        var(--recovery) 0%,
        var(--recovery-2) 100%
    ) !important;
    color: #000 !important;
    font-weight: 800 !important;
    border: none !important;
    padding: 10px 14px !important;
    font-size: 12px !important;
    letter-spacing: 0.04em !important;
    text-transform: uppercase !important;
    box-shadow:
        0 0 0 1px rgba(22, 236, 6, 0.4),
        0 8px 24px -8px var(--recovery-glow) !important;
}

.settings-btn {
    appearance: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    padding: 8px 12px;
    font: 500 12px/1 var(--font);
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}
.settings-btn:hover {
    color: var(--text);
    border-color: var(--border-hi);
}

.status-line {
    font-size: 10px;
    color: var(--text-faint);
    text-align: center;
    padding-top: 8px;
    border-top: 1px solid var(--hairline);
    margin-top: 4px;
    word-break: break-word;
}

/* ───────────────────────────────────────────────── */
/* Main / Top bar                                     */
/* ───────────────────────────────────────────────── */

main.content {
    padding: 0 32px 80px 32px;
    min-width: 0;
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0;
    background: linear-gradient(180deg, var(--bg) 60%, transparent);
    backdrop-filter: saturate(140%) blur(8px);
}
.top-bar-left,
.top-bar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.date-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    color: var(--text-2);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.date-pill .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--recovery);
    box-shadow: 0 0 8px var(--recovery-glow);
}

.location-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.icon-btn {
    appearance: none;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        background 120ms,
        color 120ms;
    position: relative;
}
.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}
.icon-btn svg {
    width: 18px;
    height: 18px;
}
.icon-btn .badge-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--bad);
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 12px 4px 4px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-1);
    cursor: pointer;
    transition:
        border-color 120ms,
        background 120ms;
}
.user-profile:hover {
    background: var(--surface-2);
    border-color: var(--border-hi);
}
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--recovery), var(--strain));
    color: var(--bg);
    font-weight: 800;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.user-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 4px;
}
.user-name .chevron {
    color: var(--text-muted);
    font-size: 9px;
}
.user-email {
    font-size: 10px;
    color: var(--text-muted);
}

/* ───────────────────────────────────────────────── */
/* Tab panels                                         */
/* ───────────────────────────────────────────────── */

.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
}

.panel-header {
    padding: 12px 0 24px 0;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
}
.panel-header h1 {
    font-size: 36px;
}
.panel-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 6px;
}
.panel-date {
    color: var(--text-muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.welcome-text {
    background: linear-gradient(135deg, #ffffff, #b5b5bd);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.controls {
    display: flex;
    gap: 8px;
}
.controls select,
.controls input {
    appearance: none;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 12px;
    font: 600 12px var(--font);
    border-radius: 10px;
    cursor: pointer;
}
.controls select:hover {
    border-color: var(--border-hi);
}

/* ───────────────────────────────────────────────── */
/* Cards                                              */
/* ───────────────────────────────────────────────── */

.card {
    background: linear-gradient(180deg, var(--surface-1) 0%, #0b0b10 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
}
.card::before {
    /* subtle top-edge highlight */
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--hairline),
        transparent
    );
    pointer-events: none;
}
.card .card-eyebrow {
    margin-bottom: 14px;
    display: block;
}
.card .big-num {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 200;
    line-height: 1;
    letter-spacing: -0.04em;
    color: var(--text);
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    font-variant-numeric: tabular-nums;
}
.card .big-num .unit {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0;
}
.card .muted {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
}

/* Hero ring cards — Whoop-style */
.card-hero {
    padding: 32px 24px 28px 24px;
    text-align: center;
    background:
        radial-gradient(
            80% 60% at 50% 0%,
            rgba(255, 255, 255, 0.04),
            transparent 70%
        ),
        linear-gradient(180deg, var(--surface-1) 0%, #08080c 100%);
}

/* ───────────────────────────────────────────────── */
/* Grids                                              */
/* ───────────────────────────────────────────────── */

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--gutter);
}
.grid > .span-2 {
    grid-column: span 2;
}
.grid > .span-3 {
    grid-column: span 3;
}
.grid > .span-4 {
    grid-column: span 4;
}

@media (max-width: 1100px) {
    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .grid > .span-3,
    .grid > .span-4 {
        grid-column: span 2;
    }
}

/* ───────────────────────────────────────────────── */
/* Mobile: iPhone PWA layout                          */
/* ───────────────────────────────────────────────── */

@media (max-width: 720px) {
    body {
        grid-template-columns: 1fr;
        /* Respect iOS safe-areas (notch on left in landscape, home indicator) */
        padding-left: var(--sa-left);
        padding-right: var(--sa-right);
    }
    .sidebar {
        display: none;
    }

    main.content {
        padding: 12px 14px calc(80px + var(--sa-bottom)) 14px; /* leave room for bottom nav */
    }

    /* Make topbar compact + respect status-bar inset */
    .top-bar {
        height: auto;
        min-height: 52px;
        padding-top: var(--sa-top);
        margin-bottom: 6px;
    }
    .user-profile .user-info {
        display: none;
    }
    .user-profile {
        padding: 4px;
    }
    .date-pill {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Panel header: smaller hero, no right-aligned date hugging */
    .panel-header {
        padding: 8px 0 16px 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .panel-header h1 {
        font-size: 26px;
    }
    .panel-subtitle {
        font-size: 13px;
    }
    .panel-date {
        font-size: 11px;
    }

    /* All grids collapse to one column on phone */
    .grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .grid > .span-2,
    .grid > .span-3,
    .grid > .span-4 {
        grid-column: span 1;
    }

    /* Hero ring trio stacks; ring smaller */
    .hero-ring-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .ring-wrap {
        width: 180px;
        height: 180px;
    }
    .ring-wrap.big {
        width: 220px;
        height: 220px;
    }
    .ring-value .num {
        font-size: 56px;
    }
    .ring-value .num.big {
        font-size: 72px;
    }
    .ring-value .num .unit {
        font-size: 22px;
    }

    /* Cards: tighter padding */
    .card {
        padding: 16px 16px;
    }
    .card .card-eyebrow {
        margin-bottom: 10px;
    }
    .card .big-num {
        font-size: 28px;
    }
    h1 {
        font-size: 24px;
    }
    h2 {
        font-size: 18px;
    }

    /* Live HR card: stack the now-grid below the bpm again */
    .now-tile {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .now-hr {
        font-size: 44px !important;
    }
    .now-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Plan illustration smaller */
    #plan-zone {
        width: 44px !important;
        height: 44px !important;
    }

    /* Charts shorter */
    .chart-wrap {
        height: 160px;
    }
    .chart-wrap.tall {
        height: 200px;
    }

    /* Settings drawer takes full width on mobile */
    .drawer {
        width: 100vw;
        max-width: 100vw;
        padding: 24px 20px calc(24px + var(--sa-bottom)) 20px;
    }

    /* Reveal mobile bottom nav */
    .mobile-nav {
        display: flex !important;
    }
}

/* Mobile bottom navigation — hidden on desktop, visible on phone */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + var(--sa-bottom));
    padding-bottom: var(--sa-bottom);
    background: rgba(10, 10, 14, 0.92);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--border);
    justify-content: space-around;
    align-items: stretch;
    z-index: 50;
}
.mobile-nav .mtab {
    flex: 1;
    appearance: none;
    background: transparent;
    border: none;
    color: var(--text-faint);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    font: 600 9px var(--font);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 6px 0;
    transition: color 120ms;
}
.mobile-nav .mtab svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.mobile-nav .mtab.active {
    color: var(--recovery);
}
.mobile-nav .mtab:active {
    transform: scale(0.92);
}

/* ───────────────────────────────────────────────── */
/* Hero rings (Whoop-style)                            */
/* ───────────────────────────────────────────────── */

.hero-ring-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--gutter);
}
@media (max-width: 880px) {
    .hero-ring-row {
        grid-template-columns: 1fr;
    }
}

.ring-card {
    padding: 28px 24px 24px 24px;
    text-align: center;
    background:
        radial-gradient(
            70% 60% at 50% 10%,
            rgba(255, 255, 255, 0.05),
            transparent 70%
        ),
        linear-gradient(180deg, var(--surface-1) 0%, #08080c 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
}
.ring-card .ring-eyebrow {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.ring-card.recovery .ring-eyebrow {
    color: var(--recovery);
}
.ring-card.strain .ring-eyebrow {
    color: var(--strain);
}
.ring-card.sleep .ring-eyebrow {
    color: var(--sleep);
}

.ring-wrap {
    position: relative;
    width: 220px;
    height: 220px;
    margin: 14px auto 8px auto;
}
.ring-wrap.big {
    width: 300px;
    height: 300px;
}
.ring-wrap svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.ring-value {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.ring-value .num {
    font-family: var(--font-display);
    font-size: 72px;
    font-weight: 200;
    letter-spacing: -0.05em;
    line-height: 1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.ring-value .num .unit {
    font-size: 28px;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 2px;
    letter-spacing: 0;
}
.ring-value .num.big {
    font-size: 96px;
}
.ring-value .sub {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 6px;
}

.ring-card .ring-foot {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-variant-numeric: tabular-nums;
}
.ring-card .ring-foot strong {
    color: var(--text);
    font-weight: 600;
}

/* Sparkline — fixed-height wrapper prevents Chart.js (responsive +
   maintainAspectRatio:false) from feedback-looping with the card's content
   height and growing the canvas to tens of thousands of pixels.
   Belt-and-braces: hard-cap the canvas itself with max-height + !important so
   Chart.js's inline style can never override us (it sometimes writes
   style.height directly during resize). */
.ring-card .spark-wrap {
    position: relative;
    width: 100%;
    height: 36px;
    max-height: 36px;
    margin-top: 14px;
    overflow: hidden;
}
.ring-card canvas.spark {
    display: block;
    width: 100% !important;
    height: 36px !important;
    max-height: 36px;
}

/* ───────────────────────────────────────────────── */
/* "Now" Live tile                                    */
/* ───────────────────────────────────────────────── */

.now-tile {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 18px;
    align-items: center;
}
.now-hr {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-family: var(--font-display);
    font-size: 56px;
    font-weight: 200;
    letter-spacing: -0.04em;
    color: var(--text);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.now-hr .unit {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}
.heart-pulse {
    display: inline-flex;
    align-items: center;
    margin-left: 10px;
    color: var(--bad);
    animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 0.85;
    }
    50% {
        transform: scale(1.18);
        opacity: 1;
    }
}
.now-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}
.now-grid > div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid var(--hairline);
    padding-bottom: 4px;
}
.now-grid .lbl {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.now-grid span:last-child {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ───────────────────────────────────────────────── */
/* Plan / Insights / Workouts                         */
/* ───────────────────────────────────────────────── */

.plan-card {
    background:
        radial-gradient(
            80% 100% at 100% 0%,
            rgba(22, 236, 6, 0.08),
            transparent 60%
        ),
        linear-gradient(180deg, var(--surface-1) 0%, #08080c 100%);
}
.plan-illust {
    font-size: 36px;
    line-height: 1;
    margin-bottom: 6px;
    filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.1));
}
#plan-zone {
    font-family: var(--font-display);
    font-size: 28px !important;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 2px 0 !important;
}
#plan-label {
    font-size: 14px !important;
    font-weight: 600;
    color: var(--text-2) !important;
    margin-bottom: 8px !important;
}
#plan-message {
    font-size: 12px !important;
    color: var(--text-muted) !important;
    line-height: 1.6 !important;
}
#plan-target {
    font-size: 11px !important;
    color: var(--text-faint) !important;
    margin-top: 10px !important;
    padding-top: 8px;
    border-top: 1px solid var(--hairline);
}

.workout-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.workout-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
}
.workout-row .wo-time {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.workout-row .wo-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.workout-row .wo-strain {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 300;
    color: var(--strain);
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

/* Insights */
.insight {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 12px;
}
.insight .ins-icon {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.insight.warn .ins-icon {
    background: rgba(255, 176, 32, 0.14);
    color: var(--warn);
}
.insight.info .ins-icon {
    background: rgba(3, 181, 243, 0.14);
    color: var(--strain);
}
.insight.critical .ins-icon {
    background: rgba(255, 71, 87, 0.14);
    color: var(--bad);
}
.insight .ins-icon svg {
    width: 16px;
    height: 16px;
}
.insight .ins-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}
.insight .ins-body {
    color: var(--text-muted);
    line-height: 1.55;
}

/* Empty states */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 28px 12px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}
.empty-state svg {
    width: 72px;
    height: 72px;
    opacity: 0.4;
}

/* ───────────────────────────────────────────────── */
/* Charts container                                   */
/* ───────────────────────────────────────────────── */

.chart-wrap {
    position: relative;
    width: 100%;
    height: 200px;
}
.chart-wrap.tall {
    height: 280px;
}
.chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Hypnogram */
.hypnogram-wrap {
    width: 100%;
    height: 220px;
}
.hypnogram-wrap svg {
    width: 100%;
    height: 100%;
}
.legend {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    flex-wrap: wrap;
    font-size: 11px;
    color: var(--text-muted);
}
.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

/* Stage bars (Sleep tab) */
.stage-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.stage-bars .row {
    display: grid;
    grid-template-columns: 60px 1fr auto;
    gap: 12px;
    align-items: center;
    font-size: 12px;
}
.stage-bars .lbl {
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.04em;
}
.stage-bars .v {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.stage-bars .barwrap {
    height: 8px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
}
.stage-bars .bar {
    height: 100%;
    border-radius: inherit;
    box-shadow: 0 0 12px currentColor;
}

/* Component bars (Recovery tab) */
.components {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.component-row {
    display: grid;
    grid-template-columns: 90px 1fr 40px;
    gap: 12px;
    align-items: center;
    font-size: 12px;
}
.component-row .name {
    color: var(--text-muted);
    font-weight: 500;
}
.component-row .val {
    color: var(--text);
    font-weight: 700;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.component-row .barwrap {
    height: 8px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
}
.component-row .bar {
    height: 100%;
    border-radius: inherit;
}

/* Zones row (Strain tab) */
.zones-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}
.zone-cell {
    text-align: center;
    background: var(--surface-2);
    border-radius: 10px;
    padding: 10px 4px;
    border: 1px solid var(--border);
}
.zone-cell .zlbl {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}
.zone-cell .zval {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 400;
    color: var(--text);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.donut-wrap {
    display: flex;
    justify-content: center;
}
.donut-wrap svg {
    width: 180px;
    height: 180px;
}

/* ───────────────────────────────────────────────── */
/* Tables                                             */
/* ───────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
table th,
table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--hairline);
}
table th {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
    background: var(--surface-2);
    position: sticky;
    top: 0;
}
table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}
table td {
    color: var(--text-2);
}

/* Calendar heatmap */
.cal-cell {
    transition: transform 120ms;
}
.cal-cell:hover {
    transform: scale(1.18);
    z-index: 2;
    position: relative;
}
@media (max-width: 720px) {
    #recovery-cal-grid {
        grid-template-columns: repeat(10, 1fr) !important;
    }
}

/* Journal tags */
.journal-tag {
    appearance: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 6px 12px;
    font: 600 11px var(--font);
    cursor: pointer;
    transition: all 120ms;
}
.journal-tag:hover {
    border-color: var(--border-hi);
    color: var(--text);
}
.journal-tag.active {
    background: rgba(22, 236, 6, 0.12);
    border-color: var(--recovery);
    color: var(--recovery);
}
#journal-text {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    color: var(--text);
    font: 13px/1.5 var(--font);
    resize: vertical;
    min-height: 70px;
}
#journal-text:focus {
    outline: none;
    border-color: var(--border-hi);
}
#journal-date {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 6px 10px;
    font: 12px var(--font);
    color-scheme: dark;
}
#journal-save {
    appearance: none;
    background: var(--text);
    color: var(--bg);
    border: none;
    border-radius: 10px;
    padding: 8px 16px;
    font: 700 12px var(--font);
    cursor: pointer;
}
#journal-save:hover {
    opacity: 0.9;
}

/* ───────────────────────────────────────────────── */
/* Modals                                             */
/* ───────────────────────────────────────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    max-width: 540px;
    width: 92%;
}
.modal-card h2 {
    margin-bottom: 12px;
}

/* ───────────────────────────────────────────────── */
/* Settings drawer (right slide-out)                  */
/* ───────────────────────────────────────────────── */

.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 90;
    display: none;
}
.backdrop.open {
    display: block;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 92vw;
    height: 100vh;
    background: linear-gradient(180deg, var(--surface-1) 0%, #0a0a0e 100%);
    border-left: 1px solid var(--border);
    padding: 28px 32px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    transform: translateX(100%);
    visibility: hidden;
    /* Keep the drawer in the layout (display:flex) and slide it with transform so
     the transition actually plays; delay visibility:hidden until the slide-out
     finishes so it isn't interactive while open. */
    transition:
        transform 240ms ease,
        visibility 0s linear 240ms;
    box-shadow: -16px 0 48px rgba(0, 0, 0, 0.5);
}
.drawer.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 240ms ease;
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--hairline);
}
.drawer-head h2 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
}
.close-btn {
    appearance: none;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 36px;
    height: 36px;
    font-size: 20px;
    font-weight: 400;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.close-btn:hover {
    color: var(--text);
    border-color: var(--border-hi);
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.settings-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.settings-form input,
.settings-form select {
    appearance: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    border-radius: 10px;
    font-variant-numeric: tabular-nums;
}
.settings-form input:focus,
.settings-form select:focus {
    outline: none;
    border-color: var(--strain);
    box-shadow: 0 0 0 3px rgba(3, 181, 243, 0.18);
}
.settings-form .primary {
    appearance: none;
    background: var(--text);
    color: var(--bg);
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 4px;
    transition: opacity 120ms;
}
.settings-form .primary:hover {
    opacity: 0.85;
}
.settings-form .hint {
    font-size: 11px;
    color: var(--text-faint);
    font-weight: normal;
    letter-spacing: 0;
    text-transform: none;
}

.drawer hr {
    border: none;
    border-top: 1px solid var(--hairline);
    margin: 0;
}
.drawer .actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.drawer .actions button {
    appearance: none;
    background: var(--surface-3);
    border: 1px solid var(--border-hi);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 10px;
    font: 600 12px var(--font);
    cursor: pointer;
}
.drawer .actions button:hover {
    background: var(--surface-glow);
}
.drawer .actions .hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* Live tab — Device events log + Session stats */
.row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid var(--hairline);
    font-size: 13px;
}
.row:last-child {
    border-bottom: none;
}
.row .k {
    color: var(--text-muted);
    font-weight: 500;
}
.row .v {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ev {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--hairline);
    font-size: 12px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}
.ev:last-child {
    border-bottom: none;
}
.ev .kind {
    display: inline-block;
    padding: 2px 8px;
    background: var(--surface-3);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Misc */
.muted {
    color: var(--text-muted);
}
.big-num {
    font-family: var(--font-display);
}
.unit {
    font-size: 0.5em;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 4px;
}

/* Hide some clutter in the BT panel when disconnected */
#mvp-panel #mvp-spo2,
#mvp-panel #mvp-temp,
#mvp-panel #mvp-rr,
#mvp-panel #mvp-hr {
    font-variant-numeric: tabular-nums;
}
#mvp-panel details > summary {
    list-style: none;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
}
#mvp-panel details > summary:hover {
    color: var(--text);
}
#mvp-panel details > summary::-webkit-details-marker {
    display: none;
}
#mvp-panel details[open] > summary::before {
    content: "▾ ";
}
#mvp-panel details:not([open]) > summary::before {
    content: "▸ ";
}

/* Make export buttons compact + outline-only */
#mvp-panel button[id^="mvp-export"],
#mvp-panel #mvp-import,
#mvp-panel #mvp-reset {
    background: transparent !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border) !important;
    padding: 4px 8px !important;
    font-size: 10px !important;
    letter-spacing: 0;
}
#mvp-panel button[id^="mvp-export"]:hover,
#mvp-panel #mvp-import:hover,
#mvp-panel #mvp-reset:hover {
    color: var(--text) !important;
    border-color: var(--border-hi) !important;
}
