:root {
    --bg: #101216;
    --bg-elevated: #22262e;
    --bg-elevated-2: #2c313b;
    --border: #3c414c;
    --text: #eef0f3;
    --text-dim: #9aa1ac;
    --text-faint: #6c7380;
    /* Accent sauge/forêt, en écho à l'arbre du logo Theravie — assez saturé
       pour rester visible sur fond sombre. Réservé aux éléments cliquables
       et aux 2-3 points chauds du dashboard (total URSSAF, prochain RDV). */
    --accent: #57b46e;
    --accent-strong: #2f7a45;
    --accent-soft: rgba(87, 180, 110, 0.16);
    --green: #46c98a;
    --red: #e0625f;
    --orange: #e0a95f;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.icon {
    width: 1.05rem;
    height: 1.05rem;
    flex-shrink: 0;
    stroke: currentColor;
}

* { box-sizing: border-box; }

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

body {
    padding-bottom: 5rem;
}

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

header.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header.topbar h1 {
    font-size: 1.1rem;
    margin: 0;
    font-weight: 600;
}

header.topbar h1 a.brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.brand-icon {
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 0.45rem;
    object-fit: cover;
    flex-shrink: 0;
}

header.topbar .icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    text-decoration: none;
    padding: 0.4rem;
    transition: color 0.15s ease;
}
header.topbar .icon-link:hover { color: var(--accent); }

header.topbar div { display: flex; align-items: center; }

.topbar-actions { gap: 0.3rem; }

.logout-form { display: inline; margin: 0; }
.icon-link-btn {
    background: none;
    border: none;
    width: auto;
    margin: 0;
    cursor: pointer;
}

.sms-gauge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-dim);
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    margin-right: 0.3rem;
}
.sms-gauge .icon { width: 0.95rem; height: 0.95rem; }
.sms-gauge-value { font-size: 1.2rem; font-weight: 700; color: var(--text); line-height: 1; }

.sms-gauge.ok { border-color: rgba(70, 201, 138, 0.35); }
.sms-gauge.ok .sms-gauge-value { color: var(--green); }

.sms-gauge.warn { color: var(--orange); border-color: rgba(224, 169, 95, 0.35); }
.sms-gauge.warn .sms-gauge-value { color: var(--orange); animation: sms-pulse-soft 2.2s ease-in-out infinite; }

.sms-gauge.critical { color: var(--red); border-color: rgba(224, 98, 95, 0.4); }
.sms-gauge.critical .sms-gauge-value { color: var(--red); animation: sms-pulse-strong 1.3s ease-in-out infinite; }

@keyframes sms-pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
@keyframes sms-pulse-strong {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
    .sms-gauge.warn .sms-gauge-value,
    .sms-gauge.critical .sms-gauge-value {
        animation: none;
    }
}

main {
    padding: 1rem;
    max-width: 640px;
    margin: 0 auto;
}

.flash {
    padding: 0.8rem 1rem;
    border-radius: 0.6rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}
.flash.ok { background: rgba(70, 201, 138, 0.15); color: var(--green); border: 1px solid rgba(70, 201, 138, 0.3); }
.flash.error { background: rgba(224, 98, 95, 0.15); color: var(--red); border: 1px solid rgba(224, 98, 95, 0.3); }

input[type=text], input[type=search], input[type=tel], input[type=email], input[type=password], textarea, select {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 0.7rem;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 0.7rem;
}

textarea { min-height: 6rem; resize: vertical; }

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%239aa1ac' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.6rem;
}
select:focus { outline: none; border-color: var(--accent); }

label {
    font-size: 0.85rem;
    color: var(--text-dim);
    display: block;
    margin-bottom: 0.3rem;
}

.mois-select-row {
    display: flex;
    gap: 0.75rem;
}
.mois-select-row .field { flex: 1 1 0; min-width: 0; margin-bottom: 0.9rem; }
.mois-select-row select { margin-bottom: 0; }

.field { margin-bottom: 0.9rem; }

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem 1.2rem;
    border-radius: 0.8rem;
    border: none;
    background: var(--accent-strong);
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    margin-bottom: 0.7rem;
    -webkit-tap-highlight-color: transparent;
}
button:active, .btn:active { opacity: 0.8; }

.btn.secondary { background: var(--bg-elevated-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn.call { background: var(--green); }
.btn.sms { background: var(--orange); }
.btn.small { padding: 0.6rem 0.9rem; font-size: 0.9rem; width: auto; }

.btn-row { display: flex; gap: 0.6rem; }
.btn-row .btn { flex: 1; margin-bottom: 0; }

.search-wrap { margin-bottom: 1rem; }

.fiche-actions { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.fiche-actions details { flex: 1; min-width: 0; }
.link-danger {
    background: transparent;
    border: none;
    color: var(--red);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.link-danger:active { opacity: 0.7; }

.sort-toggle { display: flex; gap: 0.6rem; margin-bottom: 1rem; font-size: 0.85rem; }
.sort-toggle a {
    color: var(--text-dim);
    text-decoration: none;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
}
.sort-toggle a.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }

.client-list-scroll {
    max-height: 20rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.4rem;
    margin-bottom: 0.9rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.client-list-scroll::-webkit-scrollbar { width: 6px; }
.client-list-scroll::-webkit-scrollbar-track { background: transparent; }
.client-list-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.client-list { list-style: none; margin: 0; padding: 0; }

.client-card {
    display: block;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.6rem 0.9rem;
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow-card);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.client-card:hover, .client-card:active {
    background: var(--bg-elevated-2);
    border-color: var(--accent);
}

.client-card .name-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.15rem 0.7rem;
    margin-bottom: 0.15rem;
}
.client-card .name { font-size: 1rem; font-weight: 600; color: var(--text); min-width: 0; flex: 1 1 auto; }
.client-card .phone { font-size: 0.86rem; color: var(--text-dim); flex: 0 0 auto; white-space: nowrap; }
.client-card .meta { font-size: 0.76rem; color: var(--text-faint); }

.empty-state { text-align: center; color: var(--text-dim); padding: 3rem 1rem; }

.fab {
    position: fixed;
    bottom: 1.2rem;
    right: 1.2rem;
    left: 1.2rem;
    max-width: 600px;
    margin: 0 auto;
    z-index: 20;
}

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    padding: 1.1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-card);
}

.section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin: 1.5rem 0 0.6rem;
}

.reservation-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
.reservation-row:last-child { border-bottom: none; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge.confirme { background: rgba(70, 201, 138, 0.15); color: var(--green); }
.badge.annule { background: rgba(224, 98, 95, 0.15); color: var(--red); }
.badge.reprogramme { background: rgba(224, 169, 95, 0.15); color: var(--orange); }

.seance-choice {
    display: block;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 0.9rem 1.1rem;
    margin-bottom: 0.6rem;
    text-decoration: none;
    color: var(--text);
}
.seance-choice .duree { color: var(--text-dim); font-size: 0.85rem; }

.seance-choice-speciale {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.import-row {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    padding: 0.8rem;
    border-bottom: 1px solid var(--border);
}
.import-row input[type=checkbox] {
    width: 1.4rem;
    height: 1.4rem;
    margin-top: 0.2rem;
    flex-shrink: 0;
}
.import-row .info { flex: 1; font-size: 0.9rem; }
.import-row .dup { color: var(--orange); font-size: 0.8rem; }

.back-link {
    display: inline-block;
    color: var(--text-dim);
    text-decoration: none;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.hint { color: var(--text-dim); font-size: 0.85rem; margin: 0.5rem 0 1rem; }

.mode-choice { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.9rem; }
.mode-radio {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: var(--bg-elevated);
    font-size: 0.95rem;
}
.mode-radio input { width: 1.2rem; height: 1.2rem; margin: 0; flex-shrink: 0; }

.urssaf-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.urssaf-table th, .urssaf-table td {
    padding: 0.7rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.urssaf-table thead th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.urssaf-table tbody tr:last-child td { border-bottom: none; }
.urssaf-table tfoot th { border-top: 1px solid var(--border); border-bottom: none; font-weight: 700; color: var(--text); }

/* --- Dashboard 3 colonnes (accueil) --- */

main:has(.dashboard) {
    max-width: 1400px;
}

.dashboard {
    display: grid;
    gap: 1.4rem;
    grid-template-columns: 1fr;
    grid-template-areas:
        "rdv"
        "contacts"
        "urssaf";
    align-items: start;
}

@media (min-width: 720px) {
    .dashboard {
        gap: 1.8rem;
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "rdv    contacts"
            "urssaf contacts";
    }
}

@media (min-width: 1100px) {
    .dashboard {
        gap: 2.2rem;
        grid-template-columns: 1.15fr 1.4fr 1.15fr;
        grid-template-areas:
            "rdv  contacts urssaf";
    }
}

.col-rdv { grid-area: rdv; }
.col-contacts { grid-area: contacts; }
.col-urssaf { grid-area: urssaf; }

.dashboard-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-card);
}

.col-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.85rem;
}

.rdv-day {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text);
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin: 1.1rem 0 0.5rem;
    padding: 0.45rem 0.7rem;
}
.rdv-day:first-child { margin-top: 0; }

.rdv-lunch-break {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin: 0.5rem 0;
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
}
.rdv-lunch-break::before,
.rdv-lunch-break::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.rdv-row {
    display: flex;
    gap: 0.9rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}
.rdv-row:last-child { border-bottom: none; }

.rdv-row-next {
    border-left: 3px solid var(--accent);
    border-bottom-color: transparent;
    background: var(--accent-soft);
    border-radius: 0 0.5rem 0.5rem 0;
    padding: 0.6rem 0.7rem;
}

.rdv-heure {
    font-weight: 500;
    color: var(--text-dim);
    flex-shrink: 0;
    min-width: 3.2rem;
}

.rdv-nom { font-size: 1rem; font-weight: 700; color: var(--text); }
.rdv-nom a { color: var(--text); text-decoration: none; }
.rdv-nom a:hover { color: var(--accent); }
.rdv-nom span { color: var(--text); }
.rdv-type { font-size: 0.78rem; color: var(--text-faint); margin-top: 0.1rem; }

.rdv-loading, .rdv-empty { color: var(--text-dim); font-size: 0.9rem; padding: 0.5rem 0; }

.dispo-block {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: 0.7rem;
    padding: 0.7rem 0.9rem;
    margin-bottom: 1.1rem;
}

.dispo-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.dispo-title .icon { width: 0.85rem; height: 0.85rem; }

.dispo-row {
    display: block;
    width: 100%;
    font: inherit;
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--text);
    background: none;
    border: none;
    text-align: left;
    padding: 0.3rem 0.2rem;
    border-radius: 0.4rem;
    cursor: pointer;
}
.dispo-row:hover, .dispo-row:focus-visible { background: rgba(255, 255, 255, 0.08); }
.dispo-row:active { background: rgba(255, 255, 255, 0.14); }

.dispo-loading, .dispo-empty { font-size: 0.84rem; color: var(--text-dim); }

.dispo-row-autre {
    font-size: 0.82rem;
    font-weight: 500;
    font-style: italic;
    color: var(--text-dim);
    margin-top: 0.3rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--accent);
}

.urssaf-mini-card {
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 1rem 1.1rem;
    margin-bottom: 0.6rem;
    box-shadow: var(--shadow-card);
}
.urssaf-mini-card.en-cours {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.urssaf-mini-card.en-cours .urssaf-mini-total { color: var(--accent); }

.urssaf-mini-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-en-cours {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: transparent;
    color: var(--accent);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: normal;
    padding: 0;
}
.badge-en-cours::before {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: var(--accent);
}

.urssaf-mini-total { font-size: 1.85rem; font-weight: 800; color: var(--text); margin: 0.3rem 0; line-height: 1.1; }
.urssaf-mini-ventil { font-size: 0.76rem; color: var(--text-faint); }

.urssaf-mini-detail {
    margin-top: 0.7rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.urssaf-detail-row {
    font-size: 0.78rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.urssaf-detail-more { font-size: 0.76rem; margin-top: 0.1rem; display: inline-block; }
.urssaf-detail-empty {
    font-size: 0.78rem;
    color: var(--text-faint);
    margin-top: 0.7rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
}

.urssaf-actions {
    display: flex;
    gap: 0.6rem;
    margin: 0.6rem 0;
}
.urssaf-actions .btn { width: auto; flex: 1 1 0; margin-bottom: 0; }

.urssaf-mini-tools {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.1rem 0 0.5rem;
}
.urssaf-tool-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    width: auto;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.urssaf-tool-link:active { opacity: 0.7; }
.urssaf-tool-sep { color: var(--text-faint); font-size: 0.76rem; }
.urssaf-tool-confirm { display: none; font-size: 0.76rem; font-weight: 600; }

.urssaf-past-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0.3rem 0.1rem;
    font-size: 0.82rem;
}
.urssaf-past-label { color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.03em; font-size: 0.72rem; }
.urssaf-past-total { color: var(--text-dim); font-variant-numeric: tabular-nums; }

.login-body { padding-bottom: 0; }

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.2rem;
}

.login-card {
    width: 100%;
    max-width: 360px;
    text-align: center;
    margin-bottom: 0;
}

.login-logo {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 0.8rem;
}

.login-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.2rem;
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin: 0 0 1.3rem;
}

.login-card form { text-align: left; }
.login-card .flash { text-align: left; }

/* Modale "Prendre RDV" (bloc Prochaines disponibilités) */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}
/* display:flex ci-dessus a la meme specificite que la regle [hidden] du
   navigateur : sans cette regle explicite, l'attribut hidden est ignore et
   la modale reste visible en permanence des le chargement de la page. */
.modal-backdrop[hidden] { display: none; }
@media (min-width: 720px) {
    .modal-backdrop {
        align-items: center;
        padding: 1.5rem;
    }
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 1rem 1rem 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
    .modal { border-radius: 1rem; }
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 1rem;
}
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.modal-subtitle { font-size: 0.86rem; color: var(--accent); margin-top: 0.2rem; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.3rem;
    cursor: pointer;
    flex-shrink: 0;
}
.modal-close:hover { color: var(--text); }

.modal-step-label {
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    margin-bottom: 0.6rem;
}

.modal-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.86rem;
    padding: 0 0 0.8rem;
    cursor: pointer;
}

.modal-seance-choice, .modal-client-row {
    width: 100%;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.modal-client-list {
    max-height: 45vh;
    overflow-y: auto;
    margin-bottom: 0.8rem;
}
.modal-client-row { margin-bottom: 0.5rem; }

.modal-sans-fiche { width: 100%; font: inherit; text-align: center; cursor: pointer; }
