:root {
    --primary-color: #f3661f;
    --primary-hover: #e55c18;
    --secondary-color: #153151;
    --light-bg: #f0f4f8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
    background-color: var(--light-bg);
    min-height: 100vh;
}

/* Navbar Styles */
.top-navbar {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #1a3d5c 100%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 0;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff !important;
    font-weight: 600;
    font-size: 1.2rem;
    padding: 15px 20px;
}

.navbar-brand .brand-icon {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(243, 102, 31, 0.4);
}

.navbar-brand .brand-icon i {
    font-size: 1.3rem;
    color: #fff;
}

.navbar-toggler {
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 8px 12px;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.8%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

.navbar-nav .nav-link {
    color: rgba(255, 255, 255, 0.8) !important;
    padding: 12px 20px;
    transition: all 0.3s ease;
    border-radius: 8px;
    margin: 0 5px;
}

.navbar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff !important;
}

.navbar-nav .nav-link i {
    margin-left: 8px;
}

/* Main Content */
.main-content {
    padding: 30px 15px;
}

/* Tax Filter Card */
.tax-filter-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    border: 2px solid #e9ecef;
}

.tax-filter-card .form-check-input:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.tax-filter-label {
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

/* Filter Section */
.filter-section {
    background: white;
    border-radius: 16px;
    padding: 0;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    border: 1px solid #e9ecef;
}

.filter-header {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #1a3d5c 100%);
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-header:hover {
    background: linear-gradient(135deg, #1a3d5c 0%, var(--secondary-color) 100%);
}

.filter-header-title {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-header-icon {
    color: white;
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.filter-header[aria-expanded="true"] .filter-header-icon {
    transform: rotate(180deg);
}

.filter-body {
    padding: 1.5rem;
}

.filter-group {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    border: 1px solid #e9ecef;
}

.filter-group-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-input-wrapper {
    position: relative;
}

.date-input-wrapper .form-control {
    padding-right: 2.5rem;
}

.date-input-wrapper i {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-color);
    pointer-events: none;
}

/* KPI Cards */
.kpi-card {
    background: white;
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    height: 100%;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.kpi-card .kpi-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
    opacity: 0.2;
}

.kpi-card .kpi-content {
    text-align: right;
    /* margin-left: 70px; */
    position: relative;
    z-index: 1;
}

.kpi-card .kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary-color);
    direction: ltr;
    text-align: right;
}

.kpi-card .kpi-label {
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.25rem;
}

.kpi-card .kpi-percent {
    font-size: 0.85rem;
    margin-top: 4px;
}

.kpi-card small {
    font-size: 0.75rem;
}

/* Clickable KPI Card */
.kpi-card.clickable {
    cursor: pointer;
}

.kpi-card.clickable::after {
    content: '\f35d';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.7rem;
    color: #ccc;
    transition: all 0.3s ease;
}

.kpi-card.clickable:hover::after {
    color: var(--primary-color);
}

/* Chart Cards */
.chart-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
}

.chart-card .chart-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-card .chart-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin: 0;
}

.chart-card .chart-body {
    padding: 1rem;
}

.chart-container {
    min-height: 300px;
    width: 100%;
    position: relative;
}

/* Ensure chart containers have proper dimensions */
#sales-returns-chart,
#company-sales-chart,
#hourly-chart,
#branch-sales-section,
#monthly-sales-chart,
#yearly-totals-pie-chart {
    width: 100%;
    min-height: 300px;
}

#sales-returns-chart {
    min-height: 400px;
}

#company-sales-chart {
    height: 400px;
}

#hourly-chart {
    min-height: 300px;
}

/* Summary Cards Mobile Responsive */
@media (max-width: 768px) {
    #sqSummaryCards .card-body {
        padding: 0.75rem !important;
    }

    #sqSummaryCards .card-body i {
        font-size: 1rem !important;
        margin-bottom: 0.25rem !important;
    }

    #sqSummaryCards .card-body h6 {
        font-size: 0.7rem !important;
        margin-bottom: 0.25rem !important;
    }

    #sqSummaryCards .card-body h4 {
        font-size: 1rem !important;
    }
}

/* Branch Chart Cards */
.branch-chart-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 16px;
    margin-bottom: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid #e9ecef;
}

.branch-chart-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.branch-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.branch-chart-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #2c3e50;
}

.branch-chart-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.branch-achievement-badge {
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    color: white;
}

.branch-chart-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
    direction: ltr;
    text-align: right;
}

.branch-area-chart {
    height: 100px;
    width: 100%;
    margin: 0;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.riyal-svg {
    width: 1rem;
    height: 1rem;
    fill: currentColor;
    margin-right: 0.2rem;
    vertical-align: -0.1rem;
}

/* Table Styles */
.table-wrapper {
    max-height: 500px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid #eee;
}

.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
}

.sortable:hover {
    background-color: #f8f9fa;
}

.sortable:after {
    content: '⇅';
    font-size: 12px;
    color: #aaa;
    margin-right: 5px;
}

.sortable.sort-asc:after {
    content: '↑';
    color: #333;
}

.sortable.sort-desc:after {
    content: '↓';
    color: #333;
}

.progress {
    height: 8px;
    margin-top: 5px;
    background-color: #f0f0f0;
}

.progress-bar-branch {
    background-color: #3498db;
}

.progress-bar-returns {
    background-color: #e74c3c;
}

/* Status Badges */
.status-invoiced {
    background-color: #28a745;
}

.status-pending {
    background-color: #ffc107;
    color: #000;
}

.status-canceled {
    background-color: #dc3545;
}

.status-return {
    background-color: #6c757d;
}

/* Select2 Responsive Fix - Global */
.select2-container {
    width: 100% !important;
}

.select2-container .select2-selection--multiple {
    min-height: 38px;
    width: 100% !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    margin-top: 5px;
}



/* Responsive Design */
@media (max-width: 768px) {

    /* Full-width mobile layout - remove ALL padding and margins */
    body {
        padding: 0 !important;
        margin: 0 !important;
        overflow-x: hidden !important;
    }

    .main-content {
        padding: 0 !important;
        margin: 0 !important;
    }

    .container-fluid {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Remove any Bootstrap container padding */
    .container,
    .container-sm,
    .container-md,
    .container-lg,
    .container-xl,
    .container-xxl {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
    }

    .kpi-card .kpi-value {
        font-size: 1.1rem;
    }

    .kpi-card .kpi-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .filter-section {
        padding: 1rem;
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* Mobile Filter Toggle Button */
    .mobile-filter-toggle {
        display: block !important;
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Hide filter body by default on mobile */
    .filter-body.mobile-hidden {
        display: none;
    }

    .chart-container {
        min-height: 250px;
    }

    .navbar-brand .brand-icon i {
        font-size: 1.1rem;
    }

    /* Mobile filter fields - full width */
    /* .filter-group .row>div {
        flex: 0 0 100%;
        max-width: 100%;
    } */

    /* Select2 mobile optimization */
    .select2-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    .select2-container .select2-selection--multiple {
        width: 100% !important;
    }

    /* Company sales cards - 2 per row on mobile */
    #company-summary-cards .col-md-2 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .pie-chart-container {
        display: flex;
        flex-direction: column;
    }



    /* Analysis sections - full width cards on mobile (Image 3 & 4) */
    #item-class-section .col-md-6,
    #item-class-section .col-lg-6,
    #hourly-analysis-section .col-12 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Peak hour analysis - better layout on mobile (Image 2) */
    .peak-hour-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .peak-hour-card .card-body {
        padding: 1rem !important;
    }

    .peak-hour-card h5,
    .peak-hour-card h6 {
        margin-bottom: 0.5rem;
    }

    .peak-hour-card .badge {
        font-size: 0.75rem;
        padding: 0.35rem 0.65rem;
    }

    /* Best period icon - transparent background */
    .peak-hour-card .period-icon {
        opacity: 0.15;
        position: absolute;
        font-size: 4rem;
        z-index: 0;
    }

    .peak-hour-card .period-content {
        position: relative;
        z-index: 1;
    }

    /* Card headers - proper alignment */
    .chart-card .chart-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .chart-card .chart-header .d-flex {
        width: 100%;
        justify-content: space-between;
    }

    .chart-title {
        width: 100%;
        text-align: right;
        margin-bottom: 0.5rem;
    }

    /* Peak Hour Analysis - center content */
    #hourly-analysis-section .chart-body {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
    }


    #sales-returns-chart {
        min-height: 350px !important;
    }

    /* Modal body padding */
    .modal-body {
        padding: 0.75rem !important;
    }

    .modal-body .card-body {
        padding: 0.5rem !important;
    }

    /* Remove all side margins on mobile */
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .col,
    [class*="col-"] {
        padding-left: 0px !important;
        padding-right: 0px !important;
    }

    .mb-3,
    .mb-4 {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Remove any Bootstrap container padding */
    .container,
    .container-sm,
    .container-md,
    .container-lg,
    .container-xl,
    .container-xxl {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
    }

    /* Tax filter card - full width */
    .tax-filter-card {
        border-radius: 0;
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-left: none;
        border-right: none;
    }

    /* KPI Section - full width */
    #kpi-section {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Chart cards - full width */
    .chart-card {
        border-radius: 0;
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-left: none;
        border-right: none;
    }

    /* Sales comparison cards - stack vertically (Image 5) */
    .sales-comparison-section .row {
        flex-direction: column;
    }

    .sales-comparison-section .col-md-6 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 1rem;
    }

    .sales-comparison-section h4,
    .sales-comparison-section h3 {
        font-size: 1.1rem !important;
        line-height: 1.4;
        margin-bottom: 0.5rem;
    }

    .sales-comparison-section .badge {
        display: block;
        margin: 0.5rem auto;
        width: fit-content;
    }

    /* Chart axis labels - abbreviated numbers */

    /* Sales Quotation Modal Styles */
    #salesQuotationModal .table-responsive {
        max-height: calc(100vh - 450px);
        overflow-y: auto;
    }

    #salesQuotationModal .table thead th {
        font-size: 0.75rem;
        padding: 0.5rem 0.25rem;
    }

    #salesQuotationModal .table tbody td {
        font-size: 0.7rem;
        padding: 0.4rem 0.25rem;
    }

    #salesQuotationModal .pagination .page-link {
        font-size: 0.85rem;
        padding: 0.375rem 0.75rem;
    }

    #salesQuotationModal .modal-body {
        padding: 1.5rem;
    }

    #salesQuotationModal .table thead th {
        position: sticky;
        top: 0;
        background-color: #f8f9fa;
        z-index: 10;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        white-space: nowrap;
        font-size: 0.85rem;
        font-weight: 600;
        padding: 0.75rem 0.5rem;
    }

    #salesQuotationModal .table tbody td {
        font-size: 0.8rem;
        padding: 0.5rem;
        vertical-align: middle;
    }

    #salesQuotationModal .table tbody tr:hover {
        background-color: #f8f9fa;
    }

    /* Extra Small Screens - Less than 500px */
    @media (max-width: 500px) {
        body {
            padding: 0;
        }

        .main-content {
            padding: 10px 0 !important;
        }

        .container-fluid {
            padding-left: 0 !important;
            padding-right: 0 !important;
        }
    }

    /* Tax Filter Card */
    .tax-filter-card {
        border-radius: 0;
        margin-left: 0;
        margin-right: 0;
        border-left: none;
        border-right: none;
    }

    /* Filter Section */
    .filter-section {
        border-radius: 0;
        margin-left: 0;
        margin-right: 0;
        border-left: none;
        border-right: none;
    }

    .filter-header {
        padding: 1rem;
        border-radius: 0;
    }

    .filter-body {
        padding: 1rem 0.75rem;
    }

    .filter-group {
        padding: 1rem 0.75rem;
        margin-left: 0;
        margin-right: 0;
        border-radius: 8px;
    }

    /* KPI Cards */
    .kpi-card {
        border-radius: 8px;
        padding: 0.85rem;
        margin-left: 0;
        margin-right: 0;
    }

    .kpi-card .kpi-value {
        font-size: 0.95rem;
    }

    .kpi-card .kpi-label {
        font-size: 0.75rem;
    }

    .kpi-card .kpi-icon {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
    }



    /* Chart Cards */
    .chart-card {
        border-radius: 0;
        margin-left: 0;
        margin-right: 0;
        border-left: none;
        border-right: none;
    }

    .chart-card .chart-header {
        padding: 0.85rem 1rem;
    }

    .chart-card .chart-title {
        font-size: 0.8rem;
    }

    .chart-card .chart-body {
        padding: 0.75rem;
    }

    /* Branch Cards */
    .branch-chart-card {
        border-radius: 8px;
        padding: 12px;
    }

    /* Remove row margins */
    .row {
        margin-left: 0;
        margin-right: 0;
    }

    .row>* {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Navbar */
    .navbar-brand {
        font-size: 0.9rem;
        padding: 10px 15px;
    }

    .navbar-brand .brand-icon {
        width: 35px;
        height: 35px;
    }

    .navbar-brand .brand-icon i {
        font-size: 1rem;
    }

    /* Filter Group Title */
    .filter-group-title {
        font-size: 0.85rem;
        padding-bottom: 0.5rem;
    }

    /* Form Controls */
    .form-control,
    .form-select {
        font-size: 0.85rem;
        padding: 0.5rem;
    }

    .form-label {
        font-size: 0.8rem;
        margin-bottom: 0.35rem;
    }

    /* Buttons */
    .btn {
        font-size: 0.85rem;
        padding: 0.5rem 1rem;
    }

    /* Chart Container */
    .chart-container {
        min-height: 220px;
    }
}