/* ============================================================
   SahaBill — UI monochrome + accents neutres
   Défaut : noir / blanc / gris
   Couleur PDF par société (Ma marque) — sidebar toujours noir
   Breakpoints : desktop ≥1100 · tablette 768–1099 · mobile <768
   ============================================================ */

:root {
    --sidebar-bg: #111111;
    --brand: #111111;
    --brand-deep: #0A0A0A;
    --brand-accent: #2A2A2A;
    --brand-soft: #F0F0F0;
    --brand-border: #D4D4D4;

    /* Alias historiques (composants existants) */
    --bleu: var(--brand);
    --bleu-deep: var(--brand-deep);
    --bleu-accent: var(--brand-accent);
    --bleu-soft: var(--brand-soft);

    --vert: #2F7D4A;
    --orange: #B8860B;
    --rouge: #C0392B;

    --bg: #F7F7F7;
    --bg-pattern: none;
    --surface: #FFFFFF;
    --surface-2: #F0F0F0;
    --ink: #111111;
    --muted: #5C5C5C;
    --line: #E2E2E2;

    --vert-soft: #E8F5EE;
    --orange-soft: #F7F1E3;
    --rouge-soft: #F8EAEA;
    --accent-bg: #F3F3F3;

    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08);
    --font: "Figtree", system-ui, sans-serif;
    --display: "Outfit", system-ui, sans-serif;
    --sidebar: 268px;
    --touch: 44px;
    --space: clamp(1rem, 2.5vw, 2rem);
    --content-max: 1200px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    background-image: var(--bg-pattern);
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.55;
    font-size: 15px;
}

img, svg, video { max-width: 100%; height: auto; }

a { color: var(--bleu-accent); text-decoration: none; }
a:hover { color: var(--bleu); text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--bleu-accent);
    outline-offset: 2px;
}

/* ——— Shell ——— */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar-overlay {
    display: none;
}

/* ——— Sidebar ——— */
.sidebar {
    background: var(--sidebar-bg);
    color: #F5F5F5;
    padding: 1.35rem 1rem 1.25rem;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    z-index: 40;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 1.75rem;
    padding: 0 0.35rem;
}

.sidebar-close {
    display: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.sidebar-close:hover { background: rgba(255, 255, 255, 0.18); }

.brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    min-width: 0;
}

.brand-logo {
    display: block;
    width: auto;
    max-width: 100%;
    height: 44px;
    object-fit: contain;
    border-radius: 8px;
    background: transparent;
}

.brand-logo-login {
    display: block;
    height: auto;
    max-height: 48px;
    max-width: 220px;
    width: auto;
    object-fit: contain;
    border-radius: 0;
    background: transparent;
}

.brand-text {
    display: block;
    font-family: var(--display);
    font-size: clamp(0.95rem, 2.5vw, 1.1rem);
    font-weight: 700;
    color: #fff;
    line-height: 1.25;
    word-break: break-word;
}

.brand-text-logo {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.35rem;
}

.brand-text-logo .brand-text-title {
    font-family: var(--display);
    font-size: clamp(1.25rem, 4vw, 1.5rem);
    font-weight: 700;
    color: var(--bleu);
    line-height: 1.2;
}

.brand-text-logo small {
    color: var(--muted);
    font-size: 0.9rem;
}

.brand-logo-empty {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 100px;
    border: 2px dashed var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 600;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: none;
    display: grid;
    place-items: center;
    font-family: var(--display);
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    flex-shrink: 0;
}

.brand strong {
    display: block;
    font-family: var(--display);
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}
.brand small {
    color: #A8B8C8;
    font-size: 0.72rem;
    line-height: 1.35;
    display: block;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    flex: 1;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.nav a,
.nav-link {
    color: rgba(255, 255, 255, 0.78);
    padding: 0.65rem 0.85rem;
    min-height: var(--touch);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    transition: background 0.15s ease, color 0.15s ease;
    border: 0;
    background: transparent;
}
.nav a:hover,
.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
}
.nav a.active,
.nav-link.active {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    box-shadow: inset 3px 0 0 #FFFFFF;
    font-weight: 600;
}
.nav a:focus-visible,
.nav-link:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}
.nav-ico {
    flex-shrink: 0;
    opacity: 0.9;
}
.nav-link.active .nav-ico {
    opacity: 1;
}

.nav-link.nav-admin-primary {
    background: rgba(255, 255, 255, 0.12);
    color: #fff !important;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 0.15rem;
}
.nav-link.nav-admin-primary:hover {
    background: rgba(255, 255, 255, 0.18);
}
.nav-link.nav-admin-primary.active {
    box-shadow: inset 3px 0 0 #FFFFFF;
}

.nav-link.nav-link-guide {
    margin-top: 0.15rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.72);
    border: 1px dashed rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.06);
}
.nav-link.nav-link-guide:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.35);
}

.nav-section-label {
    display: block;
    margin: 0.15rem 0.5rem 0.35rem;
    padding-top: 0.1rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
}

.sidebar-user {
    margin-top: 1.25rem;
    padding: 1rem 0.85rem 0.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.8rem;
    color: #A8B8C8;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.sidebar-user-company {
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.sidebar-user a {
    color: #fff;
    font-weight: 600;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

/* ——— Main ——— */
.main-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem var(--space) 0.65rem;
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(244, 247, 250, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid transparent;
    overflow: visible;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex-wrap: wrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-shrink: 0;
    flex-wrap: nowrap;
    position: relative;
    z-index: 40;
}

/* ——— Menu + Créer ——— */
.create-menu {
    position: relative;
    display: inline-block;
    z-index: 50;
}
.create-menu > summary {
    list-style: none;
    cursor: pointer;
}
.create-menu > summary::-webkit-details-marker,
.create-menu > summary::marker {
    display: none;
    content: '';
}

.create-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 40px;
    padding: 0.45rem 0.9rem 0.45rem 0.75rem;
    border: 1px solid var(--bleu);
    border-radius: var(--radius-sm);
    background: var(--bleu);
    color: #fff;
    font: inherit;
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1;
    box-shadow: var(--shadow);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.create-menu-btn:hover {
    background: var(--bleu-accent);
    border-color: var(--bleu-accent);
}
.create-menu[open] > .create-menu-btn {
    background: var(--bleu-deep, var(--bleu-accent));
    border-color: var(--bleu-deep, var(--bleu-accent));
}
.create-menu-plus {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
}
.create-menu-caret {
    width: 0;
    height: 0;
    margin-left: 0.1rem;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid rgba(255, 255, 255, 0.85);
}
.create-menu[open] .create-menu-caret {
    transform: rotate(180deg);
}

.create-menu-panel {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    width: max-content;
    min-width: 16.5rem;
    max-width: min(20rem, calc(100vw - 1.5rem));
    margin: 0;
    padding: 0.4rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
    z-index: 100;
    flex-direction: column;
    gap: 0.15rem;
    box-sizing: border-box;
}
.create-menu[open] > .create-menu-panel {
    display: flex;
}

.create-menu-panel a {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0.7rem 0.85rem;
    border-radius: 8px;
    color: var(--ink, #1a2332);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
}
.create-menu-panel a:hover,
.create-menu-panel a:focus-visible {
    background: var(--bleu-soft);
    color: var(--bleu);
    text-decoration: none;
    outline: none;
}

.topbar-company {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 14rem;
}

.topbar h1 {
    font-family: var(--display);
    font-size: clamp(1.25rem, 2.5vw, 1.65rem);
    font-weight: 600;
    color: var(--bleu);
    letter-spacing: -0.025em;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-toggle {
    display: none;
    width: var(--touch);
    height: var(--touch);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    box-shadow: var(--shadow);
}
.nav-toggle-bar {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: var(--bleu);
}

.badge-devise {
    background: var(--bleu-soft);
    color: var(--bleu);
    font-family: var(--display);
    font-weight: 700;
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.content {
    padding: 1rem var(--space) calc(2rem + var(--safe-bottom));
    flex: 1;
    width: 100%;
    max-width: calc(var(--content-max) + 2 * var(--space));
}

.app-footer {
    padding: 1rem var(--space) calc(1.35rem + var(--safe-bottom));
    color: var(--muted);
    font-size: 0.82rem;
}

/* ——— Cards ——— */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(1.1rem, 2.5vw, 1.5rem);
    box-shadow: var(--shadow);
    margin-bottom: 1.15rem;
}
.card h2 {
    font-family: var(--display);
    font-size: 1.05rem;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--bleu);
    letter-spacing: -0.015em;
}
.card-intro { color: var(--muted); margin-bottom: 1.15rem; }
.field-hint {
    margin: 0.45rem 0 0;
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.45;
}
.field-hint code {
    font-size: 0.82em;
    padding: 0.1em 0.35em;
    background: var(--surface-2);
    border-radius: 4px;
}
.link-btn {
    appearance: none;
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    color: var(--bleu);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.link-btn:hover { opacity: 0.85; }
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.card-header-row h2 { margin-bottom: 0; }
.muted-card { background: var(--surface-2); }

/* ——— Forms ——— */
.form-stack { display: flex; flex-direction: column; gap: 0.25rem; }
.form-grid-2, .form-grid-3, .form-grid-4 {
    display: grid;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.layout-2col {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
    gap: 1.15rem;
    margin-bottom: 1.15rem;
}

.field { margin-bottom: 1rem; }
.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.35rem;
}
.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.35rem;
}
.field-label-row label { margin-bottom: 0; }
.field-label-row .btn { font-weight: 500; font-size: 0.75rem; padding: 0.3rem 0.6rem; }
.req { color: var(--rouge); }

.field input, .field textarea, .field select,
.items-table input {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.85rem;
    min-height: var(--touch);
    font: inherit;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field textarea { min-height: auto; }
.field input:focus, .field textarea:focus, .field select:focus,
.items-table input:focus {
    outline: none;
    border-color: var(--bleu-accent);
    box-shadow: 0 0 0 3px rgba(46, 107, 166, 0.18);
}
.field input.readonly { background: var(--surface-2); color: var(--muted); }
.hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.35rem; }

.legal-ids {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 1rem 1.1rem 0.35rem;
    margin: 0 0 0.5rem;
    background: #f7f9fc;
}
.legal-ids legend {
    font-family: var(--display);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--bleu);
    padding: 0 0.4rem;
}
.field-narrow { max-width: 180px; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 0.5rem;
}
.filters-actions { grid-column: 1 / -1; }

/* ——— Buttons ——— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    padding: 0.6rem 1.05rem;
    min-height: var(--touch);
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover {
    text-decoration: none;
    border-color: var(--bleu-accent);
    color: var(--bleu-accent);
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--bleu);
    border-color: var(--bleu);
    color: #fff;
}
.btn-primary:hover {
    background: var(--bleu-accent);
    border-color: var(--bleu-accent);
    color: #fff;
}
.btn-secondary {
    background: var(--bleu-soft);
    border-color: transparent;
    color: var(--bleu);
}
.btn-secondary:hover {
    background: #d5e0ed;
    color: var(--bleu);
    border-color: transparent;
}
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--bleu); border-color: var(--bleu-accent); }
.btn-danger { color: var(--rouge); }
.btn-danger:hover {
    background: var(--rouge-soft);
    border-color: var(--rouge);
    color: var(--rouge);
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; min-height: 36px; }
.btn-lg { padding: 0.9rem 1.45rem; font-size: 1rem; }
.btn:disabled, .btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

/* ——— Alerts ——— */
.alert {
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
    border: 1px solid transparent;
    font-size: 0.92rem;
}
.alert-success { background: var(--vert-soft); color: #2a7a50; border-color: #c5ebd6; }
.alert-error { background: var(--rouge-soft); color: var(--rouge); border-color: #f0c4c4; }
.alert-warning { background: var(--orange-soft); color: #9a6b1a; border-color: #f5dfb5; }
.error-list { margin-left: 1.1rem; }

/* ——— Tables ——— */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
}
.data-table, .items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    min-width: 520px;
}
.items-table { min-width: 480px; }
.data-table th, .items-table th {
    text-align: left;
    font-family: var(--display);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table td, .items-table td {
    padding: 0.8rem 0.75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.empty { color: var(--muted); padding: 1rem 0; }
.hidden { display: none !important; }

/* ——— Stats dashboard ——— */
.dash-section {
    margin-bottom: 0.35rem;
}
.dash-section-title {
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.02em;
    margin: 0 0 0.65rem;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    text-decoration: none;
    color: inherit;
    display: block;
}
a.stat-card:hover {
    text-decoration: none;
    color: inherit;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.stat-card.accent {
    background: var(--brand);
    border-color: transparent;
    color: #fff;
}
.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
    font-weight: 500;
}
.stat-card.accent .stat-label { color: rgba(255, 255, 255, 0.72); }
.stat-value {
    font-family: var(--display);
    font-size: clamp(1.25rem, 2.2vw, 1.55rem);
    font-weight: 600;
    color: var(--bleu);
    letter-spacing: -0.02em;
    word-break: break-word;
}
.stat-card.accent .stat-value { color: #fff; }
.stat-meta {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

/* ——— Client mode ——— */
.client-mode-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.radio-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.95rem;
    min-height: var(--touch);
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    background: #fff;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.radio-pill:has(input:checked) {
    background: var(--bleu-soft);
    border-color: var(--bleu-accent);
    color: var(--bleu);
}

/* ——— Summary ——— */
.summary-card .summary-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}
.summary-card .summary-row.total {
    border-bottom: none;
    margin-top: 0.35rem;
    font-size: 1.1rem;
    color: var(--vert);
    font-family: var(--display);
}

.logo-current {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}
.logo-current img {
    max-height: 48px;
    max-width: 120px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px;
    background: #fff;
}

/* ——— Status badges ——— */
.status {
    display: inline-block;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.status-brouillon { background: #E8ECF0; color: var(--muted); }
.status-envoyé,
.status-envoyée { background: var(--orange-soft); color: #9a6b1a; }
.status-accepté { background: var(--vert-soft); color: var(--vert); }
.status-refusé { background: var(--rouge-soft); color: var(--rouge); }
.status-payée { background: var(--vert-soft); color: var(--vert); }
.status-annulée,
.status-annulé { background: var(--rouge-soft); color: var(--rouge); }
.status-confirmé,
.status-validé { background: #E8F0FE; color: #1a56a8; }
.status-en_preparation { background: var(--orange-soft); color: #9a6b1a; }
.status-partiellement_livré { background: #FFF4E0; color: #9a6b1a; }
.status-livré { background: var(--vert-soft); color: var(--vert); }

.status-select {
    border-radius: 999px;
    padding: 0.35rem 0.65rem;
    min-height: 36px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--line);
    background: #fff;
    cursor: pointer;
}
.inline-statut { display: inline; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}
.notes-block {
    background: var(--surface-2);
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
}

.btn-delete-row {
    background: transparent;
    border: none;
    color: var(--rouge);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.45rem;
    min-width: var(--touch);
    min-height: var(--touch);
    line-height: 1;
    border-radius: var(--radius-sm);
}
.btn-delete-row:hover { opacity: 0.75; background: var(--rouge-soft); }

.amount-positive, .line-total-cell .line-total {
    color: var(--vert);
    font-weight: 600;
}

/* ——— Login / public ——— */
.login-page, .public-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.25rem, env(safe-area-inset-bottom));
    background:
        radial-gradient(ellipse 80% 50% at 10% 0%, rgba(251, 234, 228, 0.7), transparent 55%),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(232, 238, 245, 0.9), transparent 50%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    margin: 0;
    box-shadow: var(--shadow-lg);
}

.login-subtitle {
    text-align: center;
    color: var(--color-muted, #64748b);
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
}

.login-footer-link {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.9rem;
    color: var(--color-muted, #64748b);
}

.login-footer-link a {
    color: var(--color-primary, #111111);
    font-weight: 600;
    text-decoration: none;
}

.login-footer-link a:hover {
    text-decoration: underline;
}

.login-brand {
    margin-bottom: 1.5rem;
    color: var(--ink);
    justify-content: center;
}
.login-brand .brand-mark { color: #fff; }
.login-brand small { color: var(--muted); }
.public-wrap { width: 100%; max-width: 900px; }
.public-title {
    font-family: var(--display);
    color: var(--bleu);
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    margin-bottom: 0.35rem;
}

.pdf-preview-frame {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #e8ecef;
    min-height: 50vh;
}
.pdf-preview-frame iframe {
    width: 100%;
    height: min(75vh, 900px);
    border: 0;
    display: block;
}

/* ============================================================
   TABLETTE — ≤ 1099px
   ============================================================ */
@media (max-width: 1099px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(20, 40, 70, 0.45);
        z-index: 45;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }
    body.nav-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(300px, 88vw);
        height: 100vh;
        height: 100dvh;
        transform: translateX(-105%);
        transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
        box-shadow: var(--shadow-lg);
        z-index: 50;
        padding-top: max(1.25rem, env(safe-area-inset-top));
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    }
    body.nav-open .sidebar {
        transform: translateX(0);
    }
    body.nav-open {
        overflow: hidden;
    }

    .sidebar-top {
        margin-bottom: 1.25rem;
    }
    .brand-logo {
        height: 40px;
    }

    .sidebar-close { display: grid; place-items: center; }
    .nav-toggle { display: inline-flex; }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .form-grid-3,
    .form-grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .layout-2col {
        grid-template-columns: 1fr;
    }

    .pdf-preview-frame iframe {
        height: 55vh;
    }
}

/* ============================================================
   MOBILE — ≤ 767px
   ============================================================ */
@media (max-width: 767px) {
    body { font-size: 14.5px; }

    .topbar {
        padding-top: max(0.85rem, env(safe-area-inset-top));
        padding-bottom: 0.75rem;
        border-bottom-color: var(--line);
        align-items: flex-start;
        flex-wrap: nowrap;
        gap: 0.65rem;
    }

    .topbar-right {
        align-items: center;
        padding-top: 0.15rem;
    }

    .create-menu-label {
        display: none;
    }
    .create-menu-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 0.45rem 0.65rem;
    }
    .create-menu-caret {
        display: none;
    }
    .create-menu-panel {
        right: 0;
        left: auto;
        min-width: 15.5rem;
        max-width: calc(100vw - 1.25rem);
    }
    .create-menu-panel a {
        white-space: normal;
        padding: 0.75rem 0.85rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .stats-grid,
    .form-grid-2,
    .form-grid-3,
    .form-grid-4,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .stat-card:hover { transform: none; }

    .field-narrow { max-width: none; }

    .card-header-row {
        flex-direction: column;
        align-items: stretch;
    }
    .card-header-row .form-actions,
    .card-header-row > .btn {
        width: 100%;
    }
    .card-header-row .form-actions .btn {
        flex: 1 1 auto;
    }

    .form-actions {
        flex-direction: column;
    }
    .form-actions .btn {
        width: 100%;
    }

    .quick-actions .btn {
        flex: 1 1 calc(50% - 0.35rem);
        min-width: 140px;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }
    .actions .btn,
    .actions form {
        width: 100%;
    }
    .actions form .btn {
        width: 100%;
    }

    .client-mode-toggle {
        flex-direction: column;
    }
    .radio-pill {
        width: 100%;
        justify-content: flex-start;
    }

    .data-table, .items-table {
        font-size: 0.85rem;
    }
    .data-table td, .items-table td,
    .data-table th, .items-table th {
        padding: 0.65rem 0.55rem;
    }

    .field-label-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .pdf-preview-frame {
        min-height: 40vh;
        margin: 0 -0.35rem;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }
    .pdf-preview-frame iframe {
        height: 50vh;
    }

    .login-card {
        padding: 1.25rem !important;
    }

    .app-footer {
        text-align: center;
        font-size: 0.75rem;
        line-height: 1.45;
    }
}

/* ============================================================
   TRÈS PETIT — ≤ 380px
   ============================================================ */
@media (max-width: 380px) {
    .quick-actions .btn {
        flex: 1 1 100%;
    }
    .badge-devise {
        font-size: 0.68rem;
        padding: 0.3rem 0.55rem;
    }
    .create-menu-panel {
        position: fixed;
        right: 0.75rem;
        left: 0.75rem;
        top: auto;
        width: auto;
        min-width: 0;
        max-width: none;
    }
}

/* ——— Ma marque / charte graphique ——— */
.brand-logo-preview img {
    max-height: 80px;
    max-width: 220px;
    object-fit: contain;
}

.brand-color-inputs {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-color-inputs input[type="color"] {
    width: 3rem;
    height: 2.5rem;
    padding: 0.15rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: #fff;
}

.brand-color-inputs input[type="text"] {
    flex: 1;
    max-width: 8rem;
    font-family: ui-monospace, monospace;
    text-transform: uppercase;
}

.brand-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.brand-swatch {
    width: 2rem;
    height: 2rem;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--border);
    padding: 0;
}

.brand-swatch:hover {
    transform: scale(1.08);
}

.brand-swatch-inline {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 0.35rem;
    box-shadow: 0 0 0 1px var(--line);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

@media (min-width: 960px) {
    .template-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 640px) {
    .template-grid {
        grid-template-columns: 1fr;
    }
}

.template-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
}

.template-card:hover {
    border-color: var(--bleu-accent);
}

.template-card.is-selected {
    border-color: var(--bleu);
    box-shadow: 0 0 0 3px var(--bleu-soft);
}

.template-label {
    font-size: 1rem;
    color: var(--ink);
}

.template-desc {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.4;
}

.template-preview {
    aspect-ratio: 3 / 4;
    background: #fff;
    border: 1px solid #E6EBF0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.tp-header {
    height: 18%;
    background: var(--tpl-dark, #0B1F3A);
}

.template-preview-modern .tp-header {
    height: 4%;
    background: var(--tpl-primary, #111111);
}

.template-preview-classic .tp-header {
    display: none;
}

.tp-body {
    padding: 8%;
}

.tp-line {
    height: 6px;
    background: #E6EBF0;
    border-radius: 2px;
    margin-bottom: 6px;
}

.tp-line-short {
    width: 55%;
}

.tp-table {
    margin-top: 10%;
    border: 1px solid #E6EBF0;
    border-radius: 2px;
    overflow: hidden;
}

.template-preview-classic .tp-table {
    border-color: #333;
}

.tp-row {
    height: 10px;
    background: #fff;
    border-bottom: 1px solid #EEF1F4;
}

.tp-row-head {
    height: 12px;
    background: var(--tpl-primary, #1E4D8C);
}

.template-preview-corporate .tp-row-head {
    background: var(--tpl-primary, #1E4D8C);
    opacity: 0.85;
}

.template-preview-classic .tp-row-head {
    background: #F0F0F0;
    border-bottom: 2px solid var(--tpl-primary, #111111);
}

.tp-row-alt {
    background: var(--tpl-soft, #F4F6F8);
}

.tp-total {
    margin-top: 10%;
    margin-left: 45%;
    height: 14px;
    background: var(--tpl-light, #E8F1FB);
    border-radius: 2px;
}

.template-preview-modern .tp-total {
    background: var(--tpl-primary, #111111);
    opacity: 0.9;
}

.template-preview-wave .tp-header {
    height: 26%;
    background: #000;
    position: relative;
    overflow: hidden;
}

.template-preview-wave .tp-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--tpl-primary, #7FB88A);
    clip-path: polygon(0 0, 100% 0, 100% 38%, 72% 62%, 48% 48%, 22% 58%, 0 46%);
}

.template-preview-wave .tp-footer-wave {
    height: 18%;
    margin-top: auto;
    background: #000;
    position: relative;
    overflow: hidden;
}

.template-preview-wave {
    display: flex;
    flex-direction: column;
}

.template-preview-wave .tp-body {
    flex: 1;
}

.template-preview-wave .tp-footer-wave::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--tpl-primary, #7FB88A);
    clip-path: polygon(0 100%, 100% 100%, 100% 62%, 72% 38%, 48% 52%, 22% 42%, 0 54%);
}

.template-preview-wave .tp-row-head {
    background: #000;
}

.template-preview-wave .tp-total {
    border: 1px solid #000;
    background: #fff;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
