/* ============================================================
   ChowHub — Global Styles
   Rules here are ONLY for things Tailwind CDN cannot express:
   - Webkit scrollbar theming
   - .pos-layout responsive grid (complex named areas)
   - Floorplan absolute positioning, resize handles
   - Computed calc() geometry for resize handles
   - Shared .modal overlay base
   - Data-selector hooks with zero visual opinion (.bill-badge etc.)
   ============================================================ */

/* ── Scrollbars ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgb(82, 82, 82) !important; border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: rgb(110, 110, 110) !important; }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Mobile / iPad Viewport Height Fix ───────────────────────
   100vh on iOS Safari INCLUDES the browser chrome (address bar,
   tab bar) which means h-screen overflows the visible area and
   clips bottom rounded corners.
   100dvh (dynamic vh) is chrome-aware and fixes this.
   We also account for the home-indicator safe area.
   ──────────────────────────────────────────────────────────── */
body {
    /* !important needed: Tailwind's h-screen class (0,1,0 specificity)
       beats this element rule (0,0,1) without it */
    height: 100vh !important;
    height: 100dvh !important; /* chrome-aware, fixes iOS Safari viewport clipping */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
}

/* ── Modal overlay base ───────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 0.65);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
    overflow-y: auto;
}

/* ── POS Layout Grid (responsive) ────────────────────────── */
.pos-layout {
    display: grid;
    /* Mobile: single column, all panels stack */
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1rem;
    padding-bottom: 1rem; /* matches panel gap — corners clear without excess space */
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* ── Scroll-container padding-bottom fix ─────────────────────
   padding-bottom is silently ignored in overflow:auto containers.
   A ::after spacer block is the reliable workaround.
   ─────────────────────────────────────────────────────────── */
#products-container::after,
#order-items::after {
    content: '';
    display: block;
    height: 1rem; /* matches the p-4 top/side padding already on these elements */
}

/* Tablet: tables+menu on left (2 rows), order sidebar on right */
@media (min-width: 768px) {
    .pos-layout {
        grid-template-columns: 1fr 20rem;
        grid-template-rows: 1fr 1fr;
        overflow: auto;          /* was hidden — caused bottom corner clipping */
        padding-bottom: 1.5rem;  /* ensures rounded corners show fully */
    }
    .pos-layout > aside {
        grid-row: 1 / span 2;
        grid-column: 2;
        min-height: 0;
    }
    /* History / accounts overlaid sections */
    .pos-layout > section#history-view,
    .pos-layout > section#accounts-view {
        grid-column: 1;
    }
}

/* Desktop: true 3-column side-by-side */
@media (min-width: 1280px) {
    .pos-layout {
        grid-template-columns: 1fr 1fr 20rem;
        grid-template-rows: 1fr;
    }
    .pos-layout > aside {
        grid-row: auto;
        grid-column: auto;
    }
}

/* Floorplan active: hide menu section, expand tables */
@media (min-width: 1280px) {
    .pos-layout.floorplan-active {
        grid-template-columns: 1fr 20rem;
    }
}

/* ── Floorplan Canvas ──────────────────────────────────────── */
.floorplan-table {
    position: absolute;
    width: 6.25rem;
    height: 6.25rem;
    background-color: rgb(38 38 38);
    border: 2px solid rgb(255 255 255 / 0.1);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.5);
    transition: box-shadow 0.2s, border-color 0.2s, background-color 0.2s;
    user-select: none;
}

.floorplan-table:hover {
    border-color: rgb(255 255 255 / 0.3);
    box-shadow: 0 15px 20px -5px rgb(0 0 0 / 0.6);
}

.floorplan-table.draggable { cursor: grab; }
.floorplan-table.draggable:active {
    cursor: grabbing;
    opacity: 0.9;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.8);
    z-index: 50;
}

.floorplan-table.selected {
    border-color: rgb(59 130 246);
    box-shadow: 0 0 15px rgb(59 130 246 / 0.5);
    background-color: rgb(23 23 23);
}

.floorplan-table.edit-active {
    border-color: rgb(59 130 246);
    border-style: dashed;
    box-shadow: 0 0 0 2px rgb(59 130 246 / 0.5);
    z-index: 60;
}

.floorplan-table.shape-square { border-radius: 0.75rem; }

.floorplan-table-name {
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    pointer-events: none;
}

.floorplan-table-meta {
    font-size: 0.75rem;
    color: rgb(163 163 163);
    margin-top: 0.25rem;
    pointer-events: none;
}

/* ── Resize handles (floorplan edit mode) ─────────────────── */
.resize-handle {
    position: absolute;
    width: 1rem;
    height: 1rem;
    background-color: white;
    border: 3px solid rgb(59 130 246);
    border-radius: 50%;
    z-index: 100;
}

.resize-handle.tl { top: -0.5rem; left: -0.5rem; cursor: nwse-resize; }
.resize-handle.tr { top: -0.5rem; right: -0.5rem; cursor: nesw-resize; }
.resize-handle.bl { bottom: -0.5rem; left: -0.5rem; cursor: nesw-resize; }
.resize-handle.br { bottom: -0.5rem; right: -0.5rem; cursor: nwse-resize; }

.resize-handle.tc { top: -0.5rem; left: calc(50% - 0.75rem); cursor: ns-resize; width: 1.5rem; border-radius: 0.25rem; }
.resize-handle.bc { bottom: -0.5rem; left: calc(50% - 0.75rem); cursor: ns-resize; width: 1.5rem; border-radius: 0.25rem; }
.resize-handle.ml { top: calc(50% - 0.75rem); left: -0.5rem; cursor: ew-resize; height: 1.5rem; border-radius: 0.25rem; }
.resize-handle.mr { top: calc(50% - 0.75rem); right: -0.5rem; cursor: ew-resize; height: 1.5rem; border-radius: 0.25rem; }

.floorplan-table.draggable:active .resize-handle { display: none; }

/* ── Cash drawer bill badge (populated by JS) ─────────────── */
.bill-badge {
    display: inline-flex;
    align-items: center;
    background: rgb(38 38 38);
    color: rgb(229 229 229);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    border: 1px solid rgb(64 64 64);
    font-size: 0.875rem;
    font-weight: 500;
}

.empty-bills {
    color: rgb(115 115 115);
    font-size: 0.875rem;
    font-style: italic;
}

/* ── Checkout calc grid ────────────────────────────────────── */
.calc-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ── Image source tabs (product modal) ───────────────────── */
.image-source-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid rgb(229 229 229);
}

.dark .image-source-tabs { border-bottom-color: rgb(38 38 38); }

.image-source-tab {
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    color: rgb(115 115 115);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.image-source-tab.active {
    color: rgb(59 130 246);
    border-color: rgb(59 130 246);
}

/* ── Photo preview ────────────────────────────────────────── */
.photo-preview {
    margin-top: 0.5rem;
    width: 100%;
    max-height: 9.375rem;
    object-fit: contain;
    border-radius: 0.75rem;
}

/* ── Checkout chair row (populated by JS) ────────────────── */
.checkout-chair-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: rgb(23 23 23);
    border: 1px solid rgb(38 38 38);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.checkout-chair-row:hover { background: rgb(38 38 38); }

.checkout-chair-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: rgb(59 130 246);
    cursor: pointer;
}

/* ── Mobile Tab Navigation (≤ 767px only) ─────────────────────
   Tablet (768px+) and desktop keep the existing grid layout.
   ─────────────────────────────────────────────────────────── */
.mobile-tab-bar { display: none; }

@media (max-width: 767px) {

    /* ── Tab bar — sits between header and main, full width ── */
    .mobile-tab-bar {
        display: flex;
        gap: 8px;
        padding: 8px 12px;
        flex-shrink: 0;
        /* Match the header glass style */
        background: rgba(255, 255, 255, 0.6);
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .dark .mobile-tab-bar {
        background: rgba(0, 0, 0, 0.4);
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .mobile-tab-btn {
        flex: 1;
        padding: 7px 8px;
        border-radius: 12px;
        font-size: 0.8rem;
        font-weight: 600;
        text-align: center;
        cursor: pointer;
        transition: all 0.15s;
        /* Inactive — matches the "+ Table" ghost button style */
        background: rgba(255, 255, 255, 0.5);
        border: 1px solid rgba(0, 0, 0, 0.1);
        color: inherit;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    .dark .mobile-tab-btn {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.1);
    }

    /* Active — matches the "Floor Plan" button exactly */
    .mobile-tab-btn.active {
        background: rgba(37, 99, 235, 0.9);
        color: white;
        border-color: rgba(96, 165, 250, 0.2);
        box-shadow: 0 1px 3px rgba(59, 130, 246, 0.3);
    }

    /* ── pos-layout becomes a positioned shell ── */
    .pos-layout {
        display: block;
        position: relative;
        overflow: hidden;
        padding: 0;
        gap: 0;
    }

    /* All panels hidden; JS adds .mobile-active to show one */
    #tables-section,
    #menu-section,
    #order-panel {
        display: none;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* Active panel fills the entire pos-layout area */
    .mobile-active {
        display: flex !important;
        flex-direction: column;
        position: absolute !important;
        inset: 0;
        width: 100%;
        height: 100%;
    }

    /* Hide action buttons (+ Product, ⋮) on mobile */
    #menu-section > header > .flex:last-child { display: none !important; }

    /* Hide cash drawer on mobile */
    #cash-drawer-footer { display: none !important; }
}