:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #1f2937;
    --dim: #9ca3af;
    --border: #e5e7eb;
    --accent: #16a34a;
    --accent-soft: #dcfce7;
    --chip-bg: #f3f4f6;
    --shadow: 0 1px 3px rgba(0, 0, 0, .07);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111418;
        --card: #1b1f26;
        --text: #e5e7eb;
        --dim: #6b7280;
        --border: #2c323b;
        --accent: #22c55e;
        --accent-soft: #14351f;
        --chip-bg: #262c35;
        --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    padding-bottom: env(safe-area-inset-bottom);
}

.loading { padding: 40px; text-align: center; color: var(--dim); }
.dim { color: var(--dim); }

/* ---- Header ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 10px 14px calc(0px + 0px);
    padding-top: calc(10px + env(safe-area-inset-top));
    box-shadow: var(--shadow);
}

.topbar .row1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.brand { font-weight: 700; font-size: 17px; }
.brand .tractor { margin-right: 4px; }

.me-name {
    font-size: 13px;
    color: var(--dim);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.weeknav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 8px 0 2px;
}

.weeknav .label {
    font-weight: 600;
    min-width: 170px;
    text-align: center;
    font-size: 15px;
}

/* Onglets — barre du bas (pouce) en mobile, segmented control en desktop */
.tab {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--dim);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 639px) {
    .tabs {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 30;
        display: flex;
        gap: 4px;
        background: var(--card);
        border-top: 1px solid var(--border);
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 10px rgba(0, 0, 0, .07);
    }

    .tab {
        flex-direction: column;
        gap: 2px;
        padding: 5px 0 3px;
        border-radius: 10px;
        font-size: 11px;
    }

    .tab .tab-ico { font-size: 21px; line-height: 1.15; }

    .tab.on {
        color: var(--accent);
        background: var(--accent-soft);
    }

    .content { padding-bottom: 86px; }
}

@media (min-width: 640px) {
    .topbar .row1, .weeknav { max-width: 760px; margin-left: auto; margin-right: auto; }

    .tabs {
        display: flex;
        gap: 2px;
        max-width: 520px;
        margin: 10px auto 2px;
        background: var(--chip-bg);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 3px;
    }

    .tab {
        flex-direction: row;
        gap: 7px;
        padding: 8px 0;
        border-radius: 9px;
        font-size: 14px;
    }

    .tab .tab-ico { font-size: 15px; }

    .tab.on {
        background: var(--card);
        color: var(--text);
        box-shadow: var(--shadow);
    }
}

/* ---- Boutons ---- */
button { font-family: inherit; }

.btn, .mini {
    border: 1px solid var(--border);
    background: var(--chip-bg);
    color: var(--text);
    border-radius: 10px;
    cursor: pointer;
}

.btn { padding: 9px 14px; font-size: 15px; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.mini { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.mini[disabled] { opacity: .35; cursor: default; }
.mini.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.navbtn {
    width: 38px; height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--chip-bg);
    color: var(--text);
    font-size: 17px;
    cursor: pointer;
}

/* ---- Contenu ---- */
.content { padding: 14px; max-width: 760px; margin: 0 auto; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 12px 14px;
    margin-bottom: 12px;
}

.card.day.today { border-color: var(--accent); }

.dayhead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 700;
}

.dayhead .today-dot { color: var(--accent); font-size: 12px; margin-left: 4px; }

.halflabel { font-size: 12px; color: var(--dim); margin: 6px 0 4px; font-weight: 600; text-transform: uppercase; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    border: 1px solid var(--border);
    background: var(--chip-bg);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 13px;
    font-size: 15px;
    cursor: pointer;
    transition: transform .05s;
}

.chip:active { transform: scale(.95); }

.chip.on {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.input {
    border: 1px solid var(--border);
    background: var(--chip-bg);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    font-family: inherit;
    min-width: 0;
}

.agenda {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}

.agenda-ev {
    font-size: 13px;
    color: var(--dim);
    line-height: 1.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agenda-time {
    display: inline-block;
    min-width: 44px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.me-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

/* ---- Vue équipe ---- */
.teamwrap { overflow-x: auto; }

table.team {
    border-collapse: collapse;
    width: 100%;
    font-size: 15px;
}

table.team th, table.team td {
    padding: 7px 6px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.team th { color: var(--dim); font-size: 13px; font-weight: 600; }

table.team td.name, table.team th.name {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--card);
    font-weight: 600;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
}

table.team tr.me td { background: var(--accent-soft); }
table.team tr.me td.name { background: var(--accent-soft); }

.recap-day { margin-bottom: 10px; line-height: 1.5; }
.recap-day .d { font-weight: 700; }

/* ---- Répartition par jour ---- */
.repart-day {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.repart-day:last-child { border-bottom: none; padding-bottom: 2px; }

.repart-title { font-weight: 700; margin-bottom: 6px; }

.repart-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 3px 0;
    font-size: 14px;
}

.repart-lieu {
    min-width: 128px;
    font-weight: 600;
    white-space: nowrap;
}

.repart-count {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    padding: 1px 8px;
}

.repart-names {
    color: var(--dim);
    font-size: 13px;
    flex: 1;
    line-height: 1.5;
}

.tip {
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    cursor: help;
}

/* ---- Admin ---- */
.admin-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.admin-row:last-child { border-bottom: none; }

.admin-row input[type="text"], .admin-row input[type="email"] {
    border: 1px solid var(--border);
    background: var(--chip-bg);
    color: var(--text);
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 14px;
}

.admin-row .w-name { width: 100px; }
.admin-row .w-fullname { width: 150px; }
.admin-row .w-email { flex: 1; min-width: 150px; }
.admin-row .w-emoji { width: 52px; text-align: center; }
.admin-row .w-letter { width: 44px; text-align: center; }

.admin-row label.check { font-size: 13px; color: var(--dim); display: flex; align-items: center; gap: 3px; }
.admin-row .last-seen { font-size: 12px; white-space: nowrap; }

h2.section { font-size: 16px; margin: 18px 0 8px; }

/* ---- Toast ---- */
#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
    z-index: 99;
    max-width: 90vw;
}

#toast.show { opacity: 1; }

/* ---- Vacances ---- */
.vac-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.vac-row:last-of-type { border-bottom: none; }
.vac-period { font-weight: 600; }

/* ---- Calendrier de sélection de plage ---- */
.cal-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 12px 0 8px;
}

.cal-duo {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    user-select: none;
}

@media (min-width: 560px) {
    .cal-duo { grid-template-columns: 1fr 1fr; }
}

.cal-head {
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 6px;
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-dow {
    font-size: 11px;
    color: var(--dim);
    text-align: center;
    padding: 4px 0;
    font-weight: 600;
}

.cal-day {
    aspect-ratio: 1;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    position: relative;
    padding: 0;
}

.cal-day:active { transform: scale(.92); }
.cal-day.out { visibility: hidden; }
.cal-day.we { color: var(--dim); }

.cal-day.today { outline: 2px solid var(--accent); outline-offset: -2px; }

.cal-day.in-range {
    background: var(--accent-soft);
    border-radius: 0;
}

.cal-day.sel {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.cal-day.has-vac::after {
    content: '';
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
}

.cal-day.sel.has-vac::after { background: #fff; }

.vac-confirm {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--accent-soft);
    border-radius: 12px;
    flex-wrap: wrap;
    font-size: 14px;
}

.vac-hint {
    margin-top: 12px;
    font-size: 14px;
    line-height: 1.5;
}

/* Frise des vacances */
.tl-months {
    position: relative;
    height: 24px;
    margin-left: 92px;
    font-size: 12px;
    font-weight: 700;
    color: var(--dim);
}

.tl-months > span {
    position: absolute;
    top: 3px;
    transform: translateX(-50%);
    white-space: nowrap;
    text-transform: capitalize;
}

.tl-months .tl-today-lbl {
    color: #ef4444;
    font-size: 10px;
    top: auto;
    bottom: -2px;
}

.tl-body { position: relative; }

.tl-bg {
    position: absolute;
    left: 92px;
    right: 0;
    top: 0;
    bottom: 0;
    pointer-events: none;
    border-radius: 8px;
    overflow: hidden;
}

.tl-band {
    position: absolute;
    top: 0;
    bottom: 0;
    border-left: 1px solid var(--border);
}

.tl-band.alt { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.tl-today {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #ef4444;
    opacity: .8;
}

.tl-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    position: relative;
}

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

.tl-name {
    width: 86px;
    font-size: 13px;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.tl-track {
    position: relative;
    flex: 1;
    height: 30px;
}

.tl-bar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 21px;
    background: var(--accent);
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    padding: 0 7px;
    min-width: 8px;
}

/* Palette catégorielle validée (CVD ΔE 16.3, ≥3:1 sur fond clair et sombre) */
:root {
    --tl-c0: #2a78d6;
    --tl-c1: #0f8a63;
    --tl-c2: #a16207;
    --tl-c3: #15803d;
    --tl-c4: #6353c9;
    --tl-c5: #c92a2a;
    --tl-c6: #c2417c;
    --tl-c7: #c2410c;
}

@media (prefers-color-scheme: dark) {
    :root { --tl-c4: #7668dd; }
}

.tl-bar.tl-c0, .tl-dot.tl-c0 { background: var(--tl-c0); }
.tl-bar.tl-c1, .tl-dot.tl-c1 { background: var(--tl-c1); }
.tl-bar.tl-c2, .tl-dot.tl-c2 { background: var(--tl-c2); }
.tl-bar.tl-c3, .tl-dot.tl-c3 { background: var(--tl-c3); }
.tl-bar.tl-c4, .tl-dot.tl-c4 { background: var(--tl-c4); }
.tl-bar.tl-c5, .tl-dot.tl-c5 { background: var(--tl-c5); }
.tl-bar.tl-c6, .tl-dot.tl-c6 { background: var(--tl-c6); }
.tl-bar.tl-c7, .tl-dot.tl-c7 { background: var(--tl-c7); }

.tl-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: baseline;
    flex-shrink: 0;
}

/* ---- Curseur (brush) de la frise ---- */
.brush {
    position: relative;
    height: 32px;
    margin: 14px 0 4px 92px;
    background: var(--chip-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    touch-action: none;
    cursor: pointer;
}

.brush-tick {
    position: absolute;
    top: 7px;
    bottom: 7px;
    width: 1px;
    background: var(--border);
    pointer-events: none;
}

.brush-lbl {
    position: absolute;
    top: 50%;
    transform: translate(5px, -50%);
    font-size: 10px;
    font-weight: 600;
    color: var(--dim);
    pointer-events: none;
    white-space: nowrap;
}

.brush-lbl.now { color: #ef4444; }

.brush-now {
    position: absolute;
    top: 5px;
    bottom: 5px;
    width: 2px;
    background: #ef4444;
    border-radius: 2px;
    pointer-events: none;
}

.brush-win {
    position: absolute;
    top: 2px;
    bottom: 2px;
    min-width: 26px;
    background: color-mix(in srgb, var(--accent) 20%, transparent);
    border: 1.5px solid var(--accent);
    border-radius: 999px;
    cursor: grab;
}

.brush-win:active { cursor: grabbing; }

.brush-handle {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translate(-50%, -50%);
    width: 15px;
    height: 24px;
    background: var(--card);
    border: 1.5px solid var(--accent);
    border-radius: 7px;
    cursor: ew-resize;
    box-shadow: var(--shadow);
}

.brush-handle::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 6px;
    bottom: 6px;
    width: 2px;
    transform: translateX(-50%);
    background: var(--accent);
    border-radius: 1px;
}

.brush-handle[data-h="r"] { left: 100%; }

/* ---- Signature ---- */
.footer-sig {
    text-align: center;
    color: var(--dim);
    font-size: 12px;
    padding: 18px 0 10px;
}

/* ---- Landing ---- */
.landing {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.landing-card { text-align: center; max-width: 340px; padding: 32px 24px; }
.landing-logo { font-size: 52px; }
.landing-card h1 { margin: 8px 0 4px; }
