/* ==========================================================================
   HOP GRAPE Manager – design system
   ========================================================================== */

:root {
    --primary: #2D5F2D;
    --primary-hover: #244D24;
    --primary-dark: #1B3A1B;
    --primary-soft: #EAF3EA;
    --primary-ring: rgba(45, 95, 45, .22);
    --secondary: #6B2D8B;
    --secondary-soft: #F3EAF8;

    --bg: #F4F5F2;
    --surface: #FFFFFF;
    --surface-muted: #F8F9F7;
    --text: #1D2621;
    --text-muted: #5A655F;
    --text-subtle: #8A948F;
    --border: #E2E5E0;
    --border-strong: #C9CEC8;

    --success: #1E7A3C;  --success-soft: #E6F4EA;
    --danger: #B8322A;   --danger-soft: #FCEAE8;
    --warning: #9A5B00;  --warning-soft: #FFF3DC;
    --info: #1D5BA6;     --info-soft: #E7F0FB;
    --neutral: #5B6460;  --neutral-soft: #EEF0ED;
    --violet: #6B2D8B;   --violet-soft: #F3EAF8;
    --dark: #2B2F2D;     --dark-soft: #E4E6E4;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(20, 30, 25, .06);
    --shadow: 0 1px 3px rgba(20, 30, 25, .08), 0 4px 12px rgba(20, 30, 25, .04);
    --shadow-lg: 0 12px 32px rgba(20, 30, 25, .18);

    --sidebar-width: 248px;
    --topbar-height: 64px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
p { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
code { font-size: .85em; background: var(--neutral-soft); padding: .1em .35em; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-width);
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    background: var(--primary-dark);
    color: #DDE8DD;
    z-index: 40;
    transition: transform .2s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .75rem;
    height: var(--topbar-height);
    padding: 0 1.25rem;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark {
    width: 36px; height: 36px; flex: none;
    display: grid; place-items: center;
    background: #fff; border-radius: 9px;
}
.brand-mark img { width: 28px; height: 28px; }
.brand-name { font-weight: 700; letter-spacing: .02em; line-height: 1.1; }
.brand-name small { display: block; font-weight: 500; font-size: 11px; color: #A9C2A9; letter-spacing: .08em; text-transform: uppercase; }

.sidebar-nav { flex: 1; padding: 1rem .75rem; overflow-y: auto; }
.nav-label { padding: 1rem .75rem .4rem; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #8FAD8F; }
.nav-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem .75rem; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: #D5E2D5; font-weight: 500;
}
.nav-item i { width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(255, 255, 255, .12); color: #fff; box-shadow: inset 3px 0 0 #9BD19B; }
.nav-count {
    margin-left: auto; min-width: 22px; padding: 0 7px;
    font-size: 11px; font-weight: 600; line-height: 20px; text-align: center;
    background: #C9473E; color: #fff; border-radius: 10px;
}

.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.user-chip { display: flex; align-items: center; gap: .65rem; padding: .5rem; border-radius: var(--radius-sm); color: #fff; }
.user-chip:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.avatar {
    width: 32px; height: 32px; flex: none;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--secondary); color: #fff;
    font-size: 12px; font-weight: 600;
}
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }
.user-chip .meta { min-width: 0; line-height: 1.2; }
.user-chip .meta small { display: block; color: #A9C2A9; font-size: 12px; }
.user-chip form { margin-left: auto; }
.icon-button {
    display: inline-grid; place-items: center;
    width: 32px; height: 32px;
    border: 0; border-radius: var(--radius-sm);
    background: transparent; color: inherit; cursor: pointer;
}
.icon-button:hover { background: rgba(255, 255, 255, .1); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 1rem;
    min-height: var(--topbar-height);
    padding: .75rem 2rem;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar-toggle { display: none; color: var(--text); }
.topbar-toggle:hover { background: var(--neutral-soft); }
.topbar-heading { min-width: 0; flex: 1; }
.topbar-heading h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: .35rem; font-size: 13px; color: var(--text-subtle); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb span + span::before { content: '/'; margin-right: .35rem; color: var(--border-strong); }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; }

.content { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 1.75rem 2rem 3rem; }
.content-narrow { max-width: 880px; margin: 0 auto; }

.sidebar-backdrop { display: none; }

/* ---------- Grids & utilities ---------- */

.stack { display: flex; flex-direction: column; gap: 1.25rem; }
.stack-sm { display: flex; flex-direction: column; gap: .5rem; }
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main-aside { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.grid-aside-main { grid-template-columns: 220px minmax(0, 1fr); }
.span-2 { grid-column: span 2; }
.ml-auto { margin-left: auto; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.text-right { text-align: right; } .text-center { text-align: center; }
.text-muted { color: var(--text-muted); } .text-subtle { color: var(--text-subtle); }
.text-danger { color: var(--danger); } .text-success { color: var(--success); } .text-warning { color: var(--warning); }
.text-sm { font-size: 13px; } .text-xs { font-size: 12px; } .text-lg { font-size: 16px; }
.fw-400 { font-weight: 400; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.hidden { display: none !important; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.card-header h2, .card-title { font-size: 15px; font-weight: 600; }
.card-header .subtitle { font-size: 13px; color: var(--text-muted); font-weight: 400; }
.card-body { padding: 1.25rem; }
.card-body-flush { padding: 0; }
.card-footer { padding: .85rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-muted); border-radius: 0 0 var(--radius) var(--radius); }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-subtle); margin-bottom: .75rem; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    height: 38px; padding: 0 1rem;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    font: inherit; font-weight: 500; line-height: 1;
    white-space: nowrap; cursor: pointer; user-select: none;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }
.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-muted); border-color: var(--text-subtle); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--neutral-soft); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #9C2921; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #17642F; }
.btn-sm { height: 32px; padding: 0 .75rem; font-size: 13px; }
.btn-icon { width: 34px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.actions { display: inline-flex; align-items: center; gap: .25rem; }

/* Menu déroulant */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 50;
    min-width: 220px; padding: .35rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: .6rem; width: 100%;
    padding: .55rem .7rem; border: 0; border-radius: var(--radius-sm);
    background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.dropdown-item i { width: 16px; color: var(--text-subtle); }
.dropdown-item:hover { background: var(--surface-muted); text-decoration: none; }
.dropdown-item.danger, .dropdown-item.danger i { color: var(--danger); }
.dropdown-divider { height: 1px; margin: .35rem 0; background: var(--border); }
.dropdown-menu form { margin: 0; }

/* ---------- Forms ---------- */

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.label { font-size: 13px; font-weight: 500; color: var(--text); }
.label .req { color: var(--danger); margin-left: 2px; }
.help { font-size: 12px; color: var(--text-subtle); }
.input, .select, .textarea {
    width: 100%; min-height: 38px;
    padding: .5rem .75rem;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font: inherit;
    transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.select { appearance: none; padding-right: 2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235A655F' d='M6 8.5 1.5 4h9z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.input[readonly] { background: var(--surface-muted); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }
.input-sm { min-height: 32px; padding: .3rem .6rem; font-size: 13px; }
.input-number { text-align: right; font-variant-numeric: tabular-nums; }
.input-color { padding: .2rem; width: 52px; }
.input-group { position: relative; display: flex; align-items: center; }
.input-group > i { position: absolute; left: .8rem; color: var(--text-subtle); pointer-events: none; }
.input-group > .input { padding-left: 2.2rem; }
.input-addon { display: flex; }
.input-addon .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-addon span { display: grid; place-items: center; padding: 0 .75rem; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-muted); color: var(--text-muted); font-size: 13px; }

.check { display: flex; align-items: flex-start; gap: .65rem; cursor: pointer; }
.check input { margin: .2rem 0 0; width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
.check strong { display: block; font-weight: 500; }
.check span { color: var(--text-muted); font-size: 13px; }

.form-section + .form-section { margin-top: 1.75rem; padding-top: 1.75rem; border-top: 1px solid var(--border); }
.form-section-title { font-size: 15px; font-weight: 600; margin-bottom: .25rem; }
.form-section-desc { color: var(--text-muted); font-size: 13px; margin-bottom: 1.1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }

/* ---------- Toolbar (filtres) ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--border); }
.toolbar .input-group { flex: 1 1 260px; max-width: 360px; }
.toolbar .select { width: auto; min-width: 160px; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.tab {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .45rem .8rem; border-radius: 999px;
    color: var(--text-muted); font-weight: 500; font-size: 13px; white-space: nowrap;
}
.tab:hover { background: var(--neutral-soft); color: var(--text); text-decoration: none; }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.tab .count { font-size: 11px; padding: 0 6px; line-height: 18px; border-radius: 9px; background: var(--neutral-soft); color: var(--text-muted); }
.tab.active .count { background: var(--primary); color: #fff; }

/* ---------- Tables ---------- */

.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    padding: .7rem 1rem;
    font-size: 12px; font-weight: 600; text-align: left; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-subtle); background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table th a { color: inherit; display: inline-flex; gap: .3rem; align-items: center; }
.table th a:hover { color: var(--text); text-decoration: none; }
.table th a.sorted { color: var(--text); }
.table td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #FAFBF9; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .actions-cell { text-align: right; white-space: nowrap; width: 1%; }
.table .check-cell { width: 1%; }
.table-compact td, .table-compact th { padding: .55rem .9rem; }
.table tfoot td { background: var(--surface-muted); font-weight: 600; }
.row-link { color: var(--text); font-weight: 600; }
.cell-sub { display: block; font-size: 12px; color: var(--text-subtle); }

/* ---------- Badges ---------- */

.badge {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .18rem .6rem;
    font-size: 12px; font-weight: 600; line-height: 1.4;
    border-radius: 999px; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }
.badge-dark { background: var(--dark-soft); color: var(--dark); }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem; border-radius: 999px; background: var(--neutral-soft); font-size: 12px; color: var(--text-muted); }
.chip form { display: inline; }
.chip button { border: 0; background: none; padding: 0 0 0 .15rem; color: var(--text-subtle); cursor: pointer; line-height: 1; }
.chip button:hover { color: var(--danger); }
.chip-important { background: var(--danger-soft); color: var(--danger); }
.chip-spam { background: var(--dark-soft); color: var(--dark); }
.chip-normal { background: var(--info-soft); color: var(--info); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .1); vertical-align: middle; }

/* ---------- Alerts & toasts ---------- */

.flash-stack { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.25rem; }
.alert {
    display: flex; align-items: flex-start; gap: .75rem;
    padding: .8rem 1rem;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    font-size: 14px;
    transition: opacity .25s, transform .25s;
}
.alert > i { margin-top: .15rem; }
.alert .alert-body { flex: 1; min-width: 0; }
.alert .alert-close { border: 0; background: none; color: inherit; opacity: .6; cursor: pointer; font-size: 18px; line-height: 1; padding: 0 .1rem; }
.alert .alert-close:hover { opacity: 1; }
.alert-success { background: var(--success-soft); color: #145A2B; border-color: #C5E5CF; }
.alert-error, .alert-danger { background: var(--danger-soft); color: #8A2019; border-color: #F3C9C4; }
.alert-warning { background: var(--warning-soft); color: #7A4800; border-color: #F5DDB0; }
.alert-info { background: var(--info-soft); color: #164A88; border-color: #C9DCF4; }
.alert.is-hiding { opacity: 0; transform: translateY(-6px); }

.toast-region { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; width: min(380px, calc(100vw - 2rem)); }
.toast-region .alert { box-shadow: var(--shadow-lg); }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 90;
    display: grid; place-items: center; padding: 1rem;
    background: rgba(20, 28, 24, .45);
    animation: fade .15s ease;
}
.modal {
    width: min(460px, 100%);
    background: var(--surface); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: pop .15s ease;
}
.modal-body { padding: 1.5rem; display: flex; gap: 1rem; }
.modal-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--danger-soft); color: var(--danger); }
.modal-icon.info { background: var(--primary-soft); color: var(--primary); }
.modal h3 { font-size: 16px; margin-bottom: .35rem; }
.modal p { color: var(--text-muted); }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.5rem; background: var(--surface-muted); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(4px); } }

/* ---------- KPI ---------- */

.kpi { display: flex; flex-direction: column; gap: .4rem; padding: 1.15rem 1.25rem; color: inherit; }
a.kpi:hover { text-decoration: none; background: var(--surface-muted); }
.kpi-head { display: flex; align-items: center; justify-content: space-between; color: var(--text-muted); font-size: 13px; font-weight: 500; }
.kpi-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; font-size: 14px; }
.kpi-icon.green { background: var(--primary-soft); color: var(--primary); }
.kpi-icon.violet { background: var(--violet-soft); color: var(--violet); }
.kpi-icon.orange { background: var(--warning-soft); color: var(--warning); }
.kpi-icon.red { background: var(--danger-soft); color: var(--danger); }
.kpi-icon.blue { background: var(--info-soft); color: var(--info); }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12px; color: var(--text-subtle); }
.trend { font-weight: 600; }
.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }

.chart-box { position: relative; height: 280px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-subtle); font-size: 13px; text-align: center; }

/* ---------- Lists ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: .85rem; padding: .8rem 1.25rem; border-bottom: 1px solid var(--border); color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover { background: var(--surface-muted); text-decoration: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 500; }
.list-item .sub { font-size: 12px; color: var(--text-subtle); }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1.25rem; margin: 0; }
.dl dt { color: var(--text-subtle); font-size: 13px; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.empty {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    padding: 3rem 1.5rem; color: var(--text-muted);
}
.empty-icon { width: 56px; height: 56px; display: grid; place-items: center; margin-bottom: 1rem; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 22px; }
.empty h3 { font-size: 16px; color: var(--text); margin-bottom: .35rem; }
.empty p { max-width: 420px; margin-bottom: 1.1rem; }
.empty-sm { padding: 1.5rem 1rem; font-size: 13px; }

/* Chronologie */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 15px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; display: flex; gap: .85rem; padding-bottom: 1rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline-dot { position: relative; z-index: 1; width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--neutral-soft); color: var(--neutral); font-size: 12px; border: 3px solid var(--surface); }
.timeline-dot.success { background: var(--success-soft); color: var(--success); }
.timeline-dot.danger { background: var(--danger-soft); color: var(--danger); }
.timeline-dot.info { background: var(--info-soft); color: var(--info); }
.timeline-dot.warning { background: var(--warning-soft); color: var(--warning); }
.timeline-dot.violet { background: var(--violet-soft); color: var(--violet); }
.timeline-dot.dark { background: var(--dark-soft); color: var(--dark); }
.timeline-content { padding-top: .3rem; min-width: 0; }
.timeline-content .when { font-size: 12px; color: var(--text-subtle); }

/* ---------- Pagination ---------- */

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .85rem 1.25rem; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.pages { display: flex; gap: .25rem; }
.page-link { min-width: 32px; height: 32px; padding: 0 .55rem; display: inline-grid; place-items: center; border-radius: var(--radius-sm); color: var(--text-muted); border: 1px solid var(--border); background: var(--surface); }
.page-link:hover { background: var(--surface-muted); text-decoration: none; color: var(--text); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.disabled { opacity: .45; pointer-events: none; }

/* ---------- Settings nav ---------- */

.subnav { display: flex; flex-direction: column; gap: 2px; padding: .5rem; }
.subnav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .75rem; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; }
.subnav a i { width: 16px; text-align: center; color: var(--text-subtle); }
.subnav a:hover { background: var(--surface-muted); color: var(--text); text-decoration: none; }
.subnav a.active { background: var(--primary-soft); color: var(--primary); }
.subnav a.active i { color: var(--primary); }

/* ---------- Invoice ---------- */

.doc { padding: 2.5rem; }
.doc-head { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; padding-bottom: 1.5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.doc-title { font-size: 26px; font-weight: 700; color: var(--primary); letter-spacing: .02em; }
.doc-number { font-size: 15px; color: var(--text-muted); margin-top: .2rem; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.75rem; }
.doc-party { padding: 1rem 1.15rem; background: var(--surface-muted); border-radius: var(--radius-sm); }
.doc-party .name { font-weight: 600; font-size: 15px; margin-bottom: .2rem; }
.doc-totals { margin-left: auto; width: min(340px, 100%); }
.doc-totals .line { display: flex; justify-content: space-between; padding: .45rem 0; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.doc-totals .line.grand { margin-top: .35rem; padding-top: .75rem; border-top: 2px solid var(--text); color: var(--primary); font-size: 18px; font-weight: 700; }
.doc-totals .line.due { color: var(--danger); font-weight: 600; }

.line-editor { min-width: 780px; }
.table-wrap:has(.line-editor) { position: relative; } /* garde .sr-only dans la zone défilante */
.line-editor td { padding: .5rem .5rem; vertical-align: top; }
.line-editor th { padding: .6rem .5rem; }
.line-editor .col-product { width: 190px; }
.line-editor .col-qty { width: 136px; }
.line-editor .col-price { width: 130px; }
.line-editor .col-vat { width: 100px; }
.line-editor .col-total { width: 120px; }
.line-editor .line-total { display: block; padding-top: .55rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.totals-panel { background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }
.totals-panel .line { display: flex; justify-content: space-between; padding: .3rem 0; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.totals-panel .line.grand { margin-top: .4rem; padding-top: .7rem; border-top: 1px solid var(--border-strong); color: var(--primary); font-size: 18px; font-weight: 700; }

.qty-stepper { display: flex; align-items: center; gap: .25rem; }
.qty-stepper .input { flex: 1; min-width: 0; padding-left: .3rem; padding-right: .3rem; text-align: center; -moz-appearance: textfield; appearance: textfield; }
.qty-stepper .input::-webkit-outer-spin-button, .qty-stepper .input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-stepper .btn { flex: none; width: 26px; font-size: 11px; }

.product-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.product-card {
    display: flex; align-items: center; gap: .65rem; min-width: 0; padding: .6rem .75rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: inherit; font: inherit; text-align: left; cursor: pointer;
    transition: border-color .12s ease, background-color .12s ease;
}
.product-card:hover { border-color: var(--primary); background: var(--surface-muted); }
.product-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.product-card.selected { border-color: var(--primary); background: var(--primary-soft); }
.product-swatch { flex: none; width: 14px; height: 30px; border-radius: 4px; background: var(--border-strong); }
.product-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.product-card-name { font-weight: 600; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.product-card-price { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.product-card-count { flex: none; font-size: 12px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }

.combo { position: relative; }
.combo-list {
    position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
    max-height: 280px; overflow-y: auto; padding: .3rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.combo-option { padding: .5rem .65rem; border-radius: 4px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.combo-option.active { background: var(--primary-soft); }
.combo-create { color: var(--primary); font-weight: 600; }

/* ---------- Tableau de bord : à faire ---------- */

.todo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1px; background: var(--border); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.todo-item { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.25rem; background: var(--surface); color: inherit; }
.todo-item:hover { background: var(--surface-muted); text-decoration: none; }
.todo-item:hover .todo-arrow { color: var(--primary); }
.todo-item .grow { flex: 1; min-width: 0; }
.todo-item .kpi-icon { flex: none; }
.todo-title { display: block; font-weight: 600; }
.todo-detail { display: block; font-size: 12px; color: var(--text-muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.todo-arrow { flex: none; font-size: 11px; color: var(--text-subtle); }
.todo-done { display: flex; align-items: center; gap: .75rem; color: var(--text-muted); }

/* ---------- Logo ---------- */

.logo-setting { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.logo-setting .grow { flex: 1; min-width: 240px; }
.logo-preview { flex: none; display: grid; place-items: center; width: 160px; height: 88px; padding: .5rem; background: #FFFFFF; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }
.logo-preview img { display: block; max-width: 144px; max-height: 72px; }
.logo-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.logo-form .input { flex: 1; min-width: 200px; }
.doc-logo { display: block; max-width: 150px; max-height: 56px; margin-bottom: .5rem; }

/* ---------- Palette de commandes ---------- */

.palette-trigger {
    display: inline-flex; align-items: center; gap: .5rem; flex: none; min-height: 34px; padding: 0 .65rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface-muted); color: var(--text-muted); font: inherit; font-size: 13px; cursor: pointer;
}
.palette-trigger:hover { border-color: var(--border-strong); color: var(--text); }
.palette-trigger:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
kbd { padding: .05rem .35rem; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text-subtle); font: 600 11px var(--font); white-space: nowrap; }
.palette-backdrop { place-items: start center; padding-top: min(12vh, 96px); }
.palette { width: min(620px, 100%); overflow: hidden; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop .12s ease; }
.palette-search { display: flex; align-items: center; gap: .65rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); color: var(--text-subtle); }
.palette-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 15px; }
.palette-list { max-height: min(56vh, 420px); overflow-y: auto; padding: .35rem; }
.palette-list:empty { display: none; }
.palette-group { padding: .6rem .7rem .25rem; font-size: 11px; font-weight: 600; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .04em; }
.palette-item { display: flex; align-items: center; gap: .7rem; padding: .5rem .7rem; border-radius: var(--radius-sm); cursor: pointer; }
.palette-item i { flex: none; width: 16px; text-align: center; color: var(--text-subtle); }
.palette-item.active { background: var(--primary-soft); }
.palette-item.active i { color: var(--primary); }
.palette-text { flex: 1; min-width: 0; }
.palette-title, .palette-sub { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.palette-title { font-weight: 500; }
.palette-sub { font-size: 12px; color: var(--text-muted); }
.palette-status:not(:empty) { padding: .75rem 1.1rem; font-size: 13px; color: var(--text-muted); }

/* ---------- Emails ---------- */

.mail-list .mail-row { display: flex; align-items: center; gap: .85rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); }
.mail-list .mail-row:last-child { border-bottom: 0; }
.mail-list .mail-row:hover { background: #FAFBF9; }
.mail-row.unread { background: #FBFDFB; }
.mail-row.unread .mail-from, .mail-row.unread .mail-subject { font-weight: 700; color: var(--text); }
.mail-row .mail-link { display: flex; align-items: center; gap: .85rem; flex: 1; min-width: 0; color: inherit; }
.mail-row .mail-link:hover { text-decoration: none; }
.mail-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; }
.mail-row.unread .mail-dot { background: var(--primary); }
.mail-from { width: 190px; flex: none; color: var(--text-muted); }
.mail-main { flex: 1; min-width: 0; }
.mail-subject { color: var(--text); }
.mail-preview { color: var(--text-subtle); }
.mail-date { flex: none; font-size: 12px; color: var(--text-subtle); white-space: nowrap; }
.mail-row .actions { opacity: 0; transition: opacity .15s; }
.mail-row:hover .actions, .mail-row:focus-within .actions { opacity: 1; }
.bulk-bar { display: none; align-items: center; gap: .5rem; padding: .6rem 1.25rem; background: var(--primary-soft); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.bulk-bar.visible { display: flex; }

.mail-header { display: flex; gap: 1rem; align-items: flex-start; }
.mail-frame { width: 100%; min-height: 320px; border: 0; display: block; background: #fff; }
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }

/* ---------- Auth & error pages ---------- */

.auth-page {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 2rem 1rem;
    background: radial-gradient(1200px 600px at 10% -10%, #3E7A3E 0%, transparent 60%),
                radial-gradient(900px 500px at 110% 110%, #7E3BA0 0%, transparent 55%),
                var(--primary-dark);
}
.auth-card { width: min(420px, 100%); background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.25rem; }
.auth-brand { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 1.75rem; }
.auth-brand img { width: 64px; height: 64px; margin-bottom: .75rem; }
.auth-brand h1 { font-size: 20px; }
.auth-brand p { color: var(--text-muted); margin-top: .3rem; }
.auth-footer { margin-top: 1.5rem; text-align: center; font-size: 12px; color: rgba(255, 255, 255, .6); }
.error-code { font-size: 64px; font-weight: 800; color: var(--primary); line-height: 1; letter-spacing: -.03em; }

/* ---------- Responsive ---------- */

@media (max-width: 1200px) {
    .hide-md { display: none !important; }
    .palette-trigger { width: 34px; padding: 0; justify-content: center; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main-aside { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(20, 28, 24, .4); }
    .main { margin-left: 0; }
    .topbar { padding: .75rem 1rem; flex-wrap: wrap; }
    .topbar-toggle { display: inline-grid; }
    .topbar-actions { width: 100%; justify-content: flex-start; }
    .content { padding: 1.25rem 1rem 2.5rem; }
    .grid-2, .grid-3, .grid-aside-main { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: auto; }
    .doc { padding: 1.25rem; }
    .doc-parties { grid-template-columns: 1fr; }
    .mail-from { width: 120px; }
    .mail-preview { display: none; }
    .mail-row .actions { opacity: 1; }
}

@media (max-width: 640px) {
    .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .col-8, .col-6, .col-4, .col-3 { grid-column: span 12; }
    .toolbar .input-group { max-width: none; }
    .toolbar .select { flex: 1; }
    .hide-sm { display: none !important; }
    .mail-row { flex-wrap: wrap; }
    .mail-from { width: auto; flex: 1; }
    .kpi-value { font-size: 21px; }
    .todo-grid { grid-template-columns: minmax(0, 1fr); }
    .product-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: .75rem 1rem; }
    .palette-backdrop { padding-top: 1rem; }
    .palette-search kbd { display: none; }
    .modal-body { flex-direction: column; }
    .auth-card { padding: 1.5rem; }
}

@media print {
    .sidebar, .topbar, .flash-stack, .no-print { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
}
