/* =========================================================================
   Boîte à outils — fenêtres flottantes et déplaçables.

   ⚠️ TOUT EST PRÉFIXÉ `.oas-` (outils à soi) ET AUCUNE RÈGLE GLOBALE N'EST
   REDÉFINIE. La feuille est chargée sur TOUTES les pages par `base.html` :
   une règle non préfixée comme `button { … }` déborderait sur les écrans
   métier, et le défaut serait difficile à relier à ce fichier.

   ⚠️ LES COULEURS VIENNENT UNIQUEMENT DES VARIABLES DE `style.css`.
   Le site a un thème sombre ET un thème clair, plus une couleur d'accent
   réglable : écrire `#4da3ff` en dur ferait une fenêtre qui jure dès que le
   gestionnaire change la palette.
   ========================================================================= */

/* ---------- Calque ---------- */

/* ⚠️ `pointer-events: none` SUR LE CALQUE, `auto` SUR LES FENÊTRES.
   Sans cela, un calque plein écran — même transparent — avalerait tous les
   clics de la page, y compris ceux qui ne sont pas sous une fenêtre. */
.oas-calque {
    position: fixed;
    inset: 0;
    z-index: 950;          /* au-dessus de la barre (300), sous les modales (1000) */
    pointer-events: none;
}

/* ---------- Fenêtre ---------- */

.oas-fenetre {
    position: fixed;
    display: flex;
    flex-direction: column;
    width: 340px;
    max-width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .35);
    pointer-events: auto;
    overflow: hidden;
    /* ⚠️ PAS DE TRANSITION SUR `transform`/`top` : la fenêtre doit suivre la
       souris SANS retard. Une animation de 150 ms donne l'impression que la
       fenêtre « flotte » et se désynchronise du curseur. */
}

.oas-fenetre.oas-large { width: 420px; }

.oas-fenetre[hidden] { display: none; }

/* Filet d'accent en haut : identifie la fenêtre comme un outil, pas comme un
   panneau de l'application. */
.oas-fenetre::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-color),
                                var(--societe-couleur, var(--primary-color)));
    opacity: .85;
}

/* ---------- Barre de titre (poignée) ---------- */

.oas-tete {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .55rem .5rem .8rem;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border-color);
    cursor: grab;
    /* ⚠️ `touch-action: none` : sans cela, sur tablette, le glissement fait
       défiler la page au lieu de déplacer la fenêtre. */
    touch-action: none;
    user-select: none;
    flex: 0 0 auto;
}

.oas-tete.oas-glisse { cursor: grabbing; }

.oas-titre {
    font-size: .82rem;
    font-weight: 700;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.oas-tete-actions {
    display: flex;
    align-items: center;
    gap: .15rem;
    margin-left: auto;
}

.oas-btn-icone {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: .95rem;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.oas-btn-icone:hover {
    background: var(--bg-hover);
    color: var(--text-color);
    border-color: var(--border-color);
}

.oas-btn-icone:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -1px;
}

.oas-btn-icone.oas-fermer:hover {
    background: rgba(224, 85, 99, .2);
    color: #ff8a96;
    border-color: rgba(224, 85, 99, .45);
}

/* ---------- Corps ---------- */

.oas-corps {
    padding: .75rem .8rem .85rem;
    overflow: auto;
    /* ⚠️ `min-height: 0` EST INDISPENSABLE. Dans une colonne flex, un enfant
       ne rétrécit pas sous sa taille de contenu par défaut : sans cette ligne,
       un contenu long déborde de la fenêtre au lieu de défiler. */
    min-height: 0;
    flex: 1 1 auto;
}

.oas-fenetre.oas-reduite .oas-corps { display: none; }

/* ---------- Calculatrice : écran ---------- */

.oas-ecran {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 9px;
    padding: .55rem .7rem .6rem;
    margin-bottom: .6rem;
    text-align: right;
    overflow: hidden;
}

.oas-ecran-expression {
    font-size: .74rem;
    color: var(--text-muted);
    min-height: 1.1em;
    white-space: nowrap;
    overflow-x: auto;
    /* ⚠️ PAS DE BARRE DE DÉFILEMENT APPARENTE : elle mange la hauteur de
       l'écran et attire l'œil sur un détail. Le défilement reste possible. */
    scrollbar-width: none;
}

.oas-ecran-expression::-webkit-scrollbar { display: none; }

.oas-ecran-resultat {
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    color: var(--text-color);
    white-space: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.oas-ecran-resultat::-webkit-scrollbar { display: none; }

/* ⚠️ UNE ERREUR DOIT SE VOIR SANS CRIER : le calcul reste modifiable, on ne
   veut pas d'un écran rouge qui donne l'impression d'avoir cassé l'outil. */
.oas-ecran-resultat.oas-erreur {
    font-size: 1rem;
    font-weight: 600;
    color: var(--warning-color);
}

.oas-ecran-resultat.oas-prevu { color: var(--text-muted); }

/* ---------- Calculatrice : clavier ---------- */

.oas-touches {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .32rem;
}

.oas-touche {
    padding: .58rem 0;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-family: inherit;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .12s, border-color .12s, transform .06s;
    /* ⚠️ EMPÊCHE LA SÉLECTION DE TEXTE AU DOUBLE-CLIC RAPIDE : sans cela, une
       frappe vive sélectionne le libellé du bouton au lieu de calculer. */
    user-select: none;
}

.oas-touche:hover { background: var(--bg-hover); }

/* ⚠️ RETOUR VISUEL AU CLIC — `:active` ET NON UNE CLASSE JAVASCRIPT.
   C'est instantané, ça ne dépend d'aucun script, et ça fonctionne aussi quand
   la touche est actionnée au clavier (Espace/Entrée). */
.oas-touche:active { transform: scale(.96); }

.oas-touche:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.oas-touche.oas-op {
    color: var(--primary-color);
    background: rgba(77, 163, 255, .12);
    border-color: rgba(77, 163, 255, .34);
}

.oas-touche.oas-op:hover { background: rgba(77, 163, 255, .2); }

.oas-touche.oas-efface { color: #ff8a96; }
.oas-touche.oas-efface:hover { background: rgba(224, 85, 99, .16); }

.oas-touche.oas-egal {
    color: #fff;
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.oas-touche.oas-egal:hover { background: var(--primary-hover); }

.oas-touche.oas-large2 { grid-column: span 2; }

/* ---------- Ligne de copie ---------- */

.oas-copie {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-top: .6rem;
    flex-wrap: wrap;
}

.oas-copie-champ {
    flex: 1 1 90px;
    min-width: 0;
    padding: .34rem .45rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-color);
    font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
    font-size: .8rem;
    text-align: right;
    /* ⚠️ LECTURE SEULE MAIS SÉLECTIONNABLE : c'est le repli quand le
       presse-papiers est refusé (HTTP simple). L'utilisateur peut alors
       faire Ctrl+C lui-même. */
}

.oas-copie-champ:focus {
    outline: none;
    border-color: var(--primary-color);
}

.oas-statut {
    font-size: .7rem;
    line-height: 1.4;
    margin-top: .4rem;
    min-height: 1em;
    color: var(--text-muted);
}

.oas-statut.oas-ok { color: var(--success-color); }
.oas-statut.oas-attention { color: var(--warning-color); }

/* ---------- Historique de la calculatrice ---------- */

.oas-historique {
    margin-top: .6rem;
    border-top: 1px solid var(--border-color);
    padding-top: .45rem;
    max-height: 96px;
    overflow-y: auto;
}

.oas-historique:empty { display: none; }

.oas-historique-ligne {
    display: flex;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    padding: .18rem .1rem;
    background: none;
    border: none;
    border-radius: 5px;
    color: var(--text-muted);
    font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
    font-size: .72rem;
    text-align: left;
    cursor: pointer;
    transition: background .12s, color .12s;
}

.oas-historique-ligne:hover {
    background: var(--bg-hover);
    color: var(--text-color);
}

.oas-historique-op {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.oas-historique-res {
    font-weight: 700;
    color: var(--text-color);
    flex: 0 0 auto;
}

/* ---------- Calcul de dates : onglets ---------- */

.oas-onglets {
    display: flex;
    gap: .2rem;
    padding: .22rem;
    margin-bottom: .7rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.oas-onglet {
    flex: 1 1 0;
    padding: .34rem .3rem;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: .73rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
}

.oas-onglet:hover { color: var(--text-color); }

.oas-onglet.oas-actif {
    background: rgba(77, 163, 255, .16);
    border-color: rgba(77, 163, 255, .4);
    color: var(--primary-color);
}

.oas-onglet:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.oas-volee[hidden] { display: none; }

/* ---------- Calcul de dates : champs ---------- */

.oas-champ {
    display: block;
    margin-bottom: .55rem;
}

.oas-etiquette {
    display: block;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: .2rem;
}

.oas-saisie,
.oas-liste {
    width: 100%;
    padding: .36rem .45rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-color);
    font-family: inherit;
    font-size: .8rem;
}

.oas-saisie:focus,
.oas-liste:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(77, 163, 255, .16);
}

.oas-duo {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .45rem;
}

.oas-triple {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: .45rem;
}

.oas-case {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .76rem;
    color: var(--text-color);
    cursor: pointer;
    margin-bottom: .55rem;
}

.oas-case input { accent-color: var(--primary-color); }

/* ---------- Résultats ---------- */

.oas-resultat-bloc {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 9px;
    padding: .55rem .65rem;
    margin-top: .65rem;
}

.oas-resultat-principal {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
}

.oas-resultat-date {
    font-size: 1.12rem;
    font-weight: 800;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

.oas-resultat-note {
    font-size: .7rem;
    color: var(--text-muted);
}

/* ⚠️ GRILLE DE MESURES : `auto-fit` + `minmax` plutôt que des colonnes
   fixes. Les libellés vont de « Jours » à « Jours ouvrables », et une grille
   figée tronquerait les plus longs ou laisserait un vide à droite. */
.oas-mesures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: .4rem;
    margin-top: .5rem;
}

.oas-mesure {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: .35rem .45rem;
}

.oas-mesure-valeur {
    display: block;
    font-size: .95rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--text-color);
}

.oas-mesure-label {
    display: block;
    font-size: .64rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-top: .06rem;
}

/* Une mesure mise en avant : celle qui répond à la question posée. */
.oas-mesure.oas-mise-en-avant {
    border-color: rgba(77, 163, 255, .45);
    background: rgba(77, 163, 255, .1);
}

.oas-mesure.oas-mise-en-avant .oas-mesure-valeur { color: var(--primary-color); }

.oas-detail {
    margin-top: .5rem;
    font-size: .72rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.oas-detail b { color: var(--text-color); font-weight: 700; }

.oas-detail code {
    background: var(--bg-input);
    padding: .02rem .25rem;
    border-radius: 4px;
    font-size: .7rem;
}

/* ---------- Recherche de localité ---------- */

/* ⚠️ `max-height` + `overflow` : une recherche sur une seule lettre peut
   ramener des dizaines de lignes. Sans plafond, la fenêtre s'allongerait
   jusqu'à sortir de l'écran, et le bouton de fermeture avec elle. */
.oas-loc-liste {
    max-height: 210px;
    overflow-y: auto;
    margin-top: .15rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
}

.oas-loc-item {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    width: 100%;
    padding: .38rem .55rem;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-family: inherit;
    font-size: .8rem;
    text-align: left;
    color: var(--text-color);
    cursor: pointer;
    transition: background .12s, color .12s;
}

.oas-loc-item:last-child { border-bottom: none; }

.oas-loc-item:hover,
.oas-loc-item:focus-visible {
    background: rgba(77, 163, 255, .14);
    outline: none;
}

.oas-loc-code {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--primary-color);
    flex: 0 0 auto;
}

.oas-loc-nom {
    color: var(--text-color);
    min-width: 0;
    overflow-wrap: anywhere;
}

.oas-loc-vide {
    margin: 0;
    padding: .5rem .55rem;
    font-size: .76rem;
    color: var(--text-muted);
}

/* ---------- Note de bas de fenêtre ---------- */
.oas-note {
    font-size: .68rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin-top: .6rem;
    padding-left: .55rem;
    border-left: 2px solid var(--border-color);
}

/* ---------- Bouton de la barre latérale ---------- */

/* ⚠️ CE SONT DES `<button>`, PAS DES `<a>` : ils n'ont pas de destination.
   Un `<a href="#">` ferait remonter la page en haut à chaque clic, et un
   lecteur d'écran l'annoncerait comme un lien — donc comme une navigation
   qui ne navigue pas. */
.sidebar-link-outil {
    width: calc(100% - 1rem);
    text-align: left;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    font-family: inherit;
    cursor: pointer;
}

.sidebar-link-outil:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

/* ---------- Réactif ---------- */

@media (max-width: 520px) {
    /* ⚠️ SUR UN PETIT ÉCRAN, ON PASSE EN PLEINE LARGEUR EN BAS.
       Une fenêtre de 340 px déplaçable au doigt sur 360 px d'écran ne laisse
       aucune prise : la faire glisser revient à viser le bord. */
    .oas-fenetre,
    .oas-fenetre.oas-large {
        left: .5rem !important;
        right: .5rem;
        top: auto !important;
        bottom: .5rem;
        width: auto;
        max-height: 76vh;
    }

    .oas-tete { cursor: default; }
}

