/* =====================================================================
   Mobile / responsive polish for the POS system
   ---------------------------------------------------------------------
   Layered on top of Bootstrap 5.3 + custom.css. Goals:
     - Comfortable touch targets (≥44px) on phones/tablets
     - Tables that scroll horizontally instead of breaking the layout
     - Button groups that wrap to a second row instead of overflowing
     - Modals go full-screen on small viewports
     - Sticky "process" action bar on the POS so the primary CTA is
       always reachable without scrolling
     - Safe-area padding for notched devices
   No JS changes needed — purely additive CSS.
   ===================================================================== */

/* ---- Global ------------------------------------------------------- */
html, body {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    /* Respect iOS safe areas at the bottom (home indicator). */
    padding-bottom: env(safe-area-inset-bottom);
}

main, .container, .container-fluid {
    /* Avoid horizontal scroll caused by stray wide content. */
    overflow-x: clip;
}

.main-container {
    /* Bounded reading width on huge monitors, full-width below. */
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    padding-left: clamp(0.75rem, 2vw, 1.5rem);
    padding-right: clamp(0.75rem, 2vw, 1.5rem);
}

/* Slightly larger comfortable line-height on small screens. */
@media (max-width: 575.98px) {
    body { font-size: 0.975rem; line-height: 1.5; }
    .container { padding-left: 0.75rem; padding-right: 0.75rem; }
    h1, .h1 { font-size: 1.6rem; }
    h2, .h2 { font-size: 1.4rem; }
    h3, .h3 { font-size: 1.25rem; }
    h4, .h4 { font-size: 1.1rem; }
    .card-header h4 { margin-bottom: 0; }
}

/* ---- Touch targets ------------------------------------------------ */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .form-control,
    .form-select,
    .nav-link {
        min-height: 44px;
    }
    .btn-sm { min-height: 36px; }
    /* Bigger tap area for table action buttons */
    .table .btn { padding: 0.4rem 0.7rem; }
}

/* ---- Navbar ------------------------------------------------------- */
.navbar-brand img {
    object-fit: contain;
}
.navbar-collapse .nav-link {
    /* On collapsed mobile menus, give each link breathing room. */
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
}
@media (max-width: 991.98px) {
    .navbar-nav.ms-auto {
        margin-top: 0.5rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding-top: 0.5rem;
    }
}

/* ---- Cards & spacing --------------------------------------------- */
.card {
    border-radius: 0.75rem;
    border: 1px solid rgba(0, 0, 0, 0.075);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
[data-bs-theme="dark"] .card {
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.card-header {
    /* Background is set by theme.css to a subtle brand tint so the
       section title is clearly visible. We just enforce the typography
       and a solid bottom border here. */
    border-bottom: 1px solid rgba(0, 0, 0, 0.075);
    font-weight: 500;
}
[data-bs-theme="dark"] .card-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}
@media (max-width: 575.98px) {
    .card-body { padding: 0.875rem; }
}

/* ---- Tables (auto-responsive) ------------------------------------ */
/* Any plain `.table` that is not already inside `.table-responsive`
   still gets horizontal scroll on narrow screens via this trick. */
@media (max-width: 767.98px) {
    .table:not(.table-fixed) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    .table-responsive .table { display: table; white-space: normal; }
    .table thead th { font-size: 0.85rem; }
    .table td, .table th { padding: 0.5rem 0.6rem; }
}

/* ---- Forms -------------------------------------------------------- */
.form-control, .form-select {
    border-radius: 0.5rem;
}
.input-group > .form-control,
.input-group > .form-select {
    /* Bootstrap’s own rule keeps borders sharp inside groups; we override
       just the outermost corners so groups look modern. */
    border-radius: 0;
}
.input-group > :first-child { border-top-left-radius: 0.5rem; border-bottom-left-radius: 0.5rem; }
.input-group > :last-child  { border-top-right-radius: 0.5rem; border-bottom-right-radius: 0.5rem; }

/* ---- Button groups: wrap on mobile instead of overflowing -------- */
.btn-group {
    flex-wrap: wrap;
}
.btn-group > .btn {
    flex: 1 1 auto;
}
@media (max-width: 575.98px) {
    .btn-group > .btn {
        /* Force at least two per row, never a single tiny button. */
        flex: 1 1 calc(50% - 0.25rem);
        margin-bottom: 0.25rem;
        border-radius: 0.5rem !important;
    }
    /* Restore neighbour spacing because we rounded corners. */
    .btn-group > .btn + .btn { margin-left: 0; }
}

/* ---- POS specific ------------------------------------------------- */
/* Make the cart scroll vertically inside the card on small screens
   instead of pushing the payment panel off screen. */
@media (max-width: 991.98px) {
    #cart-table {
        max-height: none;
    }
}

/* Sticky checkout button on phones — always visible. */
@media (max-width: 767.98px) {
    .pos-sticky-action {
        position: sticky;
        bottom: 0;
        background: var(--bs-body-bg);
        padding: 0.75rem 0;
        margin: 0 -0.875rem -0.875rem;  /* bleed to card edges */
        padding-left: 0.875rem;
        padding-right: 0.875rem;
        border-top: 1px solid rgba(0, 0, 0, 0.08);
        z-index: 5;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
    [data-bs-theme="dark"] .pos-sticky-action {
        border-top-color: rgba(255, 255, 255, 0.08);
    }
}

/* Barcode scanner input deserves a roomy tap area on phones. */
#barcode-scanner {
    font-size: 1.05rem;
    height: 48px;
}

/* ---- Modals: fullscreen on phones -------------------------------- */
@media (max-width: 575.98px) {
    .modal-dialog:not(.modal-fullscreen):not(.modal-fullscreen-sm-down) {
        margin: 0;
        max-width: 100%;
        min-height: 100%;
    }
    .modal-dialog:not(.modal-fullscreen):not(.modal-fullscreen-sm-down) .modal-content {
        border: 0;
        border-radius: 0;
        min-height: 100vh;
    }
}

/* ---- Alerts ------------------------------------------------------- */
.alert {
    border-radius: 0.65rem;
    border: 0;
}

/* ---- Stat cards --------------------------------------------------- */
.stat-card {
    background: var(--bs-body-bg);
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
}
[data-bs-theme="dark"] .stat-card {
    border-color: rgba(255, 255, 255, 0.08);
}

/* ---- Back-to-top button: smaller, less intrusive on mobile ------- */
@media (max-width: 575.98px) {
    #backToTop {
        padding: 14px !important;
        font-size: 16px !important;
        bottom: calc(12px + env(safe-area-inset-bottom));
        right: 12px;
    }
}

/* ---- Daterangepicker fixes for narrow viewports ------------------ */
.daterangepicker {
    max-width: calc(100vw - 1rem);
}
@media (max-width: 575.98px) {
    .daterangepicker .drp-calendar { max-width: 100%; }
    .daterangepicker .ranges,
    .daterangepicker .drp-calendar.left,
    .daterangepicker .drp-calendar.right { float: none; width: 100%; }
}

/* ---- Select2 polish ---------------------------------------------- */
.select2-container--bootstrap-5 .select2-selection {
    border-radius: 0.5rem;
}

/* ---- Utility: hide noise on small screens, prefer icons ---------- */
@media (max-width: 575.98px) {
    .hide-xs { display: none !important; }
}

/* ---- Print -------------------------------------------------------- */
@media print {
    .navbar, #backToTop, .pos-sticky-action, .no-print { display: none !important; }
    .card { border: 0; box-shadow: none; }
}
