/* ============================================
   GÉNÉRATEUR DE TRAITES
   Design : propre, sobre, humain
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --calib-top:  0mm;
    --calib-left: 0mm;

    /* Une seule couleur principale — bleu encre, pas "tech" */
    --ink:        #1b2a4a;
    --ink-light:  #2e4170;
    --accent:     #1b2a4a;
    --accent-muted: #e8ecf4;

    /* Neutres chauds — pas de gris froid */
    --bg:         #f5f4f0;
    --surface:    #ffffff;
    --border:     #dddad4;
    --border-hover: #b8b4ac;

    /* Textes */
    --text-strong: #111;
    --text-body:   #3d3d3d;
    --text-muted:  #888;
    --text-label:  #555;

    /* Sémantique */
    --green:      #2d6a4f;
    --green-bg:   #eaf4ef;
    --teal:       #1a6b72;
    --purple:     #4a3880;
    --red:        #c0392b;
    --gold:       #b7791f;
    --gold-bg:    #fef9ee;

    /* Typographie */
    --font: 'Inter', 'Segoe UI', system-ui, sans-serif;

    /* Géométrie */
    --radius:    7px;
    --radius-lg: 12px;
    --shadow:    0 1px 4px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,.07);
}

/* ── Reset ── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font);
    color: var(--text-body);
    background: var(--bg);
    min-height: 100vh;
    line-height: 1.6;
    padding: 32px 16px 64px;
}

/* ════════════════════════════════════════
   CONTENEUR
════════════════════════════════════════ */
.app-container {
    max-width: 780px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    overflow: hidden;
}

/* ════════════════════════════════════════
   HEADER — sobre, typographique
════════════════════════════════════════ */
.app-header {
    background: var(--ink);
    padding: 36px 40px 30px;
}

.header-content h1 {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.01em;
    margin-bottom: 4px;
}

.subtitle {
    font-size: 13px;
    color: rgba(255,255,255,.5);
    font-weight: 400;
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* ════════════════════════════════════════
   CONTENU
════════════════════════════════════════ */
.main-content {
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ── Encart guide ── */
.instructions-panel { margin-bottom: 0; }

.info-box {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    background: var(--surface);
}

.info-box h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-strong);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: .01em;
}

.info-box ol {
    margin-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-box li {
    font-size: 13px;
    color: var(--text-label);
    line-height: 1.6;
}

.tip {
    margin-top: 14px;
    background: var(--gold-bg);
    border: 1px solid #f0d998;
    border-radius: var(--radius);
    padding: 11px 14px;
    font-size: 12.5px;
    color: #7a5a1a;
    line-height: 1.6;
}

/* ════════════════════════════════════════
   FORMULAIRE
════════════════════════════════════════ */
.form-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* ── Sections fieldset ── */
.form-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 22px 14px;
    margin-bottom: 16px;
    background: var(--surface);
}

.form-section legend {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: 0 6px;
}

/* ── Grille ── */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 14px;
}

.form-group.full-width { grid-column: 1 / -1; }

/* ── Labels ── */
.form-group label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-label);
    letter-spacing: .01em;
}

.required {
    color: var(--red);
    font-weight: 700;
    margin-right: 2px;
}

/* ── Inputs ── */
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"] {
    width: 100%;
    padding: 9px 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13.5px;
    font-family: var(--font);
    color: var(--text-strong);
    line-height: 1.5;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:hover:not(:focus) {
    border-color: var(--border-hover);
}

.form-group input:focus {
    border-color: var(--ink-light);
    box-shadow: 0 0 0 3px rgba(27,42,74,.1);
}

.form-group input::placeholder {
    color: #bbb;
    font-weight: 400;
}

/* Erreur */
.form-group input.error {
    border-color: var(--red) !important;
    box-shadow: 0 0 0 3px rgba(192,57,43,.09) !important;
}

/* Lecture seule */
.readonly-field {
    background: var(--bg) !important;
    color: var(--text-muted) !important;
    cursor: default;
    font-style: italic;
    border-color: var(--border) !important;
}
.readonly-field:hover { border-color: var(--border) !important; }

/* ── Checkboxes ── */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 4px 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-body);
    user-select: none;
}

.checkbox-label:hover { color: var(--ink); }

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--ink);
}

/* ════════════════════════════════════════
   BOUTONS — un seul style clair par action
════════════════════════════════════════ */
.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    border: 1px solid transparent;
    white-space: nowrap;
}

.btn span { font-size: 14px; }

.btn:active { transform: scale(.98); }

/* Simulation */
.btn-info {
    background: var(--purple);
    color: #fff;
    border-color: var(--purple);
}
.btn-info:hover { background: #3a2d6a; border-color: #3a2d6a; }

/* Aperçu */
.btn-secondary {
    background: var(--teal);
    color: #fff;
    border-color: var(--teal);
}
.btn-secondary:hover { background: #145a60; border-color: #145a60; }

/* Imprimer — action principale */
.btn-primary {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}
.btn-primary:hover { background: #235a42; border-color: #235a42; }

/* Réinitialiser — action neutre */
.btn-outline {
    background: #fff;
    color: var(--text-label);
    border-color: var(--border);
}
.btn-outline:hover {
    background: var(--bg);
    border-color: var(--border-hover);
    color: var(--text-strong);
}

/* ════════════════════════════════════════
   IMPRESSION
════════════════════════════════════════ */
.print-area { display: none; }

@media print {
    body { background: white; padding: 0; }
    .app-container > *:not(.print-area) { display: none !important; }
    .print-area { display: block !important; }

    .traite-form-overlay {
        position: relative;
        width: 210mm; height: 297mm;
        margin: 0; padding: 0; overflow: hidden;
    }

    .field {
        position: absolute;
        font-family: Arial, sans-serif;
        color: #000;
        background: transparent;
        border: none;
        padding: 0; margin: 0;
        line-height: 1.2;
    }

    .field.ordre-paiement    { top:calc(18mm+var(--calib-top)); left:calc(120mm+var(--calib-left)); width:80mm;  font-size:10pt; font-weight:600; }
    .field.date-echeance     { top:calc(45mm+var(--calib-top)); left:calc(150mm+var(--calib-left)); width:50mm;  font-size:11pt; }
    .field.montant           { top:calc(70mm+var(--calib-top)); left:calc(140mm+var(--calib-left)); width:60mm;  font-size:12pt; font-weight:bold; text-align:right; }
    .field.monnaie           { top:calc(70mm+var(--calib-top)); left:calc(198mm+var(--calib-left)); width:12mm;  font-size:11pt; }
    .field.montant-lettres   { top:calc(77mm+var(--calib-top)); left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; font-style:italic; white-space:normal; word-wrap:break-word; }
    .field.code-itab         { top:calc(88mm+var(--calib-top)); left:calc(118mm+var(--calib-left)); width:20mm;  font-size:10pt; }
    .field.code-agence       { top:calc(88mm+var(--calib-top)); left:calc(140mm+var(--calib-left)); width:20mm;  font-size:10pt; }
    .field.numero-compte     { top:calc(88mm+var(--calib-top)); left:calc(162mm+var(--calib-left)); width:38mm;  font-size:10pt; }
    .field.banque            { top:calc(100mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.a-lordre-de       { top:calc(110mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.payeur            { top:calc(120mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.aval-field        { top:calc(125mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.tireur            { top:calc(130mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.tire              { top:calc(140mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.nom-cedant        { top:calc(150mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.lieu-creation     { top:calc(162mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:85mm;  font-size:10pt; }
    .field.date-creation     { top:calc(162mm+var(--calib-top));left:calc(100mm+var(--calib-left)); width:50mm;  font-size:10pt; }
    .field.echeance-duplicate{ top:calc(162mm+var(--calib-top));left:calc(155mm+var(--calib-left)); width:45mm;  font-size:10pt; }
    .field.valeur-en         { top:calc(172mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:85mm;  font-size:10pt; }
    .field.domiciliation     { top:calc(182mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:190mm; font-size:11pt; }
    .field.protestable       { top:calc(195mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:5mm; height:5mm; line-height:5mm; text-align:center; font-size:13pt; font-weight:bold; }
    .field.acceptation       { top:calc(203mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:5mm; height:5mm; line-height:5mm; text-align:center; font-size:13pt; font-weight:bold; }
    .field.avail             { top:calc(211mm+var(--calib-top));left:calc(10mm+var(--calib-left));  width:5mm; height:5mm; line-height:5mm; text-align:center; font-size:13pt; font-weight:bold; }
    .field.protestable.checked::before,
    .field.acceptation.checked::before,
    .field.avail.checked::before { content:"X"; display:block; }

    @page { size:A4; margin:0; }
    html, body { width:210mm; height:297mm; margin:0; padding:0; overflow:hidden; }
}

/* ════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════ */
@media (max-width: 600px) {
    body { padding: 12px 8px 40px; }
    .main-content { padding: 20px 16px; }
    .app-header { padding: 24px 20px 20px; }
    .form-row { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column; }
    .btn { width: 100%; }
}
