/* ════════════════════════════════════════════════════════════════════
   GLOBAL RESPONSIVE OVERRIDES — StationMGT / PGL ERP
   Covers: 320px → 1920px+ (phones, phablets, tablets, desktops)
   Loaded AFTER theme CSS so it wins specificity ties.
   ════════════════════════════════════════════════════════════════════ */

/* ── 0. ROOT SAFETY ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

img, video, canvas, svg, iframe {
    max-width: 100%;
    height: auto;
}

/* Prevent iOS zoom-on-focus for inputs ≤ 16px */
input, select, textarea { font-size: 16px; }
@media (min-width: 768px) {
    input, select, textarea { font-size: 0.875rem; }
}

/* Smooth touch scrolling */
.scrollable, .table-responsive, [data-simplebar], .leftside-menu {
    -webkit-overflow-scrolling: touch;
}

/* ── 1. CONTENT PAGE PADDING ────────────────────────────────────── */
.content-page .content {
    padding: 0.5rem;
}
@media (min-width: 576px) {
    .content-page .content { padding: 0.75rem; }
}
@media (min-width: 768px) {
    .content-page .content { padding: 1rem; }
}
@media (min-width: 1200px) {
    .content-page .content { padding: 1.5rem; }
}

/* ── 2. TYPOGRAPHY SCALING ──────────────────────────────────────── */
h1, .h1 { font-size: clamp(1.5rem, 4vw, 2.25rem); }
h2, .h2 { font-size: clamp(1.25rem, 3vw, 1.75rem); }
h3, .h3 { font-size: clamp(1.1rem, 2.5vw, 1.5rem); }
h4, .h4 { font-size: clamp(1rem, 2vw, 1.25rem); }
h5, .h5 { font-size: clamp(0.9rem, 1.5vw, 1.1rem); }
h6, .h6 { font-size: clamp(0.85rem, 1.2vw, 1rem); }

.page-title, .page-title-box h4 {
    font-size: clamp(1.1rem, 3vw, 1.5rem) !important;
}

/* ── 3. CARDS ───────────────────────────────────────────────────── */
.card {
    margin-bottom: 0.75rem;
}
@media (max-width: 575.98px) {
    .card {
        margin-bottom: 0.5rem;
        border-radius: 0.5rem;
    }
    .card-body { padding: 0.875rem; }
    .card-header { padding: 0.625rem 0.875rem; }
    .card-title { font-size: 0.95rem; }
}

/* ── 4. STAT / METRIC / DASHBOARD CARDS ─────────────────────────── */
/* Convert any row of stat cards to a responsive grid */
.row [class*="col-"] > .card,
.row [class*="col-"] > .widget-card {
    height: 100%;
}

/* Mini stat cards: 1 col on phones, 2 on large phones, 3+ on tablets */
@media (max-width: 575.98px) {
    .row.g-2, .row.g-3 { --bs-gutter-x: 0.5rem; --bs-gutter-y: 0.5rem; }
}

/* Avatar sizing on mobile */
@media (max-width: 575.98px) {
    .avatar-sm { width: 1.75rem; height: 1.75rem; }
    .avatar-md { width: 2.25rem; height: 2.25rem; }
    .avatar-lg { width: 2.75rem; height: 2.75rem; }
}

/* ── 5. TABLES ──────────────────────────────────────────────────── */
/* Wrap all tables in scrollable containers if not already */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.table-responsive::-webkit-scrollbar { height: 6px; width: 6px; }
.table-responsive::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.4); border-radius: 3px; }

.table {
    --bs-table-bg: transparent;
    margin-bottom: 0.5rem;
}
.table thead th {
    font-size: 0.8rem;
    white-space: nowrap;
}
.table td, .table th {
    padding: 0.5rem 0.5rem;
    vertical-align: middle;
}
@media (min-width: 768px) {
    .table td, .table th { padding: 0.75rem; }
}

/* On very small screens, allow horizontal scroll for all tables */
@media (max-width: 767.98px) {
    .table { min-width: 600px; }
    .table:not(.table-borderless) :is(th,td) { white-space: nowrap; }
}

/* ── 6. FORMS ───────────────────────────────────────────────────── */
.form-control, .form-select, .input-group-text {
    font-size: 16px; /* prevent iOS zoom */
}
@media (min-width: 768px) {
    .form-control, .form-select, .input-group-text { font-size: 0.875rem; }
}

.form-label { font-size: 0.85rem; }

/* Touch-friendly: minimum 44px tap target */
.btn, .form-check-input, .page-link {
    min-height: 40px;
    min-width: 40px;
}
.btn-sm { min-height: 34px; min-width: 34px; }
.btn-icon { min-width: 40px; }

@media (max-width: 575.98px) {
    .form-control, .form-select { padding: 0.625rem 0.75rem; }
    textarea.form-control { min-height: 80px; }
    .input-group { flex-wrap: wrap; }
    .input-group > * { border-radius: 0.375rem !important; margin-bottom: 0.25rem; }
}

/* Floating labels: ensure they don't overflow on narrow screens */
.form-floating > label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── 7. BUTTONS & BUTTON GROUPS ─────────────────────────────────── */
@media (max-width: 575.98px) {
    .btn-group { flex-wrap: wrap; gap: 0.25rem; }
    .btn-group .btn { border-radius: 0.375rem !important; margin: 0; }
    .btn-group-vertical { flex-direction: column; width: 100%; }
    .btn-group-vertical .btn { width: 100%; }
    /* Full-width primary action buttons on mobile */
    .btn-primary:not(.btn-sm):not(.btn-icon) { width: 100%; }
}

/* ── 8. MODALS ──────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100vw - 1rem);
    }
    .modal-dialog-centered { min-height: calc(100vh - 1rem); }
    .modal-content { max-height: calc(100vh - 1rem); overflow-y: auto; }
    .modal-body { padding: 0.875rem; }
    .modal-header { padding: 0.625rem 0.875rem; }
    .modal-footer { padding: 0.625rem 0.875rem; flex-wrap: wrap; }
    .modal-footer .btn { width: 100%; margin: 0.25rem 0; }
}

/* Full-screen modal on very small phones */
@media (max-width: 380px) {
    .modal-dialog {
        margin: 0;
        max-width: 100vw;
        height: 100vh;
    }
    .modal-content { height: 100vh; border-radius: 0; max-height: 100vh; }
}

/* Large modals (modal-lg, modal-xl) should never exceed viewport */
.modal-lg, .modal-xl { max-width: 95vw; }
@media (max-width: 991.98px) {
    .modal-lg, .modal-xl { max-width: calc(100vw - 1rem); }
}

/* ── 9. NAV / TABS ──────────────────────────────────────────────── */
/* Horizontal scroll for tab navigation on mobile */
.nav-tabs, .nav-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}
.nav-tabs::-webkit-scrollbar, .nav-pills::-webkit-scrollbar { display: none; }
.nav-tabs .nav-link, .nav-pills .nav-link {
    white-space: nowrap;
    flex-shrink: 0;
}

/* Breadcrumb: scrollable on mobile */
.breadcrumb {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
}
.breadcrumb::-webkit-scrollbar { display: none; }

/* ── 10. TOPBAR / NAVBAR ────────────────────────────────────────── */
.navbar-custom .topbar {
    padding: 0 0.5rem;
    min-height: 56px;
}
@media (max-width: 575.98px) {
    .navbar-custom .topbar {
        padding: 0 0.375rem;
        min-height: 52px;
    }
    .logo-topbar .logo-lg { display: none !important; }
    .logo-topbar .logo-sm { display: block !important; }
    .logo-topbar .logo-sm img { height: 36px; }
    .button-toggle-menu { padding: 0.5rem; }
    .nav-user .user-name { display: none; }
    .nav-user img { width: 32px; height: 32px; }
}

/* Hide non-essential topbar items on small screens */
@media (max-width: 767.98px) {
    .topbar-menu .d-none.d-sm-inline-block { display: none !important; }
    .topbar-menu { gap: 0.25rem !important; }
}

/* ── 11. PAGE TITLE BOX ─────────────────────────────────────────── */
.page-title-box {
    padding: 0.5rem 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}
@media (min-width: 768px) {
    .page-title-box {
        flex-direction: row;
        align-items: center;
        padding: 0.75rem 0;
    }
}
.page-title-box .page-title-right {
    margin-top: 0.5rem;
    width: 100%;
}
@media (min-width: 768px) {
    .page-title-box .page-title-right { margin-top: 0; width: auto; }
}

/* ── 12. DROPDOWNS ──────────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .dropdown-menu {
        max-width: calc(100vw - 2rem);
        min-width: 200px;
    }
    .dropdown-menu-end {
        right: 0 !important;
        left: 0 !important;
    }
    .dropdown-item { padding: 0.625rem 1rem; }
}

/* ── 13. ALERTS & BADGES ────────────────────────────────────────── */
.alert { padding: 0.75rem; border-radius: 0.5rem; }
.badge { font-size: 0.7rem; padding: 0.35em 0.5em; }

/* Wrap badge groups */
.flex-wrap-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* ── 14. ACCORDIONS ─────────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .accordion-button { padding: 0.75rem 0.875rem; font-size: 0.9rem; }
    .accordion-body { padding: 0.75rem 0.875rem; }
}

/* ── 15. DATA TABLES (jQuery DataTables) ────────────────────────── */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin: 0.5rem 0;
    font-size: 0.8rem;
}
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    .dataTables_wrapper .dataTables_filter input { width: 100% !important; }
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.75rem;
    }
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
    }
    .dataTables_wrapper .dataTables_info {
        text-align: center !important;
    }
}

/* ── 16. CHARTS ─────────────────────────────────────────────────── */
.apexcharts-canvas, .chartjs-render-monitor {
    max-width: 100%;
    overflow: hidden;
}
.apexcharts-legend {
    flex-wrap: wrap;
    gap: 0.25rem;
}
@media (max-width: 575.98px) {
    .apexcharts-legend-series { margin: 0 0.25rem; }
}

/* ── 17. UTILITY: HORIZONTAL SCROLL WRAPPER ─────────────────────── */
.scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    white-space: nowrap;
}
.scroll-x::-webkit-scrollbar { height: 5px; }
.scroll-x::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.35); border-radius: 3px; }

/* ── 18. GRIDS: force stack on extra-small ──────────────────────── */
@media (max-width: 380px) {
    .row > .col-6 { flex: 0 0 100%; max-width: 100%; }
    .row > .col-sm-6:not(.col-md-4):not(.col-md-3):not(.col-md-8) { flex: 0 0 100%; max-width: 100%; }
}

/* ── 19. FOOTER ─────────────────────────────────────────────────── */
.footer {
    padding: 0.75rem 0.5rem;
    text-align: center;
}
.footer .footer-links {
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}
@media (max-width: 575.98px) {
    .footer img { height: 40px !important; }
    .footer .text-start, .footer .text-end { text-align: center !important; }
}

/* ── 20. OFFCANVAS / RIGHT SIDEBAR ──────────────────────────────── */
.offcanvas {
    max-width: 90vw;
}

/* ── 21. PROGRESS BARS ──────────────────────────────────────────── */
.progress { height: 0.5rem; border-radius: 1rem; }

/* ── 22. TIMELINE & LIST GROUPS ─────────────────────────────────── */
@media (max-width: 575.98px) {
    .list-group-item { padding: 0.625rem 0.75rem; }
    .timeline-item { padding-left: 1.5rem; }
    .timeline-item::before { left: 0; }
}

/* ── 23. PRINT REMAINS UNAFFECTED ───────────────────────────────── */
@media print {
    .leftside-menu, .navbar-custom, .footer, .rightbar { display: none !important; }
    .content-page { margin: 0 !important; }
}

/* ── 24. SEARCH / FILTER BARS ───────────────────────────────────── */
.filter-bar, .search-bar {
    flex-direction: column;
    gap: 0.5rem;
}
@media (min-width: 768px) {
    .filter-bar, .search-bar { flex-direction: row; align-items: center; }
}

/* ── 25. STAT NUMBERS ───────────────────────────────────────────── */
.stat-num, .metric-value {
    font-size: clamp(1.25rem, 3vw, 2rem);
    line-height: 1.2;
}

/* ── 26. COUNTRY SELECTOR (Topbar) ──────────────────────────────── */
.country-selector-btn {
    display: flex !important;
    align-items: center;
    gap: 4px;
    padding: 0.375rem 0.5rem !important;
    border-radius: 8px;
    transition: background 0.2s;
    cursor: pointer;
    white-space: nowrap;
}
.country-selector-btn:hover {
    background: rgba(128, 128, 128, 0.12);
}
.country-flag-current {
    font-size: 1.35rem;
    line-height: 1;
}
.country-flag-img {
    width: 24px;
    height: 16px;
    border-radius: 2px;
    object-fit: cover;
    display: inline-block;
    vertical-align: middle;
}
.country-code-current {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.country-currency-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(11, 31, 106, 0.12);
    color: #0B1F6A;
    line-height: 1.4;
    letter-spacing: 0.3px;
}
.country-selector-btn .ri-arrow-down-s-line {
    font-size: 1rem;
    opacity: 0.6;
}
.country-currency-tag {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(11, 31, 106, 0.08);
    color: #0B1F6A;
    margin-left: auto;
    margin-right: 6px;
    line-height: 1.4;
}
.country-item.active .country-currency-tag {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* Country dropdown menu */
.country-selector-menu {
    min-width: 280px;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
@media (max-width: 575.98px) {
    .country-selector-menu {
        min-width: calc(100vw - 2rem);
        max-width: 320px;
    }
}

.country-search-box .input-group-text {
    border-right: 0;
    padding: 0.25rem 0.5rem;
}
.country-search-box .form-control-sm {
    border-left: 0;
    padding-left: 0.25rem;
}
.country-search-box .form-control-sm:focus {
    box-shadow: none;
}

.country-list-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(128, 128, 128, 0.3) transparent;
}
.country-list-scroll::-webkit-scrollbar {
    width: 5px;
}
.country-list-scroll::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: 3px;
}

.country-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 0;
}
.country-item:hover,
.country-item.active {
    background: rgba(0, 123, 255, 0.08);
}
.country-item .country-flag {
    flex-shrink: 0;
    width: 24px;
    height: 16px;
    border-radius: 2px;
    object-fit: cover;
}
.country-item .country-name {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.country-item .country-iso {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Dark mode adjustments */
[data-bs-theme="dark"] .country-selector-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}
[data-bs-theme="dark"] .country-selector-menu {
    background: var(--ct-dropdown-bg, #313a46);
    border-color: rgba(255, 255, 255, 0.1);
}
[data-bs-theme="dark"] .country-item:hover,
[data-bs-theme="dark"] .country-item.active {
    background: rgba(255, 255, 255, 0.06);
}
[data-bs-theme="dark"] .country-search-box {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

/* Hide country code text on very small screens to save space */
@media (max-width: 380px) {
    .country-code-current { display: none; }
}

/* ════════════════════════════════════════════════════════════════════
   END GLOBAL RESPONSIVE OVERRIDES
   ════════════════════════════════════════════════════════════════════ */
