:root {
    --primary-color: #922b21;
    /* Deep Red */
    --primary-hover: #7b241c;
    --sidebar-bg: #fff;
    --sidebar-text: #333;
    --sidebar-active: #922b21;
    --sidebar-active-text: #fff;
    --background-color: #f4f6f7;
    --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

body {
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: var(--background-color);
    display: flex;
    min-height: 100vh;
    font-size: 0.9rem;
    /* Slightly smaller base font */
    overflow-x: hidden;
    /* prevent the sidebar from moving when tables are wide */
}

/* always show horizontal scrollbars in responsive tables when needed */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

/* Sidebar - Compact */
.sidebar {
    width: 240px;
    /* Reduced from 260px */
    background-color: var(--sidebar-bg);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100%;
    height: 100%;
    transition: transform 0.3s ease, width 0.3s ease;
    z-index: 1000;
    overflow: hidden;
}

.sidebar-header {
    text-align: center;
    border-bottom: 1px solid #eee;
    background-color: #fff;
}

.sidebar-logo {
    max-width: 100%;
    height: auto;
    max-height: 50px;
    object-fit: contain;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
    /* Reduced margin */
    flex-grow: 1;
    overflow-y: auto;
    max-height: calc(100vh - 70px);
}

.sidebar-menu li {
    margin-bottom: 2px;
    /* Tighter spacing */
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    /* Reduced padding */
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.85rem;
}

.sidebar-menu a:hover {
    background-color: #fceceb;
    color: var(--primary-color);
}

.sidebar-menu a.active {
    background-color: var(--sidebar-active);
    color: var(--sidebar-active-text);
    border-right: 4px solid #7b241c;
}

.sidebar-menu i {
    margin-right: 10px;
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
}

.sidebar-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #6d6d6d;
    padding: 0.75rem 1.25rem 0.45rem;
    margin: 0.35rem 0 0.15rem;
    border-top: 1px solid #f0f0f0;
    position: relative;
}

.sidebar-section-title::before {
    content: "";
    position: absolute;
    left: 1.25rem;
    top: 0.35rem;
    width: 26px;
    height: 2px;
    background: var(--primary-color);
    border-radius: 2px;
    opacity: 0.8;
}

.sidebar-section {
    list-style: none;
}

.sidebar-section-toggle {
    width: 100%;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1.25rem;
    color: #444;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sidebar-section-toggle:hover {
    background-color: #fceceb;
    color: var(--primary-color);
}

.sidebar-section-toggle.active {
    background-color: var(--sidebar-active);
    color: var(--sidebar-active-text);
    border-right: 4px solid #7b241c;
}

.sidebar-section-toggle.price {
    border-left: 4px solid #f1c40f;
}

.sidebar-section-toggle.points {
    border-left: 4px solid #f1c40f;
}

.sidebar-section-toggle.price.active {
    background: linear-gradient(135deg, #ffe08a 0%, #f1c40f 100%);
    color: #4a3a00;
    border-right: 4px solid #f1c40f;
}

.sidebar-section-toggle.points.active {
    background: linear-gradient(135deg, #ffe08a 0%, #f1c40f 100%);
    color: #4a3a00;
    border-right: 4px solid #f1c40f;
}

.sidebar-section-toggle i {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.sidebar-section-toggle[aria-expanded="true"] i {
    transform: rotate(180deg);
}

.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0 0 0.25rem;
}

.sidebar-submenu a {
    padding-left: 2.3rem;
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    margin-left: 240px;
    /* Aligned with sidebar */
    width: calc(100% - 240px);
    padding: 1.25rem;
    /* Reduced from 2rem */
    /* padding-top: 4.5rem; */
    /* Space for fixed header */
    /* Space for fixed header */
    transition: margin-left 0.3s ease, width 0.3s ease;
    overflow: visible !important;
    /* Critical for position: sticky to work */
}

/* Fixed Top Navbar */
.top-navbar {
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.05);
    position: fixed;
    top: 0;
    right: 0;
    left: 240px;
    z-index: 999;
    height: 50px;
    transition: left 0.3s ease;
    /* Reduced from 60px */
}

.sidebar-toggle-btn {
    color: var(--primary-color);
    font-size: 1.25rem;
    padding: 0;
    margin-right: auto;
    border: none;
    background: transparent;
    /* display: flex; */
    align-items: center;
    width: auto;
    height: auto;
    cursor: pointer;
}

.sidebar-toggle-btn:focus {
    box-shadow: none;
}

.top-navbar .user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.top-navbar .user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
}

.top-navbar .user-role {
    font-size: 0.75rem;
    color: #888;
}

.top-navbar .logout-btn {
    font-size: 0.8rem;
    color: #d32f2f;
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background 0.2s;
}

.sidebar-toggle-btn:hover {
    background-color: #fef1f0;
}

/* Shared UI Components */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    position: -webkit-sticky;
    /* for Safari */
    position: sticky;
    top: 50px;
    /* Below navbar */
    z-index: 990;
    background-color: var(--background-color);
    padding: 7px;
    /* Reduced from 2rem */
    width: 100%;
    /* Ensure full width */
}

.page-title {
    color: #333;
    margin: 0;
    font-size: 1.25rem;
    /* More compact title */
    font-weight: 700;
}

.card-shadow-dashboard {
    /* Stronger shadow as requested */
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.2),
        0 2px 4px -1px rgba(0, 0, 0, 0.1) !important;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.card-shadow-dashboard:hover {
    /* Even stronger shadow on hover */
    box-shadow:
        0 10px 15px -3px rgba(0, 0, 0, 0.2),
        0 4px 6px -2px rgba(0, 0, 0, 0.1) !important;
    transform: translateY(-2px);
}

.card {
    background: #fff;
    border: none;
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    padding: 1rem;
    /* Compact padding */
    margin-bottom: 1rem;
}

/* Sidebar Collapsed State (Desktop) */
@media (min-width: 992px) {
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-collapsed .main-content {
        margin-left: 0;
        width: 100%;
    }

    body.sidebar-collapsed .top-navbar {
        left: 0;
    }
}

.card-body {
    padding: 0;
}

/* Tables - Compact Design */
.table {
    margin-bottom: 0;
    font-size: 0.85rem;
}

.table-responsive {
    display: block;
    max-width: 100%;
    overflow: auto;
    max-height: 70vh;
    /* always show horizontal scrollbar so user notices oversize tables */
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable both-edges;
    position: relative;
    /* for overflow shadow */
}

/* subtle gradient to indicate more content to the right */
/* .table-responsive::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 30px;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
} */

.table-scroll {
    max-height: 55vh;
}

/* print layout tweaks */
@media print {
    @page {
        size: landscape;
    }

    /* make tables expand for printing instead of clipping
       and disable sticky positioning which doesn't translate well */
    .table-responsive {
        overflow: visible !important;
    }

    .sticky-top-card-header,
    .sticky-table-with-filters th,
    .sticky-top-table-head th,
    .sticky-filters {
        position: static !important;
    }
}

.table-responsive>.table {
    /* keep table at least as wide as its container but allow it to grow
       based on its contents; using max-content prevents excessive
       compression when there are many narrow columns */
    width: max-content;
    min-width: 100%;
}

/* when there are lots of columns we don't want each one squeezing
   to a couple of pixels; this gives every cell a reasonable minimum
   width so the overall table becomes wider than the wrapper and
   a horizontal scrollbar appears */
.table-responsive>.table th,
.table-responsive>.table td {
    white-space: nowrap;
    min-width: 120px;
}

.table-responsive .table {
    margin-bottom: 0;
}

.table thead th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 10px;
}

/* Badges */
.badge {
    padding: 0.35em 0.65em;
    font-weight: 500;
    font-size: 0.75rem;
}

/* Buttons */
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Pagination / Tabs */
.btn-group .btn {
    font-size: 0.8rem;
}

/* Modals - Clean Design */
.modal-content {
    border-radius: 12px;
    overflow: hidden;
}

.modal-header {
    padding: 1rem 1.5rem;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
}

/* Login Page Styles */
.login-body {
    background: linear-gradient(135deg, #fdfefe 0%, #f4f6f7 100%);
    display: flex !important;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-card {
    background: #fff;
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
    transition: transform 0.3s ease;
}

.login-card:hover {
    transform: translateY(-5px);
}

.login-header h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.login-logo {
    max-width: 150px;
    height: auto;
    display: block;
    margin: 0 auto;
}

.login-header p {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
}

.login-form .form-group {
    margin-bottom: 1.25rem;
    text-align: left;
}

.login-form label {
    display: block;
    margin-bottom: 0.4rem;
    color: #333;
    font-weight: 600;
}

.login-form .form-control {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.9rem;
    box-sizing: border-box;
    /* Essential to prevent overflow */
    display: block;
}

.login-form .form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

.password-toggle-wrapper {
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.password-toggle-wrapper .form-control {
    padding-right: 45px !important;
}

#togglePassword {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    z-index: 10;
}

.login-form .btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem;
    width: 100%;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.login-form .btn-primary:hover {
    background-color: var(--primary-hover);
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: 240px;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }

    .top-navbar {
        left: 0;
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        display: none;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* Print Overrides for standard pages */
@media print {

    .no-print,
    .sidebar,
    .top-navbar,
    .page-header .btn {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: none !important;
        /* Changed from 1px solid #eee */
    }
}

/* Custom Card Heading - Added by User Request */
.card-header-custom {
    background: linear-gradient(135deg,
            var(--primary-color) 0%,
            var(--primary-hover) 100%);
    color: white !important;
    padding: 10px 18px;
    border-radius: 6px;
    /* Space below */
    min-height: 41px;
    /* Explicit height for sticky calc */
    display: flex;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(146, 43, 33, 0.2);
    /* Soft shadow matching primary color */
    display: flex;
    align-items: center;
    border-left: 5px solid #f1c40f;
    /* Gold accent border */
}

.card-header-custom i {
    opacity: 0.9;
}

/* Custom Back Button - Added by User Request */
.btn-back-custom {
    background: linear-gradient(135deg,
            var(--primary-color) 0%,
            var(--primary-hover) 100%);
    color: white !important;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(146, 43, 33, 0.2);
    display: inline-flex;
    align-items: center;
}

.btn-back-custom:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(146, 43, 33, 0.3);
    color: white !important;
}

.btn-back-custom i {
    margin-right: 8px;
}

/* Metric Card Custom Styles */
.metric-card-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.metric-icon-wrapper {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    transition: transform 0.3s ease;
}

.metric-card-body:hover .metric-icon-wrapper {
    transform: scale(1.1);
}

.metric-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.metric-value {
    margin-bottom: 0;
    line-height: 1.2;
}

/* Sticky Headers for Reports */
.sticky-top-card-header {
    position: sticky;
    top: 95px;
    /* Navbar (50px) + Page Header (~60px) */
    /* Below navbar (50px height) */
    z-index: 101;
    margin-bottom: 0 !important;
    border-radius: 6px 6px 0 0;
    background: linear-gradient(135deg,
            var(--primary-color) 0%,
            var(--primary-hover) 100%);
}

/* Ensure filter buttons stick too if needed, or just table head */
.sticky-top-table-head th {
    position: sticky;
    /* top: 170px; */
    top: 130px;
    /* Navbar (50px) + Page Header (60px) + Card Header (60px) */
    /* Navbar (50px) + Card Header (~42px) */
    padding: 10px;
    z-index: 100;
    background-color: #f8f9fa;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

.table-responsive .sticky-top-table-head th {
    top: 0;
}

/* Sticky Header for Modals */
.sticky-modal-table-head th {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: #fff;
    /* Ensure it is not transparent */
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

/* Sticky Filters for Coupon Report */
.sticky-filters {
    position: sticky;
    top: 135px;
    z-index: 95;
    background-color: #fff;
    padding: 10px 0;
    margin-bottom: 0 !important;
    border-bottom: 1px solid #dee2e6;
}

/* Sticky Table Header below Filters */
.sticky-table-with-filters th {
    position: sticky;
    top: 199px;
    /* 170px (Filter Top) + ~55px (Filter Height) */
    z-index: 90;
    background-color: #f8f9fa;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

.table-responsive .sticky-table-with-filters th {
    top: 0;
}
