:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8f9fa;
    --surface-tint: #eef2ff;
    --text: #1f2937;
    --muted: #6c757d;
    --line: #e5e9f2;
    --line-strong: #ced4da;
    --primary: #3b7ddd;
    --primary-dark: #2f64b1;
    --primary-soft: #e8f1ff;
    --danger: #dc3545;
    --success: #1cbb8c;
    --warning: #fcb92c;
    --sidebar: #222e3c;
    --sidebar-hover: #2b3949;
    --sidebar-active: #3b7ddd;
    --sidebar-text: #ced4da;
    --shadow: 0 0 2rem 0 rgba(33, 37, 41, .08);
    --shadow-soft: 0 .125rem .25rem rgba(0, 0, 0, .045);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font: inherit; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 264px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 18px 14px;
    z-index: 20;
    overflow-y: auto;
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 4px 10px 20px;
    margin-bottom: 8px;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}
.brand strong { display: block; color: #fff; font-size: 18px; letter-spacing: .02em; }
.brand small { display: block; color: #adb5bd; margin-top: 2px; text-transform: capitalize; }
nav { display: grid; gap: 3px; }
nav a, .nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 42px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--sidebar-text);
    font-weight: 600;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
}
nav a:hover, .nav-group-toggle:hover { background: var(--sidebar-hover); color: #fff; }
nav a.active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 .25rem .875rem rgba(59, 125, 221, .24);
}
.nav-group { display: grid; gap: 3px; }
.nav-group-toggle span {
    transition: transform .16s ease;
    color: #adb5bd;
}
.nav-group.open .nav-group-toggle span { transform: rotate(180deg); }
.nav-submenu {
    display: none;
    gap: 3px;
    padding-left: 10px;
    margin: 0 0 4px 6px;
    border-left: 1px solid rgba(206, 212, 218, .18);
}
.nav-group.open .nav-submenu { display: grid; }
.nav-submenu a {
    min-height: 36px;
    padding: 8px 10px;
    font-size: 13px;
    color: #adb5bd;
}
.nav-submenu a.active {
    background: rgba(59, 125, 221, .18);
    color: #fff;
    box-shadow: none;
}

.shell {
    min-height: 100vh;
    margin-left: 264px;
    padding: 0;
}
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 72px;
    padding: 16px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}
.content-wrap { padding: 28px; }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: 0; line-height: 1.15; font-weight: 700; }
.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.user-chip {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    white-space: nowrap;
    color: #495057;
    font-weight: 700;
}
.icon-btn { display: none; }

.card, .auth-card {
    background: var(--surface);
    border: 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.card { padding: 20px; margin-bottom: 20px; }
.card h2 { margin: 0 0 16px; font-size: 18px; letter-spacing: 0; font-weight: 700; }
.auth-card { width: min(430px, 100%); padding: 30px; }
.auth-card h1 { margin-top: 0; font-size: 28px; }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.metric {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.metric::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--primary);
}
.metric:nth-child(2)::before { background: var(--success); }
.metric:nth-child(3)::before { background: #6f42c1; }
.metric:nth-child(4)::before { background: var(--warning); }
.metric:nth-child(5)::before { background: var(--danger); }
.metric small {
    color: var(--muted);
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.metric strong { font-size: 24px; line-height: 1.1; font-weight: 800; }
.metric-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 13px;
    padding: 0 0 0 3px;
    vertical-align: middle;
    line-height: 1;
    opacity: .7;
    transition: opacity .15s;
}
.metric-info-btn:hover { opacity: 1; color: var(--primary); }
.metric-tooltip {
    display: none;
    position: fixed;
    z-index: 999;
    max-width: 280px;
    background: #1e293b;
    color: #f1f5f9;
    font-size: 13px;
    line-height: 1.5;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,.25);
    pointer-events: none;
}
.metric-tooltip.visible { display: block; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
    background: #fbfcfe;
}
.form-section h3 {
    margin: 0 0 14px;
    font-size: 15px;
    color: #253044;
}
.field { display: grid; gap: 7px; }
.field label { font-size: 13px; color: #495057; font-weight: 700; }
.field.full { grid-column: 1 / -1; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    min-height: 40px;
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 .2rem rgba(59, 125, 221, .16);
}
textarea { min-height: 90px; resize: vertical; }
.price-stack { display: grid; gap: 4px; min-width: 260px; }
.price-stack span:first-child { color: #6c757d; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.btn {
    border: 1px solid transparent;
    background: var(--primary);
    color: #fff;
    border-radius: 6px;
    padding: 9px 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    font-weight: 700;
    transition: background .14s ease, border-color .14s ease, box-shadow .14s ease;
}
.btn:hover { background: var(--primary-dark); box-shadow: 0 .25rem .875rem rgba(59, 125, 221, .2); }
.btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn.secondary { background: #fff; color: #495057; border-color: var(--line-strong); box-shadow: none; }
.btn.secondary:hover { background: var(--surface-soft); color: var(--primary); }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.warning { background: var(--warning); color: #212529; }

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 760px; }
th, td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
th {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    font-size: 12px;
    color: #6c757d;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}
tbody tr:hover td { background: #f8fbff; }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 800;
    background: var(--primary-soft);
    color: var(--primary-dark);
}
.badge.danger { background: #f8d7da; color: #842029; }
.badge.success { background: #d1e7dd; color: #0f5132; }

.alert {
    margin: 0 28px 18px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid #b6d4fe;
    background: #e7f1ff;
    color: #084298;
    box-shadow: var(--shadow-soft);
}
.alert.error { background: #f8d7da; color: #842029; border-color: #f5c2c7; }
.alert.success { background: #d1e7dd; color: #0f5132; border-color: #badbcc; }
.alert.info { background: #cff4fc; color: #055160; border-color: #b6effb; }

/* Tabs */
.tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 2px solid var(--line); }
.tab { padding: 10px 20px; text-decoration: none; color: var(--muted); font-weight: 500; border-radius: 6px 6px 0 0; transition: background .15s, color .15s; }
.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: #fff; color: var(--accent); border: 2px solid var(--line); border-bottom: 2px solid #fff; margin-bottom: -2px; }

.pagination { display: flex; gap: 4px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.pagination a,
.pagination span {
    display: grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #fff;
    color: #495057;
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
}
.pagination span.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span.pgn-disabled { color: #bbb; background: var(--surface-soft); cursor: default; }
.pagination span.pgn-ellipsis { border: 0; background: transparent; min-width: 20px; letter-spacing: .05em; }

.pos-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 20px;
    align-items: start;
}
.cart-panel {
    position: sticky;
    top: 92px;
    border-top: 4px solid var(--primary);
}
.cart-panel h2 { margin-bottom: 6px; }
.cart-line {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
}
.cart-line:last-of-type {
    margin-top: 4px;
    padding: 13px 0;
    color: var(--primary);
}
.cart-panel form > .cart-line strong:last-child { font-size: 22px; }
.cart-qty-form {
    display: flex;
    align-items: center;
    margin: 5px 0 3px;
}
.cart-qty-input {
    width: 60px !important;
    min-height: 28px !important;
    padding: 3px 6px !important;
    font-size: 13px;
    text-align: center;
}

/* POS product card list */
.pos-product-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.pos-product-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--line);
}
.pos-product-card:last-child { border-bottom: 0; }
.pos-product-info {
    flex: 1;
    min-width: 0;
}
.pos-product-name {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pos-product-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 3px 0 5px;
    font-size: 12px;
    flex-wrap: wrap;
}
.pos-product-prices {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.pos-price-chip {
    font-size: 12px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 2px 7px;
    white-space: nowrap;
}
.pos-price-chip strong { font-size: 12px; }
.pos-price-chip { display: inline-flex; align-items: center; gap: 5px; flex-wrap: wrap; white-space: normal; }
.pos-barcode-tag {
    font-size: 10px;
    color: var(--muted);
    font-family: monospace;
    letter-spacing: .03em;
}
.pos-product-action {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    width: 180px;
}
.pos-product-action select {
    width: 100%;
    font-size: 13px;
}
.pos-qty-row {
    display: flex;
    gap: 6px;
}
.pos-qty-row input[type=number] {
    width: 56px;
    flex-shrink: 0;
    font-size: 13px;
}
.pos-qty-row .btn {
    flex: 1;
    font-size: 13px;
    padding: 7px 8px;
    white-space: nowrap;
}
.receipt {
    width: 320px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #111;
    background: #fff;
    padding: 14px;
}
.receipt table { min-width: 0; font-size: 12px; }
.receipt th, .receipt td { padding: 5px 0; border: 0; }

input.barcode-check[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--primary);
}
.barcode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.barcode-label {
    border: 1px dashed #94a3b8;
    background: #fff;
    padding: 10px;
    text-align: center;
    break-inside: avoid;
}
.barcode-label svg { width: 100%; height: 70px; display: block; }

@media (max-width: 980px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    body.menu-open .sidebar { transform: translateX(0); }
    .shell { margin-left: 0; }
    .content-wrap { padding: 16px; }
    .topbar { padding: 14px 16px; align-items: flex-start; }
    .icon-btn {
        display: inline-grid;
        place-items: center;
        width: 40px;
        height: 40px;
        border: 1px solid var(--line);
        border-radius: 6px;
        background: #fff;
        color: var(--text);
    }
    .grid, .form-grid, .pos-layout { grid-template-columns: 1fr; }
    .span-3, .span-4, .span-6, .span-8, .span-12 { grid-column: span 1; }
    .cart-panel { position: static; }
    .user-chip { display: none; }
    .topbar h1 { font-size: 22px; }
    .alert { margin: 0 16px 16px; }

    body[data-page="pos"] .pos-layout { gap: 12px; }
}

@media (max-width: 640px) {
    .content-wrap { padding: 12px; }
    .card { padding: 14px; margin-bottom: 12px; }
    .actions .btn { width: 100%; }
    table { min-width: 650px; }
    .metric strong { font-size: 20px; }

    .pos-product-card { flex-wrap: wrap; }
    .pos-product-action { width: 100%; }
    .pos-qty-row .btn { min-height: 42px; }

    body[data-page="pos"] .cart-line { align-items: flex-start; gap: 10px; }
    body[data-page="pos"] .cart-line a { color: var(--danger); font-weight: 800; white-space: nowrap; }
    body[data-page="pos"] .cart-panel form { display: grid; gap: 10px; }
    body[data-page="pos"] .cart-panel .actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
}

/* ── Category combobox ─────────────────────────────────────────────────── */
.cat-combo { position: relative; }
.cat-combo input[type="text"] { padding-right: 32px; }
.cat-combo::after {
    content: '▾';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--muted);
    font-size: 13px;
}
.cat-list {
    display: none;
    position: absolute;
    z-index: 200;
    left: 0; right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.10);
    max-height: 220px;
    overflow-y: auto;
    margin: 0;
    padding: 4px 0;
    list-style: none;
}
.cat-list li {
    padding: 9px 14px;
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
    transition: background .1s;
}
.cat-list li:hover,
.cat-list li.active { background: var(--surface-tint); color: var(--primary); }

@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print, .alert { display: none !important; }
    .shell { margin: 0; padding: 0; }
    .content-wrap { padding: 0; }
    .card { box-shadow: none; border: 0; padding: 0; margin: 0; }
    .print-only { display: block !important; }
}
