/* ============================================================
   WIDGET BRUT / NET — feuille autonome (widget-brut-net.html)

   Volontairement indépendante de style.css :
   - style.css pose `body { min-height: 100vh }`. Dans une iframe, 100vh vaut
     la hauteur de l'iframe : la page mesurée ne pouvait plus jamais être plus
     petite que son cadre, et la hauteur automatique ne faisait que grimper.
   - 62 Ko de règles du site pour une carte de 700 px de large, chargées sur
     des sites tiers : inutile.
   Les jetons reprennent les noms et les valeurs de la DA « bulletin de paie ».
   ============================================================ */

@font-face {
    font-family: 'Bricolage Grotesque';
    src: url('fonts/BricolageGrotesque-500-800.woff2') format('woff2');
    unicode-range: U+0000-202E, U+2030-FFFF; /* U+202F quasi nul dans Bricolage */
    font-weight: 500 800;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('fonts/IBMPlexMono-500.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('fonts/IBMPlexMono-600.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --paper-2: #F9F8F4;
    --field: #EEEBE3;
    --ink: #15191F;
    --highlight: #FFE27A;
    --mark: var(--highlight);
    --card: #FFFFFF;
    --text: #15191F;
    --text-light: #4A515B;
    --text-lighter: #646B75;
    --border: #DDD8CC;
    --error: #B42318;
    --focus: #15191F;
    /* Surchargés par le paramètre ?couleur= (script en tête de page). */
    --accent: #0B6B4B;
    --on-accent: #FFFFFF;

    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-display: 'Bricolage Grotesque', var(--font-body);
    --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

/* Thème sombre (?theme=sombre). Pas de `color-scheme: dark` : si le schéma de
   l'iframe diffère de celui de la page hôte, Chrome peint un fond opaque
   derrière l'iframe et les coins arrondis de la carte deviennent des carrés. */
:root[data-theme="sombre"] {
    --paper-2: #1F242B;
    --field: #2A3038;
    --ink: #F3F1EA;
    --mark: rgba(255, 226, 122, 0.30);
    --card: #171B21;
    --text: #F3F1EA;
    --text-light: #C3C8CF;
    --text-lighter: #A2A9B2;
    --border: #3A424C;
    --error: #FF9B8F;
    --focus: #FFE27A;
}

html,
body {
    background: transparent;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* ---------- Carte ---------- */
/* C'est CET élément qui est mesuré pour la hauteur automatique : rien ne doit
   dépasser de lui (pas d'ombre portée, pas de marge extérieure). */
.w {
    display: flow-root;
    /* Sans effet dans l'iframe (680 px conseillés) ; évite une carte de
       1 440 px de large si la page est ouverte directement. */
    max-width: 760px;
    margin: 0 auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.w__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    background: var(--paper-2);
    border-bottom: 1px dashed var(--border);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-light);
}

.w__title {
    color: var(--ink);
}

.w__body {
    display: grid;
    gap: 14px;
    padding: 14px;
}

/* Côte à côte dès 560 px : une colonne de blog WordPress fait 600 à 650 px,
   et empilé le widget y mesurait 730 px de haut au lieu de 450. */
@media (min-width: 560px) {
    .w__body {
        grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
        align-items: start;
        gap: 18px;
        padding: 16px;
    }
}

/* ---------- Réglages ---------- */
/* Requête de conteneur, pas de média : c'est la largeur de la colonne des
   réglages qui décide, et elle ne suit pas celle de l'iframe (empilé à
   520 px, elle est plus large que côte à côte à 620 px). Le conteneur est
   .controls, la règle vise son enfant .ctl-grid. */
.controls {
    display: grid;
    gap: 12px;
    min-width: 0;
    container-type: inline-size;
}

.ctl-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

/* Sous 290 px, « Non-cadre | Cadre » ne tient plus dans une demi-colonne. */
@container (min-width: 290px) {
    .ctl-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 10px;
    }
}

.ctl {
    min-width: 0;
    border: 0;
}

.lbl {
    display: block;
    margin-bottom: 5px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-light);
}

/* Une <legend> ne se met pas en page comme un bloc : flottée, elle le devient. */
legend.lbl {
    float: left;
    width: 100%;
    padding: 0;
}

legend.lbl + .seg {
    clear: both;
}

/* Boutons segmentés : de vrais boutons radio, masqués visuellement mais pas
   retirés (flèches du clavier, lecteurs d'écran, zone de clic = libellé). */
.seg {
    display: flex;
    gap: 3px;
    padding: 3px;
    background: var(--field);
    border-radius: 8px;
}

.seg label {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
}

.seg input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.seg span {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 6px 5px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    color: var(--text-light);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.seg label:hover input:not(:checked) + span {
    background: var(--card);
    color: var(--ink);
}

.seg input:checked + span {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 700;
    /* Filet intérieur : l'option choisie reste visible même si la couleur
       fournie est très proche du fond. */
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}

.seg input:focus-visible + span {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

/* Montant */
.amount {
    position: relative;
}

.amount input {
    width: 100%;
    height: 48px;
    padding: 0 38px 0 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.amount input:hover {
    border-color: var(--text-lighter);
}

.amount input:focus-visible {
    outline-offset: 1px;
    border-color: var(--ink);
}

.amount input[aria-invalid="true"] {
    border-color: var(--error);
}

.amount__cur {
    position: absolute;
    top: 50%;
    right: 13px;
    transform: translateY(-50%);
    font-family: var(--font-mono);
    font-size: 18px;
    color: var(--text-light);
    pointer-events: none;
}

.hint {
    margin-top: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--error);
}

/* Liste déroulante des parts */
.select {
    position: relative;
}

.select select {
    width: 100%;
    height: 40px;
    padding: 0 32px 0 11px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.select::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 13px;
    width: 7px;
    height: 7px;
    margin-top: -5px;
    border-right: 2px solid var(--text-light);
    border-bottom: 2px solid var(--text-light);
    transform: rotate(45deg);
    pointer-events: none;
}

.select select:hover {
    border-color: var(--text-lighter);
}

@media (pointer: coarse) {
    .seg span {
        min-height: 40px;
    }

    .select select {
        height: 46px;
    }
}

/* ---------- Bulletin ---------- */
.bul {
    min-width: 0;
    container-type: inline-size;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    overflow: hidden;
}

.bul__lines {
    padding: 2px 14px 0;
}

.bul__line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px dotted var(--border);
}

.bul__line:last-child {
    border-bottom: 0;
}

.bul__line dt {
    min-width: 0;
    font-size: 14px;
    color: var(--text-light);
}

.bul__line dt small {
    display: block;
    font-size: 12px;
    color: var(--text-lighter);
}

.bul__line dd {
    font-family: var(--font-mono);
    font-size: 14.5px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--ink);
}

.bul__line--sub dt,
.bul__line--sub dd {
    font-weight: 600;
    color: var(--ink);
}

/* Net → Brut : la réponse cherchée est le brut, on la marque aussi. */
.bul__line--answer dt {
    font-weight: 600;
    color: var(--ink);
}

.bul__line--answer dd {
    padding: 0 4px;
    margin-right: -4px;
    font-weight: 600;
    background-image: linear-gradient(transparent 50%, var(--mark) 50%, var(--mark) 94%, transparent 94%);
}

.bul__total {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 4px 12px;
    margin: 0 14px;
    padding: 12px 0 14px;
    border-top: 3px double var(--ink);
}

.bul__total-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink);
}

.bul__total-sub {
    display: block;
    margin-top: 1px;
    font-size: 12.5px;
    color: var(--text-light);
}

.bul__total-value {
    padding: 0 5px;
    margin-right: -5px;
    font-family: var(--font-display);
    font-size: 34px;
    /* Relatif à la largeur du bulletin, pas de l'iframe. */
    font-size: clamp(30px, 12.5cqi, 40px);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--ink);
    background-image: linear-gradient(transparent 56%, var(--mark) 56%, var(--mark) 92%, transparent 92%);
}

.bul__cents {
    font-size: 0.5em;
    letter-spacing: 0;
}

.bul__foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 2px 10px;
    padding: 9px 14px;
    background: var(--paper-2);
    border-top: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text-light);
}

.bul__foot small {
    font-size: 12px;
    color: var(--text-lighter);
}

.bul__foot strong {
    font-family: var(--font-mono);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--ink);
}

/* ---------- Pied : crédit ---------- */
.w__foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 2px 12px;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-lighter);
}

.w__foot a {
    display: inline-block;
    padding: 4px 0;
    font-weight: 600;
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.w__foot a:hover {
    text-decoration-thickness: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .seg span {
        transition: none;
    }
}
