:root {
    color-scheme: dark;
    --void: #0D111A;
    --surface: #161D2B;
    --elevated: #1F293D;
    --amber: #E58310;
    --emerald: #10B981;
    --over: #F87171;
    --under: #60A5FA;
    --text: #F9FAFB;
    --subtle: #9CA3AF;
    --muted: #6B7280;
}

* { box-sizing: border-box; }

html, body {
    min-height: 100%;
    margin: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,.05) 1px, transparent 1px) 0 0 / 18px 18px, #090B10;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }

.app-stage { min-height: 100vh; display: flex; justify-content: center; align-items: stretch; }

.phone-shell {
    width: min(100vw, 430px);
    min-height: 100vh;
    background: var(--void);
    border-left: 1px solid rgba(255,255,255,.08);
    border-right: 1px solid rgba(255,255,255,.08);
    position: relative;
    overflow-x: hidden;
}

.app-content { min-height: 100vh; padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
.screen { padding: calc(18px + env(safe-area-inset-top)) 16px 24px; }
.screen-header, .brand-bar, .status-row, .metric-strip, .playback-bar, .editor-footer, .setting-line, .oauth-row, .spread { display: flex; align-items: center; gap: 12px; }
.screen-header, .brand-bar, .spread, .setting-line { justify-content: space-between; }

.eyebrow, .section-title, .hero-panel p, .metric-strip span, .numeric-stepper span, .setting-line span, .log-row span, .card-topline {
    color: var(--subtle);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.screen-title { margin: 2px 0 0; color: var(--text); font-size: 1.05rem; line-height: 1.2; }
.brand-bar { min-height: 46px; color: #F7B58A; }
.nav-spacer { flex: 1; }
.mini-ble { width: 9px; height: 9px; border-radius: 999px; background: var(--emerald); box-shadow: 0 0 0 5px rgba(16,185,129,.12); }
.avatar { background: var(--elevated) !important; color: var(--text) !important; }
.search-box, .panel, .hero-panel, .profile-card, .log-row { background: var(--surface); border: 1px solid rgba(255,255,255,.07); border-radius: 8px; }
.search-box { margin: 12px 0; }
.filter-row, .stage-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }

.filter-chip, .stage-chips span {
    border: 0;
    white-space: nowrap;
    border-radius: 8px;
    padding: 9px 14px;
    background: #111827;
    color: var(--subtle);
    font: inherit;
    font-size: .78rem;
}

.filter-chip.active { background: rgba(229,131,16,.2); color: #FDBA74; box-shadow: inset 0 0 0 1px rgba(229,131,16,.42); }
.profile-list, .stage-editor-list, .log-list { display: grid; gap: 14px; margin-top: 14px; }
.profile-card { color: var(--text) !important; overflow: hidden; }
.profile-card h2 { margin: 4px 0 12px; font-size: 1.18rem; }

.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    margin: 12px 0;
    overflow: hidden;
    border-radius: 7px;
    background: rgba(255,255,255,.06);
}

.metric-grid div { background: #111827; padding: 10px; }
.metric-grid span, .metric-grid b { display: block; }
.metric-grid span { color: var(--subtle); font-size: .75rem; }
.metric-grid b { font-size: .95rem; }
.profile-fab {
    position: fixed !important;
    right: max(18px, calc((100vw - 430px) / 2 + 18px));
    bottom: calc(90px + env(safe-area-inset-bottom));
    width: 52px !important;
    height: 52px !important;
    border-radius: 12px !important;
    background: var(--amber) !important;
    color: #111827 !important;
    box-shadow: 0 16px 32px rgba(229,131,16,.28);
}
.status-row { margin-top: 10px; }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 7px;
    padding: 6px 10px;
    background: rgba(107,114,128,.14);
    color: var(--subtle);
    font-size: .72rem;
    font-weight: 900;
    text-transform: uppercase;
}

.status-pill.connected { background: rgba(16,185,129,.12); color: var(--emerald); }
.ble-warning {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(248,113,113,.14);
    color: #FECACA;
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.35;
}

.hero-panel {
    margin-top: 14px;
    padding: 22px 18px 16px;
    text-align: center;
    background: linear-gradient(180deg, #202331, var(--surface));
    box-shadow: inset 0 1px 0 rgba(229,131,16,.7), 0 20px 40px rgba(0,0,0,.22);
}

.hero-panel strong { display: block; margin: 8px 0 22px; color: #FFB185; font-size: 2.85rem; line-height: 1; }
.hero-panel strong span { margin-left: 4px; color: var(--text); font-size: 1rem; }
.metric-strip { justify-content: space-around; border-top: 1px solid rgba(255,255,255,.06); padding-top: 16px; }
.metric-strip div { min-width: 0; }
.metric-strip b { display: block; margin-top: 4px; font-size: 1.1rem; }
.offline-callout {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(96,165,250,.11);
    color: #BFDBFE;
    font-size: .84rem;
    font-weight: 700;
}
.delta-good { color: #FCA5A5; }
.delta-hot { color: var(--over); }
.panel { margin-top: 14px; padding: 16px; }
.timeline { display: grid; gap: 10px; margin-top: 12px; }
.timeline-step { display: grid; grid-template-columns: 14px 1fr; gap: 10px; color: var(--muted); }
.timeline-step.active { color: var(--text); }
.timeline-step.active .timeline-copy { background: var(--elevated); border: 1px solid rgba(255,255,255,.1); }
.timeline-step.completed { color: var(--subtle); text-decoration: line-through; }
.timeline-dot { width: 9px; height: 9px; margin-top: 12px; border-radius: 999px; background: currentColor; }
.timeline-step.completed .timeline-dot { background: var(--emerald); }
.timeline-step.active .timeline-dot { background: #FDAE69; }
.timeline-copy { border-radius: 8px; padding: 12px; }
.step-heading { display: flex; justify-content: space-between; gap: 8px; }
.timeline-copy p { margin: 8px 0; color: var(--subtle); font-size: .86rem; }
.brew-chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: rgba(255,255,255,.06); stroke-width: 1; }
.target-line { fill: none; stroke: #60A5FA; stroke-dasharray: 4 6; opacity: .55; }
.flow-line { fill: none; stroke: #F59E0B; stroke-width: 3; }
.flow-area { fill: url(#flowFill); }
.cursor-dot { fill: #FDBA74; stroke: var(--surface); stroke-width: 3; }

.playback-bar, .editor-footer, .bottom-nav {
    position: fixed;
    left: 50%;
    width: min(100vw, 430px);
    transform: translateX(-50%);
    background: rgba(13,17,26,.94);
    backdrop-filter: blur(18px);
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 20;
}

.playback-bar { bottom: calc(68px + env(safe-area-inset-bottom)); padding: 10px 16px; }
.control-button { width: 44px; height: 44px; border-radius: 8px !important; background: var(--elevated) !important; }
.pause-button { flex: 1; min-height: 48px; border-radius: 8px !important; font-weight: 800 !important; }
.bottom-nav { bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.bottom-nav-item { display: grid; place-items: center; gap: 3px; color: var(--subtle); font-size: .72rem; }
.bottom-nav-item.active { color: #FDBA74; }
.editor-screen { padding-bottom: 104px; }
.stepper-grid, .stage-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.numeric-stepper { border-radius: 8px; background: var(--elevated); padding: 10px; }
.numeric-stepper div { display: flex; justify-content: space-between; align-items: center; }
.ratio-row { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding: 12px; border-radius: 8px; background: #111827; }
.ratio-row span, .setting-line span { display: block; margin-top: 3px; text-transform: none; letter-spacing: 0; font-weight: 600; }
.stage-editor { display: grid; gap: 10px; padding: 12px; border-radius: 8px; background: var(--elevated); }
.drag-handle { color: var(--muted); font-weight: 900; }
.stage-actions { display: flex; justify-content: flex-end; }
.editor-footer { bottom: calc(68px + env(safe-area-inset-bottom)); justify-content: space-between; padding: 10px 16px; }
.analytics-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.analytics-hero div { padding: 12px; border-radius: 8px; background: var(--elevated); }
.analytics-hero span, .analytics-hero b { display: block; }
.analytics-hero span { color: var(--subtle); font-size: .78rem; }
.analytics-hero b { margin-top: 8px; font-size: 1.45rem; }
.log-row { justify-content: space-between; padding: 14px; }
.log-row b, .log-row span { display: block; }
.log-row > div:last-child { text-align: right; }
.settings-panel { display: grid; gap: 14px; }
.oauth-row { flex-wrap: wrap; }
.empty-state { display: grid; min-height: 70vh; place-items: center; text-align: center; }

.loading-progress {
    display: block;
    width: 6rem;
    height: 6rem;
    margin: 28vh auto 1rem;
}

.loading-progress circle {
    fill: none;
    stroke-width: .55rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:first-child { stroke: var(--elevated); }
.loading-progress circle:last-child { stroke: var(--amber); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * .8), 500%; }
.loading-progress-text { text-align: center; color: var(--subtle); }
.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0;
    z-index: 1000;
    padding: .7rem 1rem;
    background: #7f1d1d;
    color: white;
}

@media (max-width: 430px) {
    body { background: var(--void); }
    .phone-shell { border: 0; }
}
