:root {
    --bg: #f3f1ec;
    --surface: #ffffff;
    --ink: #1c1917;
    --muted: #6b6560;
    --line: #e6e1d8;
    --accent: #1c7c4e;
    --accent-dark: #145c3a;
    --accent-soft: #e7f4ed;
    --sidebar: #16191f;
    --sidebar-text: #c5ccd6;
    --danger: #c5364e;
    --danger-soft: #fdecef;
    --warn: #9a6700;
    --warn-soft: #fbf3df;
    --shadow: 0 1px 2px rgba(28, 25, 23, .04), 0 14px 34px rgba(28, 25, 23, .05);
    --radius: 16px;
    --font: "Segoe UI Variable Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-dark); text-decoration: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; letter-spacing: -0.03em; }
h2 { font-size: 16px; letter-spacing: -0.02em; }
.lede, .hint { color: var(--muted); }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }

.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 18px 12px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand, .login-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: white;
    padding: 6px 10px 18px;
}
.brand strong, .login-brand strong { display: block; font-size: 15px; }
.brand small, .login-brand small { color: #8e99a8; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 11px;
    display: grid; place-items: center;
    background: var(--accent); color: white; font-weight: 750;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.side-nav a {
    display: flex; align-items: center; gap: 10px;
    color: var(--sidebar-text);
    padding: 10px 12px;
    border-radius: 12px;
    font-weight: 650;
}
.side-nav a:hover { background: rgba(255,255,255,.05); color: white; }
.side-nav a.active { background: rgba(255,255,255,.1); color: white; }
.side-user {
    margin-top: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px 8px 4px;
}
.side-user .who strong, .side-user .who small { display: block; }
.side-user .who strong { color: white; font-size: 14px; }
.side-user .who small { color: #8e99a8; text-transform: capitalize; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    background: #2a3140; color: white; font-weight: 750; font-size: 13px;
}
.icon-btn {
    width: 36px; height: 36px; border-radius: 10px;
    display: inline-grid; place-items: center;
    border: 1px solid transparent; background: transparent; color: inherit;
}
.sidebar .icon-btn { color: #c5ccd6; }
.sidebar .icon-btn:hover { background: rgba(255,255,255,.06); color: white; }
.main { min-width: 0; }
.mobile-bar, .sidebar-backdrop, .cart-fab { display: none; }
.content { padding: 28px; }
.page-pos .content { padding: 0; height: 100vh; }

.page-head, .panel-head, .cart-head {
    display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
}
.page-head { margin-bottom: 18px; }
.page-actions, .toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar { margin-bottom: 14px; }
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.panel + .panel, .split { margin-top: 16px; }
.panel-head { margin-bottom: 12px; align-items: center; }
.split { display: grid; grid-template-columns: 1.3fr .7fr; gap: 16px; }
.split .panel { margin-top: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.card span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.card strong { display: block; margin-top: 8px; font-size: 22px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.card em { display: block; margin-top: 4px; color: var(--muted); font-style: normal; font-size: 13px; }

.btn {
    height: 40px; padding: 0 14px; border-radius: 11px;
    border: 1px solid var(--line); background: white; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { border-color: #d4cec3; }
.btn-primary { background: var(--accent); border-color: transparent; color: white; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: transparent; color: white; }
.btn-sm { height: 34px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 48px; width: 100%; font-size: 16px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 1px solid var(--line); background: white; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: #3f3a34; }
.field.inline { flex-direction: row; align-items: center; }
.field input, .field select, .field textarea, .toolbar select, .menu button, .customer-pick .search input {
    border: 1px solid var(--line); border-radius: 11px; background: white; padding: 0 12px; height: 42px; font-weight: 600;
}
.field textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus, .toolbar select:focus {
    outline: 3px solid #d7efe3; border-color: var(--accent);
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-panel { max-width: 640px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 700; }

.search {
    display: flex; align-items: center; gap: 8px;
    background: white; border: 1px solid var(--line); border-radius: 12px;
    padding: 0 12px; min-width: min(360px, 100%); height: 42px; color: var(--muted);
}
.search input { border: 0; outline: 0; width: 100%; height: 100%; background: transparent; font-weight: 600; color: var(--ink); }
.toolbar select { height: 42px; border-radius: 12px; padding: 0 12px; background: white; }

.table-wrap { overflow: auto; background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; font-size: 12px; letter-spacing: .04em; text-transform: uppercase;
    color: var(--muted); padding: 12px 14px; background: #faf8f5; font-weight: 750;
}
td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7fbf8; }
.badge {
    display: inline-flex; align-items: center; height: 24px; padding: 0 8px;
    border-radius: 999px; font-size: 12px; font-weight: 750; background: #f3f1ec; color: #4b453e;
}
.badge.ok { background: var(--accent-soft); color: var(--accent-dark); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.muted { color: var(--muted); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bar i {
    display: block; width: 100%; max-width: 42px; border-radius: 8px 8px 4px 4px;
    background: linear-gradient(#2f9d68, #1c7c4e); min-height: 4px;
}
.bar span { font-size: 12px; color: var(--muted); font-weight: 700; }
.bar b { font-size: 11px; font-weight: 700; }

.pos { height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) 400px; }
.pos-catalog { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pos-toolbar { padding: 18px 18px 8px; display: flex; flex-direction: column; gap: 12px; }
.pos-toolbar .search { background: white; }
.chips { display: flex; gap: 8px; overflow: auto; padding-bottom: 4px; }
.chips button {
    border: 1px solid var(--line); background: white; border-radius: 999px;
    height: 34px; padding: 0 12px; font-weight: 750; white-space: nowrap;
}
.chips button.active { background: var(--ink); color: white; border-color: var(--ink); }
.product-grid {
    overflow: auto; padding: 8px 18px 24px;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; align-content: start;
}
.product {
    text-align: left; background: white; border: 1px solid var(--line); border-radius: 16px;
    padding: 14px; min-height: 118px; display: flex; flex-direction: column; gap: 6px;
    box-shadow: var(--shadow);
}
.product:hover { border-color: #b7dcc8; }
.product strong { font-size: 15px; letter-spacing: -0.02em; }
.product .price { margin-top: auto; font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; }
.product small { color: var(--muted); }
.product.out { opacity: .55; }
.pos-cart {
    background: white; border-left: 1px solid var(--line);
    display: flex; flex-direction: column; min-height: 0;
}
.cart-head, .customer-pick, .cart-foot { padding: 16px 16px 0; }
.cart-head p, .change-line { color: var(--muted); font-size: 13px; }
.customer-pick { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 8px; padding-top: 12px; }
.customer-pick .search { min-width: 0; }
.menu {
    position: absolute; z-index: 5; top: 58px; left: 16px; right: 60px;
    background: white; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow); max-height: 240px; overflow: auto;
}
.menu button { display: block; width: 100%; text-align: left; background: white; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; height: auto; padding: 10px 12px; }
.menu button small { display: block; color: var(--muted); font-weight: 600; }
.cart-lines { flex: 1; overflow: auto; padding: 8px 16px 12px; }
.line {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
    padding: 12px 0; border-bottom: 1px solid var(--line);
}
.line .name { font-weight: 750; }
.line .meta { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.qty {
    display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.qty button { width: 30px; height: 32px; border: 0; background: #faf8f5; }
.qty input { width: 52px; height: 32px; border: 0; text-align: center; font-weight: 750; }
.price-edit {
    width: 84px; height: 32px; border: 1px dashed var(--line); border-radius: 10px; text-align: right; padding: 0 8px; font-weight: 750;
}
.price-edit.edited { border-style: solid; border-color: var(--warn); background: var(--warn-soft); }
.line-total { font-weight: 750; font-variant-numeric: tabular-nums; }
.remove { border: 0; background: transparent; color: var(--muted); }
.totals { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.totals div, .receipt dl div { display: flex; justify-content: space-between; gap: 12px; }
.totals .grand { font-size: 20px; }
.pay-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.pay-toggle button { height: 40px; border-radius: 11px; border: 1px solid var(--line); background: white; font-weight: 750; }
.pay-toggle button.active { background: var(--ink); color: white; border-color: var(--ink); }
.cart-foot { padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.change-line { min-height: 20px; margin: 8px 0; font-weight: 700; }
.change-line.good { color: var(--accent-dark); }
.change-line.bad { color: var(--danger); }

.modal-back, .drawer-back {
    position: fixed; inset: 0; background: rgba(22, 25, 31, .42);
    display: grid; place-items: center; z-index: 30; padding: 20px;
}
.modal {
    width: min(640px, 100%); background: white; border-radius: 20px;
    box-shadow: var(--shadow); max-height: calc(100vh - 40px); overflow: auto;
}
.modal.wide { width: min(860px, 100%); }
.modal header, .drawer header, .modal footer {
    display: flex; justify-content: space-between; gap: 12px; align-items: center;
    padding: 16px 18px;
}
.modal .body, .drawer .body { padding: 0 18px 18px; }
.modal footer { border-top: 1px solid var(--line); }
.drawer-back { justify-content: end; padding: 0; }
.drawer {
    width: min(520px, 100%); height: 100%; background: white;
    box-shadow: var(--shadow); overflow: auto;
}
.alert { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 12px; font-weight: 700; }
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: white; border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); max-width: 320px; }
.toast.error { background: var(--danger); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
    width: min(440px, 100%); background: white; border: 1px solid var(--line);
    border-radius: 24px; padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 8px 0; }
.login-card .lede { margin-bottom: 16px; }
.login-brand { padding: 0 0 8px; color: var(--ink); }
.login-brand small { color: var(--muted); }

.receipt-body { background: #eceae4; padding: 24px; }
.receipt-actions { width: 360px; margin: 0 auto 12px; display: flex; gap: 8px; }
.receipt {
    width: 360px; margin: 0 auto; background: white; padding: 22px 18px;
    border-radius: 8px; box-shadow: var(--shadow);
}
.receipt header { text-align: center; margin-bottom: 12px; }
.receipt header strong { display: block; font-size: 20px; }
.receipt table { width: 100%; }
.receipt td { border: 0; padding: 6px 0; }
.receipt td small { display: block; color: var(--muted); }
.receipt td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.receipt dl { margin: 10px 0 0; border-top: 1px dashed var(--line); padding-top: 8px; }
.receipt dt, .receipt dd { margin: 0; }
.receipt-foot { text-align: center; color: var(--muted); margin-top: 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs button { height: 36px; border-radius: 999px; border: 1px solid var(--line); background: white; padding: 0 14px; font-weight: 750; }
.tabs button.active { background: var(--ink); color: white; }
.low-row, .stat-line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-bottom: 14px; }
.detail-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.hero-balance { font-size: 32px; letter-spacing: -0.04em; margin: 4px 0 12px; }
.count-table input { width: 90px; height: 36px; border: 1px solid var(--line); border-radius: 10px; text-align: right; padding: 0 8px; font-weight: 750; }
.diff-pos { color: var(--accent-dark); font-weight: 750; }
.diff-neg { color: var(--danger); font-weight: 750; }

@media (max-width: 1200px) {
    .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .split { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; z-index: 40; transform: translateX(-105%); transition: transform .18s ease; width: 260px; }
    .sidebar.open { transform: none; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
    .mobile-bar {
        display: flex; align-items: center; gap: 10px;
        padding: 10px 14px; position: sticky; top: 0; background: rgba(243,241,236,.92); backdrop-filter: blur(8px); z-index: 20;
    }
    .content { padding: 16px; }
    .page-pos .content { height: auto; }
    .pos { height: auto; min-height: calc(100vh - 56px); grid-template-columns: 1fr; }
    .pos-cart {
        position: fixed; z-index: 25; inset: auto 0 0 0; height: min(86vh, 720px);
        border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
        transform: translateY(110%); transition: transform .18s ease;
    }
    .pos-cart.open { transform: none; }
    .cart-fab {
        display: flex; position: fixed; z-index: 24; left: 16px; right: 16px; bottom: 16px;
        height: 52px; border: 0; border-radius: 14px; background: var(--ink); color: white;
        align-items: center; justify-content: space-between; padding: 0 16px; font-weight: 750;
    }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
@media print {
    .receipt-actions { display: none; }
    .receipt-body { background: white; padding: 0; }
    .receipt { box-shadow: none; width: auto; }
}
