/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --header-h: 58px;
    --header-bg: #0f172a;
    --header-border: #1e293b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --cart-w: 390px;
    --radius: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow: 0 4px 12px rgba(0,0,0,.10);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.15);
}

html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ===== LOGIN PAGE ===== */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #0f172a 100%);
    overflow: auto;
}

.login-wrap { width: 100%; max-width: 400px; padding: 20px; }

.login-card {
    background: white;
    border-radius: 18px;
    padding: 42px 36px;
    box-shadow: 0 28px 80px rgba(0,0,0,.4);
}

.login-logo { text-align: center; margin-bottom: 34px; }

.logo-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: white;
    border-radius: 18px;
    font-size: 22px; font-weight: 800;
    margin-bottom: 14px;
    letter-spacing: 1px;
    box-shadow: 0 8px 24px rgba(37,99,235,.35);
}

.login-logo h1 { font-size: 22px; font-weight: 800; color: #0f172a; margin-bottom: 4px; }
.login-logo p { color: var(--text-muted); font-size: 13px; font-weight: 500; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.field input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #d1d5db;
    border-radius: 9px;
    font-size: 14px; outline: none;
    font-family: inherit;
    transition: border-color .2s, box-shadow .2s;
    color: var(--text);
}
.field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.alert { padding: 11px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; margin-bottom: 14px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px;
    border: none; border-radius: 9px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all .2s; font-family: inherit;
    white-space: nowrap; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37,99,235,.3); }

.btn-secondary { background: #f1f5f9; color: #475569; border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

.btn-outline-white { background: transparent; color: rgba(255,255,255,.9); border: 1.5px solid rgba(255,255,255,.3); }
.btn-outline-white:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.55); }

.btn-full { width: 100%; padding: 14px; font-size: 15px; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 7px; }
.btn-icon { width: 16px; height: 16px; flex-shrink: 0; }

.btn-checkout {
    width: 100%; padding: 16px;
    font-size: 15px; font-weight: 700;
    background: linear-gradient(135deg, #059669, #047857);
    color: white; border-radius: 11px; margin-bottom: 8px;
    letter-spacing: .3px;
}
.btn-checkout:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(5,150,105,.3); }

.btn-clear {
    width: 100%; padding: 10px;
    background: white; color: #dc2626;
    border: 1.5px solid #fecaca; border-radius: 9px;
    font-size: 13px; font-weight: 600;
}
.btn-clear:hover { background: #fef2f2; }

/* ===== POS LAYOUT ===== */
body.pos-page { overflow: hidden; height: 100vh; display: flex; flex-direction: column; }

.pos-header {
    height: var(--header-h);
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    display: flex; align-items: center;
    padding: 0 18px; gap: 14px;
    flex-shrink: 0; z-index: 100;
}

.header-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.brand-badge {
    background: var(--primary);
    color: white; font-size: 12px; font-weight: 800;
    padding: 4px 10px; border-radius: 7px; letter-spacing: .5px;
}

.brand-name { color: white; font-size: 15px; font-weight: 700; }

.header-center { flex: 1; max-width: 560px; margin: 0 auto; }

.scan-wrap {
    display: flex; align-items: center;
    background: rgba(255,255,255,.07);
    border: 1.5px solid rgba(255,255,255,.13);
    border-radius: 10px; padding: 0 12px; gap: 8px;
    transition: border-color .2s, background .2s;
}
.scan-wrap:focus-within {
    border-color: rgba(255,255,255,.45);
    background: rgba(255,255,255,.11);
}

.scan-icon { width: 16px; height: 16px; color: rgba(255,255,255,.45); flex-shrink: 0; }

.scan-input {
    flex: 1; background: transparent; border: none; outline: none;
    color: white; font-size: 13.5px; font-family: inherit; padding: 10px 0;
}
.scan-input::placeholder { color: rgba(255,255,255,.3); }

.scan-clear {
    background: none; border: none; color: rgba(255,255,255,.35); cursor: pointer;
    font-size: 15px; padding: 0 2px; line-height: 1; transition: color .15s;
}
.scan-clear:hover { color: rgba(255,255,255,.8); }

.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.clock { color: rgba(255,255,255,.5); font-size: 12px; font-variant-numeric: tabular-nums; letter-spacing: .5px; }

.user-chip {
    background: rgba(255,255,255,.1); color: rgba(255,255,255,.85);
    padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
    border: 1px solid rgba(255,255,255,.12);
}

/* ===== POS BODY ===== */
.pos-body { flex: 1; display: flex; overflow: hidden; min-height: 0; }

/* ===== PRODUCTS PANEL ===== */
.products-panel {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden; background: var(--bg); min-width: 0;
}

.category-bar {
    display: flex; gap: 8px; padding: 10px 14px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
}
.category-bar::-webkit-scrollbar { display: none; }

.cat-tab {
    padding: 6px 16px; border-radius: 20px;
    border: 1.5px solid var(--border);
    background: transparent; color: var(--text-muted);
    font-size: 12px; font-weight: 600; cursor: pointer;
    transition: all .15s; white-space: nowrap; font-family: inherit;
}
.cat-tab:hover { border-color: var(--primary); color: var(--primary); }
.cat-tab.active { background: var(--primary); border-color: var(--primary); color: white; }

.products-area { flex: 1; overflow-y: auto; padding: 14px; min-height: 0; }

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 12px;
}

.product-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 12px; cursor: pointer;
    transition: border-color .15s, box-shadow .15s, transform .1s;
    display: flex; flex-direction: column;
    user-select: none; -webkit-tap-highlight-color: transparent;
}
.product-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(37,99,235,.13);
    transform: translateY(-2px);
}
.product-card:active { transform: scale(.97); }

.product-img-wrap {
    width: 100%; height: 76px; background: var(--bg);
    border-radius: 7px; margin-bottom: 10px;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; flex-shrink: 0;
}
.product-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-img-placeholder {
    color: var(--text-light); font-size: 22px; font-weight: 800;
    font-family: 'Courier New', monospace; letter-spacing: 1px;
}

.product-card-name {
    font-size: 12px; font-weight: 600; color: var(--text);
    line-height: 1.35; margin-bottom: 5px; flex: 1;
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.product-card-sku { font-size: 10px; color: var(--text-light); margin-bottom: 8px; font-family: monospace; }
.product-card-price { font-size: 15px; font-weight: 800; color: var(--success); }

/* ===== CART PANEL ===== */
.cart-panel {
    width: var(--cart-w); flex-shrink: 0;
    background: var(--surface); border-left: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
}

.cart-header {
    padding: 13px 16px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0; font-weight: 700; font-size: 14px; color: var(--text);
}

.cart-badge {
    background: var(--primary); color: white;
    font-size: 11px; font-weight: 600;
    padding: 2px 10px; border-radius: 12px;
}

.cart-items { flex: 1; overflow-y: auto; min-height: 0; }

.cart-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 20px; text-align: center; color: var(--text-muted);
    height: 100%; gap: 10px;
}
.cart-empty svg { width: 44px; height: 44px; color: var(--text-light); }
.cart-empty p { font-weight: 600; font-size: 14px; }
.cart-empty span { font-size: 12px; color: var(--text-light); }

.cart-item {
    padding: 10px 14px; border-bottom: 1px solid #f1f5f9;
    display: flex; flex-direction: column; gap: 7px;
}
.cart-item:last-child { border-bottom: none; }

.cart-item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cart-item-name { font-size: 12.5px; font-weight: 600; color: var(--text); flex: 1; line-height: 1.3; }
.cart-item-remove {
    background: none; border: none; cursor: pointer;
    color: var(--text-light); font-size: 18px; line-height: 1;
    padding: 0 2px; border-radius: 4px; transition: color .15s; flex-shrink: 0;
}
.cart-item-remove:hover { color: var(--danger); }

.cart-item-meta { font-size: 10px; color: var(--text-light); font-family: monospace; }

.cart-item-bottom { display: flex; align-items: center; justify-content: space-between; }

.qty-control { display: flex; align-items: center; gap: 6px; }
.qty-btn {
    width: 28px; height: 28px; background: var(--bg);
    border: 1.5px solid var(--border); border-radius: 7px;
    cursor: pointer; font-size: 17px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    color: var(--text); transition: all .15s; font-family: inherit;
    line-height: 1; -webkit-tap-highlight-color: transparent;
}
.qty-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

.qty-val { min-width: 28px; text-align: center; font-size: 13px; font-weight: 700; color: var(--text); }

.cart-item-price { font-size: 13px; font-weight: 700; color: var(--text); }

/* ===== CART FOOTER ===== */
.cart-footer {
    border-top: 1px solid var(--border);
    padding: 12px 14px; flex-shrink: 0;
    display: flex; flex-direction: column; gap: 10px;
    overflow-y: auto; max-height: 55vh;
}

.discount-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.discount-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.discount-input {
    width: 90px; padding: 7px 10px;
    border: 1.5px solid var(--border); border-radius: 7px;
    font-size: 13px; text-align: right; font-family: inherit; outline: none;
    transition: border-color .2s;
}
.discount-input:focus { border-color: var(--primary); }

.totals { background: #f8fafc; border-radius: 9px; padding: 11px 13px; }
.total-row {
    display: flex; justify-content: space-between;
    font-size: 13px; color: var(--text-muted); margin-bottom: 6px;
}
.total-row:last-child { margin-bottom: 0; }
.total-final {
    border-top: 1px solid var(--border); padding-top: 9px; margin-top: 3px;
    font-size: 20px; font-weight: 800; color: var(--text);
}
.discount-amount { color: var(--danger); font-weight: 700; }

.checkout-fields { display: flex; flex-direction: column; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 500; cursor: pointer; color: var(--text-muted); }
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--primary); }

#customerFields { display: flex; flex-direction: column; gap: 8px; }

.field-input {
    width: 100%; padding: 9px 12px;
    border: 1.5px solid var(--border); border-radius: 8px;
    font-size: 13px; font-family: inherit; outline: none;
    transition: border-color .2s; background: var(--surface); color: var(--text);
}
.field-input:focus { border-color: var(--primary); }

.checkout-actions { display: flex; flex-direction: column; gap: 7px; }

/* ===== LOADING / EMPTY STATES ===== */
.loading-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 80px 20px; gap: 16px; color: var(--text-muted);
}
.empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 80px 20px; gap: 12px; text-align: center;
}
.empty-state svg { width: 48px; height: 48px; color: var(--text-light); }
.empty-state p { font-size: 16px; font-weight: 600; color: var(--text-muted); }
.empty-state span { font-size: 13px; color: var(--text-light); }

.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner-large {
    width: 46px; height: 46px;
    border: 4px solid rgba(255,255,255,.2); border-top-color: white;
    border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 200; padding: 20px;
}
.modal-box {
    background: white; border-radius: 16px;
    max-height: 92vh; overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0,0,0,.4);
    animation: modalIn .22s ease; width: 100%;
}
@keyframes modalIn { from { transform: scale(.95) translateY(8px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.receipt-modal { max-width: 430px; }

.modal-actions {
    display: flex; gap: 10px;
    padding: 14px 20px; border-top: 1px solid var(--border);
    position: sticky; bottom: 0; background: white;
}
.modal-actions .btn { flex: 1; }

/* ===== RECEIPT ===== */
.receipt-print-area { padding: 20px; }

.receipt {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px; line-height: 1.75;
    border: 1px dashed #bbb; padding: 20px;
    border-radius: 8px; background: #fff;
    max-width: 380px; margin: 0 auto;
}
.receipt-shop-name { font-size: 19px; font-weight: 700; text-align: center; }
.receipt-tagline { text-align: center; color: #777; font-size: 11px; }
.receipt-divider { border: none; border-top: 1px dashed #bbb; margin: 10px 0; }
.receipt-kv { display: flex; justify-content: space-between; gap: 8px; }
.receipt-kv .k { color: #666; }
.receipt-item { margin-bottom: 3px; }
.receipt-item-name { font-weight: 600; }
.receipt-item-detail { color: #888; font-size: 11px; padding-left: 8px; }
.receipt-item-line { display: flex; justify-content: space-between; }
.receipt-total { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; margin-top: 4px; }
.receipt-footer { text-align: center; color: #888; font-size: 11px; margin-top: 6px; line-height: 1.6; }
.receipt-order-badge {
    text-align: center; margin-bottom: 10px;
    font-size: 13px; font-weight: 700; color: #059669;
    background: #f0fdf4; padding: 6px 12px; border-radius: 6px;
    border: 1px solid #bbf7d0;
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center; z-index: 300;
}
.loading-box {
    background: #1a1f36; border-radius: 16px; padding: 32px 44px;
    text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.loading-box p { font-size: 14px; color: rgba(255,255,255,.65); }

/* ===== TOAST NOTIFICATIONS ===== */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: #1e293b; color: white;
    padding: 12px 20px; border-radius: 10px;
    font-size: 13px; font-weight: 500;
    box-shadow: var(--shadow-lg); z-index: 400;
    animation: toastIn .3s ease; max-width: 340px;
    pointer-events: none;
}
.toast.success { background: #064e3b; border-left: 4px solid var(--success); }
.toast.error { background: #7f1d1d; border-left: 4px solid var(--danger); }
@keyframes toastIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== PRINT STYLES ===== */
@media print {
    body > *:not(.modal-overlay) { display: none !important; }
    .modal-overlay { position: static !important; background: none !important; padding: 0 !important; }
    .modal-box { box-shadow: none !important; border-radius: 0 !important; max-height: none !important; }
    .no-print, .modal-actions { display: none !important; }
    .receipt-print-area { padding: 0 !important; }
    .receipt { border: none !important; padding: 0 !important; max-width: 80mm !important; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 960px) {
    :root { --cart-w: 330px; }
    .brand-name { display: none; }
    .header-center { max-width: none; }
    .clock { display: none; }
    .products-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

@media (max-width: 640px) {
    :root { --cart-w: 100%; }
    body.pos-page { overflow-y: auto; height: auto; }
    .pos-body { flex-direction: column; overflow: visible; }
    .products-panel { height: auto; }
    .products-area { max-height: 52vh; }
    .cart-panel { border-left: none; border-top: 2px solid var(--border); }
    .cart-items { max-height: 220px; }
    .cart-footer { max-height: none; }
    .pos-header { padding: 0 12px; gap: 8px; }
    .user-chip { display: none; }
    .header-right { gap: 8px; }
    .products-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
    .product-img-wrap { height: 60px; }
}
