/* ============================================================
   Pas à Pas – Factures
   CSS natif – dark/light mode – responsive
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables – Light ────────────────────────────────────── */
:root,
[data-theme="light"] {
    --bg:           #f5f4f0;
    --bg-card:      #ffffff;
    --bg-hover:     #f0ede8;
    --border:       #e2ddd6;
    --border-focus: #5a7a6a;

    --text:         #1a1a18;
    --text-muted:   #6b6660;
    --text-light:   #9a9490;

    --accent:       #4a7060;     /* vert sauge */
    --accent-hover: #3a5c4e;
    --accent-light: #e8f0ec;

    --danger:       #c0392b;
    --danger-light: #fbeae8;
    --warning:      #e67e22;
    --warning-light:#fef3e2;
    --success:      #27ae60;
    --success-light:#e8f8ee;
    --info-light:   #e8f2fb;

    --shadow-sm:    0 1px 3px rgba(0,0,0,.06);
    --shadow:       0 2px 8px rgba(0,0,0,.08);
    --shadow-md:    0 4px 16px rgba(0,0,0,.10);

    --radius:       10px;
    --radius-sm:    6px;

    --font:         'DM Sans', sans-serif;
    --font-mono:    'DM Mono', monospace;
    --header-h:     60px;
}

/* ── Variables – Dark ─────────────────────────────────────── */
[data-theme="dark"] {
    --bg:           #141412;
    --bg-card:      #1e1e1b;
    --bg-hover:     #252520;
    --border:       #2e2e28;
    --border-focus: #7aaa8a;

    --text:         #e8e6e0;
    --text-muted:   #888278;
    --text-light:   #555048;

    --accent:       #7aaa8a;
    --accent-hover: #90bfa0;
    --accent-light: #1e2e24;

    --danger:       #e05a4a;
    --danger-light: #2a1816;
    --warning:      #f0943a;
    --warning-light:#2a2010;
    --success:      #4abf74;
    --success-light:#182a20;
    --info-light:   #141e2a;

    --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
    --shadow:       0 2px 8px rgba(0,0,0,.4);
    --shadow-md:    0 4px 16px rgba(0,0,0,.5);
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background .2s, color .2s;
}

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

img { max-width: 100%; display: block; }

/* ── Typography ───────────────────────────────────────────── */
h1 { font-size: 1.8rem; font-weight: 600; letter-spacing: -.02em; }
h2 { font-size: 1.35rem; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 1.1rem;  font-weight: 500; }

.page-title {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.5rem;
}
.page-title h1 { margin: 0; }

/* ── Header ───────────────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    height: var(--header-h);
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 2rem;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: var(--text);
    flex-shrink: 0;
}
.logo-mark {
    font-family: var(--font-mono);
    font-size: .9rem;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    padding: .25rem .5rem;
    border-radius: var(--radius-sm);
    letter-spacing: -.02em;
}
.logo-text {
    font-size: .95rem;
    font-weight: 600;
    line-height: 1.2;
}
.logo-text em {
    display: block;
    font-style: normal;
    font-weight: 300;
    font-size: .8rem;
    color: var(--text-muted);
}

.main-nav {
    display: flex;
    align-items: center;
    gap: .25rem;
    flex: 1;
}

.nav-link {
    padding: .4rem .75rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 400;
    color: var(--text-muted);
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-link.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }

.header-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-left: auto;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, color .15s, opacity .15s;
    text-decoration: none;
    line-height: 1;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: .4rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
    line-height: 1;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

/* Dark/light toggle */
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: none; }

/* Burger menu */
.btn-menu { flex-direction: column; gap: 4px; display: none; }
.btn-menu span { display: block; width: 20px; height: 2px; background: var(--text-muted); border-radius: 2px; transition: .2s; }

/* ── Main content ─────────────────────────────────────────── */
.main-content {
    flex: 1;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.25rem 1.5rem; }
.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.card-header h2 { margin: 0; font-size: 1rem; }

/* ── Dashboard stats ──────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 600; letter-spacing: -.02em; margin: .25rem 0; }
.stat-sub   { font-size: .8rem; color: var(--text-muted); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
thead th {
    text-align: left;
    padding: .65rem 1rem;
    font-weight: 500;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted-asc::after  { content: ' ▲'; font-size: .65rem; }
thead th.sorted-desc::after { content: ' ▼'; font-size: .65rem; }

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td { padding: .75rem 1rem; vertical-align: middle; }

.td-actions { display: flex; gap: .35rem; }

/* ── Badges statut ────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 500;
    line-height: 1;
}
.badge-brouillon { background: var(--bg-hover); color: var(--text-muted); }
.badge-envoyee   { background: var(--info-light); color: #2376b8; }
.badge-payee     { background: var(--success-light); color: var(--success); }
.badge-partielle { background: var(--warning-light); color: var(--warning); }
.badge-annulee   { background: var(--danger-light); color: var(--danger); }

/* ── Forms ────────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem 1.5rem;
}
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full-width { grid-column: 1 / -1; }

label {
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
    padding: .55rem .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: .9rem;
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(90,122,106,.15);
}
textarea { resize: vertical; min-height: 80px; }

.form-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    cursor: pointer;
}
.form-check input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: .75rem;
    align-items: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* ── Lignes de facture ────────────────────────────────────── */
.lignes-table th, .lignes-table td { padding: .5rem .6rem; }
.lignes-table input[type="text"],
.lignes-table input[type="number"],
.lignes-table select { padding: .4rem .6rem; font-size: .85rem; }
.lignes-table .btn-icon { color: var(--danger); }
.lignes-totals { text-align: right; margin-top: 1rem; font-size: .9rem; }
.lignes-totals .total-ht  { color: var(--text-muted); margin-bottom: .25rem; }
.lignes-totals .total-ttc { font-size: 1.1rem; font-weight: 600; }

/* ── Flash messages ───────────────────────────────────────── */
.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .8rem 1.2rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: .9rem;
    font-weight: 400;
}
.flash-success { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.flash-error   { background: var(--danger-light);  color: var(--danger);  border: 1px solid var(--danger); }
.flash-info    { background: var(--info-light);    color: #2376b8;        border: 1px solid #a0c4e8; }
.flash-close   { background: none; border: none; cursor: pointer; color: inherit; font-size: 1rem; line-height: 1; }

/* ── Alerts ───────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .875rem; margin-bottom: 1rem; }
.alert-error { background: var(--danger-light); color: var(--danger); }

/* ── Toolbar (search + actions) ───────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.toolbar-left  { display: flex; gap: .5rem; flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: .5rem; flex-wrap: wrap; }

.search-input {
    padding: .5rem .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font-family: var(--font);
    font-size: .875rem;
    min-width: 200px;
}
.search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(90,122,106,.15);
}

/* ── Pagination ───────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: .35rem;
    justify-content: center;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    display: inline-block;
    padding: .35rem .65rem;
    border-radius: var(--radius-sm);
    font-size: .8rem;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.pagination a:hover { background: var(--bg-hover); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Login page ───────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}
.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
}
.login-box h1 {
    font-size: 1.3rem;
    text-align: center;
    margin-bottom: 1.75rem;
    color: var(--text);
}
.login-box .form-group { margin-bottom: .9rem; }
.login-box .btn-full   { margin-top: 1.25rem; padding: .7rem; }

/* ── Facture view (aperçu) ────────────────────────────────── */
.facture-preview {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    max-width: 820px;
}
.facture-head {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
}
.facture-num { font-size: 1.5rem; font-weight: 600; color: var(--accent); }
.facture-date { font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }
.adresse-block { font-size: .875rem; line-height: 1.8; }
.adresse-block strong { font-weight: 600; }
.facture-lignes-wrap { margin: 2rem 0; }

/* ── Import SG ────────────────────────────────────────────── */
.sg-row-pointee { background: var(--success-light) !important; }
.sg-montant-credit { color: var(--success); font-weight: 500; }
.sg-montant-debit  { color: var(--danger); }

/* ── Footer ───────────────────────────────────────────────── */
.site-footer {
    border-top: 1px solid var(--border);
    text-align: center;
    padding: 1rem 1.5rem;
    font-size: .78rem;
    color: var(--text-light);
}

/* ── Utilities ────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: .8rem; }
.mono        { font-family: var(--font-mono); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { display: flex; gap: .5rem; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ── Charts dashboard ─────────────────────────────────────── */
canvas { max-width: 100%; }

@media (max-width: 768px) {
    /* Charts en colonne sur mobile */
    div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .main-nav {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        position: absolute;
        top: var(--header-h);
        left: 0; right: 0;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        padding: .75rem 1rem;
        box-shadow: var(--shadow);
        z-index: 99;
    }
    .main-nav.open { display: flex; }
    .btn-menu { display: flex; }

    .site-header { position: relative; }
    .header-inner { flex-wrap: wrap; }

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

    .facture-preview { padding: 1.25rem; }
    .facture-head { flex-direction: column; gap: 1rem; }

    h1 { font-size: 1.4rem; }

    .btn-outline.btn-sm span { display: none; }

    tbody td, thead th { padding: .55rem .6rem; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-left, .toolbar-right { width: 100%; }
}

@media (max-width: 480px) {
    .main-content { padding: 1.25rem 1rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .login-box { padding: 1.75rem 1.25rem; }
}
