:root {
  --teal: #0f766e;
  --teal-dark: #0b5550;
  --teal-soft: #e6f4f1;
  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --bg: #f2f5f7;
  --card: #ffffff;
  --line: #e2e8ee;
  --text: #17252f;
  --muted: #6b7a8c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 40, 55, .06), 0 8px 24px rgba(16, 40, 55, .06);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, #13948a, #0b5550);
  color: #fff; font-weight: 700; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text b { font-size: 13px; letter-spacing: .4px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: #f4f7f9; border-radius: 10px; padding: 4px; }
.tab {
  border: 0; background: transparent; padding: 7px 16px; border-radius: 8px;
  font-size: 13px; color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(16,40,55,.1); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.badge {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--muted);
}
.aeat-btn[data-mode="offline"] { background: var(--teal-soft); border-color: #bfe3dd; color: var(--teal-dark); }
.aeat-btn[data-mode="online"] { background: var(--amber-soft); border-color: #f0d5ae; color: var(--amber); }
.local-badge { background: #f4f7f9; }

.lang-switch { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-switch button { border: 0; background: #fff; padding: 5px 9px; font-size: 12px; color: var(--muted); }
.lang-switch button.active { background: var(--teal); color: #fff; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { color: var(--teal); border-color: #bfe3dd; }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; }

/* ---------- layout ---------- */
main { padding: 16px 20px 28px; }
.view { display: none; }
.view.active { display: block; }
#view-pos.view.active { display: grid; grid-template-columns: minmax(0, 1fr) 392px; gap: 16px; align-items: start; }

.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 15px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.head-tools { display: flex; align-items: center; gap: 8px; }
.dash { color: var(--muted); }

/* ---------- search ---------- */
.search-wrap { position: relative; flex: 1; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; stroke: var(--muted); fill: none; stroke-width: 1.8;
}
.search-wrap input {
  width: 100%; padding: 10px 12px 10px 36px; border: 1px solid var(--line);
  border-radius: 10px; background: #f9fbfc; outline: none;
}
.search-wrap input:focus { border-color: #bfe3dd; background: #fff; box-shadow: 0 0 0 3px rgba(15,118,110,.08); }

.category-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 16px 4px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 12px; font-size: 12px; color: var(--muted);
}
.chip.active { background: var(--teal-soft); border-color: #bfe3dd; color: var(--teal-dark); font-weight: 600; }

/* ---------- product grid ---------- */
.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; padding: 12px 16px 16px;
}
.product-card {
  text-align: left; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; padding: 10px 11px; display: flex; flex-direction: column; gap: 4px;
  min-height: 84px;
}
.product-card:hover { border-color: #bfe3dd; box-shadow: 0 2px 10px rgba(15,118,110,.08); }
.product-card:active { transform: scale(.985); }
.product-card .nm { font-weight: 600; font-size: 13px; line-height: 1.3; }
.product-card .cat { font-size: 11px; color: var(--muted); }
.product-card .pr { margin-top: auto; font-size: 15px; font-weight: 700; color: var(--teal-dark); }
.product-card .bc { font-size: 10px; color: #9aa9b8; font-variant-numeric: tabular-nums; }

.empty-hint { padding: 26px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- cart ---------- */
.cart-panel { display: flex; flex-direction: column; max-height: calc(100vh - 120px); position: sticky; top: 78px; }
.link-btn { border: 0; background: none; color: var(--teal); font-size: 12px; padding: 4px; }
.link-btn:hover { text-decoration: underline; }

.cart-items { flex: 1; overflow-y: auto; padding: 8px 12px; min-height: 120px; }
.cart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 26px 0; }

.cart-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  padding: 8px 4px; border-bottom: 1px dashed var(--line);
}
.cart-row:last-child { border-bottom: 0; }
.cart-name { font-size: 13px; font-weight: 600; }
.cart-sub { font-size: 11px; color: var(--muted); }
.qty-box { display: flex; align-items: center; gap: 2px; }
.qty-box button {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: #fff;
  color: var(--muted); line-height: 1;
}
.qty-box button:hover { border-color: #bfe3dd; color: var(--teal); }
.qty-val { min-width: 26px; text-align: center; font-size: 13px; font-weight: 600; }
.cart-amount { min-width: 62px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.totals { padding: 10px 16px; border-top: 1px solid var(--line); background: #fbfcfd; }
.sum-row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; color: var(--muted); }
.sum-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.sum-row.total { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 15px; color: var(--text); font-weight: 600; }
.sum-row.total b { font-size: 20px; color: var(--teal-dark); }

.customer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: #fff; color: var(--text);
}
.field input:focus { border-color: #bfe3dd; box-shadow: 0 0 0 3px rgba(15,118,110,.08); }

.pay-row { padding: 0 16px 8px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #f4f7f9; border-radius: 10px; padding: 4px; }
.segmented button { border: 0; background: transparent; padding: 7px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.segmented button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(16,40,55,.1); }

.cash-row { padding: 0 16px 10px; display: grid; gap: 8px; }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; }
.quick-cash button {
  flex: 1; min-width: 46px; padding: 6px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; font-size: 12px; color: var(--muted);
}
.quick-cash button:hover { border-color: #bfe3dd; color: var(--teal); }
.change-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding-top: 2px; }
.change-row b { color: var(--teal-dark); font-size: 16px; font-variant-numeric: tabular-nums; }

.checkout-btn {
  margin: 0 16px 16px; padding: 13px; border: 0; border-radius: 10px;
  background: linear-gradient(150deg, #13948a, #0b5550); color: #fff; font-size: 15px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(15,118,110,.22);
}
.checkout-btn:hover { filter: brightness(1.05); }
.checkout-btn:disabled { opacity: .55; box-shadow: none; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fbfcfd;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid #f0f4f7; vertical-align: middle; }
.data-table tbody tr:hover { background: #fafcfd; }
.data-table .num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.bc-cell { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); white-space: nowrap; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.mini-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 7px;
  padding: 4px 9px; font-size: 12px; color: var(--muted);
}
.mini-btn:hover { border-color: #bfe3dd; color: var(--teal); }
.mini-btn.danger:hover { border-color: #f6c9c9; color: var(--danger); background: var(--danger-soft); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; white-space: nowrap; }
.pill.ok { background: var(--teal-soft); color: var(--teal-dark); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.off { background: #f1f4f7; color: var(--muted); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 14px 16px; }
.stat { background: #fbfcfd; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

input[type="date"], #product-filter, .date-input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; font-size: 13px;
}
input[type="date"]:focus, #product-filter:focus { border-color: #bfe3dd; }

/* ---------- buttons ---------- */
.primary-btn {
  border: 0; border-radius: 9px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  background: var(--teal); color: #fff;
}
.primary-btn:hover { background: var(--teal-dark); }
.ghost-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 8px 14px; font-size: 13px; color: var(--muted);
}
.ghost-btn:hover { border-color: #bfe3dd; color: var(--teal); }
.danger-btn {
  border: 0; border-radius: 9px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  background: var(--danger); color: #fff;
}
.danger-btn:hover { filter: brightness(.94); }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(14, 30, 40, .42);
  display: grid; place-items: center; padding: 20px; z-index: 40;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--card); border-radius: 14px; box-shadow: 0 24px 60px rgba(10,30,45,.28);
  width: min(720px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } to { opacity: 1; transform: none; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.close-x { border: 0; font-size: 20px; line-height: 1; color: var(--muted); background: none; }
.close-x:hover { color: var(--danger); }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); align-items: center; }
.modal-foot .hint { margin: 0 auto 0 0; }

.form-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px 18px; overflow-y: auto; }
.form-body label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.form-body input, .form-body select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: #fff; color: var(--text);
}
.form-body input:focus, .form-body select:focus { border-color: #bfe3dd; box-shadow: 0 0 0 3px rgba(15,118,110,.08); }
.span2 { grid-column: span 2; }
.form-body .modal-foot { grid-column: span 2; padding: 6px 0 0; border-top: 1px solid var(--line); margin-top: 4px; }

.queue-box, .data-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fbfcfd; }
.queue-line { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.queue-line b { color: var(--amber); }
.queue-line .ghost-btn { margin-left: auto; }
.data-box h4 { margin: 0 0 4px; font-size: 13px; }
.data-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.usage-line { display: flex; gap: 8px; font-size: 12px; color: var(--muted); }
.hint { font-size: 11px; color: var(--muted); }

.confirm-modal { width: min(420px, 100%); }
.confirm-modal p { margin: 0; color: var(--muted); }

/* ---------- ticket ---------- */
.ticket-modal { width: min(420px, 100%); }
.ticket-body { padding: 16px 18px; overflow-y: auto; background: #fcfcfb; }
.ticket { background: #fff; border: 1px solid #e8e8e3; border-radius: 6px; padding: 18px 18px 14px; font-size: 12px; color: #14181c; }
.ticket-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 10px; border-bottom: 1px dashed #c8c8c0; }
.ticket-head .left, .ticket-head .right { display: flex; flex-direction: column; gap: 2px; }
.ticket-head .right { text-align: right; }
.ticket-head b { font-size: 13px; }
.ticket-head span { color: #4b5359; font-size: 11px; }
.ticket-meta { display: flex; justify-content: space-between; padding: 8px 0; font-size: 11px; color: #4b5359; }
.ticket-items { padding: 4px 0 8px; border-top: 1px dashed #c8c8c0; }
.ticket-line { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding: 2px 0; }
.ticket-line .q { color: #4b5359; min-width: 26px; text-align: right; }
.ticket-line .a { min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.ticket-sums { border-top: 1px dashed #c8c8c0; padding-top: 8px; }
.ticket-sums .trow { display: flex; justify-content: space-between; font-size: 11px; color: #4b5359; padding: 1px 0; }
.ticket-sums .grand { font-size: 15px; font-weight: 700; color: #14181c; padding-top: 4px; }
.ticket-foot { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 12px; padding-top: 8px; border-top: 1px dashed #c8c8c0; font-size: 10px; color: #6b7378; gap: 10px; }
.ticket-qr { width: 82px; height: 82px; flex: none; }
.hash-line { margin-top: 6px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #17252f; color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(10,25,35,.3); z-index: 60;
}
.toast[hidden] { display: none; }
.toast.err { background: #8f1d1d; }

/* ---------- print ---------- */
@media print {
  body { background: #fff; }
  .topbar, main, .modal-foot, .toast, .modal-head { display: none !important; }
  .modal-backdrop { position: static; background: none; padding: 0; display: block; backdrop-filter: none; }
  .modal { box-shadow: none; width: auto; max-height: none; }
  .ticket-body { padding: 0; background: #fff; overflow: visible; }
  .ticket { border: 0; padding: 0; width: 80mm; margin: 0 auto; font-size: 11px; }
  #ticket-modal[hidden] { display: none !important; }
  .modal-backdrop:not(#ticket-modal) { display: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  #view-pos.view.active { grid-template-columns: 1fr; }
  .cart-panel { position: static; max-height: none; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .top-right { margin-left: 0; }
  .form-body { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
}

@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; padding: 7px 8px; }
  .panel-head { flex-wrap: wrap; align-items: flex-start; }
  .panel-head h2 { font-size: 14px; }
  .head-tools { width: 100%; flex-wrap: wrap; }
  .head-tools input { flex: 1; min-width: 0; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
  .stat-value { font-size: 16px; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .customer-grid { grid-template-columns: 1fr; }
  .cart-items { max-height: 320px; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .hint { width: 100%; }
}
