/* ── Responsive Breakpoints ──
   sm: 576px  — mobile
   md: 768px  — small tablet
   lg: 992px  — tablet / small desktop
   xl: 1200px — desktop
   2xl: 1400px— wide
   Uses: min-width (mobile-first) and max-width (overrides) as needed
*/

/* ── Sidebar ── */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: var(--hp-sidebar-width, 250px);
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1049;
    }
    .sidebar-backdrop.show {
        display: block;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .mobile-menu-toggle {
        display: inline-flex !important;
    }
}

@media (min-width: 992px) {
    .sidebar-backdrop {
        display: none !important;
    }
    .mobile-menu-toggle {
        display: none !important;
    }
}

/* ── Topbar ── */
@media (max-width: 767.98px) {
    .topbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.75rem 1rem !important;
    }
    .topbar-left {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
    }
    .topbar-left h4 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex-shrink: 1;
        min-width: 0;
    }
    .topbar-right {
        width: 100%;
        justify-content: flex-end;
        gap: 0.5rem;
    }
    .topbar-right .dropdown:first-child {
        flex: 1;
        min-width: 0;
    }
    .global-search-input {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
    #globalSearchDropdown {
        width: 100%;
        position: relative;
    }
    #globalSearchResults {
        width: calc(100vw - 2rem) !important;
        max-width: 400px !important;
        right: 0 !important;
        left: auto !important;
    }
    .topbar-right .dropdown .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }
    .topbar-right .dropdown .ms-2.text-dark {
        display: none;
    }
    .topbar-right .dropdown .bi-chevron-down.ms-2 {
        display: none;
    }
    .notification-bell {
        position: relative;
    }
    .notification-bell .badge {
        font-size: 0.6rem;
        padding: 0.2em 0.4em;
    }
}

/* ── Content Area ── */
@media (max-width: 767.98px) {
    .content-area {
        padding: 0.75rem !important;
    }
    .container-fluid.py-4,
    .container-fluid.px-4 {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
}

/* ── Grid / Cards ── */
@media (max-width: 767.98px) {
    .row.g-3 > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    .stat-card {
        padding: 1rem;
    }
    .stat-card h3 {
        font-size: 1.75rem;
    }
    .stat-card .fs-1 {
        font-size: 1.5rem !important;
    }
    .stat-card small {
        font-size: 0.75rem;
    }
}

/* ── Tables ── */
@media (max-width: 767.98px) {
    .table-responsive {
        font-size: 0.8rem;
    }
    .table-header {
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem;
    }
    .table-header h5 {
        font-size: 1rem;
    }
    .table-header .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    /* DataTable button toolbar */
    .dt-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    .dt-buttons .btn {
        padding: 0.25rem 0.4rem;
        font-size: 0.7rem;
    }
    .dataTables_wrapper .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.75rem;
    }
    .dataTables_wrapper .d-flex.justify-content-between.mb-3 {
        margin-bottom: 0.75rem !important;
    }
    .dataTables_wrapper .d-flex.justify-content-between.mt-3 {
        margin-top: 0.75rem !important;
    }
    .dataTables_info {
        font-size: 0.75rem;
    }
    .dataTables_paginate {
        font-size: 0.8rem;
    }
}

/* ── Buttons ── */
@media (max-width: 767.98px) {
    .btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.85rem;
    }
    .btn-group {
        flex-wrap: wrap;
    }
    .d-flex.gap-2 {
        gap: 0.35rem !important;
    }
}

/* ── Forms / Wizard Stepper ── */
@media (max-width: 767.98px) {
    .wizard-stepper {
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center;
        padding: 5px 0;
        margin: 0.5rem auto 2rem;
    }
    .wizard-stepper::before {
        display: none;
    }
    .stepper-item {
        width: auto;
        min-width: 60px;
        flex-direction: row;
        gap: 0.4rem;
    }
    .stepper-circle {
        width: 36px;
        height: 36px;
        font-size: 0.85rem;
    }
    .stepper-label {
        position: static;
        font-size: 0.7rem;
        white-space: nowrap;
    }
    .stepper-item.active .stepper-label {
        top: auto;
        transform: none;
    }
    .form-section {
        padding: 1rem 1rem 0.75rem;
    }
    .form-section .section-header {
        font-size: 1rem;
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }
    .section-icon {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
    .sticky-actions {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }
    .sticky-actions .d-flex {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.35rem;
    }
    .wizard-step-header h4 {
        font-size: 1rem;
    }
}

@media (max-width: 575.98px) {
    .stepper-circle {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }
    .stepper-label {
        font-size: 0.6rem;
    }
}

/* ── Modal ── */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
    }
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100vw - 1rem);
    }
    .modal-header {
        padding: 0.75rem 1rem;
    }
    .modal-body {
        padding: 1rem;
    }
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* ── Toast ── */
@media (max-width: 767.98px) {
    .toast-container {
        width: 100%;
        padding: 0.5rem !important;
        left: 0 !important;
        right: 0 !important;
    }
    .toast-container .toast {
        max-width: 100%;
        width: 100%;
    }
}

/* ── List Page Header ── */
@media (max-width: 767.98px) {
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
    .d-flex.justify-content-between.align-items-center.mb-4 .d-flex.gap-2 {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .d-flex.justify-content-between.align-items-center.mb-4 h2.h4 {
        font-size: 1.1rem;
    }
}

/* ── Detail Page ── */
@media (max-width: 767.98px) {
    .card-header {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem !important;
    }
    .card-header h4,
    .card-header h5 {
        font-size: 1rem;
    }
    .card-body {
        padding: 1rem !important;
    }
}

/* ── Bulk Action Toolbar ── */
@media (max-width: 767.98px) {
    .bulk-action-toolbar {
        left: 0.5rem;
        right: 0.5rem;
        transform: none;
        width: auto;
        padding: 10px 16px;
        border-radius: 10px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .bulk-action-toolbar.show {
        bottom: 12px;
    }
    .bulk-action-toolbar .btn-sm {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
}

/* ── Related Documents ── */
@media (max-width: 575.98px) {
    .related-doc-card .min-w-0 div:first-child {
        max-width: 120px !important;
    }
}

/* ── Activity Timeline ── */
@media (max-width: 767.98px) {
    .timeline {
        padding-left: 1.5rem;
    }
    .timeline-item::before {
        left: -1.2rem;
        width: 10px;
        height: 10px;
    }
    .timeline-content {
        font-size: 0.8rem;
    }
}

/* ── Login Page ── */
@media (max-width: 575.98px) {
    .login-card {
        margin: 1rem;
        border-radius: 16px;
    }
    .login-right {
        padding: 2rem 1.5rem !important;
    }
    .login-left h1 {
        font-size: 1.75rem;
    }
}

/* ── Dashboard Specific ── */
@media (max-width: 767.98px) {
    .card canvas {
        max-height: 200px !important;
    }
    .card .timeline {
        max-height: none !important;
    }
}

/* ── Attachment Upload ── */
@media (max-width: 575.98px) {
    .attachment-item {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .attachment-item .flex-grow-1 {
        width: calc(100% - 3rem);
    }
}

/* ── Tables inside Cards ── */
@media (max-width: 767.98px) {
    .table th,
    .table td {
        padding: 0.5rem 0.4rem !important;
        white-space: normal !important;
    }
    .overflow-hidden .table-responsive {
        margin: 0;
    }
}

/* ── Print ── */
@media print {
    .sidebar,
    .topbar,
    .bulk-action-toolbar,
    .mobile-menu-toggle,
    .spinner-overlay,
    .toast-container,
    .btn,
    .dt-buttons {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .content-area {
        padding: 0 !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

/* ═══════════════════════════════════════════════════════
   DATATABLE THEME OVERRIDES (all DataTable variants)
   Ensures DataTables respond to dark/light theme
   ═══════════════════════════════════════════════════════ */

/* ── base_datatable.html ── */
#dataTable thead { background-color: var(--hp-primary) !important; }
#dataTable thead th { border-color: var(--hp-border) !important; color: var(--hp-text-inverse) !important; }
#dataTable tbody tr:nth-child(even) { background-color: var(--hp-table-stripe) !important; }
#dataTable tbody tr:nth-child(odd) { background-color: var(--hp-table-bg) !important; }
#dataTable tbody tr:hover { background-color: var(--hp-table-hover) !important; }
#dataTable tbody tr.selected { background-color: var(--hp-input-focus-ring) !important; }
.dataTables_wrapper .dataTables_filter input {
    border: 2px solid var(--hp-border) !important;
    border-radius: var(--hp-radius-md) !important;
    background: var(--hp-input-bg) !important;
    color: var(--hp-text) !important;
}
.dt-button-collection { background: var(--hp-surface) !important; border: 1px solid var(--hp-border) !important; }

/* ── helpex_datatable.html ── */
.hx-dt-wrapper {
    background: var(--hp-card-bg) !important;
    border: 1px solid var(--hp-card-border) !important;
    box-shadow: var(--hp-card-shadow) !important;
}
.hx-dt-toolbar { background: var(--hp-surface-hover) !important; border-color: var(--hp-border) !important; }
.hx-dt-search input {
    background: var(--hp-input-bg) !important;
    border-color: var(--hp-input-border) !important;
    color: var(--hp-text) !important;
}
.hx-dt-search input:focus { border-color: var(--hp-secondary) !important; box-shadow: 0 0 0 3px var(--hp-input-focus-ring) !important; }
.hx-dt-search i { color: var(--hp-text-muted) !important; }
.hx-dt-table thead th {
    background: var(--hp-table-stripe) !important;
    color: var(--hp-text-secondary) !important;
    border-bottom-color: var(--hp-table-border) !important;
}
.hx-dt-table tbody td {
    border-bottom-color: var(--hp-border-light) !important;
    color: var(--hp-text) !important;
}
.hx-dt-table tbody tr:hover { background-color: var(--hp-table-hover) !important; }
.hx-dt-footer { background: var(--hp-surface-hover) !important; border-color: var(--hp-border) !important; }
.hx-dt-footer .dataTables_info { color: var(--hp-text-muted) !important; }
.paginate_button {
    background: var(--hp-surface) !important;
    border-color: var(--hp-border) !important;
    color: var(--hp-text) !important;
}
.paginate_button.current { background: var(--hp-secondary) !important; border-color: var(--hp-secondary) !important; color: #fff !important; }
.paginate_button:hover:not(.current) { background: var(--hp-surface-hover) !important; }

/* ── hx_datatable.html ── */
.hx-dt-container { background: var(--hp-card-bg) !important; box-shadow: var(--hp-card-shadow) !important; }
.hx-dt-toolbar { background: var(--hp-surface-hover) !important; border-color: var(--hp-border) !important; }
.hx-dt-btn { background: var(--hp-surface) !important; border-color: var(--hp-border) !important; color: var(--hp-text) !important; }
.hx-dt-btn:hover { background: var(--hp-surface-hover) !important; border-color: var(--hp-text-muted) !important; }
.hx-dt-btn-primary { background: var(--hp-secondary) !important; color: #fff !important; border-color: var(--hp-secondary) !important; }
.hx-dt-btn-primary:hover { background: var(--hp-secondary-dark) !important; }
.hx-dt-info { color: var(--hp-text-muted) !important; }

/* ── datatable.html (helpex-datatable-wrapper) ── */
.helpex-datatable-wrapper { background: var(--hp-card-bg) !important; box-shadow: var(--hp-card-shadow) !important; }
.helpex-datatable-wrapper .dt-top { background: var(--hp-surface-hover) !important; border-color: var(--hp-border) !important; }
.helpex-datatable-wrapper .dt-search input { border-color: var(--hp-input-border) !important; background: var(--hp-input-bg) !important; color: var(--hp-text) !important; }
.helpex-datatable-wrapper .dt-search i { color: var(--hp-text-muted) !important; }
.helpex-datatable-wrapper table.dataTable thead th {
    background: var(--hp-table-stripe) !important;
    color: var(--hp-text-secondary) !important;
    border-bottom-color: var(--hp-table-border) !important;
}
.helpex-datatable-wrapper table.dataTable tbody td {
    color: var(--hp-text) !important;
    border-bottom-color: var(--hp-border-light) !important;
}
.helpex-datatable-wrapper table.dataTable tbody tr:hover { background: var(--hp-table-hover) !important; }
.helpex-datatable-wrapper table.dataTable tbody tr.selected { background: var(--hp-input-focus-ring) !important; }
.helpex-datatable-wrapper .dt-bottom { background: var(--hp-surface-hover) !important; border-color: var(--hp-border) !important; }
.helpex-datatable-wrapper .dt-info { color: var(--hp-text-muted) !important; }
.helpex-datatable-wrapper .dt-pagination .paginate_button {
    color: var(--hp-text) !important;
    background: var(--hp-surface) !important;
    border-color: var(--hp-border) !important;
}
.helpex-datatable-wrapper .dt-pagination .paginate_button.current {
    background: var(--hp-secondary) !important;
    color: #fff !important;
    border-color: var(--hp-secondary) !important;
}
.helpex-datatable-wrapper .dt-pagination .paginate_button:hover { background: var(--hp-surface-hover) !important; }
.helpex-datatable-wrapper .dt-column-toggle .dropdown-menu { background: var(--hp-surface) !important; border: 1px solid var(--hp-border) !important; }
.helpex-datatable-wrapper .dt-column-toggle .dropdown-item { color: var(--hp-text) !important; }
.helpex-datatable-wrapper .dt-column-toggle .dropdown-item:hover { background: var(--hp-surface-hover) !important; }
.helpex-datatable-wrapper .btn-action.btn-view { color: var(--hp-secondary) !important; background: var(--hp-input-focus-ring) !important; }
.helpex-datatable-wrapper .btn-action.btn-edit { color: var(--hp-success) !important; background: rgba(22,163,74,0.1) !important; }
.helpex-datatable-wrapper .btn-action.btn-delete { color: var(--hp-danger) !important; background: rgba(220,38,38,0.1) !important; }
.helpex-datatable-wrapper .badge-status.active { background: var(--hp-badge-approved) !important; color: var(--hp-badge-approved-text) !important; }
.helpex-datatable-wrapper .badge-status.inactive { background: var(--hp-badge-rejected) !important; color: var(--hp-badge-rejected-text) !important; }
.helpex-datatable-wrapper .badge-status.pending { background: var(--hp-badge-pending) !important; color: var(--hp-badge-pending-text) !important; }

/* ═══════════════════════════════════════════════════════
   SELECT CONTEXT PAGE (standalone, no base.html)
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] .context-card { background: var(--hp-surface) !important; }
[data-theme="dark"] .logo-section h1 { color: var(--hp-text) !important; }
[data-theme="dark"] .logo-section p { color: var(--hp-text-secondary) !important; }
[data-theme="dark"] .section-title { color: var(--hp-text) !important; border-bottom-color: var(--hp-border) !important; }
[data-theme="dark"] .form-label { color: var(--hp-text) !important; }
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-control { background: var(--hp-input-bg) !important; border-color: var(--hp-input-border) !important; color: var(--hp-text) !important; }
[data-theme="dark"] .company-item,
[data-theme="dark"] .branch-item { border-color: var(--hp-border) !important; color: var(--hp-text) !important; }
[data-theme="dark"] .company-item:hover,
[data-theme="dark"] .branch-item:hover { background: var(--hp-surface-hover) !important; border-color: var(--hp-secondary) !important; }
[data-theme="dark"] .company-item.selected,
[data-theme="dark"] .branch-item.selected { background: var(--hp-input-focus-ring) !important; border-color: var(--hp-secondary) !important; }
[data-theme="dark"] .context-summary { background: var(--hp-bg) !important; color: var(--hp-text) !important; }
[data-theme="dark"] .step { background: var(--hp-bg) !important; color: var(--hp-text-muted) !important; }
[data-theme="dark"] .step.active { background: var(--hp-secondary) !important; color: #fff !important; }
[data-theme="dark"] .step.completed { background: var(--hp-success) !important; color: #fff !important; }
[data-theme="dark"] .step-label { color: var(--hp-text-muted) !important; }
[data-theme="dark"] .no-options { color: var(--hp-text-muted) !important; }
[data-theme="dark"] .btn-outline-secondary { color: var(--hp-text) !important; border-color: var(--hp-border) !important; }
[data-theme="dark"] .btn-outline-secondary:hover { background: var(--hp-surface-hover) !important; }

/* ═══════════════════════════════════════════════════════
   POS TEMPLATES (dark theme overrides)
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] .pos-container,
[data-theme="dark"] .pos-cashier,
[data-theme="dark"] .pos-admin {
    background: var(--hp-bg) !important;
    color: var(--hp-text) !important;
}
[data-theme="dark"] .pos-header { background: var(--hp-surface) !important; border-color: var(--hp-border) !important; }
[data-theme="dark"] .pos-sidebar { background: var(--hp-surface) !important; border-color: var(--hp-border) !important; }
[data-theme="dark"] .pos-product-card { background: var(--hp-card-bg) !important; border-color: var(--hp-card-border) !important; color: var(--hp-text) !important; }
[data-theme="dark"] .pos-cart { background: var(--hp-surface) !important; border-color: var(--hp-border) !important; }
[data-theme="dark"] .pos-cart-item { border-color: var(--hp-border) !important; color: var(--hp-text) !important; }

/* ═══════════════════════════════════════════════════════
   DASHBOARD / KPI MONITOR (dark theme overrides)
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] .dashboard-card { background: var(--hp-card-bg) !important; border-color: var(--hp-card-border) !important; }
[data-theme="dark"] .kpi-value { color: var(--hp-text) !important; }
[data-theme="dark"] .kpi-label { color: var(--hp-text-muted) !important; }
[data-theme="dark"] .kpi-trend.up { color: var(--hp-success) !important; }
[data-theme="dark"] .kpi-trend.down { color: var(--hp-danger) !important; }
[data-theme="dark"] .chart-container { background: var(--hp-card-bg) !important; border-color: var(--hp-card-border) !important; }

/* ═══════════════════════════════════════════════════════
   TAX ENGINE TEMPLATES (dark theme overrides)
   ═══════════════════════════════════════════════════════ */
[data-theme="dark"] .tax-container { background: var(--hp-bg) !important; color: var(--hp-text) !important; }
[data-theme="dark"] .tax-card { background: var(--hp-card-bg) !important; border-color: var(--hp-card-border) !important; }
[data-theme="dark"] .tax-header { background: var(--hp-surface) !important; border-color: var(--hp-border) !important; }
[data-theme="dark"] .tax-table thead th { background: var(--hp-table-stripe) !important; color: var(--hp-text-secondary) !important; border-color: var(--hp-table-border) !important; }
[data-theme="dark"] .tax-table tbody td { color: var(--hp-text) !important; border-color: var(--hp-border-light) !important; }
[data-theme="dark"] .tax-calculator { background: var(--hp-card-bg) !important; border-color: var(--hp-card-border) !important; }
[data-theme="dark"] .tax-result { background: var(--hp-surface) !important; border-color: var(--hp-border) !important; }
