:root {
    --sidebar-w: 255px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #f472b6;
    --sidebar-hover: #2d1a2e;
    --topbar-h: 57px;
    --page-bg: #f1f5f9;
}

/* ── Layout ───────────────────────────────────────────── */
body { margin: 0; background: var(--page-bg); }

#wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    position: sticky;
    top: 0;
    background: var(--sidebar-bg);
    flex-shrink: 0;
    transition: width .25s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    isolation: isolate;
}
#sidebar.collapsed { width: 62px; }

.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}
.brand-icon {
    width: 34px; height: 34px;
    background: var(--sidebar-active);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
    font-size: 1rem;
}
.brand-text {
    margin-left: .75rem;
    color: #f8fafc;
    font-weight: 700;
    font-size: .95rem;
    white-space: nowrap;
}
#sidebar.collapsed .brand-text { display: none; }

.sidebar-scroll { overflow-y: auto; flex: 1; padding-bottom: 1rem; }
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.nav-section-label {
    display: none; /* replaced by collapsible group headers */
}

#sidebar .nav-item .group-header,
#sidebar .nav-item a {
    display: flex;
    align-items: center;
    padding: .48rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background .15s, color .15s;
    white-space: nowrap;
    position: relative;
}
/* Group headers: white text, slightly bolder */
#sidebar .nav-item .group-header {
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    letter-spacing: .01em;
    padding-top: .55rem;
    padding-bottom: .55rem;
}
#sidebar .nav-item .group-header:hover,
#sidebar .nav-item a:hover  { background: var(--sidebar-hover); color: #e2e8f0; }
#sidebar .nav-item .group-header.active {
    background: rgba(244,114,182,.12);
    color: var(--sidebar-active);
    border-right: 3px solid var(--sidebar-active);
}
#sidebar .nav-item a.active {
    background: rgba(244,114,182,.12);
    color: var(--sidebar-active);
    border-right: 3px solid var(--sidebar-active);
}
#sidebar .nav-item a i.nav-icon,
#sidebar .nav-item .group-header i.nav-icon { font-size: 1.05rem; width: 1.35rem; flex-shrink: 0; }
#sidebar .nav-item a .nav-label,
#sidebar .nav-item .group-header .nav-label { margin-left: .65rem; font-size: .84rem; }
#sidebar.collapsed .nav-label { display: none; }
#sidebar.collapsed .nav-chevron { display: none; }
.nav-chevron { font-size: .65rem; margin-left: auto; transition: transform .2s; }
.group-header[aria-expanded="true"] .nav-chevron { transform: rotate(180deg); }

/* Sub-nav */
.nav-sub { list-style: none; padding: .25rem 0; margin: 0; background: rgba(255,255,255,.04); border-left: 2px solid rgba(255,255,255,.08); margin-left: 1rem; }
.nav-sub li a {
    display: flex;
    align-items: center;
    padding: .34rem 1rem .34rem 1.5rem;
    color: rgba(148,163,184,.85);
    text-decoration: none;
    font-size: .8rem;
    white-space: nowrap;
    transition: color .15s;
}
.nav-sub li a:hover  { color: #e2e8f0; }
.nav-sub li a.active { color: var(--sidebar-active); }
#sidebar.collapsed .nav-sub { display: none; }

/* ── Page content ─────────────────────────────────────── */
#page-content-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.content-area { flex: 1; padding: 1.5rem; }

/* ── Sidebar footer ───────────────────────────────────── */
.sidebar-footer {
    flex-shrink: 0;
    padding: .5rem .75rem;
    border-top: 1px solid rgba(255,255,255,.07);
}
.sf-date {
    font-size: .65rem;
    color: #475569;
    padding: 0 .25rem;
    margin-bottom: .2rem;
    white-space: nowrap;
    overflow: hidden;
}
.sf-user-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: .5rem;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: .82rem;
    padding: .35rem .5rem;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
}
.sf-user-btn:hover { background: #1e293b; color: #e2e8f0; }
.sf-icon { font-size: 1rem; flex-shrink: 0; }
.sf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sidebar.collapsed .sf-date  { display: none; }
#sidebar.collapsed .sf-name  { display: none; }

/* ── KPI Cards ────────────────────────────────────────── */
.kpi-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border: 1px solid #e2e8f0;
}
.kpi-icon {
    width: 46px; height: 46px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
}
.kpi-value { font-size: 1.65rem; font-weight: 700; color: #0f172a; line-height: 1.2; }
.kpi-label {
    font-size: .72rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.kpi-trend { font-size: .78rem; font-weight: 600; }

/* ── Chart / Table cards ──────────────────────────────── */
.erp-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border: 1px solid #e2e8f0;
    height: 100%;
}
.erp-card-title { font-size: .875rem; font-weight: 600; color: #0f172a; }

.erp-table-wrap {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border: 1px solid #e2e8f0;
    overflow: hidden;
}
.erp-table-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.erp-table-wrap .table { margin-bottom: 0; }
.erp-table-wrap .table th {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: .65rem 1rem;
}
.erp-table-wrap .table td {
    padding: .7rem 1rem;
    font-size: .855rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}
.erp-table-wrap .table tr:last-child td { border-bottom: none; }
.erp-table-wrap .table tbody tr:nth-child(even) td { background: #f8fafc; }

/* ── Page header ──────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.3rem; font-weight: 700; color: #0f172a; margin: 0; }
.page-header .breadcrumb { font-size: .78rem; margin: .15rem 0 0; }

/* ── Fixed-width icons (all Bootstrap Icons same width) ── */
.bi { display: inline-block; width: 1.25em; text-align: center; }

/* ── Icon action buttons ──────────────────────────────── */
.btn-outline-secondary.py-0 {
    background-color: #dbeafe;
    border-color: #bfdbfe;
    color: #1d4ed8;
}
.btn-outline-secondary.py-0:hover {
    background-color: #bfdbfe;
    border-color: #93c5fd;
    color: #1e40af;
}

/* ── Sidebar toggle ───────────────────────────────────── */
.sidebar-toggle-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: .25rem .3rem;
    line-height: 1;
    flex-shrink: 0;
    margin-left: auto;
    border-radius: 4px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
}
.sidebar-toggle-btn:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }

/* ── Mobile topbar ────────────────────────────────────── */
#mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 400;
    background: var(--sidebar-bg);
    height: var(--topbar-h);
    align-items: center;
    padding: 0 1rem;
    gap: .75rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.mobile-brand {
    color: #f8fafc;
    font-weight: 700;
    font-size: 1.1rem;
    flex: 1;
    letter-spacing: .04em;
}
.mobile-hamburger {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    padding: .2rem .3rem;
    display: flex;
    align-items: center;
    line-height: 1;
}

/* ── Sidebar backdrop ─────────────────────────────────── */
#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 300;
}
#sidebar-backdrop.active { display: block; }

/* ── Tables: always scrollable when they overflow ─────── */
.erp-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Mobile overrides ─────────────────────────────────── */
@media (max-width: 767.98px) {
    #mobile-topbar { display: flex; }

    /* Sidebar becomes a fixed overlay */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 350;
        width: var(--sidebar-w) !important;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    #sidebar.mobile-open { transform: translateX(0); }

    /* Always show full labels inside the mobile overlay */
    #sidebar.mobile-open .brand-text,
    #sidebar.mobile-open .nav-label,
    #sidebar.mobile-open .nav-chevron { display: revert; }
    #sidebar.mobile-open .nav-sub     { display: block; }
    #sidebar.mobile-open .sf-name     { display: block; }

    /* Page content takes full width (sidebar is out of flow) */
    #wrapper { display: block; }

    .content-area { padding: 1rem .75rem; }

    /* Page header: stack vertically, buttons wrap */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: .6rem;
        margin-bottom: 1rem;
    }
    .page-header > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: .4rem;
        width: 100%;
    }
    .page-header h1 { font-size: 1.1rem; }

    /* Forms: single column on mobile */
    .cd-form .col-3,
    .cd-form .col-4,
    .cd-form .col-5,
    .cd-form .col-6 { width: 100%; }
    .cd-form { max-width: 100% !important; }

    /* Product detail form */
    form[id="product-form"] { max-width: 100% !important; }

    /* Table headers shrink */
    .erp-table-wrap .table th,
    .erp-table-wrap .table td { padding: .5rem .6rem; font-size: .78rem; }

    /* Login card padding */
    .login-card { padding: 1.75rem 1.25rem; }
}

/* ── Login ────────────────────────────────────────────── */
.login-bg {
    background: var(--sidebar-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 2.25rem 2.5rem;
    width: 100%;
    max-width: 390px;
    box-shadow: 0 25px 60px rgba(0,0,0,.35);
}
