:root {
    --primary: #3d43d8;
    --primary-dark: #2f34ab;
    --primary-light: #eef0ff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e5ec;
    --bg: #f6f7fb;
    --success: #0f7b4d;
    --success-bg: #e4f5ec;
    --danger: #b42318;
    --danger-bg: #fdecea;
    --warning: #92400e;
    --warning-bg: #fef3e2;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ---- Top bar ---- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 8px;
    background: linear-gradient(135deg, #2b2f7e, #3d43d8);
    color: #fff; font-weight: 700; font-size: 16px;
}
.brand strong { display: block; font-size: 16px; letter-spacing: 0.05em; }
.brand small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.nav { display: flex; gap: 4px; }
.nav a {
    text-decoration: none; color: var(--muted); padding: 8px 14px;
    border-radius: 8px; font-weight: 600;
}
.nav a:hover { background: var(--primary-light); color: var(--primary); }
.nav a.active { background: var(--primary); color: #fff; }

main { padding: 24px 20px 40px; }

/* ---- Cards, alerts ---- */
.card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.card h2 { margin-top: 0; }
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
    background: var(--primary); color: #fff; font-weight: 600; font-size: 14px;
    text-decoration: none; cursor: pointer; font-family: inherit;
}
.btn:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-light { background: #fff; color: var(--text); border-color: var(--border); }
.btn-light:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #0a5f3b; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: #374151; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=number], input[type=password], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
    font-family: inherit; font-size: 14px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field { margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ---- Tables ---- */
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th {
    background: var(--primary); color: #fff; text-align: left;
    padding: 10px 12px; font-size: 13px;
}
table.list th:first-child { border-radius: 8px 0 0 0; }
table.list th:last-child { border-radius: 0 8px 0 0; }
table.list td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr:hover td { background: #fafbff; }
.num { text-align: right; white-space: nowrap; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge-draft { background: #eceef2; color: #4b5563; }
.badge-sent { background: var(--warning-bg); color: var(--warning); }
.badge-signed { background: var(--success-bg); color: var(--success); }
.badge-refused { background: var(--danger-bg); color: var(--danger); }

/* ---- Page head ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Quote editor ---- */
.item-row { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; background: #fff; }
.item-row-head { display: flex; gap: 10px; align-items: flex-start; }
.item-row-head .item-name { flex: 1; }
.item-row-grid { display: grid; grid-template-columns: 90px 130px 90px 120px auto; gap: 10px; margin-top: 10px; align-items: end; }
@media (max-width: 700px) { .item-row-grid { grid-template-columns: 1fr 1fr; } }
.item-options { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.item-options > div { min-width: 160px; }
.item-total { font-weight: 700; text-align: right; padding-bottom: 9px; }
.drag-handle { cursor: grab; color: var(--muted); padding-top: 8px; }

.totals-box { margin-left: auto; width: 320px; max-width: 100%; }
.totals-box .row { display: flex; justify-content: space-between; padding: 8px 12px; }
.totals-box .row.total { background: var(--primary-light); border-radius: 8px; font-weight: 800; font-size: 17px; color: var(--primary-dark); }

/* ---- Product picker modal ---- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 18, 34, 0.55);
    display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #fff; border-radius: 14px; width: 720px; max-width: 100%;
    max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; }
.modal-body { overflow-y: auto; padding: 10px 20px 20px; }
.picker-cat { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 0 6px; font-weight: 700; }
.picker-item {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px; cursor: pointer;
}
.picker-item:hover { border-color: var(--primary); background: var(--primary-light); }
.picker-item .p-name { font-weight: 600; }
.picker-item .p-price { font-weight: 700; white-space: nowrap; }
.picker-item small { color: var(--muted); }

/* ---- Signature pad ---- */
.sig-wrap { border: 2px dashed var(--border); border-radius: 12px; background: #fff; position: relative; }
.sig-wrap canvas { display: block; width: 100%; height: 200px; border-radius: 10px; touch-action: none; }
.sig-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #c3c8d4; font-size: 15px; pointer-events: none; }
.sig-actions { margin-top: 10px; display: flex; gap: 8px; }

/* ---- Quote preview ---- */
.preview { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.preview-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.preview h1.doc-title { font-size: 34px; margin: 0 0 12px; }
.preview .meta-table td { padding: 2px 12px 2px 0; font-size: 14px; }
.preview .addr h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.preview .addr p { margin: 0; }
table.doc-items { width: 100%; border-collapse: collapse; margin-top: 16px; }
table.doc-items th { background: var(--primary); color: #fff; padding: 9px 10px; text-align: left; font-size: 13px; }
table.doc-items td { padding: 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
table.doc-items .desc { white-space: pre-line; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.sig-images { display: flex; gap: 24px; margin-top: 24px; flex-wrap: wrap; }
.sig-images .box { border: 1px solid var(--border); border-radius: 10px; padding: 12px; width: 260px; }
.sig-images .box h5 { margin: 0 0 8px; color: var(--muted); }
.sig-images img { max-width: 100%; height: 90px; object-fit: contain; }

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

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.help { color: var(--muted); font-size: 13px; }
.mt-0 { margin-top: 0; }

/* ---- Public sign page ---- */
.public-wrap { max-width: 860px; margin: 0 auto; }

/* ---- Mentions légales / CGV ---- */
.legal { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px; margin-top: 20px; }
.legal h4 { margin: 0 0 10px; font-size: 15px; color: var(--primary-dark); text-transform: uppercase; letter-spacing: 0.06em; }
.legal h5 { margin: 12px 0 3px; font-size: 13px; }
.legal p { margin: 0; font-size: 12.5px; color: var(--muted); text-align: justify; }
details.legal-fold > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: 4px 0; }
details.legal-fold .legal { margin-top: 10px; }

/* ---- Logos ---- */
.logo-top { height: 52px; display: block; }
.logo-login { height: 110px; }
.logo-doc { height: 90px; }

/* ---- Tableaux défilants (mobile) ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table.doc-items { min-width: 540px; }

/* ---- Mobile ---- */
@media (max-width: 700px) {
    .container { padding: 0 12px; }
    main { padding: 16px 12px 32px; }

    /* Barre de navigation : logo au-dessus, menu en dessous */
    .topbar-inner {
        flex-direction: column;
        gap: 8px;
        padding-top: 10px;
        padding-bottom: 10px;
    }
    .logo-top { height: 42px; }
    .nav { flex-wrap: wrap; justify-content: center; gap: 2px; }
    .nav a { padding: 7px 10px; font-size: 13px; }

    .page-head h1 { font-size: 19px; }
    .card { padding: 14px; }

    /* Empêche le zoom automatique d'iPhone à la saisie (police < 16px) */
    input[type=text], input[type=email], input[type=tel], input[type=date],
    input[type=number], input[type=password], select, textarea { font-size: 16px; }

    /* Aperçu du devis */
    .preview { padding: 14px; }
    .preview h1.doc-title { font-size: 26px; }
    .preview-head { flex-wrap: wrap; gap: 12px; }
    .logo-doc { height: 60px; }
    .totals-box { width: 100%; }
    .sig-images .box { width: 100%; }

    /* Tableaux de listes : le tableau défile, pas la page */
    table.list { min-width: 560px; }
    table.list th, table.list td { padding: 8px 8px; font-size: 13px; }

    /* Éditeur de devis */
    .item-row { padding: 10px; }
    .item-row-head { flex-wrap: wrap; }
    .modal-backdrop { padding: 12px 8px; }
    .modal-head { flex-wrap: wrap; }
    .modal-head input { max-width: 100% !important; }

    /* Boutons plus faciles à toucher */
    .btn { padding: 10px 14px; }
    .btn-sm { padding: 7px 10px; }
}
