:root {
    --sidebar-width: 260px;
    --sidebar-bg: #1e293b;
    --sidebar-link: #cbd5e1;
    --sidebar-active-bg: rgba(255, 255, 255, .1);
    --page-bg: #f1f5f9;
}

body {
    background: var(--page-bg);
    font-size: .94rem;
}

/* ---------- Layout ---------- */
.app-sidebar {
    --bs-offcanvas-width: var(--sidebar-width);
    --bs-offcanvas-bg: var(--sidebar-bg);
    --bs-offcanvas-color: var(--sidebar-link);
    background: var(--sidebar-bg);
    color: var(--sidebar-link);
}

@media (min-width: 992px) {
    /* Bootstrap's .offcanvas-lg forces a transparent background and auto width on desktop; override both. */
    .app-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: var(--sidebar-width) !important;
        background-color: var(--sidebar-bg) !important;
        color: var(--sidebar-link) !important;
        overflow-y: auto;
        z-index: 1020;
    }

    .app-main {
        margin-left: var(--sidebar-width);
    }
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-brand a {
    color: #fff;
    font-weight: 600;
    font-size: 1.1rem;
    text-decoration: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: .75rem .5rem 1.5rem;
    min-height: calc(100% - 60px);
}

.sidebar-spacer {
    flex: 1 1 auto;
    min-height: 1rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .85rem;
    border-radius: .4rem;
    color: var(--sidebar-link);
    text-decoration: none;
    font-size: .93rem;
}

.sidebar-link:hover {
    background: var(--sidebar-active-bg);
    color: #fff;
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: #fff;
    font-weight: 600;
}

.sidebar-group > .sidebar-link .chevron {
    margin-left: auto;
    font-size: .7rem;
    transition: transform .15s;
}

.sidebar-group > .sidebar-link[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.sidebar-sub {
    padding-left: 1.6rem;
}

.sidebar-sub .sidebar-link {
    font-size: .88rem;
    padding: .4rem .85rem;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .6rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 1010;
}

.app-content {
    padding: 1.25rem;
}

@media (max-width: 575.98px) {
    .app-content {
        padding: 1rem;
    }
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

/* ---------- Cards & stats ---------- */
.card {
    border: 1px solid #e2e8f0;
    border-radius: .6rem;
}

.card-header {
    background: #fff;
    font-weight: 600;
}

.stat-card .stat-label {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #64748b;
}

.stat-card .stat-value {
    font-size: 1.45rem;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
}

.stat-card .stat-icon {
    width: 2.6rem;
    height: 2.6rem;
    border-radius: .6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

/* ---------- Tables ---------- */
.table > :not(caption) > * > * {
    padding: .6rem .75rem;
}

.table thead th {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #64748b;
    white-space: nowrap;
}

.table-totals td,
.table-totals th {
    font-weight: 700;
    background: #f8fafc;
}

.num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---------- Forms ---------- */
.filter-bar .form-label {
    font-size: .78rem;
    margin-bottom: .2rem;
    color: #64748b;
}

.line-items .form-control,
.line-items .form-select {
    min-width: 5.5rem;
}

.line-items .col-product {
    min-width: 14rem;
}

.line-total {
    white-space: nowrap;
    font-weight: 600;
    text-align: right;
}

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

/* ---------- Misc ---------- */
.profit-positive { color: #15803d; }
.profit-negative { color: #b91c1c; }

.min-w-0 { min-width: 0; }

.chart-box {
    position: relative;
    height: 260px;
}

@media print {
    .app-sidebar, .app-topbar, .page-actions, .filter-bar, .no-print { display: none !important; }
    .app-main { margin-left: 0; }
}
