:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #657084;
    --border: #e2e8f0;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --radius: 8px;
    --shadow: 0 12px 35px rgba(20, 32, 54, .08);
}

[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #111c31;
    --text: #e5edf9;
    --muted: #97a6bd;
    --border: #26344e;
    --shadow: 0 14px 35px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 245px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 6px 18px; }
.brand-logo {
    width: 42px; height: 42px; border-radius: 8px;
    background: var(--primary); color: white;
    display: grid; place-items: center; font-weight: 800;
    overflow: hidden; flex: 0 0 auto;
}
.brand-logo.large { width: 62px; height: 62px; margin: 0 auto; font-size: 22px; }
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand h1 { margin: 0; font-size: 16px; line-height: 1.1; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.nav-menu { display: grid; gap: 4px; }
.nav-menu a, .nav-title {
    display: flex; align-items: center; min-height: 38px;
    padding: 9px 11px; border-radius: 8px; color: var(--muted);
}
.nav-menu a:hover, .nav-menu a.active { background: rgba(37, 99, 235, .1); color: var(--primary); }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-top: 8px; min-height: 26px; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: rgba(244, 247, 251, .88);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    min-height: 70px;
    padding: 12px 22px;
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
[data-theme="dark"] .topbar { background: rgba(15, 23, 42, .88); }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h2 { margin: 0; font-size: 20px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.fy-pill, .user-pill {
    min-height: 34px; display: inline-flex; align-items: center;
    padding: 6px 11px; border: 1px solid var(--border); border-radius: 999px;
    background: var(--panel); color: var(--muted);
}
.content-area { padding: 22px; flex: 1; }
.app-footer {
    display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    padding: 14px 22px; color: var(--muted); border-top: 1px solid var(--border);
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header, .card-body, .card-footer { padding: 16px; }
.card-header { border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 17px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card { padding: 16px; }
.stat-card span { color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; font-size: 24px; margin-top: 8px; }

.form-grid { display: grid; gap: 13px; }
.form-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
label span, .label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
input, select, textarea {
    width: 100%; min-height: 38px; border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 10px; background: var(--panel); color: var(--text);
    outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.check-line { display: flex; align-items: center; gap: 8px; }
.check-line input { width: auto; min-height: auto; }

.btn {
    min-height: 36px; border: 1px solid transparent; border-radius: 8px;
    padding: 8px 13px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    gap: 7px; white-space: nowrap; font-weight: 700;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: var(--panel); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-sm { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn-full { width: 100%; }
.icon-btn {
    width: 36px; height: 36px; border: 1px solid var(--border); background: var(--panel);
    color: var(--text); border-radius: 8px; cursor: pointer;
}
.mobile-menu { display: none; }

.table-tools { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; background: rgba(37, 99, 235, .05); }
tbody tr:hover { background: rgba(37, 99, 235, .04); }
.text-end { text-align: right; }
.text-center { text-align: center; }
.muted { color: var(--muted); }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-success { background: rgba(5, 150, 105, .12); color: var(--success); }
.badge-danger { background: rgba(220, 38, 38, .12); color: var(--danger); }
.badge-warning { background: rgba(217, 119, 6, .14); color: var(--warning); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.pagination { display: flex; gap: 5px; list-style: none; padding: 0; margin: 16px 0 0; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 34px; min-height: 34px; display: grid; place-items: center;
    border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
}
.pagination .active span { background: var(--primary); color: #fff; border-color: var(--primary); }

.toast-stack { position: fixed; top: 82px; right: 16px; z-index: 100; display: grid; gap: 8px; }
.toast {
    min-width: 260px; max-width: 360px; padding: 12px 14px; border-radius: 8px;
    color: white; box-shadow: var(--shadow); animation: slideIn .2s ease-out;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.login-page {
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: linear-gradient(135deg, #edf4ff, #f8fbff);
}
.login-card {
    width: min(420px, 100%); background: white; border: 1px solid #e2e8f0;
    border-radius: 12px; padding: 28px; box-shadow: 0 22px 60px rgba(15, 23, 42, .12);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand h1 { margin: 10px 0 5px; font-size: 24px; }
.login-brand p { margin: 0; color: #64748b; }

.modal-lite {
    border: 0; border-radius: 10px; padding: 0; background: var(--panel); color: var(--text);
    width: min(560px, calc(100% - 24px)); box-shadow: 0 30px 80px rgba(0,0,0,.25);
}
.modal-lite::backdrop { background: rgba(15,23,42,.45); }
.modal-head, .modal-foot { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-foot { border-top: 1px solid var(--border); border-bottom: 0; justify-content: flex-end; }
.modal-body { padding: 16px; }

.pos-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.pos-table-wrap { overflow-x: auto; overflow-y: visible; }
.pos-table { min-width: 760px; }
.pos-table input { min-width: 80px; }
.search-cell { position: relative; min-width: 240px; }
.product-results {
    position: fixed; left: 0; top: 0; z-index: 9999;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow); max-height: 260px; overflow: auto; display: none;
}
.product-results.show { display: block; }
.product-option { padding: 9px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.product-option:hover, .product-option.active { background: rgba(37, 99, 235, .12); }
.product-option small { color: var(--muted); display: block; margin-top: 3px; }
.summary-box { position: sticky; top: 88px; }
.summary-line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.summary-total { font-size: 22px; font-weight: 800; }

.invoice {
    width: 148mm; margin: 0 auto; background: white; color: #111827; padding: 12mm;
}
.invoice.thermal { width: 72mm; padding: 4mm; font-size: 12px; }
.invoice-head { text-align: center; border-bottom: 1px solid #111827; padding-bottom: 8px; margin-bottom: 8px; }
.invoice-logo { max-width: 70px; max-height: 70px; object-fit: contain; }
.invoice-title { font-size: 19px; margin: 4px 0; }
.invoice-row { display: flex; justify-content: space-between; gap: 10px; }
.invoice table th, .invoice table td { color: #111827; border-color: #cbd5e1; padding: 6px; }
.invoice .qr { max-width: 90px; max-height: 90px; }
.print-actions { max-width: 148mm; margin: 15px auto; display: flex; justify-content: center; gap: 8px; }

@media print {
    body { background: white; }
    .print-actions { display: none; }
    .invoice { box-shadow: none; margin: 0; }
    @page { margin: 5mm; }
}

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pos-wrap { grid-template-columns: 1fr; }
    .summary-box { position: static; }
}

@media (max-width: 780px) {
    .sidebar {
        position: fixed; transform: translateX(-105%); transition: .2s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu { display: inline-block; }
    .topbar { align-items: flex-start; padding: 12px; }
    .topbar-actions { justify-content: flex-start; }
    .content-area { padding: 12px; }
    .grid-2, .grid-3, .grid-4, .form-row { grid-template-columns: 1fr; }
    .card-header { align-items: stretch; }
    .table-tools { width: 100%; }
    .table-tools > * { flex: 1 1 160px; }
    .toast-stack { left: 12px; right: 12px; top: 72px; }
    .toast { min-width: 0; max-width: none; }
}
