:root {
    --primary: #E41F35;
    --primary-light: #FDE8EA;
    --bg: #ffffff;
    --text: #000000;
    --subtext: #718096;
    --border: #edf2f7;
    --success: #00b894;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Inter', -apple-system, sans-serif; margin: 0; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; display: flex; }

/* Layout */
#app-section { display: flex; width: 100%; height: 100vh; }

/* Modern Slim-Expansion Sidebar */
.sidebar {
    width: 70px;
    background: white;
    border-right: 1px solid var(--border);
    padding: 15px 0;
    display: flex;
    flex-direction: column;
    z-index: 2000;
    flex-shrink: 0;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    white-space: nowrap;
    position: relative;
}

.sidebar:hover {
    width: 200px;
    box-shadow: 15px 0 40px rgba(0,0,0,0.08);
}

.sidebar h2 {
    padding-left: 24px;
    font-size: 18px;
    margin-bottom: 30px;
    opacity: 0;
    transition: opacity 0.2s;
}
.sidebar:hover h2 { opacity: 1; }

.nav-item {
    padding: 12px 24px;
    margin: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 15px;
    color: #64748b; /* Subtle Slate Gray */
    font-weight: 600;
    font-size: 14px;
    width: calc(100% - 16px);
}

.nav-item svg {
    min-width: 20px;
    height: 20px;
    stroke: #94a3b8; /* Silent Stroke */
    transition: all 0.2s ease;
}

.nav-item:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item:hover svg {
    stroke: var(--primary);
    transform: scale(1.1);
}

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(228, 31, 53, 0.2);
}

.nav-item.active svg {
    stroke: white;
}

/* Hide text when collapsed */
.nav-item-text {
    opacity: 0;
    transition: opacity 0.2s;
}
.sidebar:hover .nav-item-text { opacity: 1; }

.main { flex: 1; padding: 25px; overflow-y: auto; position: relative; background: #f8fafc; }

/* Tabs Visibility */
.tab-content { display: none; width: 100%; margin-bottom: 50px; }
.tab-content.active { display: block; }

/* Cards & Stats */
.card { background: white; padding: 20px; border-radius: 15px; border: 1px solid var(--border); margin-bottom: 20px; transition: 0.3s; }
.stat-box { background: var(--primary-light); padding: 15px; border-radius: 15px; text-align: left; border: 1px solid #f9d6d9; }
.stat-box h3 { color: var(--primary); font-size: 10px; text-transform: uppercase; margin-top: 0; margin-bottom: 6px; letter-spacing: 0.5px; }
.stat-box p { font-size: 19px; font-weight: 900; margin: 0; }

/* Tables */
.table-container { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: white; }
th { text-align: left; padding: 12px; color: var(--subtext); font-size: 10px; text-transform: uppercase; border-bottom: 2px solid var(--border); background: #f8fafc; }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; }

/* Forms */
.input-group label { font-size: 11px; color: var(--subtext); font-weight: 600; display: block; margin-bottom: 4px; }
input, select, button, textarea { padding: 9px 12px; margin: 4px 0; border-radius: 10px; border: 1px solid var(--border); width: 100%; font-size: 13.5px; outline: none; transition: 0.2s; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(228, 31, 53, 0.1); }
button { background: var(--primary); color: white; border: none; font-weight: 700; cursor: pointer; height: 40px; display: flex; align-items: center; justify-content: center; gap: 8px; }
button:hover { opacity: 0.9; }
button.secondary { background: var(--primary-light); color: var(--primary); border: 1px solid #f9d6d9; }

/* Hide Spinners for clean POS inputs */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* Unified POS Terminal V5 */
.pos-terminal-v5 { display: flex; gap: 0; height: calc(100vh - 80px); margin: -25px -40px; background: #f8fafc; overflow: hidden; }
.pos-left-v5 { flex: 1.4; padding: 20px; overflow-y: auto; background: white; border-right: 2px solid var(--border); }
.pos-right-v5 { flex: 1; padding: 20px; display: flex; flex-direction: column; background: #fff; box-shadow: -10px 0 30px rgba(0,0,0,0.02); }

/* Category Bar */
.category-bar-v5 { display: flex; gap: 10px; overflow-x: auto; padding: 5px 0 15px; scrollbar-width: none; }
.category-bar-v5::-webkit-scrollbar { display: none; }
.cat-pill-v5 { padding: 8px 18px; background: white; border: 1px solid var(--border); border-radius: 50px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: 0.2s; }
.cat-pill-v5.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Receipt Styling */
.digital-receipt-v5 { flex: 1; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; margin: 15px 0; background: white; }
.receipt-row-v5 { padding: 12px; border-bottom: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; animation: slideIn 0.3s ease-out; }
.receipt-row-v5.new-item { border-left: 4px solid var(--primary); background: var(--primary-light); animation: pulseHighlight 1s ease-out; }

@keyframes pulseHighlight {
    0% { background: var(--primary-light); }
    50% { background: #fee2e2; }
    100% { background: white; }
}

@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Quick Inputs */
.pos-input-v5 { height: 48px; border-radius: 10px; border: 1px solid var(--border); background: #f8fafc; padding: 0 15px; font-size: 14px; font-weight: 600; transition: 0.2s; }
.pos-input-v5:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 4px rgba(228,31,53,0.1); }

.quick-qty-v5 { display: flex; gap: 4px; margin-top: 8px; justify-content: center; }
.qty-btn-v5 { padding: 4px 6px; font-size: 10px; background: #f1f5f9; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-weight: 700; color: #475569; }
.qty-btn-v5:hover { background: var(--primary-light); color: var(--primary); }

.qty-adj-btn {
    width: 24px;
    height: 24px;
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.qty-adj-btn:hover { background: #f9d6d9; }

.pos-btn-v5 { height: 56px; border-radius: 14px; font-size: 18px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 12px; transition: 0.2s; }
.pos-btn-v5:active { transform: scale(0.98); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 100000; padding: 20px; }
.modal-content { 
    background: white; 
    padding: 0; 
    border-radius: 15px; 
    width: 420px; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 90vh;
}
.modal-header {
    background: linear-gradient(135deg, var(--primary) 0%, #d41a2e 100%);
    color: white;
    padding: 16px 20px;
    font-weight: 600;
    font-size: 16px;
    cursor: move;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: 0.2s;
}
.modal-header:hover {
    background: linear-gradient(135deg, #d41a2e 0%, #b01424 100%);
}
.modal-header:active {
    cursor: grabbing;
}
.modal-body {
    padding: 25px;
    flex: 1;
    overflow-y: auto;
}
.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    background: #f8fafc;
    flex-wrap: wrap;
}
.modal-footer button { width: auto; padding: 0 20px; }

/* Badge Styles */
.badge { padding: 4px 8px; border-radius: 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.badge-paid { background: #e6f7f2; color: var(--success); }
.badge-credit { background: #fff1f1; color: var(--primary); }

/* Mapping Modal Improvements */
#mapping-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px 20px;
}
.mapping-row {
    display: flex;
    flex-direction: column;
}
#mapping-body label {
    font-size: 11px;
    color: var(--subtext);
    font-weight: 700;
    display: block;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
#mapping-body select {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    width: 100%;
    font-size: 13px;
    outline: none;
    transition: 0.2s;
    background: white;
    margin-bottom: 0;
}
#mapping-body select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(228, 31, 53, 0.1);
}

.loader { width: 20px; height: 20px; border: 2px solid var(--primary-light); border-top: 2px solid var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 15px auto; display: none; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- THERMAL RECEIPT STYLES --- */
#thermal-receipt { display: none; background: white; }

.receipt-container {
    width: 72mm;
    margin: 0 auto;
    padding: 4mm;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.2;
    color: black;
    background: white;
}

.receipt-header { text-align: center; margin-bottom: 8px; }
.receipt-header h1 { font-size: 20px; margin: 0; font-weight: bold; }
.receipt-divider { border-top: 1px dashed black; margin: 8px 0; }
.receipt-details div { display: flex; justify-content: space-between; margin-bottom: 2px; font-size: 12px; }
.receipt-item-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 3px 0; }
.receipt-item-row.header { font-weight: bold; font-size: 11px; letter-spacing: 0.5px; }
.qty-c { width: 50px; flex-shrink: 0; text-align: left; }
.name-c { flex: 1; padding: 0 5px; word-wrap: break-word; white-space: normal; }
.amt-c { width: 85px; text-align: right; flex-shrink: 0; font-weight: bold; }
.receipt-items-list { margin: 5px 0; }
.receipt-totals div { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 13px; }
.receipt-grand-total { font-weight: bold; font-size: 16px; margin-top: 5px; padding-top: 5px; border-top: 1px solid black; }
.receipt-footer { text-align: center; margin-top: 15px; padding-top: 10px; border-top: 1px dashed black; }

/* Consolidated Print Media Query */
@media print {
    /* Hide everything EXCEPT the thermal receipt container */
    body > *:not(#thermal-receipt) {
        display: none !important;
    }

    #app-section, .sidebar, .main, .mobile-header, .modal, #onboarding-section, #auth-section, #premium-lock, #debug-console {
        display: none !important;
    }

    #thermal-receipt {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #thermal-receipt * {
        visibility: visible !important;
    }

    @page { size: 80mm auto; margin: 0; }
}

/* Onboarding Styles */
#onboarding-section {
    background: #f1f5f9;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 20px;
    width: 100%;
    overflow-y: auto;
}

.onboarding-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 400px;
    margin: 15px 0;
}

@media (min-width: 768px) {
    .onboarding-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        max-width: 900px;
        gap: 12px;
    }
}

.store-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100px;
}

.store-card:hover { border-color: var(--primary); background: #fffcfc; }
.store-card.selected { border: 2px solid var(--primary); background: var(--primary-light); box-shadow: 0 4px 15px rgba(228, 31, 53, 0.1); }
.store-card .icon { font-size: 32px; margin-bottom: 8px; line-height: 1; }
.store-card .label { font-weight: 700; color: #475569; font-size: 13px; line-height: 1.2; }
.store-card.selected .label { color: var(--primary); }

.onboarding-container { background: white; padding: 30px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); width: 100%; max-width: 450px; margin-top: 20px; }
.onboarding-header { text-align: center; max-width: 500px; margin-bottom: 20px; }
.onboarding-header h1 { font-size: 28px; color: #1e293b; margin-bottom: 8px; font-weight: 800; }
.onboarding-header p { color: #64748b; font-size: 14px; line-height: 1.5; }

/* Premium Lock Overlay */
#premium-lock {
    position: fixed;
    inset: 0;
    background: #f1f5f9;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
#premium-lock .card { border: none; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.2); width: 100%; max-width: 500px; }

/* Mobile Compatibility */
.mobile-header { display: none; width: 100%; height: 60px; background: white; border-bottom: 1px solid var(--border); align-items: center; padding: 0 20px; position: fixed; top: 0; left: 0; z-index: 1000; }
.menu-toggle { font-size: 24px; cursor: pointer; background: none; border: none; padding: 10px; color: var(--text); width: auto; height: auto; display: block; }

/* Branded Grids */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }

@media (min-width: 1600px) {
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

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

/* Auth Section & Error Styling */
.auth-error-box {
    display: none;
    padding: 12px;
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 10px;
    margin-top: 15px;
    font-size: 13px;
    color: #c53030;
    text-align: left;
    line-height: 1.4;
}

.auth-error-box.show { display: block; animation: shake 0.4s ease-in-out; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    50% { transform: translateX(6px); }
    75% { transform: translateX(-6px); }
}

/* Responsive Overrides */
@media (max-width: 768px) {
    body { flex-direction: column; overflow: auto; height: auto; min-height: 100vh; }
    #app-section { flex-direction: column; height: auto; min-height: 100vh; }

    .mobile-header { display: flex; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        height: calc(100vh - 60px);
        width: 260px !important;
        transform: translateX(-100%);
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
        transition: transform 0.3s ease;
        z-index: 5000;
        background: white;
        overflow: visible;
        white-space: normal;
    }
    .sidebar.show { transform: translateX(0); }
    .sidebar h2, .nav-item-text { opacity: 1 !important; }

    .main { padding: 80px 15px 40px; width: 100%; overflow-x: hidden; flex: none; height: auto; }

    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; gap: 10px; }

    /* POS Terminal Mobile (Stacked) */
    .pos-terminal-v5 { flex-direction: column; height: auto; overflow: visible; margin: -15px; }
    .pos-left-v5 { border-right: none; border-bottom: 2px solid var(--border); padding: 15px; }
    .pos-right-v5 { width: 100% !important; min-width: 0 !important; padding: 15px; box-shadow: none; border-left: none; }

    .pos-grid { grid-template-columns: 1fr 1fr; gap: 8px; }

    .pos-item-card {
        min-height: 270px !important;
        padding: 10px !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .qty-btn-v5 { font-size: 8px !important; height: 22px !important; padding: 0 2px !important; }
    .quick-qty-grid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 4px !important; margin-top: 5px !important; }
    .pos-btn-v5-inner { height: 36px !important; font-size: 10px !important; }

    .card { padding: 15px; }
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); margin-bottom: 10px; }
    table { min-width: 600px; }

    .modal-content { width: 95% !important; max-width: 100%; }
    #dashboard-extra { grid-template-columns: 1fr !important; }
}
