/* =========================================================================
   Hybrid POS & Thermal Receipt Master Stylesheet
   Full Light Mode & Dark Mode Support
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700;800&display=swap');

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #10b981;
    --danger: #ef4444;
    --amber: #f59e0b;
    --purple: #8b5cf6;

    /* Light Theme (Default) */
    --bg-main: #f8fafc;
    --surface-main: rgba(255, 255, 255, 0.95);
    --surface-card: #ffffff;
    --surface-subtle: #f1f5f9;
    --border-color: #e2e8f0;
    --border-hover: rgba(37, 99, 235, 0.4);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --card-hover-shadow: 0 14px 25px -4px rgba(37, 99, 235, 0.15), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

.dark {
    /* Dark Theme */
    --bg-main: #090d16;
    --surface-main: rgba(15, 23, 42, 0.85);
    --surface-card: #131b2e;
    --surface-subtle: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(59, 130, 246, 0.45);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    --card-hover-shadow: 0 14px 28px -5px rgba(0, 0, 0, 0.6), 0 0 16px rgba(59, 130, 246, 0.25);
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    transition: background-color 0.25s ease, color 0.25s ease;
}

.font-mono-num {
    font-family: 'JetBrains Mono', monospace;
}

/* Glassmorphism Panels */
.glass-panel {
    background: var(--surface-main);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-color: var(--border-color);
}

/* Redesigned Premium Product Card */
.pos-product-card {
    background: var(--surface-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    border-radius: 1.25rem;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    min-height: 280px;
    box-sizing: border-box;
    cursor: pointer;
    user-select: none;
    position: relative;
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.pos-product-card:hover {
    transform: translateY(-3px);
    border-color: var(--border-hover);
    box-shadow: var(--card-hover-shadow);
}

/* Ensure product catalog grid aligns rows to start without stretching row heights */
#pos-product-grid {
    align-content: start !important;
}

/* Guaranteed Packshot Thumbnail Container */
.product-packshot {
    position: relative;
    width: 100%;
    height: 125px;
    min-height: 125px;
    border-radius: 1rem;
    overflow: hidden;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    padding: 0.4rem;
}

.product-packshot img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    transition: transform 0.35s ease;
}

.pos-product-card:hover .product-packshot img {
    transform: scale(1.08);
}

/* Active Payment Chip */
.payment-method-chip.active {
    background: #2563eb !important;
    color: #ffffff !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--surface-subtle);
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.7);
}

/* Image Dropzone & Preview Styles */
.image-dropzone {
    border: 2px dashed rgba(148, 163, 184, 0.4);
    transition: all 0.2s ease;
    cursor: pointer;
}
.image-dropzone:hover, .image-dropzone.dragover {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.05);
}

/* Admin Sidebar Active Navigation Pill */
.admin-nav-item.active {
    background: #2563eb !important;
    color: #ffffff !important;
    font-weight: 800 !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

/* =========================================================================
   THERMAL RECEIPT PRINT STYLESHEET (58mm & 80mm)
   ========================================================================= */

#thermal-receipt-area {
    display: none;
}

@media print {
    @page {
        size: auto;
        margin: 5mm auto;
    }

    /* Reset root */
    html, body {
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
        overflow: visible !important;
    }

    /* Completely hide all screen elements so they occupy 0 layout height */
    body > *:not(#thermal-receipt-area):not(#label-print-area) {
        display: none !important;
    }

    #thermal-receipt-area {
        display: block !important;
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    /* Core Page-Break Rule: Each receipt copy prints on its own separate page */
    .receipt-copy {
        display: block !important;
        position: relative !important;
        box-sizing: border-box !important;
        margin: 0 auto !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        page-break-after: always !important;
        break-after: page !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    /* The last copy must not force an extra blank trailing sheet */
    .receipt-copy:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
        margin-bottom: 0 !important;
    }

    .receipt-80mm {
        width: 78mm !important;
        max-width: 78mm !important;
        font-family: 'JetBrains Mono', 'Courier New', monospace !important;
        font-size: 11px !important;
        line-height: 1.35 !important;
        color: #000000 !important;
        background: #ffffff !important;
        padding: 4mm 2mm !important;
    }

    .receipt-58mm {
        width: 52mm !important;
        max-width: 52mm !important;
        font-family: 'JetBrains Mono', 'Courier New', monospace !important;
        font-size: 9.5px !important;
        line-height: 1.25 !important;
        color: #000000 !important;
        background: #ffffff !important;
        padding: 3mm 1mm !important;
    }

    .thermal-divider {
        border-top: 1px dashed #000000 !important;
        margin: 5px 0 !important;
    }

    .thermal-double-divider {
        border-top: 2px solid #000000 !important;
        margin: 5px 0 !important;
    }

    /* ── Retail Barcode & Shelf-Edge Labels Print Formats ──────────── */
    #label-print-area {
        display: block !important;
        position: static !important;
        background: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 1. Thermal Sticker Roll (50mm x 30mm) */
    .print-thermal-sticker {
        width: 50mm !important;
        margin: 0 auto !important;
    }
    .print-thermal-sticker .thermal-sticker-card {
        width: 48mm !important;
        height: 28mm !important;
        page-break-after: always !important;
        break-after: page !important;
        margin: 1mm auto !important;
        box-sizing: border-box !important;
        border: none !important;
    }

    /* 2. Shelf-Edge Talker (80mm x 45mm) */
    .print-shelf-talker {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4mm !important;
        padding: 4mm !important;
        justify-content: flex-start !important;
    }
    .print-shelf-talker .shelf-talker-card {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        margin-bottom: 3mm !important;
        border: 1px dashed #666666 !important;
    }

    /* 3. A4 Sheet Labels (3 cols x 8 rows = 24 labels / page) */
    .print-a4-sheet {
        display: grid !important;
        grid-template-columns: repeat(3, 68mm) !important;
        grid-auto-rows: 35mm !important;
        column-gap: 2.5mm !important;
        row-gap: 0mm !important;
        padding: 10mm 4mm !important;
        box-sizing: border-box !important;
    }
    .print-a4-sheet .a4-sticker-card {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        box-sizing: border-box !important;
        border: 1px dotted #cccccc !important;
    }
}

/* ── Screen & Preview Styles for Barcode & Shelf Label Studio ─── */
#label-print-area {
    display: none;
}

.shelf-talker-card {
    width: 80mm;
    min-height: 44mm;
    background: #ffffff;
    color: #111827;
    border: 2px solid #1e293b;
    border-radius: 6px;
    padding: 3mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: system-ui, -apple-system, sans-serif;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.talker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1.5px solid #1e293b;
    padding-bottom: 1.5mm;
    margin-bottom: 1.5mm;
}
.talker-store {
    font-size: 8px;
    font-weight: 900;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #475569;
}
.talker-cat {
    font-size: 7.5px;
    font-weight: bold;
    color: #64748b;
    text-transform: uppercase;
}
.talker-title {
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    color: #0f172a;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 2mm;
}
.talker-body {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 2mm;
}
.talker-price-box {
    display: flex;
    align-items: baseline;
    gap: 1px;
}
.talker-currency {
    font-size: 13px;
    font-weight: 900;
    color: #0f172a;
}
.talker-price {
    font-size: 20px;
    font-weight: 900;
    letter-spacing: -0.5px;
    font-family: 'JetBrains Mono', monospace;
    color: #0f172a;
}
.talker-unit {
    font-size: 8.5px;
    font-weight: 600;
    color: #64748b;
    margin-left: 2px;
}
.talker-barcode-box {
    width: 38mm;
    text-align: right;
}
.label-expiry {
    font-size: 7.5px;
    font-weight: bold;
    color: #b91c1c;
    margin-top: 1mm;
    font-family: monospace;
}

/* Compact Thermal Sticker (50mm x 30mm) */
.thermal-sticker-card {
    width: 50mm;
    height: 30mm;
    background: #ffffff;
    color: #111827;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 2mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: center;
    font-family: system-ui, -apple-system, sans-serif;
}
.sticker-store {
    font-size: 7px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}
.sticker-name {
    font-size: 9px;
    font-weight: 800;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #0f172a;
}
.sticker-price {
    font-size: 11px;
    font-weight: 900;
    color: #0f172a;
    font-family: 'JetBrains Mono', monospace;
}
.sticker-unit {
    font-size: 8px;
    font-weight: normal;
    color: #64748b;
}
.sticker-barcode {
    width: 100%;
}

/* A4 Sheet Card */
.a4-sticker-card {
    width: 68mm;
    height: 35mm;
    background: #ffffff;
    color: #111827;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 2.5mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: system-ui, -apple-system, sans-serif;
}
.a4-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.a4-store {
    font-size: 7.5px;
    font-weight: 800;
    text-transform: uppercase;
    color: #64748b;
}
.a4-price {
    font-size: 11px;
    font-weight: 900;
    color: #0f172a;
    font-family: 'JetBrains Mono', monospace;
}
.a4-name {
    font-size: 9.5px;
    font-weight: 800;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #0f172a;
}
.a4-barcode {
    width: 100%;
}

/* =========================================================================
   NAVIGATION BAR FLEX & WRAPPER INTEGRITY GUARANTEES
   ========================================================================= */
#view-switcher-pills:not(.hidden),
#staff-nav-controls:not(.hidden),
#public-nav-controls:not(.hidden),
#staff-user-badge:not(.hidden) {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
}

/* =========================================================================
   MOBILE RESPONSIVENESS & TOUCH LAYOUT OPTIMIZATIONS (< 768px)
   ========================================================================= */
@media (max-width: 767px) {
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        position: relative;
    }

    /* POS Catalog & Cart Panes on Mobile */
    #pos-catalog-pane:not(.hidden),
    #pos-cart-pane:not(.hidden) {
        width: 100% !important;
        flex: 1 1 100% !important;
    }

    /* Product Grid Card sizing on small mobile */
    .pos-product-card {
        min-height: 260px !important;
        padding: 0.65rem !important;
        border-radius: 1rem !important;
        overflow: hidden !important;
    }

    .product-packshot {
        height: 110px !important;
        min-height: 110px !important;
        margin-bottom: 0.4rem !important;
        padding: 0.25rem !important;
        border-radius: 0.75rem !important;
    }

    /* Touch target optimizations */
    button, input, select {
        touch-action: manipulation;
    }

    /* Admin Sidebar on Mobile becomes horizontal swipeable chip tabs */
    #view-admin aside {
        width: 100% !important;
        padding: 0.5rem 0.6rem !important;
        border-radius: 1rem !important;
    }

    #view-admin aside nav {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        gap: 0.4rem !important;
        padding-bottom: 0.25rem !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #view-admin aside nav::-webkit-scrollbar {
        display: none;
    }

    #view-admin aside nav .admin-nav-item {
        width: auto !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        padding: 0.45rem 0.75rem !important;
        font-size: 11px !important;
        border-radius: 0.75rem !important;
    }

    /* Hide redundant desktop admin card & back button in mobile header */
    #view-admin aside .admin-header-card,
    #view-admin aside .admin-back-btn {
        display: none !important;
    }

    /* Horizontal scroll for wide tables */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Modals fit mobile screens gracefully */
    .modal-content, [id^="modal-"] > div:not(.absolute), [id$="-modal"] > div:not(.absolute) {
        max-height: 92vh !important;
        margin: 0.5rem !important;
        width: calc(100% - 1rem) !important;
        overflow-y: auto !important;
    }
}

@media (max-width: 1023px) {
    /* Hide desktop-only PC installation prompt on mobile and tablet headers */
    #btn-install-pwa {
        display: none !important;
    }
}

@media (min-width: 768px) {
    /* Always show both POS panes side-by-side on desktop/laptop */
    #pos-catalog-pane {
        display: flex !important;
    }
    #pos-cart-pane {
        display: flex !important;
    }
    #mobile-bottom-nav,
    #mobile-floating-cart-bar {
        display: none !important;
    }
}

@media (max-width: 767px) {
    /* Mobile Slide-Up Bottom Sheet for Fractional Portions */
    #fraction-modal.flex {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    #fraction-modal.flex > div {
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
        border-top-left-radius: 1.5rem !important;
        border-top-right-radius: 1.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 85vh !important;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45) !important;
        animation: slideUpSheet 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    @keyframes slideUpSheet {
        from {
            transform: translateY(100%);
            opacity: 0.5;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* =========================================================================
   Smartphone Camera Barcode Scanner
   ========================================================================= */
#pos-camera-reader {
    width: 100% !important;
    height: 100% !important;
    min-height: 280px;
    background: #000;
}
#pos-camera-reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 0 !important;
}
#pos-camera-reader canvas {
    display: none !important;
}
#pos-camera-reader img[alt="Info icon"] {
    display: none !important;
}
#pos-camera-reader select {
    background: #1e293b !important;
    color: #f8fafc !important;
    border: 1px solid #334155 !important;
    border-radius: 0.5rem !important;
    padding: 0.35rem 0.5rem !important;
    font-size: 0.75rem !important;
}

@keyframes scannerLaserAnim {
    0% { top: 8%; opacity: 0.7; }
    50% { top: 86%; opacity: 1; }
    100% { top: 8%; opacity: 0.7; }
}
.scanner-laser {
    position: absolute;
    left: 6%;
    right: 6%;
    height: 3px;
    background: linear-gradient(90deg, rgba(239, 68, 68, 0) 0%, #ef4444 50%, rgba(239, 68, 68, 0) 100%);
    box-shadow: 0 0 10px #ef4444, 0 0 4px #f87171;
    border-radius: 9999px;
    animation: scannerLaserAnim 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    pointer-events: none;
    z-index: 20;
}
.scanner-laser.success {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0) 0%, #10b981 50%, rgba(16, 185, 129, 0) 100%);
    box-shadow: 0 0 16px #10b981, 0 0 6px #34d399;
}



