/* =========================================================
   Facturation - feuille de style
   Mobile d'abord. Couleurs reprises du logo (vert, gris fonce).
   ========================================================= */

:root {
    --green: #5e8f1f;
    --green-dark: #4a7216;
    --green-soft: #eef5e3;
    --ink: #1f2328;
    --muted: #646b73;
    --line: #e2e4de;
    --bg: #f5f6f3;
    --card: #ffffff;
    --head: #1f2328;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --warn-soft: #fff6dd;
    --radius: 10px;
    --title: "Raleway", system-ui, sans-serif;
    --text: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.45 var(--text);
}

a { color: var(--green-dark); }

/* Icones SVG : taille du texte par defaut (les boutons la redefinissent) */
svg { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.18em; }

.back-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 18px; text-decoration: none; font-weight: 600; }
.back-link:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { font-family: var(--title); font-weight: 700; letter-spacing: .3px; }
h1 { font-size: 1.45rem; margin: 22px 0 14px; }
h2 { font-size: 1.15rem; margin: 22px 0 10px; }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------------------------------------------- En-tete et menu */

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }

.topbar-inner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding-top: 10px; padding-bottom: 6px;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-word { font-family: var(--title); font-weight: 600; font-size: 1.35rem; color: #8cc63f; }

.business {
    font-family: var(--title); font-weight: 600; font-size: 1.05rem; text-align: right;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%;
    display: flex; align-items: center; gap: 10px; justify-content: flex-end;
}
.business span { overflow: hidden; text-overflow: ellipsis; }
.business-logo { max-height: 44px; max-width: 120px; object-fit: contain; flex: none; }

.menu {
    display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
    padding-bottom: 0; padding-top: 2px;
}
.menu::-webkit-scrollbar { display: none; }

.menu a, .menu button {
    flex: 0 0 auto;
    font-family: var(--title); font-weight: 600; font-size: .82rem;
    text-transform: uppercase; letter-spacing: 1.5px;
    color: var(--ink); text-decoration: none;
    padding: 10px 12px; border: 0; background: none; cursor: pointer;
    border-bottom: 3px solid transparent;
}
.menu a:hover, .menu button:hover { color: var(--green-dark); }
.menu a.active { color: var(--danger); border-bottom-color: var(--danger); }
.menu-logout { margin: 0 0 0 auto; display: flex; }

@media (min-width: 760px) {
    .menu { justify-content: center; }
    .menu a, .menu button { font-size: .95rem; padding: 12px 18px; }
    .brand-word { font-size: 1.6rem; }
    .business { font-size: 1.5rem; }
}

/* ---------------------------------------------- Messages */

.flash { margin: 16px 0; padding: 12px 14px; border-radius: var(--radius); }
.flash-ok { background: var(--green-soft); border: 1px solid #c9e0a8; }
.flash-error { background: var(--danger-soft); border: 1px solid #f3c2bc; color: #7a1a12; }
.flash-warn { background: var(--warn-soft); border: 1px solid #f0dc9c; }

.field-error { color: var(--danger); font-size: .88rem; margin-top: 4px; }
.field-error:empty { display: none; }
.hint { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 18px;
    font: 600 1rem var(--text); text-decoration: none; cursor: pointer;
    border-radius: 8px; border: 1px solid #c8ccc4; background: var(--card); color: var(--ink);
}
.btn:hover { border-color: #9aa095; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-danger { color: var(--danger); border-color: #e7b1aa; }
.btn-block { width: 100%; }
.btn svg { width: 20px; height: 20px; flex: none; }

.actions-bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin: 16px 0; }

/* Petits boutons d'action (icones) dans les listes */
.icon-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.icon-actions form { margin: 0; display: inline-flex; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-width: 40px; min-height: 40px; padding: 6px 10px;
    border: 1px solid var(--line); border-radius: 8px; background: var(--card);
    color: var(--ink); cursor: pointer; text-decoration: none; font: 500 .9rem var(--text);
}
.icon-btn:hover { border-color: #9aa095; background: #fafbf8; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.ok { color: var(--green-dark); }
.icon-btn .lbl { display: inline; }
.icon-btn:disabled { opacity: .35; cursor: default; }

@media (min-width: 760px) {
    .icon-btn .lbl { display: none; }
    .icon-btn { min-width: 36px; min-height: 36px; padding: 6px; }
}

/* ---------------------------------------------- Cartes et listes */

.card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; margin: 14px 0;
}

/* Tableau sur ecran large, cartes sur mobile */
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table thead th {
    background: var(--head); color: #fff; text-align: left;
    font: 600 .82rem var(--title); text-transform: uppercase; letter-spacing: 1px;
    padding: 14px 12px;
}
.table thead th:first-child { border-top-left-radius: var(--radius); }
.table thead th:last-child { border-top-right-radius: var(--radius); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card); vertical-align: middle; }
.table tbody tr:hover td { background: #f0f6ff; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .empty td { text-align: center; padding: 48px 12px; color: var(--muted); }

@media (max-width: 759px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr {
        background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
        margin: 0 0 12px; padding: 10px 12px;
    }
    .table td { border: 0; padding: 4px 0; background: none; display: flex; justify-content: space-between; gap: 12px; }
    .table tbody tr:hover td { background: none; }
    .table td[data-label]::before {
        content: attr(data-label); font-size: .8rem; color: var(--muted);
        text-transform: uppercase; letter-spacing: .5px; padding-top: 2px;
    }
    .table td.cell-actions { order: 99; padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line); }
    .table tr { display: flex; flex-direction: column; }
    .table .num { text-align: right; }
}

.badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600;
    background: #eceee9; color: var(--muted); white-space: nowrap;
}
.badge-draft { background: var(--warn-soft); color: #7a5b00; }
.badge-issued { background: var(--green-soft); color: var(--green-dark); }
.badge-trial { background: #e7f0fb; color: #1d4f91; }
.badge-expired { background: var(--danger-soft); color: var(--danger); }

hr.sep { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; background: #eceee9; padding: 1px 5px; border-radius: 4px; }

.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; margin: 14px 0; }
.pager a, .pager span {
    min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px; border: 1px solid var(--line); background: var(--card); text-decoration: none; color: var(--ink);
    padding: 0 10px;
}
.pager .current { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700; }

/* ---------------------------------------------- Formulaires */

label { font-weight: 600; font-size: .92rem; display: block; margin-bottom: 4px; }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=tel],
input[type=number], select, textarea {
    width: 100%; min-height: 44px; padding: 9px 11px;
    font: 16px var(--text); color: var(--ink);
    border: 1px solid #c8ccc4; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible, .menu a:focus-visible {
    outline: 3px solid #b8d98a; outline-offset: 1px; border-color: var(--green);
}
input:disabled { background: #eceee9; color: #9aa095; }

.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 20px; height: 20px; margin: 0; }

.form-grid { display: grid; gap: 14px; }
@media (min-width: 760px) {
    .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
    .form-grid .span-2 { grid-column: span 2; }
}

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
@media (max-width: 759px) { .form-actions .btn { flex: 1 1 100%; } }

/* ---------------------------------------------- Editeur de facture */

.inv-head { display: grid; gap: 14px; }
@media (min-width: 760px) { .inv-head { grid-template-columns: 170px 150px 1fr; align-items: end; } }
.inv-head .small-link { font-size: .88rem; display: inline-block; margin-top: 6px; }

.lines { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font: 600 .78rem var(--title); text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 8px 6px; border-bottom: 2px solid var(--ink); }
.lines td { padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines .bold { font-weight: 700; }
.lines .comment td.desc { font-style: italic; color: #3d434a; }
.lines .editing td { background: #fffbe6; }
.lines .empty td { text-align: center; color: var(--muted); padding: 28px 6px; }
.line-tools { display: flex; gap: 4px; justify-content: flex-end; }
.line-tools .icon-btn { min-width: 36px; min-height: 36px; padding: 4px; }
.line-tools .icon-btn .lbl { display: none; }

@media (max-width: 759px) {
    .lines thead { display: none; }
    .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100%; }
    .lines tr { border-bottom: 1px solid var(--line); padding: 8px 0; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
    .lines td { border: 0; padding: 0; }
    .lines td.desc { grid-column: 1 / -1; order: -1; font-size: 1rem; }
    .lines td.qty::before { content: "Qté : "; color: var(--muted); }
    .lines td.price { display: none; }
    .lines td.total { text-align: right; font-weight: 600; }
    .lines td.tools { grid-column: 1 / -1; }
    .lines .empty { display: block; }
    .line-tools { justify-content: flex-start; margin-top: 4px; }
}

.line-form { background: #fafbf8; border: 1px dashed #c8ccc4; border-radius: var(--radius); padding: 14px; margin-top: 14px; }
.line-form .grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.line-form .grid .desc { grid-column: 1 / -1; }
.line-form .grid .type { grid-column: 1 / -1; }
@media (min-width: 760px) {
    .line-form .grid { grid-template-columns: 150px 90px 1fr 120px auto; align-items: end; }
    .line-form .grid .desc, .line-form .grid .type { grid-column: auto; }
}
.line-form .buttons { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; grid-column: 1 / -1; }
@media (min-width: 760px) { .line-form .buttons { grid-column: auto; } }

.totals { margin-left: auto; max-width: 360px; margin-top: 16px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 9px; font-size: 1.15rem; font-weight: 700; font-style: italic; }

.busy { opacity: .55; pointer-events: none; }

/* ---------------------------------------------- Connexion */

.auth-page { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; padding: 24px 16px; }
.auth-card {
    width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line);
    border-radius: 14px; padding: 24px 22px 28px; margin-top: 4vh;
}
.auth-logo { display: block; margin: 0 auto 8px; width: 150px; height: auto; }
.auth-card h1 { text-align: center; margin-top: 4px; }
.auth-card .form-grid { gap: 16px; }
.auth-links { text-align: center; margin-top: 18px; font-size: .95rem; }

/* ---------------------------------------------- Essai */

.trial-bar { background: #e7f0fb; border-bottom: 1px solid #c9dbf3; color: #1d3f6e; font-size: .92rem; }
.trial-bar .wrap { padding-top: 8px; padding-bottom: 8px; }

/* Essai termine : l'application en arriere-plan, grisee et inerte */
.trial-locked { overflow: hidden; }
.trial-locked .app { filter: grayscale(1) blur(1.5px); opacity: .55; pointer-events: none; user-select: none; }
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100; background: rgba(31, 35, 40, .45);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
    background: var(--card); border-radius: 14px; max-width: 460px; width: 100%;
    padding: 28px 24px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal h2 { margin: 8px 0 12px; font-size: 1.3rem; }
.modal p { line-height: 1.5; }
.modal form { margin-top: 8px; }

.welcome { border-color: #c9e0a8; background: var(--green-soft); }
.trial-cta { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); text-align: center; font-size: .95rem; }
.trial-cta .btn { margin-top: 10px; }
/* Champ piege de l'inscription : hors ecran (pas display:none, que certains robots sautent) */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.welcome h2 { margin-top: 0; }

/* ---------------------------------------------- Super-admin */

.sa-bar { background: #1f2328; border-bottom: 0; }
.sa-bar .business, .sa-bar .menu a, .sa-bar .menu button { color: #fff; }
.sa-bar .menu a.active { color: #b8d98a; border-bottom-color: #b8d98a; }
.sa-bar .menu a:hover, .sa-bar .menu button:hover { color: #b8d98a; }

.sa-card { margin: 32px auto; }

.card > h2:first-child, .card > .section-head:first-child h2 { margin-top: 0; }

input[type=file] { font: .92rem var(--text); max-width: 100%; }
input[type=file]::file-selector-button {
    font: 600 .9rem var(--text); margin-right: 10px; padding: 8px 14px; cursor: pointer;
    border: 1px solid #c8ccc4; border-radius: 8px; background: #fff; color: var(--ink);
}
input[type=file]::file-selector-button:hover { border-color: #9aa095; }
.upload-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.upload-row form { margin: 0; }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; gap: 6px; }
.btn-sm svg { width: 16px; height: 16px; }

/* Liste des utilisateurs d'une entreprise */
.section-head + .user-list, .section-head + .link-box, .section-head + .empty-note { margin-top: 14px; }
.user-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.user-list:empty { display: none; }
.user-item {
    display: grid; gap: 10px 18px; padding: 14px 16px; align-items: center;
    grid-template-columns: 1fr;
}
.user-item + .user-item { border-top: 1px solid var(--line); }
.user-item.inactive { background: #f7f7f5; }
.user-item.inactive .user-name, .user-item.inactive .user-email { color: #9aa095; }
.user-name { font-weight: 700; font-size: 1.02rem; text-decoration: none; color: var(--ink); }
.user-name:hover { color: var(--green-dark); text-decoration: underline; }
.user-display { color: var(--muted); margin-left: 6px; }
.user-email { color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.user-state .hint { margin-top: 3px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-actions form { margin: 0; display: inline-flex; }
@media (min-width: 760px) {
    .user-item { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; }
    .user-actions { justify-content: flex-end; }
}

.link-box { background: var(--warn-soft); border: 1px solid #f0dc9c; border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; }
.link-box label { font-weight: 500; }
.link-box input { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.empty-note { color: var(--muted); text-align: center; padding: 24px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }
.row-inactive td { color: #9aa095; }
.logo-preview { max-height: 80px; max-width: 240px; object-fit: contain; display: block; margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.section-head h2 { margin: 0; }
.danger-zone { border-color: #f3c2bc; }
textarea { min-height: 96px; resize: vertical; }

/* ---------------------------------------------- Pied de page */

.footer { text-align: center; padding: 28px 16px 36px; }
.footer img { opacity: .85; }
