/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
    min-width: 240px;
    max-width: 240px;
    min-height: 100vh;
    background: #1a1f2e;
    color: #c8ccd8;
    display: flex;
    flex-direction: column;
    transition: all 0.3s;
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    overflow-y: auto;
}

#sidebar .sidebar-brand {
    padding: 1.25rem 1.25rem 0.75rem;
    border-bottom: 1px solid #2d3348;
}

#sidebar .sidebar-brand h5 {
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    margin: 0;
    letter-spacing: 0.02em;
}

#sidebar .sidebar-brand small {
    color: #6b7280;
    font-size: 0.7rem;
}

#sidebar .nav-section {
    padding: 0.6rem 1rem 0.25rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #4b5563;
    font-weight: 600;
}

#sidebar .nav-link {
    color: #9ca3af;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
}

#sidebar .nav-link:hover {
    background: #252b3b;
    color: #e5e7eb;
}

#sidebar .nav-link.active {
    background: #2563eb;
    color: #fff;
    font-weight: 500;
}

#sidebar .nav-link .bi {
    font-size: 1rem;
    width: 1.1rem;
    text-align: center;
}

#sidebar .badge-pill {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 0.2em 0.55em;
}

.sidebar-footer {
    margin-top: auto;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid #2d3348;
    font-size: 0.75rem;
    color: #6b7280;
}

.sync-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #22c55e;
    margin-right: 4px;
}

.sync-dot.error  { background: #ef4444; }
.sync-dot.syncing { background: #f59e0b; animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ── Main content ─────────────────────────────────────────────────────────── */
#main-content {
    margin-left: 240px;
    min-height: 100vh;
    background: #f3f4f6;
}

.top-bar {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.6rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-body {
    padding: 1.5rem;
}

/* ── KPI cards ───────────────────────────────────────────────────────────── */
.kpi-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    border: 1px solid #e5e7eb;
    height: 100%;
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.kpi-card .kpi-label {
    font-size: 0.78rem;
    color: #6b7280;
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kpi-card .kpi-icon {
    font-size: 1.6rem;
    opacity: 0.15;
    float: right;
    margin-top: -0.25rem;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-card {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
}

.data-card .card-header-bar {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
}

.data-card .card-header-bar h6 {
    margin: 0;
    font-weight: 600;
    font-size: 0.875rem;
}

.table-sm td, .table-sm th {
    font-size: 0.82rem;
    vertical-align: middle;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge-state-draft     { background:#e5e7eb; color:#374151; }
.badge-state-sale      { background:#dbeafe; color:#1d4ed8; }
.badge-state-done      { background:#dcfce7; color:#15803d; }
.badge-state-cancel    { background:#fee2e2; color:#b91c1c; }

.badge-inv-nothing     { background:#f3f4f6; color:#6b7280; }
.badge-inv-to-invoice  { background:#fef3c7; color:#b45309; }
.badge-inv-invoiced    { background:#dcfce7; color:#15803d; }

.badge-pay-not_paid    { background:#fee2e2; color:#b91c1c; }
.badge-pay-partial     { background:#fef3c7; color:#b45309; }
.badge-pay-paid        { background:#dcfce7; color:#15803d; }
.badge-pay-reversed    { background:#f3f4f6; color:#6b7280; }

.badge-change-create   { background:#dbeafe; color:#1d4ed8; }
.badge-change-update   { background:#fef3c7; color:#b45309; }
.badge-change-cancel   { background:#fee2e2; color:#b91c1c; }
.badge-change-return   { background:#f3e8ff; color:#7e22ce; }

.badge-match-matched   { background:#dcfce7; color:#15803d; }
.badge-match-unmatched { background:#fee2e2; color:#b91c1c; }
.badge-match-manual    { background:#f3e8ff; color:#7e22ce; }

/* ── Sortable table headers ──────────────────────────────────────────────── */
.sort-header {
    cursor: pointer;
    white-space: nowrap;
}
.sort-header:hover { color: #2563eb; }

/* ── Filter builder ──────────────────────────────────────────────────────── */
.flt-btn {
    font-size: 0.78rem;
    padding: 0.2em 0.65em;
    transition: filter 0.1s;
}
.flt-btn:hover { filter: brightness(0.93); }

/* ── Chevron rotation (shared: changelog tree + dashboard rows) ──────────── */
.chevron-icon {
    transition: transform 0.18s ease;
    display: inline-block;
}
.tree-toggle:not(.collapsed) .chevron-icon,
.today-row:not(.collapsed) .chevron-icon {
    transform: rotate(90deg);
}
.today-row:hover { background: #f3f4f6; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.filter-bar .form-select, .filter-bar .form-control {
    font-size: 0.82rem;
    padding: 0.3rem 0.6rem;
    height: auto;
    max-width: 180px;
}

/* ── Sync spinner ────────────────────────────────────────────────────────── */
.spin { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile sidebar — collapsible on narrow screens ───────────────────────
   The fixed 240px sidebar consumes half the viewport on phones, leaving
   the actual content squeezed. Below 768px we slide it off-screen by
   default and reveal it via a hamburger button (.sidebar-toggle) in the
   top-bar. Tapping a nav link or the backdrop closes it. */
.sidebar-toggle {
    display: none;
    background: transparent;
    border: 0;
    font-size: 1.4rem;
    color: #4b5563;
    padding: 0.25rem 0.6rem;
    margin-right: 0.25rem;
    cursor: pointer;
    line-height: 1;
}
.sidebar-toggle:hover { color: #111827; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 999;
}
body.sidebar-open .sidebar-backdrop { display: block; }

@media (max-width: 768px) {
    .sidebar-toggle { display: inline-flex; align-items: center; }
    #sidebar {
        transform: translateX(-100%);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.35);
        width: 260px;
    }
    #sidebar.is-open { transform: translateX(0); }
    #main-content { margin-left: 0 !important; }
    .top-bar    { padding: 0.5rem 0.75rem; }
    .page-body  { padding: 0.75rem; }
}
