/* ============================================
   ====== MOBILE RESPONSIVE OVERRIDES ======
   ============================================ */

/* --- Global Mobile Fixes --- */
@media (max-width: 768px) {
    /* Reduce main content padding for mobile */
    #main {
        padding: 60px 10px 10px 10px !important;
    }

    /* Page Title */
    .pagetitle h1 {
        font-size: 1.4rem !important;
        line-height: 1.4 !important;
    }

    .pagetitle {
        margin-bottom: 1rem !important;
    }

    /* Breadcrumb */
    .breadcrumb {
        font-size: 0.8rem !important;
    }

    /* Card padding reduction */
    .card-body {
        padding: 1rem 0.8rem !important;
    }

    .card-title {
        font-size: 0.95rem !important;
    }

    .card {
        margin-bottom: 1rem !important;
        border-radius: 12px !important;
    }

    /* Tables */
    table.table {
        font-size: 0.8rem !important;
        border-spacing: 0 6px !important;
    }

    table.table thead th {
        padding: 0.6rem 0.5rem !important;
        font-size: 0.7rem !important;
        white-space: nowrap;
    }

    table.table tbody tr td {
        padding: 0.6rem 0.5rem !important;
        font-size: 0.8rem !important;
    }

    /* Forms */
    .form-group {
        margin-bottom: 1rem !important;
    }

    input.form-control,
    textarea.form-control,
    select.form-select {
        padding: 0.55rem 0.8rem !important;
        font-size: 0.85rem !important;
    }

    label {
        font-size: 0.85rem !important;
        margin-bottom: 0.3rem !important;
    }

    /* Buttons */
    .btn {
        padding: 0.45rem 0.8rem !important;
        font-size: 0.8rem !important;
    }

    .btn-sm {
        padding: 0.3rem 0.6rem !important;
        font-size: 0.75rem !important;
    }

    /* Stats/Info Cards — Stack properly */
    .info-card .card-body {
        padding: 0.8rem !important;
    }

    .info-card .card-body h5.card-title {
        font-size: 0.8rem !important;
    }

    .info-card .card-body h6 {
        font-size: 1.1rem !important;
    }

    .info-card .card-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1rem !important;
    }

    .info-card .card-icon i {
        font-size: 1rem !important;
    }

    /* Pagination */
    .pagination .page-item .page-link {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.75rem !important;
        margin: 0 0.15rem !important;
    }

    /* d-flex actions wrapper in show pages */
    .pagetitle .d-flex.gap-2 {
        flex-wrap: wrap;
        gap: 0.4rem !important;
    }

    .pagetitle .d-flex.gap-2 .btn {
        font-size: 0.75rem !important;
        padding: 0.35rem 0.6rem !important;
    }

    /* Alerts */
    .alert {
        font-size: 0.82rem !important;
        padding: 0.6rem 0.8rem !important;
    }

    /* Modal */
    .modal-dialog {
        margin: 0.5rem !important;
    }

    .modal-title {
        font-size: 1rem !important;
    }

    .modal-body {
        padding: 1rem !important;
    }

    /* Metric boxes (owner-reports, etc.) */
    .metric-box {
        padding: 12px !important;
    }

    .metric-icon {
        width: 42px !important;
        height: 42px !important;
        font-size: 1.3rem !important;
        margin-left: 10px !important;
    }

    .metric-data h3 {
        font-size: 1.1rem !important;
    }

    .metric-data h6 {
        font-size: 0.75rem !important;
    }

    /* Filter panels */
    .filter-panel {
        padding: 12px !important;
    }

    /* Tabs */
    .nav-tabs .nav-link {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.78rem !important;
    }

    .nav-tabs .nav-link .badge {
        font-size: 0.65rem !important;
    }

    /* Invoice */
    .invoice-header {
        padding: 12px 15px !important;
        flex-direction: column !important;
        gap: 10px !important;
        text-align: center !important;
    }

    .invoice-header .d-flex.align-items-center.gap-3 {
        flex-direction: column;
        gap: 6px !important;
    }

    .invoice-header .text-end {
        text-align: center !important;
    }

    .invoice-logo {
        max-height: 40px !important;
    }

    .company-name {
        font-size: 1rem !important;
    }

    .voucher-title {
        font-size: 1rem !important;
    }

    /* Sidebar override for mobile */
    .sidebar {
        width: 260px !important;
    }

    .sidebar-nav .nav-link {
        margin: 0.15rem 0.5rem !important;
        padding: 0.6rem 0.8rem !important;
        font-size: 0.85rem !important;
    }

    .sidebar-nav .nav-heading {
        font-size: 0.75rem !important;
    }
}

/* --- Extra Small Mobile (iPhone SE, etc.) --- */
@media (max-width: 400px) {
    #main {
        padding: 55px 6px 6px 6px !important;
    }

    .pagetitle h1 {
        font-size: 1.15rem !important;
    }

    .card-body {
        padding: 0.7rem 0.5rem !important;
    }

    table.table {
        font-size: 0.72rem !important;
    }

    table.table thead th {
        font-size: 0.65rem !important;
        padding: 0.4rem 0.3rem !important;
    }

    table.table tbody tr td {
        font-size: 0.72rem !important;
        padding: 0.4rem 0.3rem !important;
    }

    .btn {
        font-size: 0.72rem !important;
        padding: 0.35rem 0.5rem !important;
    }

    .nav-tabs .nav-link {
        padding: 0.35rem 0.4rem !important;
        font-size: 0.7rem !important;
    }

    .info-card .card-body h6 {
        font-size: 0.95rem !important;
    }

    .metric-data h3 {
        font-size: 0.95rem !important;
    }
}

/* --- Tablet Fixes (768px to 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .card-body {
        padding: 1.2rem 1.5rem !important;
    }

    .pagetitle h1 {
        font-size: 1.7rem !important;
    }

    table.table {
        font-size: 0.88rem !important;
    }
}

/* --- Ensure table-responsive wraps always scroll on mobile --- */
.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* --- Fix NiceAdmin header on mobile (prevent items from overflowing) --- */
@media (max-width: 768px) {
    .header .header-nav {
        gap: 0 !important;
    }

    .header .header-nav .nav-item {
        margin: 0 !important;
    }

    .header .logo img {
        max-height: 30px !important;
    }

    /* Hide long text on mobile for profile */
    .header .nav-profile .dropdown-toggle {
        font-size: 0.8rem !important;
    }

    /* Row cols for filter forms in bookings */
    .row.g-3 > [class*="col-md-3"] {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Fix stat cards grid */
    .row.g-3 > .col-xl-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media (max-width: 480px) {
    /* On very small screens, make filter fields full width */
    .row.g-3 > [class*="col-md-3"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Stat cards full width on very small screens */
    .row.g-3 > .col-xl-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* --- Fix pagetitle flex layout on mobile --- */
@media (max-width: 768px) {
    .pagetitle.d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.6rem !important;
    }

    .pagetitle .d-flex.flex-wrap {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    /* Period filter form in target show */
    .pagetitle form.d-flex {
        flex-wrap: wrap !important;
        gap: 0.4rem !important;
    }

    .pagetitle form .form-select-sm {
        font-size: 0.8rem !important;
        min-width: 100px !important;
    }
}

/* --- Action buttons in tables (edit/delete/show) --- */
@media (max-width: 768px) {
    td .d-flex.gap-1,
    td .d-inline-flex.gap-1,
    td .btn-group {
        flex-wrap: nowrap !important;
        gap: 0.2rem !important;
    }

    td .btn-sm {
        padding: 0.2rem 0.4rem !important;
        font-size: 0.7rem !important;
    }

    td .btn-sm i {
        font-size: 0.75rem !important;
    }
}

/* --- Card hover: disable on mobile for better touch UX --- */
@media (max-width: 768px) {
    .card:hover {
        transform: none !important;
        box-shadow: 0 8px 24px rgba(149, 157, 165, 0.1) !important;
    }

    table.table tbody tr:hover {
        transform: none !important;
    }

    .btn:hover {
        transform: none !important;
    }

    .pagination .page-item .page-link:hover {
        transform: none !important;
    }
}

/* --- Global scrollable tabs for all pages --- */
@media (max-width: 768px) {
    .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE */
    }

    .nav-tabs::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .nav-tabs .nav-link {
        white-space: nowrap !important;
    }

    /* Card headers with tabs should scroll */
    .card-header {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

/* --- Show pages: stack details and action buttons vertically --- */
@media (max-width: 768px) {
    /* Any pagetitle with d-flex */
    .pagetitle.d-flex,
    .pagetitle > .d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    /* Row cols inside show pages - stack on mobile */
    .row > .col-sm-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Border-start on second column - remove on mobile stacking */
    .border-start {
        border-left: none !important;
        border-top: 1px solid #dee2e6 !important;
        padding-top: 0.8rem !important;
        margin-top: 0.8rem !important;
    }

    /* Show page detail rows */
    .row.mb-3 > .col-sm-6.text-sm-end {
        text-align: right !important;
    }
}

/* --- Bottom safe area for PWA standalone mode --- */
@media (display-mode: standalone) {
    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* --- Touch-friendly button sizes --- */
@media (max-width: 768px) {
    .btn, a.btn {
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Make select inputs touch-friendly */
    select.form-select,
    select.form-select-sm {
        min-height: 36px;
    }
}

