:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --brand: #C8203A;
    --brand-dark: #9E1830;
    --brand-soft: rgba(200, 32, 58, 0.12);
    --brand-secondary: #1E5631;
    --accent: #e36414;
    --surface: #f4f5f7;
    --sidebar-bg: #000000;
    --sidebar-bg-2: #c8203a;
    --sidebar-text: rgba(255, 255, 255, 0.82);
    --sidebar-muted: rgba(255, 255, 255, 0.42);
}

body {
    background: var(--surface);
    font-family: "Segoe UI", system-ui, sans-serif;
}

/* Bootstrap primary → Wonderchef crimson */
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
}
a:not(.nav-link):not(.btn):not(.uc-tile-link):not(.page-link) {
    color: var(--brand);
}
a:not(.nav-link):not(.btn):not(.uc-tile-link):not(.page-link):hover {
    color: var(--brand-dark);
}

/* ── App shell: fixed sidebar + scrolling main ── */
.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(185deg, #000000 0%, #c8203a 100%);
    color: #fff;
    flex-shrink: 0;
    transition: width 0.2s ease, transform 0.2s ease;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1rem 0.85rem 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    min-height: 4.25rem;
}

.sidebar-brand-lockup {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    flex: 1;
}

.sidebar-logo {
    height: 22px;
    width: auto;
    max-width: 150px;
    display: block;
    object-fit: contain;
    margin-bottom: 0.15rem;
}

.sidebar-logo-mark {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 8px;
}

.sidebar-brand-title {
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    letter-spacing: 0.01em;
}

.sidebar-brand-sub {
    font-size: 0.58rem;
    color: var(--sidebar-muted);
    letter-spacing: 0.01em;
    line-height: 1.3;
}

.sidebar-toggle {
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 0.45rem;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    min-width: 2rem;
    min-height: 2rem;
}
.sidebar-toggle:hover {
    background: rgba(200, 32, 58, 0.35);
}

.sidebar-nav-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.35rem 0 1.25rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.sidebar .nav-section {
    margin: 0.85rem 0.75rem 0.35rem;
    padding: 0.55rem 0.65rem 0.15rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    line-height: 1.2;
}
.sidebar .nav-section:first-child {
    border-top: 0;
    margin-top: 0.35rem;
}

.sidebar .nav-link {
    color: var(--sidebar-text);
    border-radius: 0.55rem;
    margin: 0.1rem 0.55rem;
    padding: 0.6rem 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.9rem;
    font-weight: 500;
    min-height: 44px;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar .nav-link i {
    width: 1.15rem;
    text-align: center;
    font-size: 0.95rem;
    opacity: 0.9;
    flex-shrink: 0;
}
.sidebar .nav-link .nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
.sidebar .nav-link.active {
    background: var(--brand-soft);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--brand);
    font-weight: 600;
}
.sidebar .nav-link.active i {
    color: #ff8a9a;
}
.sidebar .nav-link.disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* Collapsed rail */
body.sidebar-collapsed {
    --sidebar-width-current: var(--sidebar-collapsed-width);
}
body:not(.sidebar-collapsed) {
    --sidebar-width-current: var(--sidebar-width);
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}
body.sidebar-collapsed .sidebar-brand-lockup,
body.sidebar-collapsed .sidebar .nav-label,
body.sidebar-collapsed .sidebar-brand-title,
body.sidebar-collapsed .sidebar-brand-sub,
body.sidebar-collapsed .sidebar-logo-full {
    display: none !important;
}
body.sidebar-collapsed .sidebar-logo-mark {
    display: block;
    margin: 0 auto;
}
body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.85rem 0.4rem;
}
body.sidebar-collapsed .sidebar .nav-section {
    font-size: 0;
    letter-spacing: 0;
    padding: 0.35rem 0.9rem 0;
    margin: 0.55rem 0.55rem 0.15rem;
    min-height: 0.5rem;
}
body.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding: 0.7rem 0.4rem;
    margin: 0.1rem 0.45rem;
}
body.sidebar-collapsed .sidebar .nav-link i {
    margin: 0;
}
body.sidebar-collapsed .sidebar .nav-link::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #111;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.55rem;
    border-radius: 0.35rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 1100;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
body.sidebar-collapsed .sidebar .nav-link:hover::after {
    opacity: 1;
}

.main-content {
    min-width: 0;
    margin-left: var(--sidebar-width-current, var(--sidebar-width));
    width: calc(100% - var(--sidebar-width-current, var(--sidebar-width)));
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease, width 0.2s ease;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.topbar .btn {
    min-height: 36px;
}
.mobile-nav-toggle {
    display: none;
    width: 2.5rem;
    height: 2.5rem;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    background: #fff;
    color: #0f172a;
    align-items: center;
    justify-content: center;
}
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
}

.content-area {
    flex: 1;
}

.upload-dropzone {
    border: 2px dashed #b6c7ce;
    border-radius: 0.75rem;
    background: #fafcfd;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.upload-dropzone.dragover {
    border-color: var(--brand);
    background: #fde8ec;
}

.badge.status-completed { background: #198754; }
.badge.status-importing { background: #0d6efd; }
.badge.status-validated { background: #0dcaf0; color: #000; }
.badge.status-uploaded { background: #6c757d; }
.badge.status-failed,
.badge.status-rolled_back { background: #dc3545; }
.badge.status-validating { background: #ffc107; color: #000; }

.kpi-card .kpi-icon {
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 0.95rem;
}

.chart-card canvas {
    max-width: 100%;
}

/* Filters — stack on narrow screens */
#filtersForm .card-body > .row {
    --bs-gutter-y: 0.65rem;
}

/* State × Month heatmap */
.heatmap-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.heatmap-table {
    border-collapse: separate;
    border-spacing: 4px;
    width: 100%;
    min-width: 100%;
    font-size: 0.78rem;
    table-layout: auto;
}

.heatmap-table th,
.heatmap-table td {
    text-align: center;
    padding: 0.35rem 0.4rem;
    white-space: nowrap;
}

.heatmap-table thead th {
    background: #eef1f3;
    color: #334155;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.heatmap-table tbody th {
    text-align: left;
    background: #f7f8fa;
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 140px;
    font-weight: 600;
}

.heatmap-table td {
    min-width: 96px;
    border-radius: 6px;
    cursor: default;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.heatmap-table td:hover {
    transform: scale(1.06);
    box-shadow: 0 0 0 2px rgba(200, 32, 58, 0.25);
    z-index: 2;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: #6c757d;
}

.heatmap-legend-bar {
    flex: 1;
    height: 10px;
    border-radius: 999px;
    /* Bad (orange) → Good (green) — Data Visualizer scale */
    background: linear-gradient(90deg, #c25408, #e88c30, #ffd699, #bae6aa, #389e4e, #1a6b34);
    max-width: 280px;
}

.viz-legend-bar {
    background: linear-gradient(90deg, #c25408, #e88c30, #ffd699, #bae6aa, #389e4e, #1a6b34);
    max-width: 280px;
}

.viz-sum-card {
    background: #f7fafb;
    border: 1px solid #e8eef0;
    border-radius: 0.5rem;
    padding: 0.65rem 0.75rem;
}

.viz-sum-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6c757d;
}

.viz-sum-value {
    font-weight: 700;
    font-size: 0.95rem;
    color: #0f172a;
}

.viz-matrix-wrap {
    max-height: 70vh;
    overflow: auto;
}

.viz-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.viz-matrix tbody th {
    max-width: 220px;
    z-index: 1;
}

.viz-camp-name {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viz-matrix td.viz-cell {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.viz-matrix td.viz-total {
    position: sticky;
    right: 0;
    z-index: 1;
    box-shadow: -4px 0 6px rgba(0,0,0,0.04);
}

/* Pincode heat cells */
.pincode-heat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 0.5rem;
}

.pincode-heat-cell {
    border-radius: 0.5rem;
    padding: 0.65rem 0.5rem;
    text-align: center;
    transition: transform 0.12s ease;
}

.pincode-heat-cell:hover {
    transform: translateY(-2px);
}

.pincode-heat-cell .tiny {
    font-size: 0.65rem;
}

/* Stock Match actionable columns */
#stockMatchTable {
    --bs-table-striped-bg: rgba(15, 23, 42, 0.03);
}
#stockMatchTable thead th.col-action,
#stockMatchTable tbody td.col-action {
    background: rgba(200, 32, 58, 0.06);
    font-weight: 700;
}
#stockMatchTable tbody tr:nth-of-type(odd) td.col-action {
    background: rgba(200, 32, 58, 0.09);
}
#stockMatchTable td.col-action.is-low {
    color: #b91c1c !important;
}
#stockMatchTable thead th:first-child,
#stockMatchTable tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
}
#stockMatchTable tbody tr:nth-of-type(odd) td:first-child {
    background: #f8f9fa;
}

/* Mobile */
@media (max-width: 991.98px) {
    .mobile-nav-toggle { display: inline-flex; }
    .sidebar {
        transform: translateX(-105%);
        width: min(86vw, var(--sidebar-width)) !important;
        box-shadow: 8px 0 24px rgba(0,0,0,0.25);
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    body.sidebar-open .sidebar-backdrop {
        display: block;
    }
    /* On mobile ignore desktop collapsed rail width for main content */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    body.sidebar-collapsed .sidebar .nav-label,
    body.sidebar-collapsed .sidebar-brand-lockup {
        display: block !important;
    }
    body.sidebar-collapsed .sidebar .nav-section {
        font-size: 0.62rem;
        letter-spacing: 0.12em;
        padding: 0.55rem 0.65rem 0.15rem;
    }
    body.sidebar-collapsed .sidebar .nav-link {
        justify-content: flex-start;
        padding: 0.6rem 0.85rem;
    }
    body.sidebar-collapsed .sidebar .nav-link::after {
        display: none;
    }
    .topbar {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    .content-area {
        padding: 1rem !important;
    }
    .uc-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 575.98px) {
    .uc-kpi-grid {
        grid-template-columns: 1fr !important;
    }
    .topbar .btn span,
    .topbar .btn .me-1 + span {
        /* keep icons readable; labels can wrap via flex */
    }
    #filtersForm .col-auto {
        flex: 1 1 100%;
        max-width: 100%;
    }
}

/*
 * DataTables sort icons
 */
table.dataTable thead > tr > th.sorting,
table.dataTable thead > tr > th.sorting_asc,
table.dataTable thead > tr > th.sorting_desc,
table.dataTable thead > tr > th.sorting_asc_disabled,
table.dataTable thead > tr > th.sorting_desc_disabled,
table.dataTable thead > tr > td.sorting,
table.dataTable thead > tr > td.sorting_asc,
table.dataTable thead > tr > td.sorting_desc,
table.dataTable thead > tr > td.sorting_asc_disabled,
table.dataTable thead > tr > td.sorting_desc_disabled,
table.dataTable.table-sm > thead > tr > th:not(.sorting_disabled) {
    padding-right: 0.5rem !important;
    white-space: nowrap !important;
    background-image: none !important;
}

table.dataTable thead > tr > th.sorting:before,
table.dataTable thead > tr > th.sorting:after,
table.dataTable thead > tr > th.sorting_asc:before,
table.dataTable thead > tr > th.sorting_asc:after,
table.dataTable thead > tr > th.sorting_desc:before,
table.dataTable thead > tr > th.sorting_desc:after,
table.dataTable thead > tr > th.sorting_asc_disabled:before,
table.dataTable thead > tr > th.sorting_asc_disabled:after,
table.dataTable thead > tr > th.sorting_desc_disabled:before,
table.dataTable thead > tr > th.sorting_desc_disabled:after,
table.dataTable thead > tr > td.sorting:before,
table.dataTable thead > tr > td.sorting:after,
table.dataTable thead > tr > td.sorting_asc:before,
table.dataTable thead > tr > td.sorting_asc:after,
table.dataTable thead > tr > td.sorting_desc:before,
table.dataTable thead > tr > td.sorting_desc:after,
table.dataTable thead > tr > td.sorting_asc_disabled:before,
table.dataTable thead > tr > td.sorting_asc_disabled:after,
table.dataTable thead > tr > td.sorting_desc_disabled:before,
table.dataTable thead > tr > td.sorting_desc_disabled:after,
table.dataTable.table-sm > thead > tr > th:not(.sorting_disabled):before,
table.dataTable.table-sm > thead > tr > th:not(.sorting_disabled):after {
    content: none !important;
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    position: static !important;
    right: auto !important;
    left: auto !important;
    top: auto !important;
    bottom: auto !important;
    opacity: 0 !important;
}

.uc-th-label { display: inline; }

.uc-sort {
    display: inline-block !important;
    margin-left: 3px !important;
    font-size: 0.75em !important;
    line-height: 1 !important;
    vertical-align: middle !important;
    opacity: 0.55 !important;
    color: #6c757d !important;
    font-weight: 700 !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
}

table.dataTable thead th.sorting_asc .uc-sort,
table.dataTable thead th.sorting_desc .uc-sort,
table.dataTable thead td.sorting_asc .uc-sort,
table.dataTable thead td.sorting_desc .uc-sort,
a.uc-th-sort.is-active .uc-sort {
    opacity: 0.95 !important;
    color: var(--brand) !important;
}

a.uc-th-sort {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
    font-weight: 600;
}

a.uc-th-sort:hover {
    color: var(--brand);
}

a.uc-th-sort .uc-sort {
    margin-left: 3px;
}

/* Campaign / source order drill — always available (not only dashboard-summary.css) */
.uc-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    z-index: 1080;
    display: none;
}
.uc-drawer-backdrop.is-open { display: block; }
.uc-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(440px, 100vw);
    height: 100vh;
    height: 100dvh;
    background: #fff;
    z-index: 1090;
    box-shadow: -12px 0 40px rgba(15, 23, 42, .18);
    transform: translateX(105%) !important;
    transition: transform .22s ease, visibility 0s linear .22s;
    display: flex;
    flex-direction: column;
    visibility: hidden !important;
    pointer-events: none !important;
}
.uc-drawer.is-open {
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transition: transform .22s ease, visibility 0s linear 0s;
}
.uc-drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid #e8eef0;
}
.uc-drawer-kicker {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #C8203A;
    margin-bottom: .15rem;
}
.uc-drawer-body {
    padding: 1rem 1.1rem 1.5rem;
    overflow: auto;
    flex: 1;
}
body.uc-drawer-open { overflow: hidden; }

#spendDrillDrawer.uc-drawer {
    width: min(920px, 100vw);
}
#spendDrillDrawer .spend-drill-table-wrap {
    overflow-x: auto;
}
#spendDrillDrawer .spend-drill-order {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 11rem;
    background: #fff;
    box-shadow: 8px 0 10px -8px rgba(15, 23, 42, .18);
}
#spendDrillDrawer .spend-drill-order-link {
    color: #0f172a;
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}
#spendDrillDrawer .spend-drill-order-link:hover {
    color: #C8203A;
}
body.theme-glass #spendDrillDrawer.uc-drawer {
    background: rgba(255, 255, 255, 0.96);
}
body.theme-glass #spendDrillDrawer .spend-drill-order {
    background: rgba(255, 255, 255, 0.96);
}
