:root {
  --blue: #1d4ed8; --blue-d: #1e3a8a; --blue-l: #eff6ff;
  --green: #15803d; --green-l: #dcfce7;
  --red: #b91c1c; --red-l: #fee2e2;
  --amber: #b45309; --amber-l: #fef3c7;
  --ink: #0f172a; --muted: #64748b; --line: #e2e8f0; --bg: #f1f5f9; --card: #fff;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
a { color: var(--blue); }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--blue-d); color: #fff; flex-shrink: 0;
  position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 30;
  transition: transform .2s;
}
.sidebar .brand { padding: 18px 18px 14px; font-weight: 700; font-size: 17px; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .brand small { display: block; font-weight: 400; opacity: .7; font-size: 12px; margin-top: 2px; }
.sidebar nav { padding: 8px; overflow-y: auto; flex: 1; }
.sidebar nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; color: #dbeafe;
  padding: 11px 12px; border-radius: 9px; cursor: pointer; text-align: left; font-size: 15px;
}
.sidebar nav button:hover { background: rgba(255,255,255,.08); }
.sidebar nav button.active { background: #fff; color: var(--blue-d); font-weight: 600; }
.sidebar .who { padding: 12px 18px; font-size: 13px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar .who button { margin-top: 8px; width: 100%; }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 7px; margin-left: auto; font-weight: 600; }
.main { flex: 1; margin-left: 232px; min-width: 0; }
.topbar {
  display: none; position: sticky; top: 0; z-index: 20; background: var(--blue-d); color: #fff;
  padding: 12px 14px; align-items: center; gap: 12px;
}
.topbar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 4px; cursor: pointer; }
.topbar .t { font-weight: 600; flex: 1; }
.content { padding: 22px; max-width: 1150px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; }
.overlay { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .content { padding: 14px; }
  .page-head h1 { font-size: 19px; }
}

/* Staff layout (simple tabs) */
.staff-tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.staff-tabs button { flex: 1; border: 0; background: none; padding: 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.staff-tabs button.active { color: var(--blue); border-color: var(--blue); }
.staff-top { background: var(--blue-d); color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }

/* ---------- Components ---------- */
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 16px; margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat.good .v { color: var(--green); } .stat.bad .v { color: var(--red); } .stat.warn .v { color: var(--amber); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost-danger { color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; font-size: 15px;
}
.input:focus { outline: 2px solid #93c5fd; border-color: var(--blue); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .input { width: auto; flex: 1; min-width: 160px; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
td .sub { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.green { background: var(--green-l); color: var(--green); }
.chip.red { background: var(--red-l); color: var(--red); }
.chip.amber { background: var(--amber-l); color: var(--amber); }
.chip.blue { background: var(--blue-l); color: var(--blue); }
.chip.gray { background: #f1f5f9; color: var(--muted); }
.red-t { color: var(--red); font-weight: 600; } .green-t { color: var(--green); font-weight: 600; }
.muted { color: var(--muted); }

.list-item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.qty-big { font-size: 22px; font-weight: 700; text-align: center; min-width: 54px; }
.qty-big small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px; background: linear-gradient(160deg, var(--blue-d), var(--blue)); }
.auth-card { background: #fff; border-radius: 16px; padding: 26px 22px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card h1 { font-size: 22px; text-align: center; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 4px 0 20px; font-size: 14px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px; font-size: 14px; }
.auth-links a { cursor: pointer; }
.msg { padding: 10px 12px; border-radius: 9px; font-size: 14px; margin-bottom: 12px; }
.msg.err { background: var(--red-l); color: var(--red); }
.msg.ok { background: var(--green-l); color: var(--green); }
.msg.info { background: var(--blue-l); color: var(--blue-d); }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; padding: 20px; text-align: center; }
.spinner { width: 34px; height: 34px; border: 4px solid #cbd5e1; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; padding: 18px; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { font-size: 18px; }
.modal-head button { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
#toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: 92vw; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--red); } .toast.ok { background: var(--green); }

.item-row { display: grid; grid-template-columns: 1fr 70px 110px 34px; gap: 6px; margin-bottom: 8px; align-items: center; }
.item-row button { border: 0; background: var(--red-l); color: var(--red); border-radius: 8px; height: 38px; cursor: pointer; font-size: 18px; }
@media (max-width: 560px) { .item-row { grid-template-columns: 1fr 60px 90px 30px; } }
.total-box { background: var(--blue-l); border-radius: 10px; padding: 12px; display: flex; justify-content: space-between; font-weight: 700; margin: 8px 0 12px; }

/* ---------- Bill ---------- */
.bill { font-family: "Courier New", monospace; color: #000; background: #fff; }
.bill-preview { border: 1px dashed #94a3b8; padding: 14px; max-width: 320px; margin: 0 auto 6px; }
.bill .shop { text-align: center; font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.bill .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.bill hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.bill table { width: 100%; font-size: 12.5px; }
.bill th, .bill td { padding: 2px 0 2px 8px; border: 0; background: none; color: #000; text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.bill th:first-child, .bill td:first-child { padding-left: 0; }
.bill .tot { font-weight: 700; font-size: 14px; }
.bill.a4 { font-family: Arial, sans-serif; }
.bill.a4 .shop { font-size: 26px; }
.bill.a4 .row, .bill.a4 table, .bill.a4 th, .bill.a4 td { font-size: 15px; }
.bill.a4 th, .bill.a4 td { padding: 6px 4px; border-bottom: 1px solid #ddd; }

#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; }
}
