/* =====================================================
   JNCARLO ANDROID TABLET RESPONSIVE LAYER
   UI-only overrides. No business logic changes.
===================================================== */

html { -webkit-text-size-adjust: 100%; }
body { min-width: 0; }
button, input, select, textarea { font: inherit; }
button, a, select, input[type="button"], input[type="submit"] { touch-action: manipulation; }

/* Improve touch targets without changing desktop appearance */
@media (pointer: coarse) {
    button, .btn, a[class*="btn"], select, input { min-height: 42px; }
    input[type="checkbox"], input[type="radio"] { min-height: auto; }
}

@media (max-width: 1100px) {
    html, body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden !important;
    }

    /* All main module pages move beside compact sidebar in landscape tablet */
    [class$="-page"]:not(.pos-page),
    .dashboard-container,
    .main-content,
    .content-wrapper {
        margin-left: 60px !important;
        width: calc(100% - 60px) !important;
        max-width: calc(100% - 60px) !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Headers/toolbars wrap instead of clipping */
    [class$="-header"],
    [class$="-toolbar"],
    .toolbar,
    .filters,
    .filter-row,
    .header-stats,
    .form-actions,
    .action-bar {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    .header-stats { justify-content: flex-start !important; }
    .stat-card { min-width: 130px; flex: 1 1 130px; }

    /* Tables remain readable and swipe horizontally */
    [class$="-card"],
    .table-wrapper,
    .table-container,
    .table-responsive,
    .data-table-wrapper {
        max-width: 100%;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    table { min-width: 720px; }
    th, td { white-space: nowrap; }

    /* Forms/modal fit tablet viewport */
    .modal-content,
    .modal-box,
    .dialog,
    [class*="modal-content"] {
        max-width: calc(100vw - 36px) !important;
        max-height: calc(100vh - 36px) !important;
        overflow: auto !important;
    }

    input, select, textarea { max-width: 100%; }

    /* POS tablet landscape */
    .pos-page { margin-left: 60px !important; width: calc(100% - 60px) !important; }
    .pos-page .header {
        left: 60px !important;
        width: calc(100% - 60px) !important;
        height: auto !important;
        min-height: 118px;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px !important;
    }
    .pos-page .header-actions { order: 2; flex: 1 1 auto; flex-wrap: wrap; }
    .pos-page .header-price { order: 3; width: 100%; display: flex; gap: 8px; }
    .pos-page .header-price .search-product-wrap { flex: 1 1 320px; }
    .pos-page .header-action-btn { min-width: 96px; flex: 1 1 96px; }
    .pos-page .header-total-box { min-width: 180px; }
    .pos-page .main-container {
        margin-left: 0 !important;
        padding-left: 0 !important;
        width: 100% !important;
        top: 118px !important;
        bottom: 52px !important;
    }
    .pos-page .sales-area { width: 100% !important; }
    .pos-page .table-wrapper { overflow: auto !important; -webkit-overflow-scrolling: touch; }
    .pos-page #salesTable { min-width: 850px; }
    .pos-page .bottom-panel { gap: 12px; }
    .pos-page .footer { left: 60px !important; width: calc(100% - 60px) !important; }
}

/* Portrait tablet / small Android tablet: off-canvas sidebar */
@media (max-width: 820px) {
    body { overflow-y: auto !important; }

    .sidebar {
        width: 250px !important;
        transform: translateX(-100%);
        transition: transform .25s ease !important;
        box-shadow: 8px 0 24px rgba(0,0,0,.18);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar.collapsed { width: 250px !important; }
    .sidebar.collapsed .sidebar-menu a span,
    .sidebar.collapsed .user-info,
    .sidebar.collapsed .menu-section-title span,
    .sidebar.collapsed .submenu li a span { display: initial !important; }
    .sidebar.collapsed .sidebar-profile { justify-content: flex-start !important; padding: 15px !important; }
    .sidebar.collapsed .sidebar-menu li a,
    .sidebar.collapsed .submenu li a { justify-content: flex-start !important; padding: 12px 16px !important; }

    .burger-btn {
        left: 12px !important;
        top: 12px !important;
        width: 42px !important;
        height: 42px !important;
        padding: 10px 7px !important;
        border-radius: 9px;
        background: #166534 !important;
        box-shadow: 0 4px 14px rgba(0,0,0,.18);
    }
    .burger-btn span { height: 3px; }

    body::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.38);
        z-index: 900;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    body.sidebar-mobile-open::after { opacity: 1; pointer-events: auto; }

    [class$="-page"]:not(.pos-page),
    .dashboard-container,
    .main-content,
    .content-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 100vh;
        overflow: visible !important;
        padding: 64px 10px 16px !important;
    }

    [class$="-header"] { align-items: flex-start !important; }
    [class$="-header"] > * { min-width: 0; }
    .header-stats { width: 100%; }
    .stat-card { flex: 1 1 calc(50% - 8px); min-width: 120px; }

    [class$="-toolbar"], .toolbar, .filter-row, .filters { width: 100%; align-items: stretch !important; }
    [class$="-toolbar"] > *, .toolbar > *, .filters > *, .filter-row > * { max-width: 100%; }
    .search-box, [class*="search-box"] { flex: 1 1 220px; width: 100%; }
    .search-box input, [class*="search-box"] input { width: 100% !important; }

    table { min-width: 680px; }

    /* POS portrait: stack header and bottom area */
    .pos-page {
        margin-left: 0 !important;
        width: 100% !important;
        min-height: 100vh;
        overflow: auto !important;
        padding-top: 64px;
    }
    .pos-page .header {
        position: relative !important;
        left: 0 !important;
        width: 100% !important;
        top: 0 !important;
        min-height: 0;
        border-radius: 0;
        flex-direction: column;
        align-items: stretch !important;
    }
    .pos-page .header-total-box { width: 100%; min-width: 0; }
    .pos-page .header-actions { width: 100%; display: grid !important; grid-template-columns: repeat(4, minmax(0,1fr)); }
    .pos-page .header-action-btn { min-width: 0 !important; width: 100%; }
    .pos-page .header-price { flex-direction: column; }
    .pos-page .price-select, .pos-page .search-product-wrap { width: 100% !important; }
    .pos-page .main-container {
        position: relative !important;
        inset: auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: 520px;
    }
    .pos-page .sales-area { height: auto !important; min-height: 520px; }
    .pos-page .table-wrapper { min-height: 300px; }
    .pos-page .bottom-panel { flex-direction: column !important; align-items: stretch !important; }
    .pos-page .summary { width: 100% !important; }
    .pos-page .bottom-buttons { width: 100% !important; display: grid !important; grid-template-columns: 1fr 1fr; }
    .pos-page .footer {
        position: relative !important;
        left: 0 !important;
        width: 100% !important;
        min-height: 48px;
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px !important;
    }
}

@media (max-width: 600px) {
    .stat-card { flex-basis: 100%; }
    .pos-page .header-actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .modal-content, .modal-box, .dialog, [class*="modal-content"] { max-width: calc(100vw - 20px) !important; }
}
