:root {
    --bg: #0e0e10; /* Raw Cast Iron */
    --surface: #18181c; /* Machined Rim */
    --surface-alt: #232329; /* Knurled Steel */
    --primary: #ff2a2a; /* Tachometer Needle Red */
    --optimal: #2ec4b6; /* In-Zone Teal-Green */
    --eccentric: #ff9f1c; /* Amber Shift Light */
    --danger: #ff2a2a; /* Redline Alert */
    --gold: #ffd166; /* PR Gold */
    --text: #f4f4f6; /* Stencil White */
    --muted: #8a8a93; /* Brushed Steel Muted */
    --border: #2a2a30; /* Hairline Rim */
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    scrollbar-width: none;
}
*::-webkit-scrollbar {
    display: none;
}

html,
body {
    overscroll-behavior-y: none;
    background-color: var(--bg);
    color: var(--text);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: center;
}

body.vl-alert-flash {
    box-shadow: inset 0 0 0 4px var(--primary);
}

.container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Floating Top-Right Toast Container */
.toast-container {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
    max-width: 82vw;
}
.toast {
    background: rgba(24, 24, 28, 0.96);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-left: 3px solid var(--optimal);
    color: var(--text);
    padding: 9px 13px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
    animation: toastIn 0.18s ease-out;
}
.toast.error {
    border-left-color: var(--primary);
    color: #ff8080;
}
.toast.warn {
    border-left-color: var(--eccentric);
    color: var(--eccentric);
}
@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Top Instrument Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 20;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-left h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.hamburger-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 0;
}
.hamburger-btn span {
    display: block;
    width: 15px;
    height: 2px;
    background: var(--text);
}

.rest-pill {
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--optimal);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
}
.rest-pill.done {
    border-left-color: var(--primary);
    color: var(--primary);
}

.sync-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--optimal);
    display: inline-block;
}
.sync-dot.offline {
    background: var(--primary);
}

/* Explicit Session Control Cluster */
.session-banner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 9px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.session-banner.active-session {
    border-left: 3px solid var(--optimal);
}
.session-btn {
    border: none;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
}
.session-btn.start {
    background: var(--text);
    color: #000;
}
.session-btn.end {
    background: rgba(255, 42, 42, 0.16);
    color: var(--primary);
    border: 1px solid rgba(255, 42, 42, 0.4);
}

/* Compact Lift Config Pill + (+) Button */
.lift-summary-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.06);
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.lift-summary-main {
    display: flex;
    flex-direction: column;
    gap: 3px;
    cursor: pointer;
    flex: 1;
}
.lift-summary-title {
    font-size: 0.96rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--text);
}
.lift-summary-sub {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    color: var(--muted);
}
.plus-config-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.35rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

body.recording-mode .session-banner,
body.recording-mode .lift-summary-bar,
body.recording-mode #activeSessionContainer {
    display: none;
}

/* Slide-Over Utility Drawer */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    z-index: 90;
    display: none;
}
.nav-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 265px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: calc(20px + env(safe-area-inset-top)) 16px 24px 16px;
    z-index: 95;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
}
.nav-drawer.open {
    transform: translateX(0);
}
.drawer-btn {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    text-align: left;
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
}

/* Views */
.tab-view {
    display: none;
    flex-direction: column;
    gap: 10px;
}
.tab-view.active {
    display: flex;
}

/* Horizontal Scrollable Plate Ribbon */
.plate-ribbon-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.weight-box {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: left;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 800;
}
.plate-ribbon {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 2px 0;
    flex: 1;
}
.plate-chip {
    flex: 0 0 auto;
    background: var(--surface-alt);
    color: var(--text);
    border: 2px solid #35353d;
    border-radius: 20px;
    padding: 7px 12px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 800;
    cursor: pointer;
}
.plate-chip:active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.toggles-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    min-width: 0;
}
.toggle-label span {
    white-space: nowrap;
    overflow: hidden;
}
.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--primary);
}

/* Live Telemetry Instrument Cluster */
.metrics-grid {
    display: grid;
    grid-template-columns: 1.25fr 0.85fr 0.9fr;
    gap: 8px;
}
.metric-card {
    background-color: var(--surface);
    border-radius: 8px;
    padding: 12px 8px;
    text-align: center;
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.06);
}
.metric-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.metric-value {
    font-family: var(--font-mono);
    font-size: 1.85rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    color: var(--text);
    margin: 4px 0 2px 0;
}
.metric-unit {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--muted);
}

/* Expanded Two-State Recording Layout */
body.recording-mode .metrics-grid {
    grid-template-columns: 1fr 1fr;
}
body.recording-mode .metric-card:first-child {
    grid-column: span 2;
    padding: 20px 12px;
    border-left: 4px solid var(--primary);
}
body.recording-mode .metric-card:first-child .metric-value {
    font-size: 4.5rem;
}
body.recording-mode .chart-container {
    height: 295px;
}

.chart-container {
    background-color: var(--surface);
    border-radius: 8px;
    padding: 12px;
    height: 215px;
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.06);
}
canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.action-btn {
    width: 100%;
    border: none;
    border-radius: 8px;
    padding: 15px;
    font-size: 0.98rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
}
.btn-start {
    background-color: var(--text);
    color: #000;
}
.btn-armed {
    background-color: var(--eccentric);
    color: #000;
}
.btn-stop {
    background-color: var(--primary);
    color: #fff;
}

/* Persistent Bottom Tab Bar */
.bottom-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(18, 18, 22, 0.98);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom)) 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    z-index: 60;
}
.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 8px 4px;
    border-radius: 6px;
    cursor: pointer;
}
.tab-btn.active {
    background: var(--surface-alt);
    border-bottom-color: var(--primary);
    color: var(--text);
}

/* Stacked Cards, Rep Outliers & Delete Buttons */
.session-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--muted);
    padding: 6px 2px;
    border-bottom: 1px solid var(--border);
}
.btn-share-session {
    background: rgba(255, 42, 42, 0.14);
    color: var(--primary);
    border: 1px solid rgba(255, 42, 42, 0.4);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
}
.set-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.set-card.warmup {
    opacity: 0.72;
    border-style: dashed;
}
.set-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}
.set-title {
    font-size: 0.96rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}
.set-subtitle {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--muted);
    margin-top: 2px;
}
.badges-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: flex-end;
}
.badge {
    padding: 3px 7px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
}
.badge-1rm {
    background: rgba(255, 159, 28, 0.15);
    color: var(--eccentric);
}
.badge-rir {
    background: rgba(46, 196, 182, 0.15);
    color: var(--optimal);
}
.badge-pr {
    background: rgba(255, 42, 42, 0.18);
    color: var(--primary);
    border: 1px solid rgba(255, 42, 42, 0.4);
}
.badge-wu {
    background: rgba(138, 138, 147, 0.18);
    color: var(--muted);
}
.badge-outlier {
    background: rgba(255, 42, 42, 0.18);
    color: var(--primary);
    border: 1px solid rgba(255, 42, 42, 0.4);
}

.set-card-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--muted);
    background: var(--surface-alt);
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
}
.rep-drawer {
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}
.rep-row {
    display: grid;
    grid-template-columns: 52px 1fr 1fr 52px 28px;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    padding: 5px 6px;
    border-radius: 6px;
    background: var(--bg);
}
.rep-row.outlier {
    border: 1px solid rgba(255, 42, 42, 0.45);
    background: rgba(255, 42, 42, 0.08);
}
.rep-del-btn {
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    text-align: right;
    padding: 0 4px;
}
.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}
.btn-mini {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.lvp-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    height: 230px;
}
.pr-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.pr-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    background: var(--surface-alt);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
    font-family: var(--font-mono);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.86);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-color: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 20px;
    width: 100%;
    max-width: 390px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.modal-card h3 {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 1rem;
}
.modal-card input,
.modal-card select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.92rem;
    width: 100%;
}
.modal-card input:not([type="checkbox"]),
.modal-card select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.92rem;
    width: 100%;
}

.modal-actions {
    display: flex;
    gap: 8px;
}
.modal-actions button {
    flex: 1;
    padding: 11px;
    border-radius: 8px;
    border: none;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.styled-select,
.modal-card select {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg);
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8a93' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 15px;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 36px 10px 12px;
    font-size: 0.92rem;
    font-weight: 700;
    width: 100%;
    cursor: pointer;
}

/* PR Snapshot Box inside Configure Lift Modal */
.modal-pr-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 9px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.modal-pr-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.modal-pr-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    text-align: center;
    font-family: var(--font-mono);
}
.modal-pr-item-label {
    font-size: 0.66rem;
    color: var(--muted);
    text-transform: uppercase;
}
.modal-pr-item-val {
    font-size: 0.95rem;
    font-weight: 800;
    margin-top: 2px;
    color: var(--text);
}
