/**
 * CSBAG Budget Dashboard - Custom Brand Overrides
 *
 * Overrides Metronic 8 default blue (#009EF7) with CSBAG orange (#f36624)
 * Based on CSBAG brand identity from https://www.csbag.org/
 */

/* ============================================================================
   CSBAG LOGO
   ============================================================================ */

.csbag-logo-header {
    height: 50px;
    width: auto;
    transition: transform 0.2s ease;
}

.csbag-logo-header:hover {
    transform: scale(1.05);
}

/* Mobile responsive logo */
@media (max-width: 768px) {
    .csbag-logo-header {
        height: 40px;
    }
}

/* ============================================================================
   CSS CUSTOM PROPERTIES (ROOT VARIABLES)
   ============================================================================ */

:root {
    /* Override Metronic primary blue with CSBAG orange */
    --bs-primary: #f36624;
    --bs-primary-rgb: 243, 102, 36;

    /* Override blue color variable */
    --bs-blue: #f36624;

    /* Lighter and darker shades for hover/active states */
    --bs-primary-light: #ff7e3f;
    --bs-primary-dark: #d15418;
}

/* ============================================================================
   BOOTSTRAP UTILITY CLASSES
   ============================================================================ */

/* Text Colors */
.text-primary {
    color: #f36624 !important;
}

/* Background Colors */
.bg-primary {
    background-color: #f36624 !important;
}

.bg-light-primary {
    background-color: rgba(243, 102, 36, 0.1) !important;
}

/* Border Colors */
.border-primary {
    border-color: #f36624 !important;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn-primary {
    background-color: #f36624 !important;
    border-color: #f36624 !important;
    color: #ffffff !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: #d15418 !important;
    border-color: #d15418 !important;
    color: #ffffff !important;
}

.btn-outline-primary {
    color: #f36624 !important;
    border-color: #f36624 !important;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active {
    background-color: #f36624 !important;
    border-color: #f36624 !important;
    color: #ffffff !important;
}

.btn-light-primary {
    background-color: rgba(243, 102, 36, 0.1) !important;
    color: #f36624 !important;
}

.btn-light-primary:hover {
    background-color: rgba(243, 102, 36, 0.15) !important;
    color: #d15418 !important;
}

/* Ensure icons inherit button text color */
.btn-light-primary i,
.btn-light-primary .fas,
.btn-light-primary .far,
.btn-light-primary .fab {
    color: inherit;
}

/* ============================================================================
   LINKS
   ============================================================================ */

a {
    color: #f36624;
}

a:hover {
    color: #d15418;
}

.link-primary {
    color: #f36624 !important;
}

.link-primary:hover {
    color: #d15418 !important;
}

/* ============================================================================
   NAVIGATION MENU
   ============================================================================ */

/* Active menu item with underline */
.menu-item .menu-link {
    background-color: transparent !important;
    position: relative;
    transition: color 0.3s ease;
}

.menu-item .menu-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: #f36624;
    border-radius: 3px 3px 0 0;
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.menu-item.here .menu-link,
.menu-item.active .menu-link {
    color: #f36624 !important;
}

.menu-item.here .menu-link::after,
.menu-item.active .menu-link::after {
    transform: scaleX(1);
}

.menu-item.here .menu-link .menu-title,
.menu-item.active .menu-link .menu-title {
    color: #f36624 !important;
    font-weight: 600;
}

.menu-state-icon-primary .menu-item.here .menu-link .menu-icon i,
.menu-state-icon-primary .menu-item.active .menu-link .menu-icon i {
    color: #f36624 !important;
}

.menu-state-bullet-primary .menu-item.here .menu-link .menu-bullet .bullet,
.menu-state-bullet-primary .menu-item.active .menu-link .menu-bullet .bullet {
    background-color: #f36624 !important;
}

/* Menu hover state */
.menu-link:hover {
    background-color: transparent !important;
}

.menu-link:hover .menu-title {
    color: #f36624 !important;
}

/* ============================================================================
   FORMS & INPUT
   ============================================================================ */

.form-control:focus,
.form-select:focus {
    border-color: #f36624 !important;
    box-shadow: 0 0 0 0.25rem rgba(243, 102, 36, 0.25) !important;
}

.form-check-input:checked {
    background-color: #f36624 !important;
    border-color: #f36624 !important;
}

/* ============================================================================
   BADGES & LABELS
   ============================================================================ */

.badge-primary,
.badge.badge-primary {
    background-color: #f36624 !important;
    color: #ffffff !important;
}

.badge-light-primary {
    background-color: rgba(243, 102, 36, 0.1) !important;
    color: #f36624 !important;
}

/* ============================================================================
   PROGRESS BARS & SPINNERS
   ============================================================================ */

.progress-bar {
    background-color: #f36624 !important;
}

.spinner-border.text-primary {
    color: #f36624 !important;
}

/* ============================================================================
   ALERTS
   ============================================================================ */

.alert-primary {
    background-color: rgba(243, 102, 36, 0.1) !important;
    border-color: #f36624 !important;
    color: #d15418 !important;
}

/* ============================================================================
   TABLES
   ============================================================================ */

.table-primary {
    background-color: rgba(243, 102, 36, 0.1) !important;
}

/* DataTables sorting icons */
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: #f36624 !important;
    border-color: #f36624 !important;
    color: #ffffff !important;
}

/* ============================================================================
   CARDS & STATS
   ============================================================================ */

.card-primary {
    background-color: #f36624 !important;
    color: #ffffff !important;
}

.card-primary .card-title,
.card-primary .card-text {
    color: #ffffff !important;
}

/* ============================================================================
   ICONS
   ============================================================================ */

.svg-icon-primary,
.svg-icon.svg-icon-primary {
    color: #f36624 !important;
}

.svg-icon-primary svg g [fill],
.svg-icon.svg-icon-primary svg g [fill] {
    fill: #f36624 !important;
}

/* ============================================================================
   TABS & NAVIGATION
   ============================================================================ */

.nav-tabs .nav-link.active,
.nav-pills .nav-link.active {
    background-color: #f36624 !important;
    color: #ffffff !important;
}

.nav-tabs .nav-link:hover,
.nav-pills .nav-link:hover {
    color: #f36624 !important;
}

/* ============================================================================
   PAGINATION
   ============================================================================ */

.pagination .page-item.active .page-link {
    background-color: #f36624 !important;
    border-color: #f36624 !important;
}

.pagination .page-link:hover {
    color: #f36624 !important;
}

/* ============================================================================
   DROPDOWNS
   ============================================================================ */

.dropdown-item.active,
.dropdown-item:active {
    background-color: #f36624 !important;
    color: #ffffff !important;
}

.dropdown-item:hover {
    background-color: rgba(243, 102, 36, 0.1) !important;
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal-header {
    border-bottom-color: #f36624 !important;
}

/* ============================================================================
   APEXCHARTS OVERRIDES
   ============================================================================ */

.apexcharts-legend-series .apexcharts-legend-marker[rel="1"] {
    background: #f36624 !important;
}

.apexcharts-tooltip-series-group.apexcharts-active .apexcharts-tooltip-marker {
    background-color: #f36624 !important;
}

/* ============================================================================
   MISC COMPONENTS
   ============================================================================ */

/* Tooltips */
.tooltip-primary .tooltip-inner {
    background-color: #f36624 !important;
}

/* Popovers */
.popover-primary .popover-header {
    background-color: #f36624 !important;
    color: #ffffff !important;
}

/* List group */
.list-group-item.active {
    background-color: #f36624 !important;
    border-color: #f36624 !important;
}

/* Breadcrumb */
.breadcrumb-item.active {
    color: #f36624 !important;
}

/* ============================================================================
   METRONIC SPECIFIC OVERRIDES
   ============================================================================ */

/* Scrollbar thumb */
.ps__thumb-y {
    background-color: #f36624 !important;
}

/* Symbol badge */
.symbol .symbol-badge {
    background-color: #f36624 !important;
}

/* Drawer */
.drawer .drawer-close {
    color: #f36624 !important;
}

.drawer .drawer-close:hover {
    color: #d15418 !important;
}

/* ============================================================================
   MOBILE RESPONSIVENESS - MEDIA QUERIES
   ============================================================================ */

/* Mobile devices (< 576px) */
@media (max-width: 575.98px) {
    /* Header adjustments */
    .container-xxl {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .header-logo h2 {
        font-size: 1.25rem !important;
    }

    .header-logo .fs-7 {
        font-size: 0.7rem !important;
    }

    /* Page titles */
    .tw-text-3xl {
        font-size: 1.5rem !important;
    }

    /* Fiscal year selector */
    .csbag-fy-selector {
        width: 100% !important;
        max-width: 280px;
    }

    /* Toolbar - stack title and selector */
    .d-flex.flex-wrap.flex-stack {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .d-flex.flex-wrap.flex-stack > * {
        width: 100%;
    }

    /* KPI cards - full width on mobile */
    .card .card-body {
        padding: 1rem !important;
    }

    .card-body.p-4.p-lg-5 {
        padding: 1rem !important;
    }

    /* Chart cards - reduce padding */
    .card-header.tw-p-8 {
        padding: 1rem !important;
    }

    .card-body.tw-p-8 {
        padding: 1rem !important;
    }

    /* Chart titles - smaller on mobile */
    .card-title.tw-text-lg {
        font-size: 1rem !important;
    }

    .card-title.tw-text-base {
        font-size: 0.9rem !important;
    }

    /* Page title headings */
    h1.tw-text-3xl {
        font-size: 1.75rem !important;
    }

    h3.fw-bolder {
        font-size: 1.25rem !important;
    }

    /* Footer - stack items */
    .footer .d-flex {
        flex-direction: column !important;
        text-align: center;
        gap: 0.5rem;
    }
}

/* Tablets (576px - 991px) */
@media (min-width: 576px) and (max-width: 991.98px) {
    /* Header adjustments */
    .container-xxl {
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }

    /* Fiscal year selector */
    .csbag-fy-selector {
        width: 240px !important;
    }

    /* Chart cards */
    .card-header.tw-p-8 {
        padding: 1.5rem !important;
    }

    .card-body.tw-p-8 {
        padding: 1.5rem !important;
    }
}

/* Mobile and tablet (< 992px) - Menu drawer active */
@media (max-width: 991.98px) {
    /* Hide desktop logo text on very small screens */
    .header-logo {
        max-width: 150px;
    }

    /* Mobile menu drawer styles */
    .header-menu[data-kt-drawer="true"] {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1000;
        background: white;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
    }

    /* Menu items - vertical stacking */
    .menu.menu-column {
        padding: 2rem 0;
    }

    .menu-item {
        width: 100%;
        margin: 0 !important;
    }

    .menu-item .menu-link {
        padding: 1rem 1.5rem !important;
        border-bottom: 1px solid #f4f4f5;
        border-left: 3px solid transparent;
    }

    .menu-item.here .menu-link,
    .menu-item.active .menu-link {
        background-color: rgba(243, 102, 36, 0.05) !important;
        border-left-color: #f36624;
    }

    .menu-item .menu-link:hover {
        background-color: rgba(243, 102, 36, 0.05) !important;
    }

    /* Remove bottom border animation on mobile */
    .menu-item .menu-link::after {
        display: none;
    }

    /* Adjust button sizes for touch */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .btn-icon {
        width: 44px;
        height: 44px;
    }

    /* DataTables responsive */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        margin-bottom: 1rem;
    }

    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input {
        min-height: 44px;
    }

    /* Form inputs - larger touch targets */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Charts - reduce height on mobile */
    #chart-budget-trend {
        min-height: 300px !important;
    }

    #chart-expenditure,
    #chart-debt-servicing,
    #chart-classification,
    #chart-financing {
        min-height: 300px !important;
    }

    /* Social sector cards - stack vertically */
    .row.g-5 .col-md-4 {
        margin-bottom: 1rem;
    }

    /* Modal - full screen on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }

    .modal-content {
        height: 100%;
        border-radius: 0;
    }
}

/* Very small devices (< 375px) */
@media (max-width: 374.98px) {
    .header-logo img {
        height: 35px !important;
    }

    .header-logo h2 {
        font-size: 1.1rem !important;
    }

    .header-logo .fs-7 {
        display: none; /* Hide "Budget Dashboard" subtitle on very small screens */
    }

    /* Reduce padding even more */
    .container-xxl {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .card-body {
        padding: 0.75rem !important;
    }

    /* KPI values - smaller font */
    .fs-3 {
        font-size: 1.5rem !important;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 991.98px) and (orientation: landscape) {
    /* Reduce header height in landscape */
    .header {
        min-height: 60px !important;
    }

    /* Charts adapt to landscape */
    #chart-budget-trend {
        min-height: 250px !important;
    }
}

/* Touch device optimizations - applies to all touch devices regardless of screen size */
@media (hover: none) and (pointer: coarse) {
    /* All interactive elements get larger touch targets */
    a, button, .btn, .menu-link {
        min-height: 44px !important;
        min-width: 44px !important;
    }

    /* Ensure hamburger button meets WCAG AA standards */
    #kt_header_menu_mobile_toggle {
        width: 44px !important;
        height: 44px !important;
    }

    /* Remove hover effects on touch devices */
    .menu-link:hover,
    .btn:hover,
    .card:hover {
        transform: none !important;
    }

    /* Make dropdowns easier to tap */
    select, .form-select {
        min-height: 48px !important;
        font-size: 16px !important;
    }
}

/* Print styles */
@media print {
    /* Hide navigation and interactive elements */
    .header,
    .footer,
    #csbag-chatbot-button,
    .csbag-chatbot-panel,
    .btn,
    #kt_header_menu_mobile_toggle {
        display: none !important;
    }

    /* Optimize charts for print */
    .card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }

    /* Ensure page fits width */
    body {
        width: 100%;
        margin: 0;
        padding: 0;
    }
}

/* ===========================
   Map Search Control (In-Map)
   =========================== */

/* Search control container */
.leaflet-control-search {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid #f4f4f5;
    margin-top: 10px !important;
    margin-right: 10px !important;
}

.map-search-container {
    position: relative;
    width: 280px;
}

/* Search input wrapper */
.map-search-input-wrapper {
    position: relative;
    padding: 8px;
}

.map-search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #71717a;
    font-size: 14px;
    pointer-events: none;
}

/* Search input field */
.map-search-input {
    width: 100%;
    height: 36px;
    padding: 0 12px 0 36px;
    border: 1px solid #e4e4e7;
    border-radius: 6px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    color: #27272a;
    background: white;
    transition: all 150ms ease-out;
}

.map-search-input:focus {
    outline: none;
    border-color: #f36624;
    box-shadow: 0 0 0 3px rgba(243, 102, 36, 0.1);
}

.map-search-input::placeholder {
    color: #a1a1aa;
}

/* Suggestions dropdown */
.map-search-suggestions {
    display: none;
    position: absolute;
    top: 100%;
    left: 8px;
    right: 8px;
    margin-top: 4px;
    background: white;
    border: 1px solid #f4f4f5;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    max-height: 280px;
    overflow-y: auto;
    z-index: 1000;
}

.map-search-suggestions.show {
    display: block;
}

/* Suggestion items */
.map-search-suggestion-item {
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 150ms ease-out;
    border-bottom: 1px solid #f4f4f5;
}

.map-search-suggestion-item:last-child {
    border-bottom: none;
}

.map-search-suggestion-item:hover,
.map-search-suggestion-item.selected {
    background-color: #f4f4f5;
}

.map-search-suggestion-name {
    font-weight: 600;
    color: #27272a;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    margin-bottom: 2px;
}

.map-search-suggestion-details {
    font-size: 11px;
    color: #71717a;
    font-family: 'Inter', sans-serif;
}

/* Highlight matching text */
.map-search-highlight {
    background-color: rgba(243, 102, 36, 0.15);
    font-weight: 600;
    color: #f36624;
}

/* No results state */
.map-search-no-results {
    padding: 16px;
    text-align: center;
    color: #71717a;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
}

/* Compact view on smaller maps */
@media (max-width: 991px) {
    .map-search-container {
        width: 240px;
    }

    .map-search-input {
        font-size: 13px;
        height: 34px;
    }
}

/* Mobile optimization */
@media (max-width: 767px) {
    .leaflet-control-search {
        margin-top: 10px !important;
        margin-right: 10px !important;
    }

    .map-search-container {
        width: 200px;
    }

    .map-search-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        height: 40px;
    }

    .map-search-suggestions {
        max-height: 200px;
    }

    .map-search-suggestion-item {
        padding: 12px;
        min-height: 48px; /* Touch-friendly */
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .map-search-suggestion-item {
        min-height: 48px !important;
        padding: 12px !important;
    }

    .map-search-suggestion-item:hover {
        background-color: transparent;
    }

    .map-search-suggestion-item:active {
        background-color: #f4f4f5;
    }
}

/* Marker pulse animation (unchanged) */
@keyframes marker-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
}

.marker-selected {
    animation: marker-pulse 0.6s ease-in-out 2;
}
