/* ---------- Couleurs (clair par défaut, sombre automatique ou forcé) ---------- */
:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --surface-2: #efece5;
    --text: #1f2328;
    --muted: #6b7078;
    --border: #e2ded5;
    --accent: #3d6b8f;
    --accent-text: #ffffff;
    --accent-soft: #e3edf5;
    --done: #2f8f5b;
    --late: #c0471f;
    --late-soft: #fbe9e2;
    --error: #b3261e;
    --radius: 14px;
    --tabbar-h: 64px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #16181c;
        --surface: #20242a;
        --surface-2: #2a2f36;
        --text: #eceef1;
        --muted: #9aa1ab;
        --border: #323840;
        --accent: #7fb0d6;
        --accent-text: #0e1418;
        --accent-soft: #233446;
        --done: #6cc896;
        --late: #ff9d78;
        --late-soft: #3a2621;
        --error: #ff8a80;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #16181c;
    --surface: #20242a;
    --surface-2: #2a2f36;
    --text: #eceef1;
    --muted: #9aa1ab;
    --border: #323840;
    --accent: #7fb0d6;
    --accent-text: #0e1418;
    --accent-soft: #233446;
    --done: #6cc896;
    --late: #ff9d78;
    --late-soft: #3a2621;
    --error: #ff8a80;
    color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 17px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

.page {
    max-width: 560px;
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 32px);
}

.page.with-nav { padding-bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 88px); }

h1 { font-size: 1.6rem; margin: 8px 0 2px; line-height: 1.2; }
h2 { font-size: 1rem; margin: 0 0 8px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }

.page-header { margin-bottom: 16px; }
.page-header p { margin: 0; }
.page-header.with-back { display: flex; align-items: center; gap: 4px; }
.page-header.with-back h1 { margin: 0; font-size: 1.35rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--error); font-weight: 500; }
.notice { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.empty { color: var(--muted); margin: 4px 0; font-size: .95rem; }
.pre { white-space: pre-wrap; }

.section { margin: 20px 0; }
.stack, .card, .sheet-actions { display: flex; flex-direction: column; gap: 10px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 12px 0;
}

.card p { margin: 0; }

/* ---------- Formulaires ---------- */
label, .field-label { font-weight: 600; margin-top: 4px; }

.input {
    width: 100%;
    font: inherit;
    padding: 11px 13px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

.input:focus, .btn:focus-visible, .segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input-small { padding: 8px 10px; font-size: .95rem; width: auto; flex: 1; min-width: 0; }
.input-number { width: 90px; }
textarea.input { resize: vertical; }

.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.toggle { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font: inherit;
    font-weight: 600;
    min-height: 48px;
    padding: 10px 16px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    text-decoration: none;
    cursor: pointer;
}

.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-member { background: var(--member, var(--accent)); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger-text { color: var(--error); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}

.icon-btn:disabled { opacity: .3; }

.segmented {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border-radius: 12px;
    padding: 4px;
}

.segmented button {
    flex: 1;
    font: inherit;
    font-size: .92rem;
    font-weight: 500;
    min-height: 40px;
    padding: 6px 8px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.segmented button.selected { background: var(--surface); color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.segmented-wrap { flex-wrap: wrap; }
.segmented-wrap button { flex: 1 1 40%; }
.segmented-small button { min-height: 34px; font-size: .88rem; }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.filters .segmented { flex: 1 1 auto; }

.days { display: flex; gap: 6px; }
.day-btn {
    flex: 1;
    aspect-ratio: 1;
    max-width: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.day-btn.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch.selected { border-color: var(--text); }

.person {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin: 6px 0 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.person legend { font-weight: 600; padding: 0 6px; }

.rotation { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rotation li { display: flex; align-items: center; gap: 6px; background: var(--bg); border-radius: 10px; padding: 4px 4px 4px 10px; }
.spacer { flex: 1; }

code { font-size: .85em; background: var(--bg); padding: 1px 5px; border-radius: 6px; }

/* ---------- Listes de tâches ---------- */
.list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 8px;
    min-height: 58px;
    color: inherit;
    text-decoration: none;
}

.row + .row { border-top: 1px solid var(--border); }

.check {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--accent-text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    position: relative;
}

/* Le cercle visible est plus petit que la zone de toucher. */
.check::before {
    content: "";
    position: absolute;
    inset: 7px;
    border-radius: 50%;
    border: 2px solid var(--muted);
}

.check > * { position: relative; }
.check:disabled { cursor: default; }

.row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding: 6px 0;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.row-meta { color: var(--muted); font-size: .85rem; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.row.is-done .check::before, .row.is-history .check::before { background: var(--done); border-color: var(--done); }
.row.is-done .row-title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.row.is-missed .row-title, .row.is-skipped .row-title { color: var(--muted); font-weight: 500; }
.row.is-missed .check, .row.is-skipped .check { color: var(--muted); }
.row.is-missed .check::before, .row.is-skipped .check::before { border-style: dashed; }
.row.is-late .check::before { border-color: var(--late); }

.badge { font-size: .75rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.badge-late { background: var(--late-soft); color: var(--late); }

.chip {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .82rem;
    font-weight: 600;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    white-space: nowrap;
}

.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--member, var(--muted)); }
.chip-free { color: var(--muted); font-weight: 500; }
.chip-free::before { background: transparent; border: 1.5px dashed var(--muted); width: 7px; height: 7px; }

.fold { margin: 20px 0; }
.fold summary { cursor: pointer; font-weight: 600; color: var(--muted); padding: 4px 0 8px; list-style-position: inside; }
.fold .section { margin: 0; }
.count { display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--surface-2); text-align: center; font-size: .85rem; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.progress-bar { height: 100%; background: var(--done); border-radius: 999px; transition: width .3s; }
.progress + p { margin: 6px 0 0; }

/* ---------- Semaine ---------- */
.week-nav { display: flex; align-items: center; gap: 4px; }
.week-label { flex: 1; font: inherit; font-weight: 600; background: none; border: none; color: var(--text); cursor: pointer; padding: 8px; }
.day.is-today h2 { color: var(--accent); }
.day.is-past { opacity: .85; }

/* ---------- Fiche ---------- */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.effort { letter-spacing: 2px; color: var(--accent); }

/* ---------- Bouton d'ajout ---------- */
.fab {
    position: fixed;
    right: max(16px, calc(50% - 264px));
    bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 16px);
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0,0,0,.2);
    cursor: pointer;
    z-index: 10;
}

/* ---------- Barre d'onglets ---------- */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
    z-index: 20;
}

.tabbar a {
    flex: 1;
    max-width: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: .7rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    padding: 4px 0;
    border-radius: 10px;
}

.tabbar a.active { color: var(--accent); }

/* ---------- Volet du bas ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    margin: 0 auto;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
    z-index: 31;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: slide-up .18s ease-out;
}

.sheet-handle { width: 40px; height: 5px; border-radius: 999px; background: var(--border); margin: 0 auto 4px; }
.sheet-title { font-size: 1.2rem; color: var(--text); margin: 0; }
.sheet p { margin: 0; }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; }

@keyframes slide-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Bandeaux ---------- */
.toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(env(safe-area-inset-bottom) + 16px);
    max-width: 528px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px 12px 16px;
    border-radius: 12px;
    background: #2a2e34;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    z-index: 40;
}

.toast.with-nav { bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 12px); }
.toast span { flex: 1; }
.toast-action { font: inherit; font-weight: 700; color: #9cd0ff; background: none; border: none; cursor: pointer; padding: 6px; }

.offline {
    position: sticky;
    top: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
    background: var(--late-soft);
    color: var(--late);
    font-weight: 600;
    font-size: .9rem;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: #fff3cd;
    color: #5c4400;
    z-index: 50;
}

#blazor-error-ui .reload { margin-left: 8px; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }
