:root {
  --navy: #1d2d6b; --navy-2: #24387f; --red: #c8102e; --blue: #2a7de1; --green: #1f9d55;
  --bg: #f3f5fa; --card: #fff; --line: #e1e5ef; --muted: #6b7491; --text: #17213f;
  --radius: 14px; --shadow: 0 2px 10px rgba(29, 45, 107, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Inter", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg);
  display: flex; flex-direction: column; -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: ui-monospace, monospace; font-size: .8em; }

/* header */
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: #fff; border-bottom: 3px solid var(--navy);
  position: sticky; top: 0; z-index: 20; padding-top: max(8px, env(safe-area-inset-top)); }
.brand img { height: 40px; display: block; }
.event-chip { background: var(--bg); color: var(--navy); border-radius: 999px; padding: 5px 12px; font-size: .85rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.nav a { color: var(--navy); text-decoration: none; font-weight: 600; padding: 8px 11px; white-space: nowrap; border-radius: 10px; font-size: .95rem; }
.nav a.on, .nav a:hover { background: var(--navy); color: #fff; }
.nav-logout { color: var(--muted) !important; font-weight: 500 !important; }
.nav-logout:hover { background: var(--bg) !important; }
.gw-badge { font-size: .75rem; font-weight: 700; padding: 5px 10px; border-radius: 999px; color: #fff; white-space: nowrap; }
.gw-stripe { background: #635bff; } .gw-nmi { background: #0b8a5a; } .gw-tsys { background: #0072ce; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.6rem; color: var(--navy); margin-left: 4px; }

.flash-wrap { padding: 10px 16px 0; }
.flash { padding: 10px 14px; border-radius: 10px; background: #e7f6ee; color: #10603a; font-weight: 500; }
.flash-error { background: #fdecee; color: var(--red); }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 16px; }

.page { padding: 18px 20px; max-width: 1200px; width: 100%; margin: 0 auto; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
h1 { color: var(--navy); margin: 0; font-size: 1.6rem; }
h2 { color: var(--navy); font-size: 1.1rem; margin: 0 0 10px; }
h3 { color: var(--navy); font-size: 1rem; margin: 14px 0 6px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 1rem; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-lg { padding: 16px 22px; font-size: 1.1rem; }
.btn-block { width: 100%; margin-top: 10px; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-card { background: var(--blue); color: #fff; }
.btn-cash { background: var(--green); color: #fff; }
.btn-danger { background: #fff; color: var(--red); border: 2px solid var(--red); }
.btn-ghost { background: #fff; color: var(--navy); border: 2px solid var(--line); }
.btn-plain { background: var(--bg); color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--red); font-weight: 600; }

/* login */
.login-body main { display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { margin-bottom: 4px; }
#pin { position: absolute; opacity: 0; pointer-events: none; }
.pin-dots { height: 34px; display: flex; justify-content: center; gap: 12px; align-items: center; margin: 10px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; background: var(--navy); }
.pin-error { color: var(--red); font-weight: 600; margin-bottom: 8px; }
.pinpad, .keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pinpad button, .keypad button { border: 0; background: var(--bg); border-radius: 14px; font-size: 1.5rem; font-weight: 700; color: var(--navy); padding: 16px 0; }
.pinpad button:active, .keypad button:active { background: #dde3f2; }
.pinpad .pk-alt { font-size: 1rem; color: var(--muted); }
.pinpad .pk-go { background: var(--navy); color: #fff; font-size: 1.05rem; }

/* register */
.register-body { height: 100dvh; overflow: hidden; }
.register { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; }
.catalog { display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 14px 16px 0; }
.cat-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.cat-tabs button { border: 0; background: #fff; color: var(--navy); font-weight: 700; padding: 10px 18px; border-radius: 999px; white-space: nowrap; box-shadow: var(--shadow); }
.cat-tabs button.on { background: var(--navy); color: #fff; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; overflow-y: auto; padding-bottom: 16px; align-content: start; }
.tile { --tile: var(--navy); border: 0; border-radius: var(--radius); background: #fff; min-height: 110px; padding: 14px; text-align: left;
  display: flex; flex-direction: column; justify-content: space-between; box-shadow: var(--shadow); border-top: 6px solid var(--tile); transition: transform .1s; }
.tile.bump { transform: scale(.95); }
.tile-name { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.tile-price { font-weight: 800; color: var(--tile); font-size: 1.1rem; }
.cart { background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.cart-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.cart-head h2 { margin: 0; }
.cart-close { display: none; color: var(--muted); font-size: 1.8rem; line-height: 1; }
.cart-lines { list-style: none; margin: 0; padding: 0 16px; flex: 1; overflow-y: auto; }
.cart-lines li { display: grid; grid-template-columns: 1fr auto 70px; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cart-lines li.empty { display: block; text-align: center; color: var(--muted); border: 0; padding: 40px 0; }
.cl-name { font-weight: 600; } .cl-name small { display: block; color: var(--muted); font-weight: 400; }
.cl-total { text-align: right; font-weight: 700; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--bg); color: var(--navy); font-size: 1.2rem; font-weight: 700; }
.qty span { min-width: 20px; text-align: center; font-weight: 700; }
.cart-totals { padding: 10px 16px; border-top: 2px solid var(--line); }
.cart-totals div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.cart-totals .grand { color: var(--navy); font-size: 1.4rem; font-weight: 800; padding-top: 6px; }
.pay-btns { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; padding: 0 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.pay-btns .btn { padding: 18px; font-size: 1.15rem; }
.cart-bar { display: none; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15, 22, 52, .55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 20px; width: 100%; max-width: 440px; max-height: 96dvh; overflow-y: auto; padding: 18px; }
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.m-head h3 { margin: 0; font-size: 1.15rem; }
.m-head .x { background: none; border: 0; font-size: 1.8rem; color: var(--muted); line-height: 1; }
.big-amount { text-align: center; font-size: 2.6rem; font-weight: 800; color: var(--navy); margin: 12px 0; }
.big-amount small { display: block; font-size: .85rem; color: var(--muted); font-weight: 500; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.quick button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 0; font-weight: 700; color: var(--navy); }
.keypad button { padding: 12px 0; font-size: 1.3rem; }
.tip-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tip-opts .btn { padding: 18px 8px; font-size: 1.05rem; }
.reader { text-align: center; background: var(--bg); border-radius: 16px; padding: 18px; margin-bottom: 12px; }
.reader strong { display: block; color: var(--navy); font-size: 1.1rem; }
.reader small { color: var(--muted); }
.reader-anim { position: relative; height: 70px; display: flex; justify-content: center; align-items: center; }
.card-ico { width: 64px; height: 42px; border-radius: 7px; background: linear-gradient(135deg, var(--navy), var(--blue)); animation: tap 1.6s ease-in-out infinite; box-shadow: 0 6px 14px rgba(29,45,107,.3); }
.wave { position: absolute; width: 90px; height: 90px; border: 3px solid var(--blue); border-radius: 50%; opacity: 0; animation: wave 1.6s ease-out infinite; }
@keyframes tap { 0%, 100% { transform: translateY(-8px) rotate(-8deg); } 50% { transform: translateY(4px) rotate(-8deg); } }
@keyframes wave { 0% { transform: scale(.4); opacity: .8; } 100% { transform: scale(1.2); opacity: 0; } }
.entry-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.entry-btns .btn-card { grid-column: 1 / -1; }
.entry-btns .btn-ghost { padding: 10px 4px; font-size: .9rem; }
.entry-btns [data-e=keyed] { grid-column: 1 / -1; }
.gw-line { text-align: center; color: var(--muted); font-size: .85rem; margin: 12px 0 0; }
.keyed label { display: block; font-weight: 600; color: var(--navy); margin-bottom: 10px; font-size: .9rem; }
.keyed input, .field input, .field select, .search input, .send-row input {
  display: block; width: 100%; margin-top: 4px; padding: 12px; border: 2px solid var(--line); border-radius: 10px; font-size: 1rem; font-family: inherit; background: #fff; }
.keyed input:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--blue); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cash-due, .cash-rec, .cash-change { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 4px; }
.cash-due strong { font-size: 2rem; color: var(--navy); }
.cash-rec strong { font-size: 1.4rem; }
.cash-change { border-top: 2px solid var(--line); margin-top: 8px; }
.cash-change strong { font-size: 1.6rem; color: var(--green); }
.processing, .declined { text-align: center; padding: 30px 10px; }
.processing strong { display: block; font-size: 1.2rem; color: var(--navy); margin-top: 16px; }
.spinner { width: 54px; height: 54px; border: 5px solid var(--line); border-top-color: var(--blue); border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.x-mark { width: 60px; height: 60px; border-radius: 50%; background: var(--red); color: #fff; font-size: 2rem; font-weight: 800; display: flex; align-items: center; justify-content: center; margin: 0 auto; }

/* receipt */
.receipt-layout { display: grid; grid-template-columns: 340px 1fr; gap: 24px; align-items: start; }
.receipt { background: #fff; width: 100%; max-width: 340px; padding: 18px 16px; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .85rem;
  box-shadow: var(--shadow); border-radius: 4px; margin: 0 auto; }
.r-logo { display: block; width: 70%; margin: 0 auto 8px; }
.r-center { text-align: center; } .r-line { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.r-total { font-weight: 800; font-size: 1.05rem; }
.r-status { text-align: center; font-weight: 800; color: var(--red); border: 2px solid var(--red); margin: 8px 0; padding: 4px; }
.receipt hr { border: 0; border-top: 1px dashed #999; margin: 8px 0; }
.receipt-actions { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
.done-banner { display: flex; gap: 14px; align-items: center; background: #e7f6ee; border-radius: var(--radius); padding: 16px; font-size: 1.1rem; }
.done-check { width: 52px; height: 52px; border-radius: 50%; background: var(--green); color: #fff; font-size: 1.8rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-form { background: #fff; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.send-form label { font-weight: 700; color: var(--navy); }
.send-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; } .send-row input { margin: 0; }
.print-only { display: none; }
@media print {
  @page { size: 58mm auto; margin: 0; }
  body.printing > *:not(.print-only) { display: none !important; }
  body.printing .print-only { display: block; }
  body.printing .receipt { box-shadow: none; width: 58mm; max-width: none; padding: 2mm; font-size: 9pt; }
}

/* tables / reports */
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: .92rem; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table .num { text-align: right; white-space: nowrap; }
.clickable { cursor: pointer; } .clickable:hover { background: #f8f9fd; }
.tag { background: var(--bg); color: var(--navy); font-size: .7rem; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.status { font-size: .78rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.status-paid { background: #e7f6ee; color: #10603a; } .status-refunded, .status-voided { background: #fdecee; color: var(--red); }
.search { display: flex; gap: 8px; } .search input { margin: 0; min-width: 240px; }
.seg { display: inline-flex; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 4px; }
.seg a { padding: 8px 14px; border-radius: 9px; text-decoration: none; color: var(--navy); font-weight: 600; }
.seg a.on { background: var(--navy); color: #fff; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-left: 5px solid var(--navy); }
.kpi span { color: var(--muted); font-size: .85rem; display: block; } .kpi strong { font-size: 1.6rem; color: var(--navy); }
.kpi-warn { border-left-color: var(--red); }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.report-grid .card h2 + .table { margin-bottom: 16px; }

/* settings */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; }
.field { display: block; font-weight: 600; color: var(--navy); font-size: .9rem; margin-bottom: 8px; }
.field small { display: block; color: var(--muted); font-weight: 400; margin-top: 4px; }
.field ul.errorlist { color: var(--red); margin: 4px 0 0; padding-left: 18px; font-weight: 500; }
.field-check { display: flex; align-items: center; gap: 10px; }
.field-check input { width: 22px; height: 22px; margin: 0; order: -1; }
.gw-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.gw-option input { position: absolute; opacity: 0; }
.gw-card { display: flex; flex-direction: column; gap: 4px; border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; height: 100%; }
.gw-card strong { font-size: 1.15rem; color: var(--navy); }
.gw-card small { color: var(--muted); }
.gw-card em { font-style: normal; font-size: .78rem; font-weight: 700; margin-top: 4px; }
.gw-card em.ok { color: var(--green); } .gw-card em.todo { color: var(--muted); }
.gw-option input:checked + .gw-card { border-color: var(--blue); background: #f2f7fe; box-shadow: 0 0 0 3px rgba(42,125,225,.15); }
.sticky-save { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.dev-info { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0 0 16px; }
.dev-info dt { color: var(--muted); } .dev-info dd { margin: 0; font-weight: 600; word-break: break-word; }

/* ---------- tablet ---------- */
@media (max-width: 1240px) { .event-chip { display: none; } }
@media (max-width: 1000px) {
  .register { grid-template-columns: minmax(0, 1fr) 320px; }
  .event-chip { display: none; }
}
/* ---------- handheld (SUNMI P3 Mix, phones) ---------- */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 6px 10px; }
  .brand img { height: 32px; }
  .menu-btn { display: block; }
  .gw-badge { margin-left: auto; }
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: #fff; flex-direction: column; align-items: stretch;
    padding: 8px; border-bottom: 3px solid var(--navy); box-shadow: 0 10px 20px rgba(0,0,0,.1); }
  .nav.open { display: flex; }
  .nav a { padding: 14px; font-size: 1.05rem; }
  .register { grid-template-columns: minmax(0, 1fr); }
  .catalog { padding: 10px 10px 0; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 90px; }
  .tile { min-height: 96px; }
  .cart { position: fixed; inset: 0; z-index: 30; transform: translateY(100%); transition: transform .25s ease; border: 0; }
  body.cart-open .cart { transform: none; }
  .cart-close { display: block; }
  .cart-bar { display: flex; position: fixed; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 25; border: 0; border-radius: 16px;
    background: var(--muted); color: #fff; padding: 16px 18px; font-size: 1.05rem; align-items: center; justify-content: space-between; gap: 10px;
    box-shadow: 0 8px 20px rgba(29,45,107,.35); }
  .cart-bar.has-items { background: var(--navy); }
  .cart-bar strong { font-size: 1.25rem; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: 20px 20px 0 0; max-width: none; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .big-amount { font-size: 2.2rem; margin: 8px 0; }
  .page { padding: 12px; }
  .receipt-layout { grid-template-columns: 1fr; }
  .receipt-actions { max-width: none; order: -1; }
  .search input { min-width: 0; }
  .table th:nth-child(3), .table td:nth-child(3), .table th:nth-child(5), .table td:nth-child(5) { display: none; }
}

/* device sign-in / event picker */
.stack-form { display: grid; gap: 12px; text-align: left; }
.stack-form label { display: grid; gap: 5px; font-weight: 600; color: var(--navy); font-size: .9rem; }
.stack-form input, .stack-form select, .row-gap select { font: inherit; padding: 12px; border: 2px solid var(--line); border-radius: 10px; background: #fff; }
.stack-form label.check { display: flex; align-items: center; gap: 8px; }
.login-card.wide { max-width: 480px; }
.event-list { display: grid; gap: 10px; margin: 14px 0; }
.event-btn { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 16px; text-align: left; display: grid; gap: 3px; }
.event-btn strong { color: var(--navy); font-size: 1.1rem; }
.event-btn small { color: var(--muted); }
.event-btn.on, .event-btn:hover { border-color: var(--navy); }
a.event-chip { text-decoration: none; }
.cat-tabs button.on { background: var(--tab, var(--navy)); }
.tile-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; }
.tile-stock { font-size: .75rem; font-weight: 700; color: var(--muted); background: var(--bg); border-radius: 999px; padding: 2px 8px; }
.tile.sold-out { opacity: .45; }
.tip-opts .btn small { display: block; font-size: .75rem; font-weight: 500; color: var(--muted); }
.tip-opts .btn { flex-direction: column; gap: 2px; }
.tip-opts .round { border-color: var(--green); color: var(--green); }
.tip-opts .no-thanks { grid-column: 1 / -1; }
.hosted { min-height: 44px; border: 2px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; }
.hq-match { margin: 6px 0 0; font-size: .9rem; color: #10603a; }
td.low { color: var(--red); font-weight: 700; }

/* screen editor */
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.ed-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.ed-tab button { border: 0; background: var(--bg); color: var(--navy); font-weight: 700; padding: 10px 16px; border-radius: 999px; cursor: grab; }
.ed-tab.on button { background: var(--tab, var(--navy)); color: #fff; }
.ed-tiles { max-height: none; margin-bottom: 12px; }
.ed-tiles .tile { cursor: grab; }
.ed-tiles .tile.sel { outline: 3px solid var(--blue); }
.ed-tiles .hidden-item { opacity: .5; }
.dragging { opacity: .4; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } }
