:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --primary-light: #eef2ff;
    --secondary: #64748b;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --dark: #0f172a;
    --light: #f8fafc;
    --gray: #e2e8f0;
    --body-bg: #f1f5f9;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #4f46e5;
    --card-shadow: 0 1px 3px 0 rgba(0,0,0,.06), 0 1px 2px -1px rgba(0,0,0,.06);
    --card-shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.07);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    background-color: var(--body-bg);
    color: var(--dark);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: 0.9rem;
}

/* ─── Auth ──────────────────────────────────────────────── */
.auth-body {
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    display: flex;
    align-items: center;
    min-height: 100vh;
}

.auth-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.35);
    padding: 2.5rem 2rem;
    width: 100%;
}

.auth-icon { font-size: 3rem; color: var(--primary); }

/* ─── Layout ────────────────────────────────────────────── */
.wrapper { display: flex; min-height: 100vh; }

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ─── Sidebar Collapsed ─────────────────────────────────── */
.sidebar.collapsed {
    width: 60px;
}

.sidebar.collapsed .brand-name,
.sidebar.collapsed .brand-sub,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-user .user-details,
.sidebar.collapsed .logout-link span {
    display: none;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 1.25rem 0.5rem 1rem;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 0.65rem;
    gap: 0;
    position: relative;
}

.sidebar.collapsed .nav-link i {
    width: auto;
    font-size: 1.15rem;
}

.sidebar.collapsed .sidebar-nav {
    padding: 1rem 0.5rem;
}

.sidebar.collapsed .sidebar-footer {
    padding: 0.75rem 0.5rem;
}

.sidebar.collapsed .sidebar-user {
    justify-content: center;
    margin-bottom: 0.5rem;
}

.sidebar.collapsed .logout-link {
    justify-content: center;
    padding: 0.5rem;
}

/* Tooltip on collapsed icons */
.sidebar.collapsed .nav-link::after {
    content: attr(data-label);
    position: absolute;
    left: 60px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #e2e8f0;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    font-size: 0.78rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 999;
    border: 1px solid rgba(255,255,255,0.08);
}

.sidebar.collapsed .nav-link:hover::after {
    opacity: 1;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand:hover { color: white; }

.brand-icon { font-size: 1.75rem; color: #818cf8; }

.brand-name { font-size: 1rem; font-weight: 700; line-height: 1.2; }

.brand-sub { font-size: 0.7rem; color: #64748b; margin-top: 1px; }

.sidebar-nav { padding: 1rem 0.75rem; flex-grow: 1; }

.nav-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    margin-bottom: 0.35rem;
    margin-top: 1.25rem;
    padding-left: 0.75rem;
    font-weight: 700;
}

.nav-link {
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.15rem;
    text-decoration: none;
    transition: all 0.15s;
    font-size: 0.875rem;
}

.nav-link i { font-size: 1rem; width: 18px; text-align: center; }

.nav-link:hover, .nav-link:focus {
    background-color: var(--sidebar-hover);
    color: #e2e8f0;
}

.nav-link.active {
    background-color: rgba(79, 70, 229, 0.15);
    color: #a5b4fc;
    font-weight: 600;
}

.nav-link.active i { color: #818cf8; }

.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0.75rem;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.logout-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #64748b;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    transition: all 0.15s;
}

.logout-link:hover {
    background-color: rgba(239, 68, 68, 0.08);
    color: #ef4444;
}

/* ─── Main Content ──────────────────────────────────────── */
.main-content {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ─── Navbar ────────────────────────────────────────────── */
.top-navbar {
    background-color: white;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--gray);
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    color: var(--dark);
}

/* ─── Cards ─────────────────────────────────────────────── */
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--card-shadow);
    height: 100%;
    border: 1px solid rgba(0,0,0,0.04);
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.35rem;
}

.stat-value { font-size: 1.875rem; font-weight: 800; line-height: 1.1; }

.info-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 1.25rem;
    border: 1px solid rgba(0,0,0,0.04);
}

.form-container {
    background: white;
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(0,0,0,0.04);
}

.table-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.04);
}

/* ─── Tables ────────────────────────────────────────────── */
.table { margin-bottom: 0; }

.table th {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--secondary);
    font-weight: 700;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray);
    background: #fafafa;
}

.table td { padding: 0.85rem 1rem; vertical-align: middle; }

.table tbody tr { transition: background 0.1s; }
.table-hover tbody tr:hover { background-color: #fafbff; }

/* ─── Status Badges ─────────────────────────────────────── */
.badge-statut {
    padding: 0.3em 0.65em;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.75rem;
}

.statut-brouillon  { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }
.statut-emise      { background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe; }
.statut-payee_partiel { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.statut-payee      { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.statut-annulee    { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ─── Totals Box (note show) ────────────────────────────── */
.totals-box {
    background: white;
    border-radius: var(--radius);
    border: 1px solid rgba(0,0,0,0.05);
    padding: 1.25rem;
    box-shadow: var(--card-shadow);
}

.totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0;
    font-size: 0.9rem;
}

.totals-label { color: var(--secondary); }

.totals-amount { font-weight: 600; font-variant-numeric: tabular-nums; }

.net-amount-box {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-top: 0.75rem;
}

/* ─── Note Header (show.php) ────────────────────────────── */
.note-hero {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: var(--card-shadow);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.note-hero-left { display: flex; align-items: center; gap: 1rem; }

.note-icon-wrap {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.note-icon-wrap i { font-size: 1.4rem; color: var(--primary); }

.note-hero-number {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--dark);
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.note-hero-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }

.note-hero-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ─── Info Sections ─────────────────────────────────────── */
.section-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.detail-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.2rem 0.55rem;
    font-size: 0.78rem;
    color: #475569;
    font-weight: 500;
}

/* ─── Divider ───────────────────────────────────────────── */
.section-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
}

.section-divider span {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #94a3b8;
    white-space: nowrap;
}

.section-divider::before, .section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-sm { font-size: 0.8rem; }

.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

/* ─── Forms ─────────────────────────────────────────────── */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: #e2e8f0;
    font-size: 0.875rem;
    padding: 0.55rem 0.8rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.form-label { font-size: 0.82rem; font-weight: 600; color: #374151; margin-bottom: 0.35rem; }

/* ─── Flash messages ────────────────────────────────────── */
.alert {
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.875rem;
}

/* ─── Misc ──────────────────────────────────────────────── */
.letter-spacing { letter-spacing: 1px; }
.font-monospace { font-variant-numeric: tabular-nums; }

/* ─── Config page tab nav ────────────────────────────────── */
.config-nav {
    background: white;
    border-radius: var(--radius);
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: var(--card-shadow);
    padding: 0.5rem;
    position: sticky;
    top: 76px;
}

.config-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 0.1rem;
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
}

.config-nav-link:hover {
    background: #f8fafc;
    color: #0f172a;
}

.config-nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.config-nav-link.active i { color: var(--primary); }

.config-nav-link i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
    color: #94a3b8;
}

.config-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}

.config-section-title i {
    color: var(--primary);
    font-size: 1.1rem;
}

/* ─── Favicon / image upload zones ──────────────────────── */
.upload-zone {
    border: 2px dashed #e2e8f0;
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    transition: all 0.2s;
    background: #fafafa;
}

.upload-zone:hover { border-color: var(--primary); background: var(--primary-light); }

.upload-zone img {
    max-height: 80px;
    max-width: 100%;
    margin-bottom: 0.75rem;
    display: block;
    margin: 0 auto 0.75rem;
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 767px) {
    .sidebar { width: 220px; }
    .note-hero { flex-direction: column; align-items: flex-start; }
    .config-nav { position: static; margin-bottom: 1rem; }
}
