:root {
    --orange: #F5A000;
    --orange-dark: #C97F00;
    --orange-light: #FFB733;
    --dark: #111111;
    --bg: #F2F2F2;
    --card: #FFFFFF;
    --text: #2D2D2D;
    --muted: #777;
    --border: #DEDEDE;
    --ok: #28A745;
    --ko: #DC3545;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(0,0,0,0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 16px;
}

/* ===== OFFLINE BANNER ===== */
.offline-banner {
    display: none;
    background: var(--dark);
    color: white;
    text-align: center;
    font-size: 12.5px;
    font-weight: 700;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 250;
}
.offline-banner.active { display: block; }
.offline-banner .pending-count { color: var(--orange-light); }

/* ===== HEADER (formulaire) ===== */
.app-header {
    background: var(--dark);
    color: white;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0,0,0,0.22);
    min-height: 60px;
}

.btn-back {
    background: rgba(255,255,255,0.18);
    border: none;
    color: white;
    padding: 6px 14px;
    border-radius: 7px;
    font-size: 22px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    flex-shrink: 0;
}
.btn-back:hover { background: rgba(255,255,255,0.28); }

.header-logo { height: 34px; width: auto; flex-shrink: 0; background: white; border-radius: 6px; padding: 3px 6px; }

.header-title {
    flex: 1;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.2px;
    line-height: 1.2;
}

/* ===== MENU ===== */
.menu-header {
    background: linear-gradient(160deg, #1a1a1a, #000000);
    padding: 30px 20px 24px;
    text-align: center;
    color: white;
    border-bottom: 4px solid var(--orange);
}

.menu-logo-wrap { margin-bottom: 12px; }
.menu-logo { height: 78px; width: auto; background: white; border-radius: 10px; padding: 8px 14px; }

.menu-logo-fallback {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.12);
    border-radius: 14px;
    padding: 12px 22px;
    margin-bottom: 12px;
}
.menu-logo-fallback .brand-circle {
    width: 54px; height: 54px;
    border: 3px solid var(--orange);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 900; color: white;
}
.menu-logo-fallback .brand-text { font-size: 20px; font-weight: 900; color: white; }
.menu-logo-fallback .brand-text .accent { color: var(--orange); }

.menu-company { font-size: 12.5px; opacity: 0.82; margin-top: 3px; line-height: 1.6; }

.menu-content { max-width: 620px; margin: 0 auto; padding: 22px 14px 10px; }

.menu-subtitle {
    text-align: center;
    color: var(--muted);
    margin-bottom: 18px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 700;
}

.form-cards { display: flex; flex-direction: column; gap: 11px; }

.form-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow);
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    border: 2px solid transparent;
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
.form-card:hover, .form-card:active {
    border-color: var(--orange);
    box-shadow: 0 4px 16px rgba(245,160,0,0.22);
    transform: translateY(-1px);
}

.card-icon {
    width: 50px; height: 50px;
    background: var(--dark);
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    flex-shrink: 0;
    border: 2px solid var(--orange);
}

.card-info { flex: 1; }
.card-title { font-weight: 700; font-size: 15px; color: var(--text); }
.card-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-arrow { font-size: 22px; color: var(--border); flex-shrink: 0; }

/* ===== HISTORIQUE ===== */
.history-section { margin-top: 26px; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
    background: var(--card);
    border-radius: 8px;
    padding: 11px 14px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
.history-item .h-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-item .h-title { font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-sub { color: var(--muted); font-size: 11.5px; }
.history-item .h-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--orange-dark);
    background: rgba(245,160,0,0.10);
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}
.history-item .h-status {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 5px;
    flex-shrink: 0;
}
.h-status.sent { background: rgba(40,167,69,0.12); color: var(--ok); }
.h-status.pending { background: rgba(220,53,69,0.12); color: var(--ko); }
.history-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 18px; }

.menu-footer {
    text-align: center;
    padding: 24px 14px 18px;
    color: var(--muted);
    font-size: 12px;
}

/* ===== FORM LAYOUT ===== */
.form-container { max-width: 820px; margin: 0 auto; padding: 14px; }

.form-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}

.section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--orange-dark);
    margin-bottom: 13px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--orange);
}

/* ===== ENTETE ENTREPRISE (bandeau document) ===== */
.doc-header {
    background: var(--dark);
    color: white;
    padding: 18px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-start;
}
.doc-header .logo-block img { height: 60px; width: auto; background: white; border-radius: 8px; padding: 4px; }
.doc-header .logo-fallback-inline {
    display: inline-flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.1); border-radius: 8px; padding: 8px 14px;
}
.doc-header .company-info {
    text-align: right;
    font-size: 12.5px;
    opacity: 0.92;
    line-height: 1.7;
}
.doc-header .doc-title {
    width: 100%;
    text-align: center;
    font-size: 22px;
    font-weight: 900;
    margin-top: 12px;
    letter-spacing: 1px;
    color: var(--orange);
}
.doc-header .doc-number-row {
    width: 100%;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 22px;
    margin-top: 8px;
    font-size: 13px;
    opacity: 0.9;
}

/* ===== FIELDS ===== */
.field-group { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.field-group.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field.full { grid-column: 1 / -1; }

.field label {
    font-size: 11px; font-weight: 700;
    color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.4px;
}

.field input, .field textarea, .field select {
    border: 1.5px solid var(--border);
    border-radius: 7px;
    padding: 10px 11px;
    font-size: 16px;
    color: var(--text);
    background: white;
    transition: border-color 0.16s;
    -webkit-appearance: none;
    width: 100%;
    font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none; border-color: var(--orange);
}
.field input[readonly] { background: #F6F6F6; color: var(--muted); }
.field textarea { resize: vertical; min-height: 90px; }

/* ===== DICTATION ===== */
.field-label-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.field-label-row label { margin-bottom: 0; flex: 1; }
.btn-dictation {
    background: var(--dark);
    color: white;
    border: 2px solid var(--orange);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.btn-dictation.recording {
    background: #DC3545;
    border-color: #DC3545;
    animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220,53,69,0.5); }
    50%       { box-shadow: 0 0 0 8px rgba(220,53,69,0); }
}

/* ===== PILLS (choix unique / multiple) ===== */
.check-pills { display: flex; flex-wrap: wrap; gap: 9px; }
.check-pill { display: none; }
.check-pill-label {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13.5px; font-weight: 600;
    transition: all 0.14s;
    user-select: none;
}
.check-pill-label::before {
    content: '';
    width: 15px; height: 15px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: inline-block;
    flex-shrink: 0;
    transition: all 0.14s;
}
.check-pill:checked + .check-pill-label {
    border-color: var(--orange);
    background: rgba(245,160,0,0.09);
    color: var(--orange-dark);
}
.check-pill:checked + .check-pill-label::before {
    background: var(--orange);
    border-color: var(--orange);
}

/* ===== OUI / NON RADIO GROUP ===== */
.eo-radio-group { display: flex; gap: 8px; }
.eo-radio { display: none; }
.eo-radio-label {
    padding: 8px 18px; border: 1.5px solid var(--border); border-radius: 6px;
    font-size: 13px; font-weight: 700; cursor: pointer; user-select: none; color: var(--muted);
}
.eo-radio:checked + .eo-radio-label { border-color: var(--orange); background: rgba(245,160,0,0.1); color: var(--orange-dark); }

/* ===== REGISTRES (tableaux dynamiques) ===== */
.reg-table-wrap { overflow-x: auto; margin-bottom: 10px; }
.reg-table { width: 100%; border-collapse: collapse; min-width: 480px; }
.reg-table th {
    background: var(--dark); color: white;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px;
    padding: 8px 8px; text-align: left;
}
.reg-table td { padding: 5px; border-bottom: 1px solid var(--border); vertical-align: top; }
.reg-table td input {
    width: 100%; border: 1.5px solid var(--border); border-radius: 6px;
    padding: 7px 8px; font-size: 13.5px; font-family: inherit;
}
.reg-table td input:focus { outline: none; border-color: var(--orange); }
.reg-table .col-del { width: 34px; text-align: center; }
.btn-row-del {
    width: 26px; height: 26px;
    background: rgba(220,53,69,0.1); border: 1px solid var(--ko); color: var(--ko);
    border-radius: 6px; font-size: 15px; font-weight: 900; cursor: pointer; line-height: 1;
}
.btn-add-row {
    background: var(--dark); color: white; border: 2px solid var(--orange);
    border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 700; cursor: pointer;
}

/* ===== SOUS-TITRE DE SECTION ===== */
.sub-title {
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text);
    margin: 2px 0 10px;
}

/* ===== LIEN GOOGLE MAP ===== */
.map-link-row { display: flex; gap: 8px; align-items: center; }
.map-link-row input { flex: 1; min-width: 0; }
.btn-map-open {
    background: var(--dark);
    color: white;
    border: 2px solid var(--orange);
    border-radius: 7px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}

/* ===== ANNEXES ===== */
.annex-list { display: flex; flex-direction: column; gap: 9px; }
.annex-item {
    display: flex; align-items: center; gap: 10px;
    font-size: 13.5px; font-weight: 600; color: var(--text);
    cursor: pointer; user-select: none;
}
.annex-item input { width: 18px; height: 18px; accent-color: var(--orange); cursor: pointer; }

/* ===== SIGNATURES ===== */
.signatures-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.sig-block { display: flex; flex-direction: column; gap: 6px; }
.sig-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.sig-wrap {
    position: relative;
    overscroll-behavior: none;
    border: 2px dashed var(--border);
    border-radius: 8px;
    background: white;
}
.sig-wrap.has-sig { border-color: var(--orange); border-style: solid; }
.sig-canvas {
    width: 100%;
    height: 150px;
    cursor: crosshair;
    touch-action: none;
    -ms-touch-action: none;
    background: transparent;
    display: block;
    border-radius: 8px;
}
.sig-hint {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #C8C8C8;
    font-size: 13px;
    text-align: center;
    pointer-events: none;
    user-select: none;
    line-height: 1.5;
}
.sig-hint span { display: block; font-size: 26px; }
.sig-wrap.has-sig .sig-hint { display: none; }
.btn-clear-sig {
    position: absolute;
    top: 6px; right: 6px;
    background: rgba(220,53,69,0.1);
    border: 1px solid var(--ko);
    color: var(--ko);
    border-radius: 5px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    z-index: 2;
}

/* ===== PHOTOS ===== */
.photos-area { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.btn-photo-add {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 26px;
    background: var(--dark);
    color: white;
    border: 2px solid var(--orange);
    border-radius: 9px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-photo-add:active { background: #000; }

.photos-grid { display: flex; flex-wrap: wrap; gap: 9px; width: 100%; }
.photo-thumb-wrap { position: relative; width: calc(33.33% - 6px); }
.photo-thumb {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--border);
    display: block;
}
.photo-remove {
    position: absolute; top: -6px; right: -6px;
    width: 22px; height: 22px;
    background: var(--ko); color: white;
    border: 2px solid white; border-radius: 50%;
    font-size: 13px; font-weight: 900;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; line-height: 1;
}

/* ===== ACTION BUTTONS ===== */
.actions-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; margin-bottom: 44px; }

.btn-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 16px 10px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s, opacity 0.12s;
    user-select: none;
}
.btn-action:active { transform: scale(0.95); opacity: 0.85; }
.btn-action .btn-icon { font-size: 26px; line-height: 1; }
.btn-action.btn-pdf { background: #2C3E50; color: white; }
.btn-action.btn-email { background: var(--orange); color: white; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.52);
    z-index: 300;
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
    background: white;
    border-radius: 14px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 24px 50px rgba(0,0,0,0.28);
}
.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.modal-input {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-size: 16px;
    margin-bottom: 16px;
}
.modal-input:focus { outline: none; border-color: var(--orange); }
.modal-recipients { font-size: 12px; color: var(--muted); margin-bottom: 14px; line-height: 1.7; }
.modal-recipients strong { color: var(--text); }
.modal-actions { display: flex; gap: 10px; }
.btn-modal {
    flex: 1; padding: 12px;
    border: none; border-radius: 8px;
    font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-modal.cancel { background: var(--bg); color: var(--muted); }
.btn-modal.send { background: var(--orange); color: white; }

/* ===== LOADING ===== */
.loading-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.44);
    z-index: 400;
    align-items: center; justify-content: center;
    flex-direction: column;
    gap: 16px;
    color: white;
    font-size: 16px; font-weight: 600;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 52px; height: 52px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: var(--orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== RESPONSIVE ===== */
@media (max-width: 500px) {
    .field-group, .field-group.cols-3 { grid-template-columns: 1fr; }
    .actions-bar { grid-template-columns: 1fr; }
    .signatures-grid { grid-template-columns: 1fr; }
    .doc-header { flex-direction: column; }
    .doc-header .company-info { text-align: left; }
    .check-pills { gap: 7px; }
    .check-pill-label { padding: 9px 12px; font-size: 12.5px; }
}

@media print {
    .app-header .btn-back,
    .actions-bar,
    .btn-photo-add,
    .btn-clear-sig,
    .btn-add-row,
    .col-del,
    .btn-map-open,
    .modal-overlay,
    .loading-overlay,
    .offline-banner { display: none !important; }
    body { background: white; }
    .form-section { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}
