/*
 * Loupiot — mobile-first, utilisable à une main dans le noir.
 * Sombre par défaut, ardoise et pastels doux ; variante claire crème.
 */

:root {
    color-scheme: dark light;

    --bg: #22263a;
    --surface: #2a2f45;
    --surface-2: #343a53;
    --border: #3e4562;
    --line: color-mix(in srgb, var(--text) 9%, transparent);
    --text: #eceef5;
    --muted: #a4aac1;
    --accent: #9db8d9;
    --accent-strong: #bdd1ea;
    --on-accent: #1b1f30;
    --danger: #e6a397;
    --success: #b5d6a7;
    --warning: #e8c98f;

    /* Une teinte par type d'événement : pastilles, graphes, frises. */
    --c-sommeil: #9db8d9;
    --c-biberon: #f4a95f;
    --c-couche: #efe4c8;
    --c-tetee: #e9a9bc;
    --c-tirage: #c7b8e6;
    --c-solide: #b5d6a7;
    --c-medicament: #e8c98f;
    --c-mesure: #a6d4cd;
    --c-temperature: #e6a397;
    --c-note: #c5c8d4;

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;

    --radius: 16px;
    --radius-sm: 10px;
    --tap: 56px;
    --gap: 12px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f7f4ef;
        --surface: #fffdfa;
        --surface-2: #f0ebe3;
        --border: #e2dbcf;
        --text: #2a2e42;
        --muted: #6b7087;
        --accent: #5b7fae;
        --accent-strong: #456893;
        --on-accent: #ffffff;
        --danger: #c0675a;
        --success: #6f9d5e;
        --warning: #b98b2e;

        /* Les teintes les plus pâles disparaîtraient sur fond crème. */
        --c-couche: #dccb9e;
        --c-note: #aab0c2;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 17px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100dvh;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

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

h1, h2, h3, .serif {
    font-family: var(--font-serif);
    font-weight: 500;
    letter-spacing: -.005em;
}

.wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--gap) 16px;
}

/* --- icônes -------------------------------------------------------------- */

.icon {
    width: 24px;
    height: 24px;
    flex: none;
    display: inline-block;
    vertical-align: middle;
}

.icon-sm { width: 18px; height: 18px; }
.icon-lg { width: 30px; height: 30px; }

/* Pastille ronde teintée : l'icône prend la couleur du type (--tint). */
.badge-icon {
    --tint: var(--accent);
    width: 44px;
    height: 44px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--tint);
    background: color-mix(in srgb, var(--tint) 20%, transparent);
}

.badge-icon.lg { width: 56px; height: 56px; }
.badge-icon.lg .icon { width: 28px; height: 28px; }

/* Carré arrondi de couleur : <span class="dot" style="--dot: var(--c-biberon)"></span> */
.dot {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    background: var(--dot, var(--accent));
    flex: none;
    display: inline-block;
}

/* --- en-tête ------------------------------------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    max-width: 720px;
    margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 22px) 16px 10px;
}

.topbar-id {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.avatar {
    width: 54px;
    height: 54px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--avatar, var(--accent)) 30%, var(--surface));
    border: 2px solid var(--avatar, var(--accent));
    color: var(--text);
    font-family: var(--font-serif);
    font-size: 1.5rem;
    line-height: 1;
}

.avatar-sm { width: 40px; height: 40px; font-size: 1.15rem; }

.topbar h1 {
    font-size: 2rem;
    line-height: 1.1;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar .meta { color: var(--muted); font-size: .92rem; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions select { width: auto; min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); }

/* --- titres de section --------------------------------------------------- */

.section-title {
    margin: 28px 0 8px;
    font-family: var(--font-serif);
    font-size: 1.55rem;
    font-weight: 500;
    color: var(--text);
}

.page-title {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 6px 0 20px;
}

.page-title h2 { margin: 0; font-size: 1.8rem; line-height: 1.1; }
.page-title .kicker { color: var(--muted); font-size: .9rem; }

/* --- listes calmes à la Nara : rangées séparées par un filet ------------- */

.list {
    margin: 0 -16px;
    border-top: 1px solid var(--line);
}

.list-row {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
    color: inherit;
    text-decoration: none;
}

.list-row .grow { flex: 1; min-width: 0; }
.list-row .row-title { font-family: var(--font-serif); font-size: 1.2rem; line-height: 1.25; }
.list-row .row-value { font-size: 1.05rem; margin-top: 2px; }
.list-row .row-value strong { font-weight: 650; font-variant-numeric: tabular-nums; }
.list-row .row-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.list-row > .icon:last-child { color: var(--muted); align-self: center; }

.legend { display: grid; gap: 6px; margin-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 10px; font-size: .95rem; }
.legend-item .dot { width: 14px; height: 14px; }
.legend-item strong { margin-left: auto; font-variant-numeric: tabular-nums; }

/* --- cartes -------------------------------------------------------------- */

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--gap);
}

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

.card .label {
    color: var(--muted);
    font-size: .85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card .value { font-size: 1.5rem; font-weight: 600; margin-top: 4px; }
.card .sub { color: var(--muted); font-size: .85rem; }

/* --- boutons ------------------------------------------------------------- */

.grid-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--gap);
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: var(--tap);
    padding: 12px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .15s, transform .1s;
}

.btn:active { transform: scale(.985); background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn-primary:active { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-row { display: flex; gap: var(--gap); }
.btn-small { width: auto; min-height: 44px; padding: 6px 14px; font-size: .92rem; }

/* Gros pavé de saisie rapide, teinté par le type. */
.btn-big {
    --tint: var(--accent);
    min-height: 112px;
    flex-direction: column;
    gap: 8px;
    font-size: 1.08rem;
    background: var(--surface);
    border-color: var(--line);
    border-radius: 20px;
}

.btn-big:active { background: color-mix(in srgb, var(--tint) 12%, var(--surface)); }
.btn-big .hint { color: var(--muted); font-size: .8rem; font-weight: 500; margin-top: -6px; }

/* --- formulaires --------------------------------------------------------- */

.field { margin-bottom: 18px; }
.field > label { display: block; margin-bottom: 8px; color: var(--muted); font-size: .92rem; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="datetime-local"],
select, textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}

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

input[type="color"] {
    width: 100%;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

textarea { min-height: 96px; resize: vertical; }

.stepper {
    display: grid;
    grid-template-columns: 64px 1fr 64px;
    gap: 10px;
    align-items: center;
}

.stepper button {
    width: 64px;
    height: 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.stepper button:active { background: var(--surface-2); }

.stepper .display {
    text-align: center;
    font-family: var(--font-serif);
    font-size: 2.4rem;
    font-variant-numeric: tabular-nums;
}

.stepper .display small { font-family: var(--font-sans); font-size: .95rem; color: var(--muted); }

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

.segmented label {
    flex: 1 1 30%;
    min-height: var(--tap);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
}

.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:checked + span { font-weight: 650; }
.segmented label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* --- listes d'événements ------------------------------------------------- */

.day-group { margin-bottom: 22px; }
.day-group h2 { font-size: 1.3rem; margin: 0 0 6px; }

.event {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.event:last-child { border-bottom: 0; }
.event .grow { flex: 1; min-width: 0; }
.event .title { font-weight: 600; }
.event .detail { color: var(--muted); font-size: .88rem; }
.event .time { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; font-size: .9rem; }

/* --- timer --------------------------------------------------------------- */

.timer {
    --tint: var(--accent);
    display: flex;
    align-items: center;
    gap: 14px;
    background: color-mix(in srgb, var(--tint) 12%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--tint) 45%, transparent);
    border-radius: 20px;
    padding: 14px 16px;
    margin-bottom: var(--gap);
}

.timer .grow { flex: 1; min-width: 0; }
.timer .timer-label { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.timer .count {
    font-family: var(--font-serif);
    font-size: 2rem;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.timer .btn { width: auto; min-height: 52px; padding: 12px 20px; background: var(--tint); color: #1b1f30; border-color: transparent; }

/* --- navigation ---------------------------------------------------------- */

.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: color-mix(in srgb, var(--bg) 92%, black);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 20;
}

.tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 68px;
    color: var(--muted);
    text-decoration: none;
    font-size: .74rem;
    -webkit-tap-highlight-color: transparent;
}

.tabbar a .icon { width: 26px; height: 26px; }
.tabbar a.active { color: var(--accent); }

@media (prefers-color-scheme: light) {
    .tabbar { background: var(--surface); }

    /* Sur fond crème, un trait pastel pur se lit mal : on l'assombrit. */
    .badge-icon, .chip .icon { color: color-mix(in srgb, var(--tint) 55%, var(--text)); }
    .badge-icon { background: color-mix(in srgb, var(--tint) 28%, transparent); }
}

/* --- divers -------------------------------------------------------------- */

.flash {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--gap);
    border: 1px solid var(--border);
}

.flash-success { border-color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
.flash-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }

.token-reveal {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .82rem;
    word-break: break-all;
    background: var(--surface-2);
    border: 1px dashed var(--warning);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin: 8px 0;
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: var(--gap); scrollbar-width: none; }
.chips-wrap { flex-wrap: wrap; overflow: visible; }

.chip {
    --tint: var(--muted);
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 16px 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    text-decoration: none;
    font-size: .95rem;
}

.chip .icon { width: 20px; height: 20px; color: var(--tint); }
.chip.active { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.chip.active .icon { color: inherit; }

summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
summary .disclosure { color: var(--muted); transition: transform .2s; }
details[open] > summary .disclosure { transform: rotate(180deg); }

.empty-state {text-align: center; margin-top: 18vh; }
.empty-state .badge-icon { margin-bottom: 12px; }
.empty-state h1 { font-size: 2rem; margin: 0 0 6px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }

.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); }
.chart .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .lbl { fill: var(--muted); font-size: 8px; font-family: var(--font-sans); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: color-mix(in srgb, var(--accent) 20%, transparent); }

/* --- mode hors ligne (offline_queue_controller.js) ----------------------- */

/* Les cibles masquées le restent, quel que soit leur display (.timer est en flex). */
[data-offline-timer][hidden], .offline-status[hidden], .offline-pending-list[hidden] { display: none; }

.offline-banner {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    border: 1px solid var(--warning);
    background: color-mix(in srgb, var(--warning) 15%, transparent);
    font-size: .95rem;
}
.offline-tag {
    display: inline-block;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px dashed var(--warning);
    color: var(--warning);
    font-size: .8rem;
    white-space: nowrap;
}
.offline-pending { border-style: dashed; }
.offline-list { list-style: none; margin: 0 0 var(--gap); padding: 0; }
.offline-list li {
    padding: 10px 14px;
    margin-bottom: 6px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.offline-actions { display: flex; gap: 8px; margin-top: 8px; }
.offline-actions .btn { width: auto; min-height: 40px; }
