/* =====================================================================
   Kodelis Balance — charte graphique (CLAUDE.md §9)
   Thème crème chaud, accent terracotta. Clair (défaut) + sombre (html.dark).
   Aucun framework CSS. Police : Public Sans (chargée dans <head>).
   ===================================================================== */

/* ---------- 9.2 Variables — thème clair (défaut) ---------- */
:root {
    /* Fonds */
    --bg-page:       #FDF8F3;   /* fond général crème chaud */
    --bg-surface:    #F5EDE0;   /* barres, en-têtes de tableau */
    --bg-card:       #FFFFFF;   /* cartes, tableaux */
    --bg-border:     #E8D5B8;   /* bordure douce */
    --sidebar-bg:    #2C2520;   /* sidebar : toujours sombre (clair & sombre) */

    /* Accent principal */
    --accent:        #C47A3A;
    --accent-light:  #F0E4D0;
    --accent-border: rgba(196,122,58,0.25);

    /* Sémantique */
    --credit:        #2D7D5A;
    --credit-light:  #E4F2EB;
    --debit:         #C0392B;
    --debit-light:   #FCECEA;
    --warn:          #C47A3A;
    --warn-light:    #FFF3E0;
    --info:          #2D5F9A;
    --info-light:    #EEF4FF;

    /* Texte */
    --text-primary:  #2C2520;
    --text-muted:    #8A7E77;
    --text-light:    #B0A49C;

    /* Composants */
    --border:        0.5px solid var(--bg-border);
    --radius-sm:     6px;
    --radius-md:     10px;
    --radius-lg:     14px;
    --radius-pill:   20px;
}

/* ---------- 9.3 Variables — thème sombre ---------- */
html.dark {
    --bg-page:       #1E1A17;
    --bg-surface:    #2A2420;
    --bg-card:       #312B27;
    --bg-border:     #4A3F37;

    --accent:        #D4894A;
    --accent-light:  #3D2E1F;
    --accent-border: rgba(212,137,74,0.3);

    --credit:        #4CAF82;
    --credit-light:  #1A3328;
    --debit:         #E05C50;
    --debit-light:   #3D1A18;
    --warn:          #D4894A;
    --warn-light:    #3D2E1F;
    --info:          #5B8FD4;
    --info-light:    #1A2840;

    --text-primary:  #F0E8DF;
    --text-muted:    #9A8E86;
    --text-light:    #6A5E58;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { color-scheme: light; }
html.dark { color-scheme: dark; }

body {
    margin: 0;
    font-family: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;       /* corps de texte (9.4) */
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

h1, h2, h3 { font-weight: 500; color: var(--text-primary); }

/* ---------- 9.1.1 Layout global : sidebar fixe + contenu ---------- */
.app-layout {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 220px;
    min-width: 220px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
}
.main-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-page);
    display: flex;
    flex-direction: column;
}
.page-content {
    padding: 24px;
    flex: 1;
}

/* ---------- 9.1.2 Sidebar (toujours sombre, identique clair/sombre) ---------- */
.sidebar-header { padding: 18px 18px 14px; }
.sidebar-brand {
    display: block;
    font-size: 15px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
}
.sidebar-subtitle {
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    margin-top: 2px;
}
.sidebar-nav { flex: 1; padding: 4px 10px 10px; }
.section-label {
    color: rgba(255,255,255,0.25);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 14px 10px 6px;
}
.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    margin: 1px 0;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    font-size: 13px;
    transition: background .15s, color .15s;
}
.nav-item:hover:not(.active) {
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.8);
}
.nav-item.active {
    background: rgba(196,122,58,0.15);
    color: #C47A3A;
    font-weight: 500;
}
.nav-badge {
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    padding: 3px 7px;
    border-radius: var(--radius-pill);
    color: #fff;
}
.nav-badge-danger { background: var(--debit); }
.nav-badge-warn   { background: var(--accent); }

/* Pied de sidebar : avatar + identité + toggle thème */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
}
.sidebar-avatar {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
}
.sidebar-identity { min-width: 0; line-height: 1.25; }
.sidebar-name {
    font-size: 13px;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-role { font-size: 11px; color: rgba(255,255,255,0.4); }

/* ---------- Barre mobile (header_bar.php) + overlay ---------- */
.header-bar { display: none; }
.burger {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.header-bar-brand {
    font-size: 15px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
}
.sidebar-backdrop { display: none; }

/* ---------- Toggle thème (switch pill, dans la sidebar sombre) ---------- */
.theme-switch {
    position: relative;
    width: 46px;
    height: 24px;
    border-radius: var(--radius-pill);
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.18);
    cursor: pointer;
    padding: 0;
    flex: none;
}
.theme-switch .theme-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    line-height: 1;
}
.theme-icon-light { left: 6px; }   /* lune : visible en clair (=> passer en sombre) */
.theme-icon-dark  { right: 6px; }  /* soleil : visible en sombre (=> passer en clair) */
.theme-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    transition: transform .2s ease;
}
html.dark .theme-switch::after { transform: translateX(22px); }
html:not(.dark) .theme-icon-dark { display: none; }
html.dark .theme-icon-light { display: none; }

/* ---------- Contenu ---------- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; font-weight: 500; margin: 0; }

.card {
    background: var(--bg-card);
    border: var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 500; }
.card-narrow { max-width: 520px; }

/* ---------- Cartes métriques ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0;
    padding: 12px 14px;
}
.stat-label { font-size: 11px; color: var(--text-muted); }
.stat-value { font-size: 20px; font-weight: 500; color: var(--text-primary); }
.stat-value.warn { color: var(--warn); }
.stat-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.stat-link:hover { text-decoration: underline; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th, .table td {
    padding: 9px 12px;
    text-align: left;
    border-bottom: var(--border);
    vertical-align: middle;
}
.table thead th {
    background: var(--bg-surface);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
}
.table tbody tr:hover { background: var(--bg-surface); }
.table tfoot td { font-weight: 500; background: var(--bg-page); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.label-cell { max-width: 360px; }

/* Ligne « moyenne » / pied de balance */
.table-balance tfoot td { color: var(--text-muted); }

.table-preview td, .table-preview th { font-size: 12px; white-space: nowrap; }
.row-dup     { background: var(--warn-light) !important; }
.row-invalid { background: var(--debit-light) !important; color: var(--text-muted); }
.row-ignored { background: var(--bg-surface) !important; color: var(--text-muted); }
.row-inactive { opacity: .6; }

/* Avatars associés (cercle initiales) */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    background: var(--accent);
}

/* Écarts colorés */
.gap-credit  { color: var(--credit); font-weight: 500; }
.gap-deficit { color: var(--debit);  font-weight: 500; }
.gap-neutral { color: var(--text-muted); }

/* ---------- 9.5 Badges / pastilles ---------- */
.pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.pill-credit  { background: var(--credit-light); color: var(--credit); }
.pill-deficit { background: var(--debit-light);  color: var(--debit); }
.pill-warn    { background: var(--warn-light);   color: var(--warn); }
.pill-info    { background: var(--info-light);   color: var(--info); }
.pill-neutral { background: var(--bg-surface);   color: var(--text-muted); }

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-surface);
    color: var(--text-muted);
}
.tag-admin { background: var(--accent); color: #fff; }

.count-badge {
    background: var(--bg-surface);
    color: var(--text-muted);
    border-radius: var(--radius-pill);
    padding: 3px 12px;
    font-size: 12px;
    font-weight: 500;
}

/* ---------- 9.5 Formulaires ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; color: var(--text-muted); }
.field-inline { flex-direction: column; }
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-end;
}
.filters .grow, .inline-form .grow { flex: 1; min-width: 180px; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], select {
    width: 100%;
    padding: 7px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-card);
    border: var(--border);
    border-radius: var(--radius-sm);
}
input:focus, select:focus {
    outline: none;
    border: 1px solid var(--accent);
    box-shadow: 0 0 0 3px var(--accent-border);
}
input[type=file] { padding: 7px; font-size: 13px; }
select:disabled { background: var(--bg-surface); color: var(--text-light); }
::placeholder { color: var(--text-light); }

.inline-form, .inline { display: inline-flex; gap: 10px; align-items: flex-end; margin: 0; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions-cell { white-space: nowrap; }

/* ---------- 9.5 Boutons ---------- */
.btn {
    display: inline-block;
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.3;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    /* Secondaire par défaut */
    background: var(--bg-card);
    color: var(--text-primary);
    border: var(--border);
    transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; border: 1px solid transparent; }
.btn-danger  { background: var(--debit);  color: #fff; border: 1px solid transparent; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ---------- Messages flash ---------- */
.flash {
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid transparent;
}
.flash-success { background: var(--credit-light); color: var(--credit); }
.flash-error   { background: var(--debit-light);  color: var(--debit); }
.flash-info    { background: var(--info-light);   color: var(--info); }

/* ---------- Divers ---------- */
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.empty { text-align: center; color: var(--text-muted); padding: 24px; }
.summary-list { list-style: none; padding: 0; display: flex; gap: 24px; flex-wrap: wrap; }
.summary-list .warn { color: var(--warn); }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; }
code {
    background: var(--bg-surface);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.page-link {
    padding: 5px 12px;
    border: var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-card);
}
.page-link:hover { color: var(--text-primary); }
.page-link.is-active { background: var(--accent); color: #fff; border: 1px solid transparent; }

/* ---------- Pied de page ---------- */
.site-footer {
    border-top: var(--border);
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 12px;
    background: var(--bg-surface);
}

/* ---------- Page de connexion ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-page);
    padding: 20px;
}
.login-card {
    background: var(--bg-card);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 30px;
    width: 100%;
    max-width: 380px;
}
.login-title { margin: 0 0 4px; color: var(--accent); font-size: 20px; font-weight: 500; }
.login-subtitle { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }

/* ---------- Responsive (mobile < 768px, §9.1) ---------- */
@media (max-width: 768px) {
    /* Barre horizontale en haut avec logo + burger */
    .header-bar {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 14px;
        background: var(--bg-surface);
        border-bottom: var(--border);
        position: sticky;
        top: 0;
        z-index: 30;
    }
    /* Sidebar masquée par défaut, affichée en overlay */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,0.3);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    /* Voile derrière la sidebar ouverte */
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 40;
    }
    body.nav-open .sidebar-backdrop { display: block; }
    .page-content { padding: 16px; }
    .page-head h1 { font-size: 20px; }
}
