:root {
    --navy-900: #0B2545;
    --navy-800: #13315C;
    --navy-700: #134074;
    --steel-300: #8DA9C4;
    --mist-100: #EEF4ED;
    --danger-soft: #f8d7da;
    --warn-soft: #fff3cd;
    --ok-soft: #d1e7dd;
    --accent-green: #198754;
    --accent-orange: #fd7e14;
    --accent-red: #dc3545;
    --accent-teal: #0d6efd;
}

* {
    font-family: "Poppins", sans-serif;
}

body {
    background: linear-gradient(150deg, #e8f0fb, #eef4ed);
    color: var(--navy-900);
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
    width: 240px;
    background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-700) 100%);
    color: #fff;
    min-height: 100vh;
    position: sticky;
    top: 0;
    flex-shrink: 0;
}

.brand-block {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 16px;
    margin-bottom: 8px;
}

.brand-block h5 {
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 2px;
}

.brand-block small {
    color: var(--steel-300);
    font-size: 0.73rem;
}

.sidebar .nav-link {
    color: #ccd9e8;
    background: transparent;
    border-radius: 8px;
    padding: 9px 12px;
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.18s, color 0.18s;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
}

/* Active sidebar item — strong specificity to override Bootstrap nav-pills */
.sidebar .nav-pills .nav-link.active,
.sidebar .nav.nav-pills .nav-link.active,
.sidebar .flex-column .nav-link.active,
.sidebar .nav-link.active {
    background: rgba(255, 255, 255, 0.2) !important;
    color: #fff !important;
    font-weight: 700 !important;
    border-left: 3px solid #60a5fa !important;
    padding-left: 9px !important;
    box-shadow: none !important;
    border-bottom: none !important;
}


.sidebar .nav-section-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--steel-300);
    padding: 10px 12px 4px;
    margin-top: 6px;
}

.content-wrapper {
    width: calc(100% - 240px);
}

/* ===================== TOPBAR ===================== */
.topbar {
    background: var(--navy-800);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 58px;
}

.content-main {
    padding-bottom: 2rem;
}

/* ===================== DASHBOARD STAT CARDS ===================== */
.stat-card {
    background: #fff;
    border-radius: 14px;
    border: none;
    box-shadow: 0 2px 12px rgba(11, 37, 69, 0.09);
    padding: 18px 20px;
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(11, 37, 69, 0.13);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card .stat-label {
    color: #6c7a8d;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--navy-900);
    line-height: 1;
}

.stat-card .stat-sub {
    font-size: 0.75rem;
    color: #8a9bb0;
    margin-top: 4px;
}

.stat-blue .stat-icon {
    background: #dbeafe;
    color: #2563eb;
}

.stat-green .stat-icon {
    background: #dcfce7;
    color: #16a34a;
}

.stat-orange .stat-icon {
    background: #ffedd5;
    color: #ea580c;
}

.stat-red .stat-icon {
    background: #fee2e2;
    color: #dc2626;
}

.stat-purple .stat-icon {
    background: #ede9fe;
    color: #7c3aed;
}

.stat-teal .stat-icon {
    background: #ccfbf1;
    color: #0f766e;
}

.stat-blue .stat-value {
    color: #1e40af;
}

.stat-green .stat-value {
    color: #15803d;
}

.stat-orange .stat-value {
    color: #c2410c;
}

.stat-red .stat-value {
    color: #b91c1c;
}

.stat-purple .stat-value {
    color: #6d28d9;
}

.stat-teal .stat-value {
    color: #0f766e;
}

/* ===================== GENERIC CARD / TABLE CONTAINERS ===================== */
.dashboard-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2eaf4;
    box-shadow: 0 2px 12px rgba(11, 37, 69, 0.07);
}

.dashboard-card .label {
    color: var(--navy-700);
    font-size: 0.85rem;
    font-weight: 500;
}

.dashboard-card .count {
    color: var(--navy-900);
    font-size: 1.6rem;
    font-weight: 700;
}

.table-container,
.card-white {
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e2eaf4;
    box-shadow: 0 2px 12px rgba(11, 37, 69, 0.07);
}

/* ===================== Quick Action Buttons ===================== */
.quick-actions .btn {
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 10px 18px;
}

/* ===================== BADGES ===================== */
.badge-status {
    font-weight: 600;
    border-radius: 20px;
    padding: 4px 10px;
    font-size: 0.78rem;
}

.status-overdue {
    background: #fee2e2;
    color: #b91c1c;
}

.status-due {
    background: #fef9c3;
    color: #854d0e;
}

.status-completed {
    background: #dcfce7;
    color: #15803d;
}

.status-pending {
    background: #fff3cd;
    color: #856404;
}

/* ===================== TABLES ===================== */
.table thead th {
    background: #f1f6fb;
    color: var(--navy-800);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid #dce8f4;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: #f8fbff;
}

/* ===================== SECTION TITLES ===================== */
.section-title {
    color: var(--navy-900);
    font-weight: 700;
    font-size: 1rem;
}

/* ===================== BUTTONS ===================== */
.btn-primary {
    background-color: var(--navy-700);
    border-color: var(--navy-700);
}

.btn-primary:hover {
    background-color: var(--navy-800);
    border-color: var(--navy-800);
}

.btn-navy {
    background-color: var(--navy-900);
    border-color: var(--navy-900);
    color: #fff;
}

.btn-navy:hover {
    background-color: var(--navy-800);
    color: #fff;
}

/* ===================== FORMS ===================== */
.form-label {
    font-weight: 500;
    font-size: 0.875rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--navy-700);
    box-shadow: 0 0 0 0.2rem rgba(19, 64, 116, 0.15);
}

/* ===================== LOGIN ===================== */
.login-page {
    min-height: 100vh;
    background: radial-gradient(circle at top right, var(--steel-300), var(--navy-900));
}

.login-card {
    border-radius: 14px;
    border: 0;
}

/* ===================== ALERT STRIP ===================== */
.alert-strip {
    border-radius: 10px;
    font-size: 0.875rem;
    padding: 10px 16px;
}

/* ===================== PAYMENT BADGE ===================== */
.payment-badge-paid {
    background: #dcfce7;
    color: #15803d;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
}

.payment-badge-partial {
    background: #fef9c3;
    color: #854d0e;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
}

.payment-badge-due {
    background: #fee2e2;
    color: #b91c1c;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
}

/* ===================== TABS (Balance Due Report — scoped to tab navs only) ===================== */
.nav-tabs .nav-link,
.nav-pills:not(.flex-column) .nav-link {
    border-bottom: 3px solid transparent;
    padding: 10px 18px;
    font-size: 0.875rem;
    transition: color 0.15s, border-color 0.15s;
}

.nav-tabs .nav-link:hover,
.nav-pills:not(.flex-column) .nav-link:hover {
    color: #00d0ff !important;
    border-bottom-color: var(--steel-300);
}

.nav-tabs .nav-link.active,
.nav-pills:not(.flex-column) .nav-link.active {
    color: var(--navy-800) !important;
    border-bottom: 3px solid var(--navy-700);
    background: transparent;
}

/* ===================== PERIOD FILTER PILLS ===================== */
.btn-navy {
    background-color: var(--navy-900);
    border-color: var(--navy-900);
    color: #fff;
}

.btn-navy:hover,
.btn-navy:focus {
    background-color: var(--navy-800);
    border-color: var(--navy-800);
    color: #fff;
}

/* ===================== PAGINATION ===================== */
.pagination .page-link {
    font-size: 0.82rem;
    font-weight: 500;
    min-width: 34px;
    text-align: center;
    border-color: #dce8f4;
    color: var(--navy-800);
    transition: background 0.15s, color 0.15s;
}

.pagination .page-link:hover {
    background: #f1f6fb;
    color: var(--navy-900);
}

.pagination .page-item.active .page-link {
    background: var(--navy-700);
    border-color: var(--navy-700);
    color: #fff;
}

.pagination .page-item.disabled .page-link {
    color: #adb5bd;
    background: transparent;
    border-color: #dce8f4;
}

/* ===================== RESPONSIVE ===================== */

/* ── Hamburger Toggle Button ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--navy-800);
    border: none;
    color: #fff;
    font-size: 1.1rem;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 12px rgba(0,0,0,0.25);
    cursor: pointer;
    transition: background 0.2s;
}
.sidebar-toggle:hover { background: var(--navy-700); }

/* ── Sidebar Overlay (mobile backdrop) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11,37,69,0.45);
    z-index: 1050;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

@media (max-width: 991px) {

    /* Show hamburger */
    .sidebar-toggle { display: flex; }

    /* Sidebar becomes a fixed off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        z-index: 1055;
        min-height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        overflow-y: auto;
        flex-shrink: 0;
    }
    .sidebar.open { transform: translateX(0); }

    /* Content fills full width, add top padding for topbar */
    .content-wrapper {
        width: 100%;
        margin-left: 0;
    }

    /* Topbar shifts right on mobile for the hamburger button */
    .topbar {
        padding-left: 64px;
    }

    /* Stack main content padding */
    .content-main {
        padding: 1rem !important;
    }

    /* ── Page headings ── */
    .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 10px;
    }
    h4.section-title, h4.fw-bold {
        font-size: 1.1rem;
    }

    /* ── Stat cards: 2-up on mobile ── */
    .stat-card .stat-value { font-size: 1.35rem; }
    .stat-card .stat-icon  { width: 40px; height: 40px; font-size: 1.1rem; }

    /* ── Tables: horizontal scroll ── */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table { min-width: 560px; font-size: 0.82rem; }
    .table thead th { font-size: 0.75rem; padding: 8px 10px; }
    .table tbody td { padding: 8px 10px; }

    /* ── card-white padding reduction ── */
    .card-white { border-radius: 10px; }
    .card-white.p-4, .card-white.p-3 { padding: 14px !important; }

    /* ── Filter forms: stack vertically ── */
    .row.g-2 > [class*="col-md"] { width: 100%; }

    /* ── Dispatch Hero Banner ── */
    .dispatch-hero {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px 18px;
    }
    .dispatch-hero h4 { font-size: 1.05rem; }

    /* ── Stock-Out: panel layout stack ── */
    .panel-card-body { padding: 14px 16px; }
    .panel-card-header { padding: 14px 16px; }
    .panel-card-footer { padding: 12px 16px; }

    /* ── Grand total on mobile ── */
    .grand-total-bar { flex-direction: column; align-items: stretch; gap: 10px; }
    .grand-total-value { font-size: 1.2rem; }
    .btn-dispatch { width: 100%; justify-content: center; }

    /* ── Item rows: stack fields ── */
    .item-row .row > [class*="col"] { width: 100% !important; }
    .item-row .row > .col-1 { width: auto !important; }
    .item-row .line-total-display { text-align: left; margin-top: 4px; }

    /* Hide item number badge on very small screens for space */
    .item-number { display: none; }

    /* ── Type tabs ── */
    .type-tabs { flex-direction: row; }
    .type-tab { font-size: 0.8rem; padding: 8px 10px; }

    /* ── Dealer page action buttons ── */
    .d-flex.gap-2 .btn { font-size: 0.8rem; padding: 6px 12px; }

    /* ── Dealer stat cards (view page) ── */
    .dealer-stats-row .col-6 { width: 50%; }

    /* ── Pagination ── */
    .pagination .page-link { min-width: 30px; font-size: 0.78rem; padding: 5px 8px; }

    /* ── Alert boxes ── */
    .alert { font-size: 0.85rem; border-radius: 10px; }

    /* ── Nav tabs (view_dealer.php) ── */
    .nav-tabs .nav-link { padding: 8px 12px; font-size: 0.82rem; }

    /* ── Buttons in tables ── */
    .btn-sm { padding: 4px 8px; font-size: 0.78rem; }
}

@media (max-width: 576px) {
    /* Extra small: tighten up everything */
    .content-main { padding: 0.75rem !important; }

    h4.section-title, h4.fw-bold { font-size: 1rem; }

    /* 1-col stat cards */
    .row.g-3 > .col-6 { width: 100%; }

    .dispatch-hero { padding: 14px 14px; gap: 10px; }
    .dispatch-hero small { font-size: 0.75rem; }

    /* Full-width action buttons */
    .d-flex.justify-content-between .d-flex.gap-2 {
        width: 100%;
        flex-direction: column;
    }
    .d-flex.justify-content-between .d-flex.gap-2 .btn { width: 100%; }

    /* Filters: each select takes full width */
    .row.g-2 > * { width: 100% !important; }

    /* Item row fields */
    .item-row .row { gap: 6px !important; }

    .panel-card-body { padding: 12px; }

    .type-tab { font-size: 0.76rem; padding: 7px 8px; }
}