/* =====================================================================
   GraniMarbre — Devis — style.css
   ===================================================================== */

/* ─── Variables ─────────────────────────────────────────────────────── */
:root {
    --blue:      #1a3a6e;
    --blue-dark: #12295a;
    --blue-light:#2a5298;
    --copper1:   #c9873a;
    --copper2:   #e8a84c;
    --white:     #ffffff;
    --grey-bg:   #f5f5f5;
    --grey-brd:  #d0d0d0;
    --grey-txt:  #555555;
    --red:       #c0392b;
    --font:      Arial, Helvetica, sans-serif;
    --shadow:    0 2px 8px rgba(0,0,0,.12);
    --a4-width:  210mm;
}

/* ─── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); background: var(--grey-bg); color: #222; }

/* =====================================================================
   LOGIN PAGE
   ===================================================================== */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-light) 100%);
}

.login-container {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
    padding: 40px 48px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-logo {
    margin-bottom: 24px;
}

.login-header-img {
    max-width: 320px;
    max-height: 160px;
    width: 100%;
    object-fit: contain;
}

.login-title {
    font-size: 1.5rem;
    color: var(--blue);
    font-weight: bold;
    margin-bottom: 6px;
}

.login-subtitle {
    color: var(--grey-txt);
    font-size: .9rem;
    margin-bottom: 24px;
}

.login-error {
    background: #fdecea;
    color: var(--red);
    border: 1px solid #f5c6c2;
    border-radius: 4px;
    padding: 10px 14px;
    font-size: .9rem;
    margin-bottom: 20px;
    text-align: left;
}

.login-form .form-group {
    margin-bottom: 18px;
    text-align: left;
}

.login-form label {
    display: block;
    font-size: .85rem;
    font-weight: bold;
    color: var(--blue);
    margin-bottom: 6px;
}

.login-form input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--grey-brd);
    border-radius: 4px;
    font-size: 1rem;
    font-family: var(--font);
    transition: border-color .2s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(26,58,110,.15);
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--copper1), var(--copper2));
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: bold;
    font-family: var(--font);
    cursor: pointer;
    transition: opacity .2s;
    margin-top: 8px;
}

.btn-login:hover { opacity: .9; }

/* =====================================================================
   DEVIS PAGE — SCREEN
   ===================================================================== */
body.devis-page {
    background: var(--grey-bg);
    padding: 20px;
}

/* ─── Toolbar ─────────────────────────────────────────────────────────── */
/* Top toolbar */
.toolbar {
    max-width: var(--a4-width);
    margin: 0 auto 16px auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-user { font-size: .85rem; color: var(--grey-txt); }
.toolbar-user strong { color: var(--blue); }

.toolbar-left  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Indicateur de sauvegarde */
.save-status        { font-size: .78rem; color: var(--grey-txt); }
.save-status.saved  { color: #2a8a2a; font-weight: bold; }
.save-status.error  { color: var(--red); font-weight: bold; }

/* Champ num-devis (lecture seule, généré automatiquement) */
#num-devis[readonly] { background: #f0f4fb; cursor: default; color: var(--blue); font-weight: bold; }

.btn {
    display: inline-block;
    padding: 8px 18px;
    border: none;
    border-radius: 4px;
    font-family: var(--font);
    font-size: .9rem;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
    transition: opacity .2s;
}

.btn:hover { opacity: .85; }

.btn-primary {
    background: var(--blue);
    color: var(--white);
}

.btn-copper {
    background: linear-gradient(135deg, var(--copper1), var(--copper2));
    color: var(--white);
}

.btn-danger {
    background: #e74c3c;
    color: var(--white);
    padding: 4px 10px;
    font-size: .8rem;
}

.btn-secondary {
    background: var(--grey-brd);
    color: var(--blue);
}

/* ─── A4 Card ────────────────────────────────────────────────────────── */
.devis-card {
    background: var(--white);
    width: var(--a4-width);
    min-height: 297mm;
    margin: 0 auto;
    padding: 14mm 14mm 12mm 14mm;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* ─── Header ─────────────────────────────────────────────────────────── */
.devis-header {
    width: 100%;
    margin-bottom: 10px;
}

.devis-header img {
    display: block;
    margin: 0 auto;
    max-width: 320px;
    max-height: 100px;
    object-fit: contain;
}

/* ─── Title band ─────────────────────────────────────────────────────── */
.devis-title-band {
    background: var(--blue);
    color: var(--white);
    text-align: center;
    padding: 8px 0;
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: .08em;
    margin-bottom: 12px;
}

/* ─── Info grids ─────────────────────────────────────────────────────── */
.info-grids {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 14px;
}

.info-block {
    border: 1px solid var(--grey-brd);
    border-radius: 4px;
    overflow: hidden;
}

.info-block-title {
    background: var(--blue);
    color: var(--white);
    font-size: .78rem;
    font-weight: bold;
    padding: 4px 8px;
    letter-spacing: .04em;
}

.info-block-body {
    padding: 8px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    font-size: .82rem;
}

.info-block-body label {
    font-weight: bold;
    color: var(--blue);
    white-space: nowrap;
}

.info-block-body input[type="text"],
.info-block-body input[type="date"],
.info-block-body input[type="tel"] {
    border: none;
    border-bottom: 1px solid var(--grey-brd);
    font-family: var(--font);
    font-size: .82rem;
    padding: 2px 4px;
    width: 100%;
    background: transparent;
}

.info-block-body input:focus {
    outline: none;
    border-bottom-color: var(--blue);
}

/* ─── Tableau lignes ─────────────────────────────────────────────────── */
.table-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.devis-table-wrap {
    margin-bottom: 14px;
    overflow: visible;
}

.devis-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .8rem;
}

.devis-table th {
    background: var(--blue);
    color: var(--white);
    padding: 5px 6px;
    text-align: center;
    font-weight: bold;
    white-space: nowrap;
}

.devis-table th:first-child { text-align: left; }

.devis-table td {
    border-bottom: 1px solid var(--grey-brd);
    padding: 3px 4px;
    vertical-align: middle;
}

.devis-table tr:hover td { background: #f0f4fb; }

.devis-table td.col-desc { min-width: 180px; }
.devis-table td.col-num  { text-align: center; width: 60px; }
.devis-table td.col-pux  { text-align: right;  width: 75px; }
.devis-table td.col-mnt  { text-align: right;  width: 80px; font-weight: bold; color: var(--blue); }
.devis-table td.col-del  { text-align: center; width: 36px; }

.devis-table select,
.devis-table input[type="number"],
.devis-table input[type="text"] {
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 3px 4px;
    font-family: var(--font);
    font-size: .8rem;
    background: transparent;
    width: 100%;
}

.devis-table select:focus,
.devis-table input:focus {
    outline: none;
    border-color: var(--blue);
    background: var(--white);
}

.devis-table select { min-width: 160px; cursor: pointer; }
.devis-table input[type="number"] { text-align: right; }

/* ─── Combobox ───────────────────────────────────────────────────────── */
.combo-wrap {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
}

.combo-wrap:focus-within {
    border-color: var(--blue);
    background: var(--white);
}

.combo-inp {
    flex: 1;
    min-width: 0;
    border: none;
    border-radius: 3px;
    padding: 3px 4px;
    font-family: var(--font);
    font-size: .8rem;
    background: transparent;
    cursor: text;
}

.combo-inp:focus {
    outline: none;
}

.combo-arrow {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0 4px;
    cursor: pointer;
    color: var(--blue);
    font-size: .75rem;
    line-height: 1;
    opacity: .7;
}

.combo-arrow:hover { opacity: 1; }

.combo-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 999;
    min-width: 280px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--white);
    border: 1px solid var(--blue);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.combo-list.open { display: block; }

.combo-group {
    padding: 5px 10px 3px;
    font-size: .72rem;
    font-weight: bold;
    color: var(--white);
    background: var(--blue);
    letter-spacing: .03em;
    position: sticky;
    top: 0;
}

.combo-item {
    padding: 5px 12px;
    font-size: .8rem;
    cursor: pointer;
    color: #222;
}

.combo-item:hover {
    background: #e8f0fb;
    color: var(--blue);
}

.combo-empty {
    padding: 10px 12px;
    font-size: .8rem;
    color: #aaa;
    font-style: italic;
}

/* Disabled dim */
.devis-table input:disabled {
    opacity: .35;
    cursor: not-allowed;
}

/* Add row button */
.add-row-wrap {
    margin-bottom: 16px;
}

/* ─── Totaux ─────────────────────────────────────────────────────────── */
.totaux-wrap {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}

.totaux-table {
    width: 260px;
    border-collapse: collapse;
    font-size: .85rem;
}

.totaux-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--grey-brd);
}

.totaux-table .lbl { font-weight: bold; color: var(--blue); }

.totaux-table .val {
    text-align: right;
    font-weight: bold;
    min-width: 100px;
}

.totaux-table .val input {
    text-align: right;
    font-family: var(--font);
    font-size: .85rem;
    font-weight: bold;
    border: none;
    border-bottom: 1px solid var(--grey-brd);
    width: 100px;
    background: transparent;
    padding: 2px 4px;
}

.totaux-table .val input:focus {
    outline: none;
    border-bottom-color: var(--blue);
    background: var(--white);
}

.totaux-table tr.total-net td {
    background: var(--blue);
    color: var(--white);
    font-size: .95rem;
}

.totaux-table tr.total-net .val input {
    color: var(--white);
    border-bottom-color: rgba(255,255,255,.4);
    background: transparent;
}

/* ─── Signatures ─────────────────────────────────────────────────────── */
.sig-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}

.sig-section .sig-block {
    width: 260px;
}

.sig-block {
    border: 1px solid var(--grey-brd);
    border-radius: 4px;
    padding: 10px;
    font-size: .8rem;
}

.sig-block-title {
    font-weight: bold;
    color: var(--blue);
    margin-bottom: 6px;
    font-size: .82rem;
}

.sig-zone {
    height: 70px;
    border: 1px dashed var(--grey-brd);
    border-radius: 3px;
    display: flex;
    align-items: flex-end;
    padding: 4px 6px;
    color: #aaa;
    font-size: .75rem;
}

/* ─── Mentions ───────────────────────────────────────────────────────── */
.mentions {
    border-top: 2px solid var(--blue);
    padding-top: 8px;
    font-size: .68rem;
    color: var(--grey-txt);
    line-height: 1.4;
    text-align: justify;
}

.mentions strong { color: var(--blue); }

/* ─── Footer ─────────────────────────────────────────────────────────── */
.devis-footer {
    margin-top: 10px;
    text-align: center;
    font-size: .72rem;
    color: var(--blue);
    font-weight: bold;
    border-top: 1px solid var(--grey-brd);
    padding-top: 6px;
}

/* =====================================================================
   MODAL HISTORIQUE
   ===================================================================== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 20px;
}
.modal-box {
    background: #fff; border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,.35);
    width: 100%; max-width: 900px; max-height: 82vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
    background: var(--blue); color: #fff;
    padding: 14px 20px;
    display: flex; justify-content: space-between; align-items: center;
    font-weight: bold; font-size: .95rem; flex-shrink: 0;
}
.modal-close {
    background: none; border: none; color: #fff;
    font-size: 1.2rem; cursor: pointer; padding: 0 4px; opacity: .8; line-height: 1;
}
.modal-close:hover { opacity: 1; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }

/* Tableau historique */
.histo-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.histo-table th {
    background: #f0f4fb; color: var(--blue);
    padding: 8px 10px; text-align: left;
    border-bottom: 2px solid var(--blue); font-size: .78rem;
}
.histo-table td { padding: 8px 10px; border-bottom: 1px solid var(--grey-brd); vertical-align: middle; }
.histo-table tr:last-child td { border-bottom: none; }
.histo-table tr:hover td { background: #f8f9ff; }

/* =====================================================================
   PRINT STYLES
   ===================================================================== */
@media print {
    body { background: none; padding: 0; }
    .toolbar { display: none !important; }

    .devis-card {
        box-shadow: none;
        padding: 10mm 12mm 8mm 12mm;
        width: 100%;
    }

    .btn-danger,
    .add-row-wrap { display: none !important; }

    /* Show inputs as plain text */
    .devis-table select,
    .devis-table input,
    .info-block-body input,
    .totaux-table input {
        border: none !important;
        background: transparent !important;
        -webkit-appearance: none;
        appearance: none;
    }

    /* Masquer la combo-arrow et la modale à l'impression */
    .combo-arrow,
    .modal-overlay { display: none !important; }

    /* Num devis readonly : même rendu que les autres champs */
    #num-devis[readonly] { background: transparent !important; }

    @page {
        size: A4 portrait;
        margin: 0;
    }
}
