/* ============================================================
   mobile.css — responsive overrides for phones / small tablets
   Applied on top of base.css, pos.css, courses.css, login.css.
   Core desktop layout is untouched; these rules only fire below
   768 px (phones) and 1024 px (small tablets where needed).
   ============================================================ */

/* ---- Orientation disclaimer banner ---------------------------- */
/* Hidden on desktop; appears only on mobile portrait.           */
.orient-banner { display: none; }

@media (max-width: 768px) and (orientation: portrait) {
    .orient-banner {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        background: #1a1f36;
        color: #fff;
        padding: 12px 14px;
        font-size: 13px;
        line-height: 1.5;
        position: relative;
        z-index: 9999;
    }
    .orient-banner.dismissed { display: none !important; }

    .orient-icon {
        font-size: 22px;
        flex-shrink: 0;
        margin-top: 1px;
        display: inline-block;
        animation: rotate-hint 2s ease-in-out infinite;
    }
    @keyframes rotate-hint {
        0%   { transform: rotate(0deg); }
        40%  { transform: rotate(90deg); }
        60%  { transform: rotate(90deg); }
        100% { transform: rotate(0deg); }
    }

    .orient-text { flex: 1; }
    .orient-text strong { color: #facc15; }

    .orient-dismiss {
        background: transparent;
        border: none;
        color: rgba(255,255,255,0.55);
        font-size: 18px;
        cursor: pointer;
        flex-shrink: 0;
        padding: 0 2px;
        line-height: 1;
        align-self: flex-start;
        min-height: unset;
    }
    .orient-dismiss:hover { color: #fff; }
}

/* Always hidden in landscape — they've already rotated */
@media (orientation: landscape) {
    .orient-banner { display: none !important; }
}

/* ============================================================
   LANDSCAPE MODE — phones rotated horizontal
   Triggered by: orientation:landscape AND short viewport height
   (phones in landscape have height ~360–480px; tablets/desktop
    always have more vertical space so this never fires for them).
   Goal: restore the full desktop two-column POS layout.
   ============================================================ */

@media (orientation: landscape) and (max-height: 500px) {

    /* --- Top bar: restore search bar, tighten height --- */
    .ls-topbar        { height: 42px; }
    .ls-topbar-search { display: flex; }
    .ls-topbar-right  { gap: 14px; font-size: 12px; }

    /* --- Show rail, hide sidemenu (saves ~220px of horizontal space) --- */
    .ls-rail     { display: flex; width: 48px; }
    .ls-sidemenu { display: none; }

    /* --- Layout: restore side-by-side flex row --- */
    .ls-layout {
        display: flex;
        flex-direction: row;
        height: calc(100vh - 42px);
    }
    .ls-main { padding: 10px 14px; overflow-y: auto; }

    /* --- Sell grid: two columns, narrower cart pane --- */
    .sell-grid {
        grid-template-columns: minmax(0, 1fr) 300px;
        gap: 14px;
    }
    .actions-bar { margin-bottom: 8px; gap: 14px; }

    /* --- Product grid: 4 columns in landscape --- */
    .product-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    .product-tile {
        height: 72px;
        font-size: 11px;
        padding: 10px 6px 6px;
    }

    /* --- Cart: restore normal height --- */
    .cart-pane  { min-height: unset; }
    .cart-items { min-height: 100px; }

    /* --- Pay screen: restore two-column side-by-side --- */
    .pay-layout {
        display: flex;
        flex-direction: row;
    }
    .pay-layout .ls-rail     { display: flex; }
    .pay-layout .ls-sidemenu { display: none; }
    .pay-main  { padding: 10px 14px 16px; overflow-y: auto; }

    .pay-cols {
        grid-template-columns: minmax(0, 1fr) 320px;
        gap: 14px;
    }

    .pay-head           { flex-direction: row; align-items: flex-start; }
    .pay-head h2        { font-size: 22px; }
    .pay-amount-wrap    { text-align: right; }
    #pay-amount         { font-size: 24px; width: 120px; }

    .tender-primary {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }
    .tender-primary .tender-pill:nth-child(3) { grid-column: unset; }
    .tender-pill  { padding: 12px 8px; font-size: 15px; }

    .tender-secondary      { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
    .tender-soft           { padding: 10px 6px; font-size: 14px; }

    .cc-balances                      { grid-template-columns: repeat(3, 1fr); }
    .cc-balances > div:last-child     { grid-column: unset; }

    .pay-footer            { flex-direction: row; }
    .pay-footer .cust-btn  { width: auto; flex: 1; }

    /* --- Tooltip: keep at bottom but shorter so it doesn't eat the screen --- */
    .tut-tooltip {
        max-height: 38vh;
        padding: 12px 14px 10px;
        bottom: 8px;
        left: 8px;
        right: 8px;
    }
    .tut-tooltip .tt-title { font-size: 14px; }
    .tut-tooltip .tt-body  { font-size: 12px; }

    /* Padding-bottom still needed to keep Pay button above the tooltip */
    body:has(.tut-tooltip) {
        padding-bottom: 220px !important;
    }
    body:has(.tut-tooltip) .pay-screen {
        padding-bottom: 220px;
    }

    /* --- Scenario / customer modals: centred, not bottom-sheet --- */
    .scenario-overlay { align-items: center; padding: 12px; }
    .scenario-panel   {
        border-radius: 10px;
        max-height: 88vh;
        max-width: 520px;
    }
    .scenario-body    { padding: 14px; }

    .cust-modal       { align-items: center; padding: 12px; }
    .cust-modal-panel {
        border-radius: 8px;
        max-height: 90vh;
        max-width: 600px;
    }

    /* --- Courses: two-column cards in landscape --- */
    .courses-main { padding: 14px 14px 30px; }
    .courses-header { flex-direction: row; }
    .course-section-grid { grid-template-columns: repeat(2, 1fr); }
}
   ============================================================ */

/* ---------- Global touch helpers -------------------------------- */
@media (max-width: 768px) {
    /* Ensure tappable elements are at least 44 px tall */
    button, .course-btn, .tender-pill, .tender-soft,
    .cust-btn, .pay-btn, .scenario-actions button,
    .cust-tab, .side-links li, .rail-icon {
        min-height: 44px;
    }

    input, select {
        font-size: 16px !important; /* prevent iOS auto-zoom on focus */
    }
}

/* ---------- Login page ------------------------------------------ */
@media (max-width: 480px) {
    .login-shell { padding: 16px; }
    .login-card  { padding: 28px 20px; }
}

/* ---------- Top bar -------------------------------------------- */
@media (max-width: 768px) {
    .ls-topbar { padding: 0 12px; gap: 8px; }
    .ls-topbar-logo { width: auto; }
    /* Hide the decorative global search bar on mobile */
    .ls-topbar-search { display: none; }
    .ls-topbar-right  { gap: 12px; font-size: 12px; }
    .search-shortcut  { display: none; }
    .topbar-bell      { display: none; }
}

/* ---------- Left rail + side menu — hide on mobile -------------- */
@media (max-width: 768px) {
    .ls-rail    { display: none; }
    .ls-sidemenu{ display: none; }

    /* Let main content fill the full width */
    .ls-layout  { height: auto; min-height: calc(100vh - 48px); }
    .ls-main    { padding: 12px; }
}

/* ---------- POS: sell grid — stack product grid above cart ------ */
@media (max-width: 768px) {
    .sell-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .actions-bar {
        gap: 14px;
        font-size: 13px;
        margin-bottom: 10px;
    }
}

/* ---------- Product grid — fewer columns on phone -------------- */
@media (max-width: 768px) {
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
    .product-tile {
        height: 80px;
        font-size: 11px;
        padding: 12px 6px 6px;
    }
}

@media (max-width: 380px) {
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------- Cart pane ------------------------------------------ */
@media (max-width: 768px) {
    .cart-pane  { min-height: unset; }
    .cart-items { min-height: 140px; }

    .cart-line {
        grid-template-columns: 18px 28px 1fr auto 28px;
        gap: 6px;
        font-size: 13px;
    }

    .pay-btn {
        padding: 14px 16px;
        font-size: 15px;
    }
}

/* ---------- Customer bar / dropdown / chip --------------------- */
@media (max-width: 768px) {
    .customer-dropdown { max-height: 200px; }
    .customer-result   { padding: 12px 14px; }

    /* Add-new row */
    .customer-add-new  { padding: 12px 14px; }
}

/* ---------- Customer modal ------------------------------------- */
@media (max-width: 768px) {
    .cust-modal { padding: 0; align-items: flex-end; }
    .cust-modal-panel {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 24px 18px 28px;
        max-height: 92vh;
    }

    .cust-balances {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    /* Third balance card goes full-width */
    .cust-balances > div:last-child {
        grid-column: 1 / -1;
    }

    .cust-tabs { gap: 14px; overflow-x: auto; white-space: nowrap; }
    .cust-tab  { padding-bottom: 10px; flex-shrink: 0; }

    .cust-row  { grid-template-columns: 1fr; gap: 2px; }
    .cust-k    { font-size: 11px; color: #6b7280; font-weight: 500; }

    .cust-edit-form .form-grid { grid-template-columns: 1fr; }
    .cust-modal-footer { flex-wrap: wrap; }
    .cust-modal-footer .cust-btn { flex: 1 1 auto; text-align: center; }
}

/* ---------- Scenario overlay ----------------------------------- */
@media (max-width: 768px) {
    .scenario-overlay { padding: 0; align-items: flex-end; }
    .scenario-panel {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 88vh;
    }
    .scenario-body { padding: 16px; }
    .scenario-body h2 { font-size: 16px; }
    .scenario-body p, .scenario-body li { font-size: 13px; }
    .scenario-body table { font-size: 12px; }
    .scenario-body th,
    .scenario-body td  { padding: 5px 6px !important; }

    .scenario-actions        { flex-direction: column; gap: 8px; }
    .scenario-actions button { text-align: center; flex: unset; width: 100%; }
}

/* ---------- Tutorial tooltip & exit button --------------------- */
@media (max-width: 768px) {
    .tut-tooltip {
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        font-size: 14px;
        padding: 16px 16px 14px;
        /* Pin to bottom of screen so it never covers the spotlight */
        position: fixed !important;
        bottom: 12px;
        left: 12px;
        right: 12px;
        top: auto !important;
        transform: none !important;
        /* Limit height so it doesn't swallow the whole screen */
        max-height: 52vh;
        overflow-y: auto;
    }
    /* Hide arrow caret — irrelevant when pinned to bottom */
    .tut-tooltip::after { display: none; }

    .tut-tooltip .tt-title  { font-size: 15px; }
    .tut-tooltip .tt-body   { font-size: 13px; }
    .tut-tooltip .tt-actions { margin-top: 12px; }

    /* ---- KEY FIX: push ALL page content up by the tooltip height
           so buttons at the bottom of the page are never hidden under it.
           :has() is supported on all modern mobile browsers (Chrome 105+, Safari 15.4+). ---- */
    html:has(.tut-tooltip) {
        scroll-padding-bottom: 300px;
    }
    body:has(.tut-tooltip) {
        padding-bottom: 300px !important;
    }
    /* The pay screen is its own fixed fullscreen layer — pad it too */
    body:has(.tut-tooltip) .pay-screen {
        padding-bottom: 300px;
        box-sizing: border-box;
    }

    .tut-exit {
        top: 54px;
        right: 10px;
        padding: 8px 12px;
        font-size: 12px;
    }

    .training-fab {
        right: 14px;
        bottom: 14px;
        padding: 12px 16px;
        font-size: 12px;
    }
}

/* ---------- Pay screen ----------------------------------------- */
@media (max-width: 768px) {
    .pay-layout { flex-direction: column; }
    /* Hide decorative rail/sidemenu inside pay screen too */
    .pay-layout .ls-rail,
    .pay-layout .ls-sidemenu { display: none; }

    .pay-main  { padding: 12px 12px 40px; }

    /* Stack sale summary above pay card */
    .pay-cols {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .pay-head { flex-direction: column; align-items: stretch; gap: 10px; }
    .pay-head h2 { font-size: 24px; }

    .pay-amount-wrap { text-align: left; }
    .pay-amount-box  { display: inline-flex; align-items: center; }
    #pay-amount      { width: 130px; font-size: 26px; }

    /* Tender buttons: 2 columns on phone */
    .tender-primary {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    /* Move the third button (Dejavoo) to span both columns */
    .tender-primary .tender-pill:nth-child(3) {
        grid-column: 1 / -1;
    }
    .tender-pill { padding: 16px 10px; font-size: 16px; }

    .tender-secondary        { grid-template-columns: 1fr 1fr; gap: 10px; }
    .tender-secondary.single { grid-template-columns: 1fr 1fr; }
    .tender-soft             { padding: 12px 8px; font-size: 14px; }

    /* Customer balances inside pay screen */
    .cc-balances {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .cc-balances > div:last-child { grid-column: 1 / -1; }
    .cb-amt { font-size: 17px; }

    .pay-footer { flex-direction: column; }
    .pay-footer .cust-btn { width: 100%; text-align: center; }
}

/* ---------- Courses page --------------------------------------- */
@media (max-width: 768px) {
    .courses-main { padding: 20px 14px 40px; }

    .courses-header {
        flex-direction: column;
        gap: 16px;
        margin-bottom: 20px;
    }
    .courses-header h1 { font-size: 22px; }
    .progress-card { min-width: unset; width: 100%; }

    .course-section-grid {
        grid-template-columns: 1fr;
    }
    .course-card { padding: 18px 16px 16px; }
}

@media (min-width: 480px) and (max-width: 768px) {
    .course-section-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
