:root {
  --bg: #faf6ef; --panel: #fff; --ink: #2b2118; --muted: #8a7a6a; --line: #ece3d6;
  --brand: #7a4b12; --brand-2: #a8691f; --brand-soft: #f6ebd9; --gold: #e0a93b;
  --green: #2f7d4f; --green-soft: #e3f2e8; --red: #b33a2e; --red-soft: #fbe6e3; --blue: #2b5f94; --blue-soft: #e4eef8;
  --radius: 12px; --shadow: 0 1px 2px rgba(60,40,10,.06), 0 4px 14px rgba(60,40,10,.06);
  --side: 232px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }
.pos { color: var(--green); } .neg { color: var(--red); } .bold { font-weight: 600; }
.hidden { display: none !important; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #2e1f10; color: #eadcc6; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20; }
.side .brand { padding: 18px 18px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #47331d; }
.side .brand img { width: 34px; height: 34px; }
.side .brand b { display: block; color: #fff; font-size: 15px; line-height: 1.2; }
.side .brand span { font-size: 12px; color: #c3ab8a; }
.side nav { flex: 1; overflow: auto; padding: 8px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: #eadcc6; padding: 9px 12px; border-radius: 9px; margin: 1px 0; }
.side nav a:hover { background: #3e2a15; }
.side nav a.active { background: var(--gold); color: #2e1f10; font-weight: 600; }
.side nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #9b8466; padding: 12px 12px 4px; }
.side .me { padding: 12px 14px; border-top: 1px solid #47331d; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side .me a { color: #f6d48b; }
.ico { width: 18px; text-align: center; flex: none; }
.main { margin-left: var(--side); flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mob-head, .bottom-nav, .mob-cart { display: none; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.kpi { padding: 14px 16px; }
.kpi .lbl { color: var(--muted); font-size: 13px; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; min-height: 38px; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #643c0c; }
.btn.danger { color: var(--red); border-color: #efc7c1; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.lg { padding: 12px 20px; font-size: 16px; min-height: 48px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); } .badge.red { background: var(--red-soft); color: var(--red); } .badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: #eee; color: #666; }

/* forms */
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input.i, select.i, textarea.i { width: 100%; border: 1px solid #ddd0bd; background: #fff; border-radius: 9px; padding: 8px 10px; min-height: 38px; outline: none; }
input.i:focus, select.i:focus, textarea.i:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(168,105,31,.15); }
input.i.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea.i { min-height: 64px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.row > .auto { flex: none; min-width: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--brand); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters .i { width: auto; min-width: 140px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets .btn.on { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand); font-weight: 600; }

/* tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fdfaf5; position: sticky; top: 0; }
table.t td { padding: 9px 10px; border-bottom: 1px solid #f3ece1; vertical-align: top; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: #fdf7ec; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fdfaf5; }
table.t tr.cancel td { opacity: .5; text-decoration: line-through; }
table.t tr.low td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* POS */
.pos-grid { display: grid; grid-template-columns: minmax(0,1.25fr) minmax(340px,1fr); gap: 14px; align-items: start; }
.prod-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 8px; max-height: calc(100vh - 230px); overflow: auto; padding: 2px; }
.prod { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 88px; }
.prod:hover { border-color: var(--brand-2); background: #fffaf2; }
.prod b { font-size: 14px; line-height: 1.25; font-weight: 600; }
.prod .p { color: var(--brand); font-weight: 700; margin-top: auto; }
.prod .s { font-size: 12px; color: var(--muted); }
.prod.out { opacity: .55; }
.cart { position: sticky; top: 14px; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.cart-line .nm { font-weight: 600; font-size: 14px; }
.cart-line .ctl { grid-column: 1 / -1; display: grid; grid-template-columns: 110px 1fr 1fr auto; gap: 6px; align-items: center; }
.qty { display: flex; border: 1px solid #ddd0bd; border-radius: 9px; overflow: hidden; }
.qty button { border: 0; background: var(--brand-soft); width: 32px; cursor: pointer; font-size: 18px; color: var(--brand); }
.qty input { border: 0; width: 46px; text-align: center; outline: none; }
.sumrow { display: flex; justify-content: space-between; padding: 4px 0; }
.sumrow.total { font-size: 19px; font-weight: 700; border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; }
.x { border: 0; background: none; color: var(--red); cursor: pointer; font-size: 18px; padding: 0 4px; }

/* picker */
.picker { position: relative; }
.picker .list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.picker .opt { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f5efe5; }
.picker .opt:hover, .picker .opt.hl { background: var(--brand-soft); }
.picker .opt small { color: var(--muted); }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(30,20,8,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal .mh { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .mb { padding: 16px 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#toast-root { position: fixed; z-index: 200; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #2e1f10; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: up .2s ease; }
.toast.err { background: var(--red); } .toast.ok { background: var(--green); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 30% 10%, #f6ebd9, var(--bg) 60%); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login img { width: 56px; display: block; margin: 0 auto 10px; }

/* report */
.pl { width: 100%; border-collapse: collapse; }
.pl td { padding: 7px 4px; border-bottom: 1px solid #f3ece1; }
.pl td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pl tr.hl td { font-weight: 700; background: var(--brand-soft); }
.pl tr.big td { font-size: 17px; font-weight: 800; background: #2e1f10; color: #fff; }
.pl tr.sub td:first-child { padding-left: 18px; color: var(--muted); }
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--gold); } .chart .bar2 { fill: var(--brand); } .chart text { font-size: 10px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.drop { border: 2px dashed #d9c7ac; border-radius: 12px; padding: 22px; text-align: center; background: #fffaf2; cursor: pointer; }
.drop.on { border-color: var(--brand); background: var(--brand-soft); }
.err-list { max-height: 240px; overflow: auto; font-size: 13px; background: var(--red-soft); border-radius: 8px; padding: 8px 12px; }
.hint { background: var(--blue-soft); color: #1d4166; border-radius: 9px; padding: 8px 12px; font-size: 13px; }
.warn { background: #fff4dc; color: #7a5200; border-radius: 9px; padding: 8px 12px; font-size: 13px; }

/* invoice print */
.invoice { font-size: 14px; }
.invoice h2 { text-align: center; margin-bottom: 2px; }
.invoice table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.invoice td, .invoice th { padding: 4px 2px; border-bottom: 1px dashed #ccc; text-align: left; }
.invoice .r { text-align: right; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; padding: 0 6mm; }
  .modal-bg { background: none; }
}

/* mobile */
@media (max-width: 900px) {
  .side { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  body.nav-open .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }
  .main { margin-left: 0; padding: 12px 12px 90px; }
  .mob-head { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 10; background: #2e1f10; color: #fff; padding: 10px 12px; margin: -12px -12px 12px; }
  .mob-head button { background: none; border: 0; color: #fff; font-size: 22px; }
  .mob-head b { flex: 1; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { text-align: center; padding: 7px 2px 6px; font-size: 11px; color: var(--muted); }
  .bottom-nav a .ico { display: block; width: auto; font-size: 19px; }
  .bottom-nav a.active { color: var(--brand); font-weight: 600; }
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3, .g2 { grid-template-columns: minmax(0,1fr); }
  .pos-grid { grid-template-columns: minmax(0,1fr); }
  .prod-list { max-height: 46vh; grid-template-columns: repeat(auto-fill, minmax(135px,1fr)); }
  .cart { position: static; }
  .mob-cart { display: block; position: fixed; left: 10px; right: 10px; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 9; background: var(--brand); color: #fff; border: 0; border-radius: 12px; padding: 12px; font-size: 15px; box-shadow: 0 6px 20px rgba(60,40,10,.35); }
  .mob-cart.hidden { display: none; }
  .kpi .val { font-size: 19px; }
  .topbar h1 { font-size: 19px; }
  .perm-grid { grid-template-columns: minmax(0,1fr); }
  .modal-bg { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; max-width: none !important; }
  table.t { font-size: 13px; }
  .hide-m { display: none; }
}
.grid > .card { margin-top: 0 !important; }
