/* style.css — design moderne provisoire (sera remplacé au rebrand).
   Palette neutre + carte arrondies + Inter. Mobile-first, WCAG 2.1 AA.
*/

:root {
    /* Palette */
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #15803d;
    --primary-hover: #166534;
    --primary-fg: #ffffff;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --warning: #92400e;
    --warning-bg: #fef3c7;
    --primary-ring: rgba(21, 128, 61, 0.30);

    /* Typo */
    --font-base: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --fs-base: 1rem;
    --lh-base: 1.5;

    /* Espacement */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px — padding cartes */
    --space-6: 1.5rem;    /* 24px — gap entre sections */

    /* Forme */
    --radius-card: 12px;
    --radius-input: 8px;
    --radius-sm: 6px;
    --touch-target: 2.75rem;   /* 44 px — WCAG cible tactile */
    --input-height: 3rem;      /* 48 px */
    --max-width: 30rem;        /* 480 px sur desktop */

    /* Ombres */
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
    --shadow-card-hover: 0 1px 3px rgba(0, 0, 0, 0.08), 0 6px 16px rgba(0, 0, 0, 0.06);

    /* Transitions */
    --t-fast: 150ms ease;
    --t-medium: 200ms ease;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-base);
    font-size: var(--fs-base);
    line-height: var(--lh-base);
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

main { flex: 1; padding-bottom: var(--space-6); }

img, svg { max-width: 100%; height: auto; }

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover { text-decoration: underline; text-underline-offset: 0.15em; }

/* Focus ring : 2 px primary à 30% (sur les interactifs) */
:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-ring);
    border-color: var(--primary);
}
a:focus-visible {
    box-shadow: 0 0 0 3px var(--primary-ring);
    border-radius: var(--radius-sm);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--text);
    color: var(--bg);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    z-index: 100;
}
.skip-link:focus { left: var(--space-2); top: var(--space-2); }

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--space-4);
}

/* ---------- Header / footer ---------- */

.site-header {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}
.brand {
    font-weight: 700;
    color: var(--text);
    font-size: 1rem;
    letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; color: var(--primary); }

.lang-toggle { display: inline-flex; align-items: center; gap: var(--space-1); }
.lang-link {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    min-height: var(--touch-target);
    display: inline-flex;
    align-items: center;
    transition: color var(--t-fast), background var(--t-fast);
}
.lang-link:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.lang-link--active { color: var(--primary); font-weight: 600; }
.lang-sep { color: var(--border-strong); font-size: 0.85rem; }

.site-footer {
    padding: var(--space-4) 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    margin-top: var(--space-6);
    font-size: 0.85rem;
    background: var(--surface);
}
.footer-content { display: flex; flex-direction: column; gap: var(--space-3); }
.footer-brand { margin: 0; line-height: 1.4; }
.footer-brand strong { color: var(--text); display: block; }
.footer-tagline { color: var(--text-muted); font-size: 0.8rem; }
.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    font-size: 0.85rem;
}
.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    min-height: 2rem;
    display: inline-flex;
    align-items: center;
}
.footer-links a:hover { color: var(--primary); text-decoration: underline; }
.footer-copyright { margin: 0; font-size: 0.75rem; color: var(--text-muted); }

/* ---------- Intro ---------- */

.intro { padding: var(--space-5) 0 var(--space-4); }
.intro h1 {
    margin: 0 0 var(--space-1);
    font-size: clamp(1.375rem, 4vw, 1.625rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}
.lead { color: var(--text-muted); font-size: 0.95rem; margin: 0; }

/* ---------- Formulaire ---------- */

.tariff-form { display: flex; flex-direction: column; gap: var(--space-6); }

.form-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-5);
    margin: 0;
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--t-medium);
}
.form-section:focus-within { box-shadow: var(--shadow-card-hover); }
.form-section > legend {
    font-weight: 600;
    color: var(--text);
    padding: 0;
    margin: 0 0 var(--space-3);
    font-size: 0.875rem;
    letter-spacing: 0.005em;
}

/* En-tête de section utilisé quand on n'utilise pas <fieldset>/<legend>
   (cas : section "Type d'envoi" qui héberge le toggle d'aide). */
.section-header {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin: 0 0 var(--space-3);
}
.section-title {
    font-weight: 600;
    color: var(--text);
    font-size: 0.875rem;
    letter-spacing: 0.005em;
}

/* ---------- Bouton (i) d'aide + panneau replié ---------- */

.help-toggle { display: inline-flex; }
.help-toggle > summary {
    list-style: none;
    cursor: pointer;
    width: var(--touch-target);
    height: var(--touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    /* Marges négatives : on garde la zone tactile 44×44 sans gonfler le header */
    margin: -10px 0 -10px -10px;
    transition: background var(--t-fast);
}
.help-toggle > summary::-webkit-details-marker { display: none; }
.help-toggle > summary:hover { background: var(--bg); }

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 1.5px solid var(--text-muted);
    color: var(--text-muted);
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1;
    transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.help-toggle[open] .help-icon {
    background: var(--primary);
    color: var(--primary-fg);
    border-color: var(--primary);
}

/* Le panneau est rendu en HTML (donc accessible aux moteurs / SR)
   mais masqué tant que le <details> du toggle n'est pas ouvert. */
.help-panel { display: none; }
.type-section:has(.help-toggle[open]) .help-panel { display: block; }

.help-panel {
    margin-top: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg);
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
}
.help-panel-title {
    margin: 0 0 var(--space-2);
    color: var(--text);
    font-weight: 600;
    font-size: 0.875rem;
}
.help-list { margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.help-entry { margin: 0; }
.help-entry dt {
    margin: 0 0 var(--space-1);
    color: var(--text);
    font-weight: 600;
    font-size: 0.85rem;
}
.help-entry dd { margin: 0; color: var(--text-muted); line-height: 1.5; }

.field, .counter-field {
    display: flex; flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}
.field:last-child, .counter-field:last-child { margin-bottom: 0; }

label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text);
}
.unit { color: var(--text-muted); font-weight: 400; }
.req { color: var(--danger); margin-left: var(--space-1); }
.tariff-hint { display: block; color: var(--text-muted); font-weight: 400; font-size: 0.8rem; }
.field-help {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 400;
    margin: var(--space-1) 0 0;
    line-height: 1.4;
}

input[type="number"],
input[type="text"],
select,
textarea {
    font: inherit;
    font-size: 1rem;
    height: var(--input-height);
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    background: var(--surface);
    color: var(--text);
    width: 100%;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

select { cursor: pointer; padding-right: var(--space-5); appearance: auto; }
textarea {
    height: auto;
    min-height: 80px;
    padding: 12px 14px;
    line-height: 1.5;
    resize: vertical;
    font-family: inherit;
}

input:hover, select:hover, textarea:hover { border-color: var(--text-muted); }

/* Dimensions */
.field-group { border: none; padding: 0; margin: 0 0 var(--space-4); }
.field-group > legend {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text);
    padding: 0;
    margin: 0 0 var(--space-2);
}
.dim-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.field--inline { gap: var(--space-1); margin-bottom: 0; }
.field--inline label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.field--inline input[type="number"] { text-align: center; padding: 0 6px; }

.hint {
    background: #f0fdf4;
    border-left: 3px solid var(--primary);
    padding: var(--space-2) var(--space-3);
    margin: var(--space-3) 0 0;
    color: var(--text-muted);
    font-size: 0.825rem;
    line-height: 1.5;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ---------- Autocomplétion ville ---------- */

.city-field { gap: var(--space-1); }
.autocomplete { position: relative; }
.suggestions {
    list-style: none;
    margin: 0;
    padding: 0;
    position: absolute;
    top: calc(var(--input-height) + 2px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    box-shadow: var(--shadow-card-hover);
    max-height: 18rem;
    overflow-y: auto;
    z-index: 50;
}
.suggestions:empty { display: none; }
.suggestion {
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    border-bottom: 1px solid var(--border);
    min-height: var(--touch-target);
    justify-content: center;
}
.suggestion:last-child { border-bottom: none; }
.suggestion:hover,
.suggestion:focus,
.suggestion:focus-visible {
    background: #f0fdf4;
    outline: none;
    box-shadow: inset 3px 0 0 var(--primary);
}
.suggestion .city-name { color: var(--text); font-weight: 600; font-size: 0.95rem; }
.suggestion .city-country { color: var(--text-muted); font-size: 0.825rem; }

/* ---------- Bandeau "itinéraire non couvert" + info facture ---------- */

.route-warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    border-radius: var(--radius-input);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
}
.route-warning-title {
    margin: 0 0 var(--space-1);
    font-weight: 700;
    color: var(--warning);
    font-size: 0.95rem;
}
.route-warning-message {
    margin: 0 0 var(--space-3);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.4;
}

.invoice-info {
    margin-top: var(--space-3);
    background: var(--bg);
    border-left: 3px solid var(--primary);
    padding: var(--space-2) var(--space-3);
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.result-route {
    margin: 0 0 var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* Désactive visuellement le CTA "Calculer" quand un bandeau bloque l'itinéraire */
.tariff-form:has(.route-warning) .form-actions .btn--primary {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- Section assurance repliable ---------- */

.insurance-section { padding: var(--space-4) var(--space-5); }

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    cursor: pointer;
    min-height: var(--touch-target);
    padding: var(--space-1) 0;
}
.checkbox-row input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.15rem;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}
.checkbox-label {
    display: block;
    font-weight: 500;
    line-height: 1.4;
}
.checkbox-label .field-help { margin-top: 0; font-weight: 400; }

.insurance-panel {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height var(--t-medium), opacity var(--t-fast), padding-top var(--t-medium), margin-top var(--t-medium);
}
.insurance-section:has(#has_insurance:checked) .insurance-panel {
    max-height: 30rem;
    opacity: 1;
    padding-top: var(--space-4);
    margin-top: var(--space-3);
    border-top: 1px solid var(--border);
}

/* ---------- Stepper +/- ---------- */

.counter-field { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--space-3); }
.counter-field label { margin: 0; }

.counter {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    overflow: hidden;
    width: fit-content;
    background: var(--surface);
    flex-shrink: 0;
}
.counter input[type="number"] {
    width: 3rem;
    height: var(--touch-target);
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    text-align: center;
    border-radius: 0;
    padding: 0;
    -moz-appearance: textfield;
    appearance: textfield;
    font-weight: 600;
}
.counter input[type="number"]::-webkit-outer-spin-button,
.counter input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none; margin: 0;
}
.counter-btn {
    font: inherit;
    font-size: 1.15rem;
    line-height: 1;
    width: var(--touch-target);
    height: var(--touch-target);
    padding: 0;
    background: var(--surface);
    color: var(--text);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background var(--t-fast);
}
.counter-btn:hover { background: var(--bg); }
.counter-btn:active { background: var(--border); }

/* ---------- Boutons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 14px 24px;
    border-radius: var(--radius-input);
    font-weight: 600;
    font-size: 0.95rem;
    min-height: var(--touch-target);
    border: 1px solid transparent;
    cursor: pointer;
    line-height: 1.2;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.985); }

.btn--primary {
    background: var(--primary);
    color: var(--primary-fg);
}
.btn--primary:hover { background: var(--primary-hover); }

.btn--secondary {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--primary);
}
.btn--secondary:hover { background: #f0fdf4; }

/* CTA principal full-width sur mobile et desktop (conteneur étroit) */
.form-actions { display: flex; }
.form-actions .btn { width: 100%; }

.htmx-indicator { display: none; opacity: 0; transition: opacity var(--t-medium); }
.htmx-request .htmx-indicator { display: inline; opacity: 1; }
.htmx-request.btn { opacity: 0.85; cursor: progress; }

/* ---------- Résultat ---------- */

.result-zone { margin-top: var(--space-6); }
.result-zone:empty { display: none; }

/* Inline validation : message rouge sous chaque champ requis.
   `:empty` cache le placeholder tant qu'il n'y a pas d'erreur,
   évitant de réserver une bande blanche dans le layout. */
.field-error {
    color: #b91c1c;
    font-size: 0.85rem;
    margin: 0.25rem 0 0;
    min-height: 1rem;
}
.field-error:empty { display: none; }

.form-error-banner {
    background: #fef2f2;
    border-left: 3px solid #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    color: #991b1b;
}

.result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-5);
    box-shadow: var(--shadow-card);
}
.result--oversize { border-color: var(--warning); background: var(--warning-bg); }
.result--error { border-color: var(--danger); background: var(--danger-bg); }
.result--error .result-title { color: var(--danger); }

.result-title {
    margin: 0 0 var(--space-3);
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.result-message { margin: 0 0 var(--space-3); color: var(--text); }

.result-weight { margin: 0 0 var(--space-3); font-size: 0.95rem; }
.billable { font-weight: 700; color: var(--primary); font-size: 1.05rem; }
.weight-detail { color: var(--text-muted); font-size: 0.85rem; }

.result-warnings {
    list-style: none;
    padding: var(--space-2) var(--space-3);
    margin: 0 0 var(--space-3);
    background: var(--warning-bg);
    color: var(--warning);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.result-lines {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-3);
    border-top: 1px solid var(--border);
}
.result-line, .result-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}
.result-total {
    border-bottom: none;
    border-top: 2px solid var(--text);
    padding-top: var(--space-3);
    margin-top: var(--space-1);
}
.line-label { color: var(--text); font-size: 0.9rem; }
.total-label { color: var(--text); font-size: 1rem; font-weight: 600; }

.line-amount { text-align: right; white-space: nowrap; }
.amount-xof { display: block; font-weight: 600; font-size: 0.95rem; color: var(--text); }
.amount-xof--big { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.amount-eur { display: block; font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

.result-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-4);
}
.result-actions .btn { width: 100%; }
@media (min-width: 480px) {
    .result-actions { flex-direction: row; }
    .result-actions .btn { flex: 1; width: auto; }
}

/* ---------- Reduce motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
    .insurance-panel { transition: none; }
}
