:root {
    --primary: #7B1818;
    --primary-dark: #5a1212;
    --primary-light: #a02020;
    --secondary: #1a1a1a;
    --bg-body: #f4f5f7;
    --bg-card: #ffffff;
    --bg-sidebar: #1a1a1a;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-light: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --touch-min: 48px;
}

[data-theme="dark"] {
    --bg-body: #121212;
    --bg-card: #1e1e1e;
    --bg-sidebar: #0d0d0d;
    --text-primary: #f0f0f0;
    --text-secondary: #aaaaaa;
    --border-color: #333333;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
}

/* Auth */
.auth-page {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-container { width: 100%; max-width: 420px; text-align: center; }
.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-logo img { width: 100px; height: 100px; object-fit: contain; }
.auth-title { color: var(--primary); font-size: 2rem; font-weight: 700; margin: 12px 0 4px; }
.auth-subtitle { color: var(--text-secondary); margin-bottom: 28px; }
.auth-footer { color: rgba(255,255,255,0.6); margin-top: 24px; font-size: 0.85rem; }

/* Layout */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-light);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    overflow-y: auto;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.sidebar-brand { font-size: 1.15rem; font-weight: 700; color: #fff; }

.sidebar-nav { padding: 4px 0 8px; }

.nav-section {
    padding: 8px 16px 2px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255,255,255,0.4);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.875rem;
    min-height: 0;
    line-height: 1.3;
}

.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item i { width: 18px; text-align: center; font-size: 0.9rem; }

.nav-pos {
    background: var(--primary);
    color: #fff !important;
    margin: 4px 10px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-weight: 600;
}
.nav-pos:hover { background: var(--primary-light) !important; }
.nav-pos.active { background: var(--primary-light); }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.topbar-branch {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
    font-weight: 600;
}

.topbar-center { flex: 1; text-align: center; }
.session-timer { font-size: 0.85rem; color: var(--text-secondary); }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.btn-icon {
    width: 44px; height: 44px;
    border: none; background: transparent;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s;
}
.btn-icon:hover { background: var(--bg-body); color: var(--primary); }

.btn-user {
    border: none; background: transparent;
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-radius: var(--radius);
    color: var(--text-primary); cursor: pointer;
}

.page-content { padding: 24px; flex: 1; }

/* Cards & Stats */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; color: var(--text-primary); }

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-label { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }
.stat-card .stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
}

.stat-card.primary .stat-icon { background: rgba(123,24,24,0.1); color: var(--primary); }
.stat-card.success .stat-icon { background: rgba(39,174,96,0.1); color: #27ae60; }
.stat-card.warning .stat-icon { background: rgba(243,156,18,0.1); color: #f39c12; }
.stat-card.info .stat-icon { background: rgba(52,152,219,0.1); color: #3498db; }
.stat-card.danger .stat-icon { background: rgba(231,76,60,0.1); color: #e74c3c; }

.card-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-panel .card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex; align-items: center; justify-content: space-between;
}
.card-panel .card-body { padding: 20px; }

/* Buttons */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    min-height: var(--touch-min);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-lg { padding: 12px 24px; font-size: 1rem; border-radius: var(--radius); }
.btn-touch { min-height: 56px; min-width: 56px; font-size: 1.1rem; border-radius: var(--radius); }

/* Tables */
.table { color: var(--text-primary); }
.table thead th {
    background: var(--bg-body);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Forms */
.form-control, .form-select {
    min-height: var(--touch-min);
    border-radius: 8px;
    border-color: var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(123,24,24,0.15);
}

/* POS Layout */
.pos-fullscreen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-body);
    z-index: 9999;
    display: flex;
    flex-direction: column;
}

.pos-topbar {
    height: 60px;
    background: var(--secondary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
}

.pos-topbar .pos-logo { height: 36px; }
.pos-topbar .pos-branch { font-weight: 600; flex: 1; }
.pos-topbar .pos-actions { display: flex; gap: 8px; }

.pos-main { flex: 1; display: flex; overflow: hidden; }

.pos-categories {
    width: 160px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 8px;
}

.pos-category-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 16px 8px;
    margin-bottom: 8px;
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: var(--bg-body);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 80px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}
.pos-category-btn i { font-size: 1.5rem; margin-bottom: 6px; }
.pos-category-btn.active, .pos-category-btn:hover {
    border-color: var(--primary);
    background: rgba(123,24,24,0.08);
    color: var(--primary);
}

.pos-category-quick {
    border-color: #f39c12 !important;
    background: rgba(243,156,18,0.12);
}
.pos-category-quick.active, .pos-category-quick:hover {
    border-color: #e67e22 !important;
    background: rgba(243,156,18,0.25) !important;
    color: #d35400 !important;
}
.pos-category-quick i { color: #f39c12; }

/* Quick products admin */
.quick-sort-item { transition: background 0.15s; user-select: none; }
.quick-sort-item.dragging { opacity: 0.55; background: rgba(123,24,24,0.08); }
.quick-drag-handle {
    cursor: grab;
    padding: 8px 10px;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
.quick-drag-handle:active { cursor: grabbing; }
.quick-drag-handle i { font-size: 1.1rem; pointer-events: none; }
.quick-add-item:hover { background: var(--bg-body); }
#selectedProducts { min-height: 80px; }


.pos-products {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    align-content: start;
}

.pos-product-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    cursor: pointer;
    border: 2px solid var(--border-color);
    transition: all 0.15s;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.pos-product-card:active { transform: scale(0.96); border-color: var(--primary); background: rgba(123,24,24,0.05); }
.pos-product-card .product-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.pos-product-card .product-price { color: var(--primary); font-weight: 700; font-size: 1rem; }
.pos-product-card .product-img {
    width: 48px; height: 48px;
    border-radius: 8px;
    object-fit: cover;
    margin: 0 auto 8px;
    background: var(--bg-body);
}

.pos-cart {
    width: 360px;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.pos-cart-header {
    padding: 16px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pos-cart-items { flex: 1; overflow-y: auto; padding: 8px; }

.pos-cart-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    gap: 8px;
}
.pos-cart-item .item-name { flex: 1; font-weight: 600; font-size: 0.9rem; }
.pos-cart-item .item-price { font-weight: 700; color: var(--primary); min-width: 70px; text-align: right; }

.qty-control {
    display: flex;
    align-items: center;
    gap: 4px;
}
.qty-btn {
    width: 40px; height: 40px;
    border: none;
    border-radius: 8px;
    background: var(--bg-body);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-primary);
}
.qty-btn:active { background: var(--primary); color: #fff; }
.qty-value { min-width: 30px; text-align: center; font-weight: 700; }

.pos-cart-summary {
    padding: 16px;
    border-top: 2px solid var(--border-color);
    background: var(--bg-body);
}
.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.95rem;
}
.summary-row.total {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 4px;
}

.pos-cart-actions { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pos-cart-actions .btn { font-size: 1.1rem; font-weight: 600; padding: 14px; }

/* Payment Modal */
.payment-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.payment-method-btn {
    padding: 20px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-card);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 80px;
}
.payment-method-btn i { font-size: 1.8rem; display: block; margin-bottom: 8px; }
.payment-method-btn.active { border-color: var(--primary); background: rgba(123,24,24,0.08); color: var(--primary); }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.numpad-btn {
    padding: 16px;
    font-size: 1.3rem;
    font-weight: 700;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    min-height: 56px;
}
.numpad-btn:active { background: var(--primary); color: #fff; }

/* Receipt Print */
@media print {
    body * { visibility: hidden; }
    #receiptPrint, #receiptPrint * { visibility: visible; }
    #receiptPrint { position: absolute; left: 0; top: 0; width: 80mm; }
}

.receipt { font-family: monospace; font-size: 12px; width: 80mm; padding: 10px; }
.receipt .receipt-header { text-align: center; margin-bottom: 10px; }
.receipt .receipt-line { display: flex; justify-content: space-between; }
.receipt .receipt-divider { border-top: 1px dashed #000; margin: 8px 0; }

/* Responsive */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .pos-cart { width: 300px; }
}

@media (max-width: 768px) {
    .pos-main { flex-direction: column; }
    .pos-categories {
        width: 100%;
        display: flex;
        overflow-x: auto;
        padding: 8px;
        flex-direction: row;
        gap: 8px;
    }
    .pos-category-btn { min-width: 100px; min-height: 60px; margin-bottom: 0; }
    .pos-cart { width: 100%; max-height: 40vh; }
    .pos-products { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* Badge */
.badge-primary { background: var(--primary); }

/* DataTables dark mode fix */
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-color);
}
