/* ===== Design tokens ===== */
:root {
    --bg: #0f1115;
    --bg-elevated: #171a20;
    --bg-elevated-2: #1f232b;
    --border: #2a2f3a;
    --text: #f2f4f7;
    --text-muted: #9aa3b2;
    --accent: #4ade80;
    --accent-text: #0b1f13;
    --danger: #f87171;
    --danger-text: #2a0d0d;
    --warning: #fbbf24;
    --radius: 14px;
    --radius-sm: 9px;
    --tab-bar-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
    --bg: #f5f6f8;
    --bg-elevated: #ffffff;
    --bg-elevated-2: #eef0f3;
    --border: #dde1e7;
    --text: #14171c;
    --text-muted: #5b6472;
    --accent: #16a34a;
    --accent-text: #ffffff;
    --danger: #dc2626;
    --danger-text: #ffffff;
    --warning: #b45309;
}

/* ===== Couleurs d'accent alternatives (vert = défaut, ci-dessus) =====
   Chaque paire dark/light reprend le même principe que le vert : une
   teinte claire/pastel sur fond sombre (texte foncé dessus), une teinte
   plus saturée sur fond clair (texte blanc dessus). */
[data-color="blue"] { --accent: #60a5fa; --accent-text: #06121f; }
[data-color="blue"][data-theme="light"] { --accent: #2563eb; --accent-text: #ffffff; }

[data-color="red"] { --accent: #f87171; --accent-text: #2a0705; }
[data-color="red"][data-theme="light"] { --accent: #dc2626; --accent-text: #ffffff; }

[data-color="yellow"] { --accent: #fbbf24; --accent-text: #241a02; }
[data-color="yellow"][data-theme="light"] { --accent: #b45309; --accent-text: #ffffff; }

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}

body {
    min-height: 100vh;
    padding-bottom: calc(var(--tab-bar-h) + var(--safe-bottom) + 12px);
}

body.no-tabbar {
    padding-bottom: 0;
}

h1, h2, h3, p { margin: 0; }

button {
    font-family: inherit;
    color: inherit;
    cursor: pointer;
}

input, select, textarea {
    font-family: inherit;
    font-size: 16px; /* évite le zoom auto iOS */
    color: var(--text);
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

/* ===== App shell ===== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: calc(14px + var(--safe-top)) 16px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 640px;
    margin: 0 auto;
}

.app-header h1 {
    font-size: 19px;
    font-weight: 700;
}

.app-header .subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 2px;
}

main {
    display: block;
    padding: 14px 14px 24px;
    max-width: 640px;
    margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* ===== Bottom tab bar ===== */
.tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    height: calc(var(--tab-bar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
}

.tab-bar-inner {
    display: flex;
    max-width: 640px;
    height: 100%;
    margin: 0 auto;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 600;
    min-height: 44px;
}

.tab-btn .icon { width: 23px; height: 23px; }

.tab-btn.active { color: var(--accent); }

/* ===== Cards & layout helpers ===== */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.row { display: flex; align-items: center; gap: 10px; }
.row input, .row select { min-width: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated-2);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.btn-block { width: 100%; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn-primary:active { filter: brightness(0.92); }

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-lg {
    min-height: 58px;
    font-size: 17px;
}

.btn:disabled { opacity: 0.5; }

/* ===== Exercise picker ===== */
.search-input { width: 100%; }

.exercise-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    max-height: 46vh;
    overflow-y: auto;
}

.exercise-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 52px;
    padding: 10px 14px;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: left;
}

.exercise-item .name { font-weight: 600; font-size: 15px; }
.exercise-item .muscle { color: var(--text-muted); font-size: 12.5px; margin-top: 1px; }
.exercise-item .star { color: var(--warning); font-size: 16px; }

.empty-state {
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 18px 6px;
}

/* ===== Stepper (poids / répétitions) ===== */
.stepper {
    display: grid;
    grid-template-columns: 56px 1fr 56px;
    align-items: stretch;
    gap: 8px;
}

.stepper-btn {
    min-height: 58px;
    font-size: 26px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    color: var(--text);
}

.stepper-btn:active { background: var(--border); }

.stepper-value {
    /* Sans ça, un <input> dans une colonne grid "1fr" refuse de rétrécir
       en dessous de sa largeur intrinsèque par défaut (~170-200px) et fait
       déborder toute la mise en page horizontalement. */
    min-width: 0;
    width: 100%;
    text-align: center;
    font-size: 30px;
    font-weight: 800;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated-2);
    -moz-appearance: textfield;
}

.stepper-value::-webkit-outer-spin-button,
.stepper-value::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.stepper-label {
    font-size: 12.5px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stepper-fine {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

.chip {
    padding: 6px 12px;
    min-height: 32px;
    border-radius: 999px;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.chip.active { color: var(--accent); border-color: var(--accent); }

/* ===== Last performance banner ===== */
.last-perf {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13.5px;
    color: var(--text-muted);
}

.last-perf strong { color: var(--text); }

/* ===== Today's sets list ===== */
.today-sets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.today-set-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 7px 8px 7px 14px;
    font-size: 13.5px;
    font-weight: 600;
}

.today-set-chip .del {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tab-bar-h) + var(--safe-bottom) + 16px);
    transform: translate(-50%, 12px);
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    font-size: 14px;
    padding: 12px 20px;
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ===== History ===== */
.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.filters select,
.filters input {
    min-width: 0;
    width: 100%;
}

.filters .full { grid-column: 1 / -1; }

.day-group { margin-top: 18px; }

.day-heading {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: capitalize;
}

.set-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.set-row .ex-name { font-weight: 700; font-size: 14.5px; }
.set-row .ex-detail { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.set-row .time { color: var(--text-muted); font-size: 12px; }

.set-edit-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg-elevated-2);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.set-edit-form input[type="number"] { width: 84px; }

/* ===== Progression ===== */
#progress-exercise {
    width: 100%;
}

.segmented {
    display: flex;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
}

.segmented button {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 13.5px;
    padding: 8px 10px;
    border-radius: 999px;
    min-height: 38px;
}

.segmented button.active {
    background: var(--accent);
    color: var(--accent-text);
}

.chart-wrap {
    position: relative;
    height: 220px;
    margin-top: 10px;
}

.stat-pill-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.stat-pill {
    flex: 1;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    text-align: center;
}

.stat-pill .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 700; }
.stat-pill .value { font-size: 18px; font-weight: 800; margin-top: 3px; }

/* ===== Profile ===== */
.field-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
}

.bw-history-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }

.bw-history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    min-height: 44px;
    background: var(--bg-elevated-2);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    cursor: pointer;
}

.unit-toggle { display: flex; gap: 8px; }
.unit-toggle button { flex: 1; }

.theme-toggle-row { display: flex; align-items: center; justify-content: space-between; }

/* ===== Switch façon iOS ===== */
.switch {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.switch-track {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 999px;
    transition: background-color 0.2s ease;
}

.switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s ease;
}

.switch input:checked ~ .switch-track { background: var(--accent); }
.switch input:checked ~ .switch-thumb { transform: translateX(20px); }

/* ===== Pastilles de couleur d'accent ===== */
.color-swatches {
    display: flex;
    gap: 14px;
    margin-top: 10px;
}

.color-swatch {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--swatch);
    border: 3px solid transparent;
    position: relative;
    padding: 0;
}

.color-swatch.active {
    border-color: var(--text);
}

.color-swatch.active::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 800;
    font-size: 16px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ===== Inline new-exercise form ===== */
.new-exercise-form {
    margin-top: 10px;
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    display: none;
}

.new-exercise-form.open { display: block; }

.new-exercise-form .stack { gap: 8px; }

/* ===== Écran connexion / inscription ===== */
.auth-screen {
    display: none; /* affiché via JS quand non connecté */
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    padding-top: calc(24px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
}

.auth-screen.active { display: flex; }

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 22px;
    text-align: center;
}

.auth-logo {
    color: var(--accent);
    margin-bottom: 8px;
}

.auth-card h1 {
    font-size: 20px;
    font-weight: 800;
}

.auth-card .field-label,
.auth-card form > div {
    text-align: left;
}

/* ===== Misc ===== */
.loading-msg, .error-msg {
    color: var(--text-muted);
    font-size: 13.5px;
    padding: 10px 2px;
}

.error-msg { color: var(--danger); }

::-webkit-scrollbar { width: 0; height: 0; }
