/* ── Variables ── */
:root {
    --bg:         #111;
    --surface:    #1a1a1a;
    --border:     #2a2a2a;
    --text:       #e0e0e0;
    --text-dim:   #666;

    /* Effort zone colours — matched to Coggan zones */
    --z1:   #444;     /* recovery */
    --z2:   #4a90d9;  /* endurance */
    --z3:   #5cb85c;  /* tempo */
    --z4lo: #e6c027;  /* sweet spot */
    --z4hi: #e07820;  /* threshold */
    --z5lo: #e04020;  /* VO2 max lower */
    --z5hi: #cc2020;  /* VO2 max upper */
    --z6:   #aa00cc;  /* anaerobic */

    --seg-dim: #252525;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── Header ── */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#live-data {
    display: flex;
    gap: 28px;
}

.metric {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.metric .value {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    min-width: 3ch;
    text-align: right;
}

.unit {
    font-size: 0.8rem;
    color: var(--text-dim);
}

#ftp-input {
    width: 72px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 1rem;
    text-align: right;
}

#session-status {
    flex: 1;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-dim);
    padding: 0 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#btn-settings-open {
    font-size: 1rem;
    padding: 6px 10px;
}

#btn-account-pill {
    border-radius: 20px;
    padding: 6px 16px;
}

#btn-account-pill.signed-in {
    border-color: #5cb85c;
    color: #5cb85c;
}

button {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 7px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s, border-color 0.15s;
}

button:hover:not(:disabled) { background: var(--border); }
button:disabled { opacity: 0.35; cursor: default; }


#btn-connect.connected,
#btn-cadence.connected {
    border-color: #5cb85c;
    color: #5cb85c;
}

/* ── Main ── */
#main {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.page-hidden { display: none !important; }

/* ── Workout page ── */
#page-workout {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ── Manual page ── */
#page-manual {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding: 24px 32px;
    gap: 16px;
    overflow-y: auto;
}

#manual-metrics {
    display: flex;
    gap: 48px;
    justify-content: center;
}

.manual-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.manual-value {
    font-size: 5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    min-width: 3ch;
    text-align: center;
}

.manual-unit {
    font-size: 1rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

#manual-stopwatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#sw-display {
    font-size: 4rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

#sw-buttons {
    display: flex;
    gap: 16px;
}

#manual-resistance {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.manual-section-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-dim);
}

#res-mode-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.mode-btn {
    flex: 1;
    border: none;
    border-radius: 0;
    padding: 10px 28px;
    font-size: 0.95rem;
    letter-spacing: 0.06em;
    cursor: pointer;
}

.mode-btn.mode-active {
    background: var(--text);
    color: var(--bg);
}

.res-row {
    display: flex;
    align-items: center;
    gap: 24px;
}

#res-display,
#slope-display {
    font-size: 2.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 6ch;
    text-align: center;
}

/* Large buttons for manual page */
#sw-buttons button,
#res-down,
#res-up {
    font-size: 1.4rem;
    padding: 18px 36px;
    border-radius: 8px;
    min-width: 120px;
}

#res-down,
#res-up {
    font-size: 2.4rem;
    padding: 16px 32px;
    min-width: 80px;
    line-height: 1;
}

/* ── Drag divider ── */
#divider {
    width: 5px;
    flex-shrink: 0;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.15s;
}
#divider:hover,
#divider.dragging { background: #444; }

/* ── Segment table ── */
#segment-list {
    width: 300px;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 12px 16px;
    border-right: 1px solid var(--border);
}

/* Thin scrollbar */
#segment-list::-webkit-scrollbar { width: 4px; }
#segment-list::-webkit-scrollbar-track { background: transparent; }
#segment-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#workout-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#workout-table th {
    text-align: left;
    padding: 6px 10px;
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
}

#workout-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

#workout-table tr.past td { opacity: 0.3; }

#workout-table tr.current {
    background: rgba(255,255,255,0.05);
}

#workout-table tr.current td:nth-child(1) {
    border-left: 3px solid #e0e0e0;
    padding-left: 7px;
}

.effort-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.effort-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ── Rings panel ── */
#rings {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
}

.ring-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ring-centre {
    position: absolute;
    text-align: center;
    pointer-events: none;
    user-select: none;
}

.ring-effort {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.ring-effort.small {
    font-size: 1.5rem;
}

.ring-divider {
    width: 56px;
    border-top: 1px solid rgba(255,255,255,0.25);
    margin: 5px auto 4px;
}

.ring-stats {
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    letter-spacing: 0.03em;
}

.ring-countdown {
    font-size: 1.6rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

.ring-countdown.small {
    font-size: 1rem;
    color: var(--text-dim);
}

#seg-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

#btn-seg-prev,
#btn-seg-next {
    font-size: 2rem;
    line-height: 1;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
}

.ring-flank {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-align: center;
    min-width: 3ch;
}

.ring-flank-unit {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-dim);
    text-align: center;
    margin-top: 3px;
    letter-spacing: 0.05em;
}

#current-comment {
    font-size: 0.95rem;
    color: var(--text);
    text-align: center;
    padding: 0 16px;
    min-height: 1.4em;
}

#next-label {
    font-size: 0.7rem;
    letter-spacing: 0.14em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-top: 4px;
}

/* ── Footer / progress bar ── */
#footer {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#progress-bar-container {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background: var(--text);
    border-radius: 3px;
    transition: width 0.9s linear;
}

#time-remaining {
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    min-width: 52px;
}

#finish-flag {
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* ── Editor ── */
#editor-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 150;
    flex-direction: column;
}
#editor-overlay.visible { display: flex; }

.editor-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#editor-name {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 600;
    padding: 4px 0;
    outline: none;
    font-family: inherit;
}
#editor-name:focus { border-bottom-color: #888; }

.editor-btns {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.editor-body {
    flex: 1;
    overflow-y: auto;
}

#editor-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#editor-table th {
    text-align: left;
    padding: 8px 12px;
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

#editor-table td {
    padding: 3px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

#editor-table tr:hover td { background: rgba(255,255,255,0.02); }

.ed-num {
    color: var(--text-dim);
    font-size: 0.8rem;
    width: 2ch;
    text-align: right;
    padding-right: 12px !important;
}

.ed-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    color: var(--text);
    font-size: 0.9rem;
    padding: 5px 4px;
    outline: none;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}
.ed-input:focus { border-bottom-color: #555; }

.ed-dur     { width: 5ch; }
.ed-effort  { width: 3ch; text-align: center; }
.ed-rpm     { width: 4ch; text-align: center; }
.ed-comment { width: 100%; min-width: 140px; }

.ed-effort-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ed-swatch { flex-shrink: 0; }

.ed-actions {
    display: flex;
    gap: 4px;
    white-space: nowrap;
}

.ed-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-dim);
    cursor: pointer;
    padding: 3px 7px;
    border-radius: 3px;
    font-size: 0.8rem;
    transition: border-color 0.1s, color 0.1s;
}
.ed-btn:hover:not(:disabled) { border-color: var(--border); color: var(--text); }
.ed-btn:disabled { opacity: 0.18; cursor: default; }

.editor-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

/* ── Overlay (onboarding) ── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.overlay.visible { display: flex; }

.overlay-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 44px 40px;
    width: 420px;
    max-width: calc(100vw - 40px);
    display: flex;
    flex-direction: column;
    gap: 20px;
    text-align: center;
}

.overlay-card h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.overlay-card p {
    color: var(--text-dim);
    line-height: 1.6;
    font-size: 0.95rem;
}

.onboarding-row {
    display: flex;
    gap: 8px;
}

.onboarding-row input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 1rem;
}

.onboarding-row input:focus {
    outline: none;
    border-color: #888;
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.link-btn:hover { color: var(--text); }

/* ── Drawers ── */
.drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 320px;
    background: var(--surface);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}

.drawer-left  { left: 0;  border-right: 1px solid var(--border); transform: translateX(-100%); }
.drawer-right { right: 0; border-left:  1px solid var(--border); transform: translateX(100%);  }
.drawer.open  { transform: translateX(0); }

#drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
#drawer-backdrop.visible { display: block; }

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    flex-shrink: 0;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    border-radius: 4px;
}
.btn-close:hover { background: var(--border); color: var(--text); }

.drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 12px;
    font-size: 0.85rem;
    color: var(--text-dim);
    background: transparent;
    cursor: pointer;
}
.tab-btn.tab-active { color: var(--text); border-bottom-color: var(--text); }
.tab-btn:hover:not(.tab-active) { background: rgba(255,255,255,0.03); }

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.drawer-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.drawer-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}

.drawer-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

#account-info {
    font-size: 0.9rem;
    color: var(--text-dim);
}

/* ── Workout cards ── */
.workout-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    transition: background 0.15s;
}
.workout-card:hover { background: rgba(255,255,255,0.04); }

.workout-card-info {
    flex: 1;
    min-width: 0;
}

.workout-card-name {
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.workout-card-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 2px;
}

.workout-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.card-load-btn   { padding: 5px 12px; font-size: 0.8rem; }
.card-delete-btn { padding: 5px 8px;  font-size: 0.8rem; color: var(--text-dim); }

.library-hint {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-align: center;
    padding: 20px 0;
    line-height: 1.5;
}

/* ── Toasts ── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    max-width: 320px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: auto;
}
.toast.toast-visible { opacity: 1; transform: translateY(0); }
.toast-info    { background: #2a2a2a; border: 1px solid #444; }
.toast-success { background: #1a2e1a; border: 1px solid #3a6a3a; }
.toast-error   { background: #2e1a1a; border: 1px solid #6a3a3a; }
