/* HippoCalendar, version web : même allure que l'app Mac. */

:root {
    --fond: #ffffff;
    --fond-hors-mois: #fafafb;
    --texte: #1d1d1f;
    --secondaire: #6e6e73;
    --tertiaire: #b4b4b9;
    --ligne: #e3e3e8;
    --bouton: #ececf0;
    --bouton-survol: #e1e1e6;
    --accent: #ff3b30;
    --evt: #007aff;
    --evt-fond: rgba(0, 122, 255, 0.14);
    --evt-texte: #0b5cbc;
    --survol: rgba(0, 122, 255, 0.08);
    --danger: #d70015;
    --voile: rgba(0, 0, 0, 0.25);
    --ombre: 0 20px 60px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.08);

    color-scheme: light dark;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
    :root {
        --fond: #1c1c1e;
        --fond-hors-mois: #19191b;
        --texte: #f5f5f7;
        --secondaire: #a1a1a6;
        --tertiaire: #5d5d62;
        --ligne: #343437;
        --bouton: #2c2c2e;
        --bouton-survol: #3a3a3c;
        --accent: #ff453a;
        --evt: #0a84ff;
        --evt-fond: rgba(10, 132, 255, 0.26);
        --evt-texte: #6cb0ff;
        --survol: rgba(10, 132, 255, 0.14);
        --danger: #ff453a;
        --voile: rgba(0, 0, 0, 0.5);
        --ombre: 0 20px 60px rgba(0, 0, 0, 0.55);
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    background: var(--fond);
    color: var(--texte);
    padding-bottom: env(safe-area-inset-bottom);
}

/* --- Barre du haut ------------------------------------------------------ */

.barre {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}

h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.etat { font-size: 12px; color: var(--secondaire); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etat.alerte { color: var(--danger); }

.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

button {
    font: inherit;
    font-size: 13px;
    color: var(--texte);
    background: var(--bouton);
    border: 0;
    border-radius: 6px;
    min-height: 26px;
    padding: 4px 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
button:hover { background: var(--bouton-survol); }
button:focus-visible { outline: 2px solid var(--evt); outline-offset: 1px; }
button:disabled { opacity: 0.5; cursor: default; }
button.icone { width: 32px; padding: 0; font-size: 19px; line-height: 1; }
button.discret { background: none; color: var(--secondaire); }
button.discret:hover { color: var(--texte); }
button.principal { background: var(--evt); color: #fff; font-weight: 500; }
button.principal:hover { filter: brightness(1.08); }
button.danger { background: none; color: var(--danger); }

/* --- Grille du mois ----------------------------------------------------- */

.jours-semaine {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    padding-bottom: 4px;
    font-size: 13px;
    color: var(--secondaire);
}
.jours-semaine span { text-align: right; padding-right: 10px; }

.grille {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(var(--semaines, 5), minmax(0, 1fr));
    gap: 1px;
    background: var(--ligne);
    border-top: 1px solid var(--ligne);
}

.case {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 3px 4px 2px;
    overflow: hidden;
    background: var(--fond);
    cursor: default;
    outline: none;
}
.case:focus-visible { box-shadow: inset 0 0 0 2px var(--evt); }
.case.hors-mois { background: var(--fond-hors-mois); }

.numero {
    align-self: flex-end;
    display: grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    margin: 2px 2px 2px 0;
    border-radius: 12px;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}
.hors-mois .numero { color: var(--tertiaire); }
.aujourdhui .numero { background: var(--accent); color: #fff; font-weight: 700; }

.evenements {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow: hidden;
}

.evt {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-height: 0;
    padding: 1px 4px;
    border-radius: 4px;
    background: none;
    font-size: 12px;
    line-height: 16px;
    text-align: left;
    white-space: nowrap;
}
.evt::before {
    content: "";
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--evt);
}
.evt:hover { background: var(--survol); }
.evt .heure { flex: none; color: var(--secondaire); font-variant-numeric: tabular-nums; }
.evt .nom { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.evt.journee { background: var(--evt-fond); color: var(--evt-texte); font-weight: 500; }
.evt.journee::before { display: none; }

.plus { padding: 0 4px; font-size: 11px; line-height: 15px; color: var(--secondaire); }

/* --- Fenêtres ----------------------------------------------------------- */

.fenetre {
    width: min(420px, calc(100vw - 32px));
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--fond);
    color: var(--texte);
    box-shadow: var(--ombre);
}
.fenetre::backdrop { background: var(--voile); }
.fenetre > form, .fenetre > .contenu { display: flex; flex-direction: column; gap: 12px; padding: 20px; }

.fenetre h2 { margin: 0; font-size: 17px; font-weight: 600; }
.aide { margin: -6px 0 0; font-size: 13px; color: var(--secondaire); }

.fenetre label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--secondaire); }
.fenetre label.coche { flex-direction: row; align-items: center; gap: 8px; color: var(--texte); }

input[type="text"], input[type="password"], input[type="date"], input[type="time"], textarea {
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid var(--ligne);
    border-radius: 6px;
    background: var(--fond);
    color: var(--texte);
    font: inherit;
    font-size: 16px; /* 16 px : Safari sur iPhone ne zoome pas sur le champ. */
}
input:focus, textarea:focus { outline: 2px solid var(--evt); outline-offset: -1px; border-color: transparent; }
input[name="titre"] { font-weight: 600; }
textarea { resize: vertical; }

.ligne {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 110px;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--secondaire);
}
form.journee .ligne { grid-template-columns: 44px minmax(0, 1fr); }
[hidden] { display: none !important; }

.invisible { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.erreur { margin: 0; font-size: 13px; color: var(--danger); }
.erreur:empty { display: none; }

.boutons { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.espace { flex: 1; }

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

.liste-jour {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 50vh;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow: auto;
}
.liste-jour button {
    display: flex;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    font-size: 14px;
    text-align: left;
}
.liste-jour .heure { flex: none; min-width: 96px; color: var(--secondaire); font-variant-numeric: tabular-nums; }
.liste-jour .nom { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste-jour .vide { padding: 6px 0; font-size: 14px; color: var(--secondaire); }

/* --- Téléphone ---------------------------------------------------------- */

/* Pas de zoom au double toucher : un toucher agit tout de suite. */
.grille, .case, button, .fenetre { touch-action: manipulation; }

@media (max-width: 640px) {
    .barre {
        gap: 6px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    /* Le titre cède la place aux boutons sur les écrans les plus étroits. */
    h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 20px; }
    #deconnexion { display: none; }
    .actions { flex: none; gap: 4px; }
    button.icone { width: 30px; }
    #aujourdhui { padding: 4px 8px; }

    /* Les erreurs (serveur injoignable…) restent visibles, en bandeau. */
    .etat:not(.alerte) { display: none; }
    .etat.alerte {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(10px + env(safe-area-inset-bottom));
        z-index: 10;
        padding: 8px 12px;
        border-radius: 8px;
        background: var(--danger);
        color: #fff;
        font-size: 13px;
        text-align: center;
        white-space: normal;
    }

    .jours-semaine { font-size: 11px; }
    .jours-semaine span { padding: 0; text-align: center; }
    .case { padding: 2px 1px 1px; }
    .numero { align-self: center; min-width: 22px; height: 22px; margin: 0 0 2px; font-size: 13px; }
    /* Trop petits pour le doigt : un toucher sur la case ouvre la liste du
       jour, aux lignes larges, et l'événement s'ouvre depuis cette liste. */
    .evt { pointer-events: none; padding: 0 2px; border-radius: 3px; font-size: 10px; line-height: 13px; }
    .evt::before { display: none; }
    .evt:not(.journee) { border-left: 2px solid var(--evt); }
    .evt .heure { display: none; }
    .plus { padding: 0 2px; font-size: 10px; line-height: 13px; }

    .liste-jour { max-height: 60vh; }
    .liste-jour button { padding: 12px; }
}
