/* ─── Root variables ───────────────────────────────────────────────────────── */
:root {
    --sc-sidebar-width: 240px;
    --sc-sidebar-bg: #1e2a38;
    --sc-sidebar-text: #c8d3e0;
    --sc-sidebar-active-bg: rgba(255,255,255,.10);
    --sc-sidebar-active-text: #ffffff;
    --sc-sidebar-hover-bg: rgba(255,255,255,.06);
    --sc-accent: #3b82f6;
    --sc-body-bg: #1e2a38;
    --sc-content-bg: #243447;
    --sc-card-bg: #2a3d54;
    --sc-card-border: rgba(255,255,255,.1);
    --sc-card-shadow: 0 2px 12px rgba(0,0,0,.25);
    --sc-text: #d4dde8;
    --sc-text-muted: #8fa0b4;
    --sc-topbar-height: 52px;
}

/* ─── Body & layout shell ──────────────────────────────────────────────────── */
body.sc-body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--sc-body-bg);
    color: var(--sc-text);
    margin: 0;
    min-height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sc-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sc-sidebar-width);
    height: 100vh;
    background: var(--sc-sidebar-bg);
    color: var(--sc-sidebar-text);
    z-index: 1040;
    transition: transform .25s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ─── Sidebar header ───────────────────────────────────────────────────────── */
.sc-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sc-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    text-decoration: none;
    letter-spacing: .02em;
}
.sc-brand i { font-size: 1.3rem; color: var(--sc-accent); }
.sc-brand:hover { color: #fff; }

.sc-sidebar-close {
    background: none;
    border: none;
    color: var(--sc-sidebar-text);
    font-size: 1.1rem;
    cursor: pointer;
    padding: .25rem;
    line-height: 1;
}

/* ─── Sidebar nav ──────────────────────────────────────────────────────────── */
.sc-nav {
    list-style: none;
    margin: .5rem 0 0;
    padding: 0;
}
.sc-nav li { margin: 2px 8px; }
.sc-nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .85rem;
    border-radius: 6px;
    color: var(--sc-sidebar-text);
    text-decoration: none;
    font-size: .9rem;
    transition: background .15s, color .15s;
}
.sc-nav-link i { font-size: 1rem; flex-shrink: 0; }
.sc-nav-link:hover {
    background: var(--sc-sidebar-hover-bg);
    color: #fff;
}
.sc-nav-link.active {
    background: var(--sc-sidebar-active-bg);
    color: var(--sc-sidebar-active-text);
    font-weight: 600;
}
.sc-nav-link.active i { color: var(--sc-accent); }

/* ─── Sidebar footer ───────────────────────────────────────────────────────── */
.sc-sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
}
.sc-user-info {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .85rem;
    color: var(--sc-sidebar-text);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.sc-user-info i { font-size: 1.1rem; flex-shrink: 0; }
.sc-logout-btn {
    width: 100%;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.12);
    color: var(--sc-sidebar-text);
    border-radius: 6px;
    padding: .35rem .7rem;
    font-size: .82rem;
    cursor: pointer;
    text-align: left;
    transition: background .15s;
}
.sc-logout-btn:hover { background: rgba(220,60,60,.3); color: #fff; }

/* ─── Language switcher ────────────────────────────────────────────────────── */
.sc-lang-switcher {
    display: flex;
    gap: .25rem;
}
.sc-lang-btn {
    flex: 1;
    text-align: center;
    padding: .2rem 0;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
    color: var(--sc-sidebar-text);
    text-decoration: none;
    border: 1px solid rgba(255,255,255,.15);
    transition: background .15s, color .15s;
}
.sc-lang-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.sc-lang-btn.active { background: var(--sc-accent); color: #fff; border-color: var(--sc-accent); }

/* ─── Overlay (mobile) ─────────────────────────────────────────────────────── */
.sc-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1035;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
}
.sc-overlay.active { opacity: 1; pointer-events: all; }

/* ─── Main wrapper ─────────────────────────────────────────────────────────── */
.sc-main-wrapper {
    margin-left: var(--sc-sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── Top bar (mobile) ─────────────────────────────────────────────────────── */
.sc-topbar {
    height: var(--sc-topbar-height);
    background: var(--sc-sidebar-bg);
    color: #fff;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.sc-toggle-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.sc-topbar-title { font-weight: 600; font-size: 1rem; }

/* ─── Flash container ──────────────────────────────────────────────────────── */
.sc-flash-container { padding: 0; }

/* ─── Page content ─────────────────────────────────────────────────────────── */
.sc-content {
    flex: 1;
    padding: 1.25rem 1rem;
    background: var(--sc-content-bg);
}

/* ─── Footer ───────────────────────────────────────────────────────────────── */
.sc-footer {
    padding: .6rem 1.25rem;
    text-align: center;
    font-size: .75rem;
    color: var(--sc-text-muted);
    border-top: 1px solid rgba(255,255,255,.06);
    background: var(--sc-content-bg);
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
    box-shadow: var(--sc-card-shadow);
    background: var(--sc-card-bg);
    border: 1px solid var(--sc-card-border);
    border-radius: 10px;
    color: var(--sc-text);
}
.card-header {
    border-radius: 9px 9px 0 0 !important;
    border-bottom: 1px solid rgba(255,255,255,.06);
    background: rgba(255,255,255,.04);
    color: var(--sc-text);
}
.card-footer {
    background: rgba(255,255,255,.03);
    border-top: 1px solid rgba(255,255,255,.06);
}

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table { --bs-table-color: var(--sc-text); --bs-table-bg: transparent; --bs-table-border-color: rgba(255,255,255,.07); }
.table-light { --bs-table-bg: rgba(255,255,255,.05); --bs-table-color: var(--sc-text); --bs-table-border-color: rgba(255,255,255,.07); }
.table-hover > tbody > tr:hover > * { background-color: rgba(59,130,246,.1); color: var(--sc-text); }
.table thead th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--sc-text-muted); border-color: rgba(255,255,255,.07); }

/* ─── Form controls dark ───────────────────────────────────────────────────── */
.form-control, .form-select {
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.15);
    color: var(--sc-text);
}
.form-control:focus, .form-select:focus {
    background: rgba(255,255,255,.12);
    border-color: var(--sc-accent);
    color: #fff;
    box-shadow: 0 0 0 .2rem rgba(59,130,246,.25);
}
.form-control::placeholder { color: var(--sc-text-muted); }
.form-text { color: var(--sc-text-muted); }
.form-label { color: var(--sc-text); }
.input-group-text { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.12); color: var(--sc-text); }

/* ─── Dropdown options dark (fixes white-on-white on native selects) ────────── */
select option { background: #1e2a38; color: var(--sc-text); }
select option:checked { background: var(--sc-accent); color: #fff; }

/* ─── Alerts dark ──────────────────────────────────────────────────────────── */
.alert-info    { background: rgba(13,202,240,.12);  border-color: rgba(13,202,240,.25);  color: #7dd8f0; }
.alert-success { background: rgba(25,135,84,.15);   border-color: rgba(25,135,84,.3);    color: #75d4a0; }
.alert-warning { background: rgba(255,193,7,.12);   border-color: rgba(255,193,7,.25);   color: #ffd966; }
.alert-danger  { background: rgba(220,53,69,.15);   border-color: rgba(220,53,69,.3);    color: #f08090; }

/* ─── List groups dark ─────────────────────────────────────────────────────── */
.list-group-item {
    background: var(--sc-card-bg);
    border-color: rgba(255,255,255,.07);
    color: var(--sc-text);
}
.list-group-item-action:hover { background: rgba(255,255,255,.06); color: #fff; }

/* ─── Text utilities override ──────────────────────────────────────────────── */
.text-muted { color: var(--sc-text-muted) !important; }
h1,h2,h3,h4,h5,h6 { color: #e2eaf3; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-color: #2563eb;
}
.btn-primary:hover { background: linear-gradient(135deg, #2563eb, #1d4ed8); border-color: #1d4ed8; }

/* ─── Outline buttons dark-mode overrides ────────────────────────────────── */
.btn-outline-secondary {
    color: #b8c9db;
    border-color: rgba(255,255,255,.25);
}
.btn-outline-secondary:hover {
    background: rgba(255,255,255,.12);
    border-color: rgba(255,255,255,.4);
    color: #fff;
}

.btn-outline-danger {
    color: #f08090;
    border-color: rgba(220,53,69,.6);
}
.btn-outline-danger:hover {
    background: rgba(220,53,69,.2);
    border-color: rgba(220,53,69,.8);
    color: #f5a8b3;
}

.btn-outline-primary {
    color: #7cb4fb;
    border-color: rgba(59,130,246,.6);
}
.btn-outline-primary:hover {
    background: rgba(59,130,246,.18);
    border-color: rgba(59,130,246,.85);
    color: #9ecaff;
}

.btn-outline-success {
    color: #75d4a0;
    border-color: rgba(25,135,84,.6);
}
.btn-outline-success:hover {
    background: rgba(25,135,84,.18);
    border-color: rgba(25,135,84,.8);
    color: #93ddb3;
}

/* btn-close (for dismissible alerts) */
.btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* ─── Dark overrides for Bootstrap light utilities ─────────────────────────── */
.bg-light {
    background-color: rgba(255,255,255,.08) !important;
    color: var(--sc-text) !important;
}

/* ─── Modal dark theme ──────────────────────────────────────────────────────── */
.modal-content {
    background-color: var(--sc-card-bg);
    color: var(--sc-text);
    border-color: var(--sc-card-border);
}
.modal-header, .modal-footer {
    border-color: rgba(255,255,255,.1);
}
.modal-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge { font-weight: 500; }

/* ─── Mobile adjustments ───────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .sc-sidebar { transform: translateX(calc(-1 * var(--sc-sidebar-width))); }
    .sc-sidebar.open { transform: translateX(0); }
    .sc-main-wrapper { margin-left: 0; }
}

/* ─── Company context bar ──────────────────────────────────────────────────── */
/* ─── Context header bar (entreprise / exercice + user) ────────────────────── */
.sc-context-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .45rem 1.25rem;
    background: var(--sc-sidebar-bg);
    border-bottom: 1px solid rgba(255,255,255,.08);
    font-size: .875rem;
    font-weight: 600;
    color: #c8d3e0;
    gap: .5rem;
    min-height: 2.4rem;
}
.sc-context-bar-left  { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.sc-context-bar-right { display: flex; align-items: center; gap: .4rem; white-space: nowrap; color: rgba(255,255,255,.6); font-weight: 400; font-size: .8rem; }
.sc-context-bar-link  { color: #fff; text-decoration: none; }
.sc-context-bar-link:hover { color: var(--sc-accent); }
.sc-context-bar-sep   { color: rgba(255,255,255,.3); margin: 0 .1rem; }

/* ─── Period nav tabs ───────────────────────────────────────────────────────── */
.sc-period-tabs {
    display: flex;
    align-items: stretch;
    gap: 0;
    background: var(--sc-sidebar-bg);
    border-bottom: 3px solid rgba(255,255,255,.08);
    padding: 0 .25rem;
    overflow-x: auto;
    flex-shrink: 0;
    /* Hide scrollbar while keeping scroll functionality */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sc-period-tabs::-webkit-scrollbar { display: none; }
.sc-period-tab {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: .1rem;
    padding: .4rem .6rem;
    font-size: .72rem;
    color: var(--sc-text-muted);
    text-decoration: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -3px;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
}
.sc-period-tab i { font-size: 1.2rem; }
.sc-period-tab:hover  { color: #c8d3e0; border-bottom-color: rgba(255,255,255,.2); }
.sc-period-tab.active { color: #fff; border-bottom-color: var(--sc-accent); font-weight: 600; }
.sc-period-tab-sep {
    width: 1px;
    background: rgba(255,255,255,.15);
    margin: 6px 4px;
    align-self: stretch;
    flex-shrink: 0;
}

/* ─── Table small font ─────────────────────────────────────────────────────── */
table.table-sm td, table.table-sm th { font-size: .82rem; }

/* ─── Print ────────────────────────────────────────────────────────────────── */
@media print {
    /* Force background colours and images to print */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide UI chrome */
    .sc-sidebar, .sc-topbar, .sc-footer, .sc-lang-switcher,
    .sc-context-bar, .sc-period-tabs, .no-print { display: none !important; }

    /* Reset layout */
    .sc-main-wrapper { margin-left: 0 !important; }
    .sc-content { padding: .5cm !important; background: #fff !important; }
    body { background: #fff !important; color: #000 !important; }

    /* Reset dark card backgrounds but keep coloured headers */
    .card {
        background: #fff !important;
        border: 1px solid #dee2e6 !important;
        box-shadow: none !important;
        color: #000 !important;
        break-inside: avoid;
    }
    .card-body { background: #fff !important; color: #000 !important; }

    /* Keep Bootstrap coloured card headers (bg-primary / bg-success / bg-danger) */
    .card-header { background: #f8f9fa !important; color: #000 !important; border-color: #dee2e6 !important; }
    .card-header.bg-primary  { background-color: #0d6efd !important; color: #fff !important; }
    .card-header.bg-success  { background-color: #198754 !important; color: #fff !important; }
    .card-header.bg-danger   { background-color: #dc3545 !important; color: #fff !important; }
    .card-header.bg-warning  { background-color: #ffc107 !important; color: #000 !important; }
    .card-header.bg-dark     { background-color: #212529 !important; color: #fff !important; }

    /* Table resets */
    .table {
        --bs-table-color: #000;
        --bs-table-bg: transparent;
        --bs-table-border-color: #dee2e6;
    }
    .table-light   { background-color: #f8f9fa !important; color: #000 !important; }
    .table-primary { background-color: #cfe2ff !important; color: #000 !important; }
    .table-success { background-color: #d1e7dd !important; color: #000 !important; }
    .table-danger  { background-color: #f8d7da !important; color: #000 !important; }
    .table-warning { background-color: #fff3cd !important; color: #000 !important; }
    .table thead th { color: #495057 !important; }

    /* Text utilities */
    h1,h2,h3,h4,h5,h6 { color: #000 !important; }
    .text-muted   { color: #6c757d !important; }
    .text-success { color: #198754 !important; }
    .text-danger  { color: #dc3545 !important; }

    /* Alerts */
    .alert-success { background-color: #d1e7dd !important; border-color: #a3cfbb !important; color: #0f5132 !important; }
    .alert-danger  { background-color: #f8d7da !important; border-color: #f1aeb5 !important; color: #842029 !important; }
}
