/* ============================================================
   QR Facture — Design System
   Police: DM Sans (Google Fonts)
   Couleur primaire: #1a56db (bleu Infomaniak)
   ============================================================ */

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

:root {
    --primary: #1a56db;
    --primary-dark: #1045b8;
    --primary-light: #e8f0fe;
    --success: #0f9f6e;
    --danger: #e02424;
    --warning: #d97706;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-400: #9ca3af;
    --gray-600: #4b5563;
    --gray-800: #1f2937;
    --sidebar-w: 240px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 14px;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.5;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    display: flex; flex-direction: column;
    z-index: 100;
}

.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 700; font-size: 15px; color: var(--primary);
}
.sidebar-logo img { width: 28px; height: 28px; object-fit: contain; }

.sidebar-nav { flex: 1; padding: 12px 10px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius);
    color: var(--gray-600); text-decoration: none;
    font-weight: 500; transition: all .15s;
    margin-bottom: 2px;
}
.nav-item svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }
.nav-item:hover { background: var(--gray-100); color: var(--gray-800); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }

.sidebar-user {
    padding: 14px 18px;
    border-top: 1px solid var(--gray-200);
    font-size: 13px; color: var(--gray-600);
    display: flex; flex-direction: column; gap: 4px;
}
.logout-btn { color: var(--danger); text-decoration: none; font-size: 12px; }
.logout-btn:hover { text-decoration: underline; }

/* ── Main content ──────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    padding: 24px;
    min-height: 100vh;
}

/* ── Page header ───────────────────────────────────────────── */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card h2 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 8px 14px; border-radius: 6px; font-size: 13px;
    font-weight: 500; cursor: pointer; border: none;
    text-decoration: none; transition: all .15s; line-height: 1;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger   { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-blue     { background: #dbeafe; color: var(--primary); }
.btn-blue:hover { background: #bfdbfe; }
.btn-sm       { padding: 5px 10px; font-size: 12px; }
.btn-full     { width: 100%; justify-content: center; }
.btn-group    { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Badges ────────────────────────────────────────────────── */
.badge { padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-gray  { background: var(--gray-100); color: var(--gray-600); }
.badge-blue  { background: #dbeafe; color: #1e40af; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red   { background: #fee2e2; color: #991b1b; }
.badge-dark  { background: var(--gray-800); color: #fff; }

/* ── Flash messages ────────────────────────────────────────── */
.flash { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500; }
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Stats grid ────────────────────────────────────────────── */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 20px;
}
.stat-card {
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 18px 20px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: var(--shadow);
}
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; }
.stat-icon--blue   { background: #dbeafe; color: var(--primary); }
.stat-icon--indigo { background: #e0e7ff; color: #4338ca; }
.stat-icon--green  { background: #d1fae5; color: var(--success); }
.stat-icon--amber  { background: #fef3c7; color: var(--warning); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--gray-400); margin-top: 2px; }
.stat-label small { display: block; color: var(--gray-600); }

.dashboard-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ── Tables ────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.table th { text-align: left; padding: 8px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-400); border-bottom: 2px solid var(--gray-200); }
.table td { padding: 10px 10px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }
.table a { color: var(--primary); text-decoration: none; }
.table a:hover { text-decoration: underline; }
.actions { white-space: nowrap; }
.actions .btn { margin-right: 4px; }
.empty { text-align: center; color: var(--gray-400); padding: 30px !important; }
.text-red { color: var(--danger); }

/* ── Search bar ────────────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input, .search-bar select {
    padding: 8px 12px; border: 1px solid var(--gray-200);
    border-radius: 6px; font-size: 13px; background: #fff;
}
.search-bar input { flex: 1; min-width: 200px; }

/* ── Pagination ────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }
.pagination a { padding: 6px 12px; border: 1px solid var(--gray-200); border-radius: 6px; color: var(--gray-600); text-decoration: none; font-size: 13px; }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination a:hover:not(.active) { background: var(--gray-100); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-card { max-width: 820px; }
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--gray-600); }
.form-group input, .form-group select, .form-group textarea {
    padding: 8px 11px; border: 1px solid var(--gray-200);
    border-radius: 6px; font-size: 14px; background: #fff;
    font-family: inherit; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 10px; padding-top: 8px; }
.req { color: var(--danger); }
.hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--gray-600); margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--gray-200); }

/* ── Line items ────────────────────────────────────────────── */
/* Grille lignes : poignée | description | qté | prix | rabais | total | ✕ */
.line-header { display: grid; grid-template-columns: 20px 1fr 64px 110px 60px 100px 32px; gap: 6px; padding: 6px 0; font-size: 11px; text-transform: uppercase; color: var(--gray-400); font-weight: 600; align-items: center; }
.line-header span:nth-child(3) { text-align: right; }
.line-header span:nth-child(4) { text-align: right; }
.line-header span:nth-child(5) { text-align: center; }
.line-header span:nth-child(6) { text-align: right; }
.line-item { display: grid; grid-template-columns: 20px 1fr 64px 110px 60px 100px 32px; gap: 6px; margin-bottom: 0; align-items: center; }
.line-item input { padding: 6px 8px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 13px; width: 100%; box-sizing: border-box; }
.line-item .qty   { text-align: right; }
.line-item .price { text-align: right; }
.line-total { font-weight: 600; font-size: 13px; text-align: right; color: var(--gray-800); white-space: nowrap; }

/* ── Totals box ────────────────────────────────────────────── */
.totals-box { margin: 16px 0; padding: 16px; background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius); max-width: 340px; margin-left: auto; }
.total-row { font-size: 13px; }
.total-final { font-size: 16px; font-weight: 700; padding-top: 10px; border-top: 2px solid var(--gray-200); color: var(--primary); }

/* ── Invoice preview ───────────────────────────────────────── */
.invoice-preview { max-width: 820px; }
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; gap: 20px; }
.inv-from { font-size: 13px; line-height: 1.8; color: var(--gray-600); }
.inv-from strong { font-size: 15px; color: var(--gray-800); display: block; }
.inv-meta { text-align: right; font-size: 13px; }
.inv-meta div { display: flex; gap: 12px; justify-content: flex-end; margin-bottom: 4px; }
.inv-meta span { color: var(--gray-400); }
.inv-client { background: var(--gray-50); border-left: 3px solid var(--primary); padding: 16px 20px; margin-bottom: 24px; font-size: 13px; line-height: 1.9; }
.inv-table tfoot tr td { padding: 8px 10px; font-size: 13px; }
.inv-table tfoot .total-row td { font-size: 16px; font-weight: 700; color: var(--primary); }
.inv-notes { margin-top: 20px; font-size: 13px; color: var(--gray-600); padding: 12px; background: var(--gray-50); border-radius: var(--radius); }
.inv-qr { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--gray-200); text-align: center; }
.inv-qr h4 { font-size: 13px; color: var(--gray-600); margin-bottom: 10px; }
.iban-display { font-family: 'DM Mono', monospace; font-size: 13px; color: var(--gray-600); margin-top: 8px; }

/* ── Login ─────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--gray-50); }
.login-card { background: #fff; border: 1px solid var(--gray-200); border-radius: 12px; padding: 36px; width: 100%; max-width: 400px; box-shadow: var(--shadow-md); }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--primary); }
.login-subtitle { font-size: 13px; color: var(--gray-400); margin-bottom: 24px; }

/* ============================================================
   RESPONSIVE MOBILE — breakpoints 768px et 480px
   ============================================================ */

/* ── Bouton hamburger (mobile only) ───────────────────────── */
.hamburger {
    display: none;
    position: fixed; top: 12px; left: 12px; z-index: 300;
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: 8px; padding: 8px; cursor: pointer;
    box-shadow: var(--shadow);
}
.hamburger svg { width: 22px; height: 22px; stroke: var(--gray-800); fill: none; stroke-width: 2; display: block; }

/* ── Overlay fond sombre quand sidebar ouverte ─────────────── */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 150;
    background: rgba(0,0,0,.4);
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ── Tablette (≤ 900px) ─────────────────────────────────────── */
@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-grid     { grid-template-columns: repeat(2, 1fr); }
}

/* ── Mobile (≤ 768px) ───────────────────────────────────────── */
@media (max-width: 768px) {

    /* Sidebar cachée par défaut, glisse depuis la gauche */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 200;
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }

    /* Bouton hamburger visible */
    .hamburger { display: flex; }

    /* Contenu prend toute la largeur */
    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 56px; /* espace pour le hamburger */
    }

    /* Page header empile titre + bouton */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .page-header h1 { font-size: 18px; }

    /* Boutons pleine largeur dans page-header */
    .page-header .btn,
    .page-header .btn-group { width: 100%; }
    .page-header .btn-group { flex-direction: column; }
    .page-header .btn-group .btn { justify-content: center; }

    /* Stats en 2 colonnes */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card  { padding: 14px; }
    .stat-value { font-size: 18px; }

    /* Tableaux : scroll horizontal */
    .card { padding: 14px; overflow-x: auto; }
    .table { min-width: 540px; }
    .table th, .table td { padding: 8px 8px; font-size: 12px; }

    /* Cacher les colonnes moins importantes sur mobile */
    .col-hide-mobile { display: none; }

    /* Barre de recherche pleine largeur */
    .search-bar { flex-direction: column; }
    .search-bar input,
    .search-bar select,
    .search-bar .btn { width: 100%; }

    /* Formulaires */
    .form-row { grid-template-columns: 1fr; }
    .form-card { max-width: 100%; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { justify-content: center; }

    /* Lignes de facture : scroll horizontal */
    .line-header,
    .line-item { min-width: 480px; }

    /* Totals pleine largeur */
    .totals-box { max-width: 100%; }

    /* Invoice preview */
    .inv-header { flex-direction: column; gap: 12px; }
    .inv-meta   { text-align: left; }
    .inv-meta div { justify-content: flex-start; }
    .invoice-preview { max-width: 100%; }

    /* Boutons d'action facture empilés */
    .btn-group { flex-wrap: wrap; }

    /* Login card */
    .login-card { padding: 24px 18px; margin: 16px; }
}

/* ── Petit mobile (≤ 480px) ─────────────────────────────────── */
@media (max-width: 480px) {
    .stats-grid  { grid-template-columns: 1fr; }
    .stat-card   { padding: 12px; }
    .main-content { padding: 12px; padding-top: 52px; }
    .page-header h1 { font-size: 16px; }
    .card        { padding: 12px; }

    /* Tableau scroll, colonnes encore plus compactes */
    .table th, .table td { padding: 6px 6px; font-size: 11px; }

    /* Badges plus petits */
    .badge { padding: 2px 6px; font-size: 10px; }

    /* Boutons plus compacts */
    .btn { padding: 8px 12px; font-size: 12px; }
    .btn-sm { padding: 5px 8px; font-size: 11px; }
}

/* ── Sidebar section title ──────────────────────────────────── */
.nav-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--gray-400);
    padding: 12px 12px 4px;
    margin-top: 4px;
}
