/* R-8 Hardware POS — shared styles for the till (index.html) and back office (admin.html).
   Brand colours follow the R-8 website: navy #081226, royal blue #1522E8, accent #2563EB. */
:root {
  --navy: #081226;
  --navy-2: #0f1d3a;
  --royal: #1522e8;
  --accent: #2563eb;
  --bg: #f3f5f9;
  --panel: #ffffff;
  --line: #dde2ec;
  --text: #0e1525;
  --muted: #5b6577;
  --ok: #0f7b3f;
  --ok-bg: #e3f6ea;
  --warn: #8a5300;
  --warn-bg: #fff1d6;
  --bad: #b42318;
  --bad-bg: #fde7e5;
  --info-bg: #e8eeff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(8, 18, 38, .06), 0 4px 16px rgba(8, 18, 38, .06);
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: .75rem; }
.spacer { flex: 1; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .5rem 1rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:hover { border-color: #b9c2d6; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(37, 99, 235, .35); outline-offset: 1px; }
.btn.primary { background: var(--royal); border-color: var(--royal); color: #fff; }
.btn.primary:hover { background: #1019c2; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: .25rem .6rem; font-size: .85rem; }
.btn.big { min-height: 58px; font-size: 1.15rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { min-height: 80px; }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; }
.field { margin-bottom: .75rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 20px; height: 20px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: .45rem .8rem; min-height: 40px; cursor: pointer; font-weight: 600; }
.seg button[aria-pressed=true] { background: var(--navy); color: #fff; }

/* ---------- badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--royal); }

.alert { padding: .7rem .9rem; border-radius: 8px; background: var(--info-bg); border: 1px solid #c9d5ff; }
.alert.warn { background: var(--warn-bg); border-color: #f3d39a; }
.alert.bad { background: var(--bad-bg); border-color: #f5b8b2; }
.alert.ok { background: var(--ok-bg); border-color: #a9dfbf; }

/* ---------- top bar */
.topbar {
  display: flex; align-items: center; gap: .75rem; padding: .5rem 1rem;
  padding-top: calc(.5rem + env(safe-area-inset-top, 0px));
  background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; letter-spacing: .2px; }
.brand img { width: 30px; height: 30px; border-radius: 6px; }
.brand small { font-weight: 500; opacity: .7; }
.topbar .btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.15); color: #fff; min-height: 38px; }
.topbar .btn:hover { background: rgba(255,255,255,.16); }
.conn { display: inline-flex; align-items: center; gap: .45rem; padding: .3rem .7rem; border-radius: 999px; font-weight: 700; font-size: .85rem; border: 0; cursor: pointer; }
.conn::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.conn.online { background: #d9f7e5; color: #0b6a35; }
.conn.offline { background: #ffe1dc; color: #a3180d; }
.conn.syncing { background: #e3e9ff; color: #1522e8; }
.conn.auth { background: #fff0cc; color: #7a4a00; }
.queue-count { background: #fff; color: var(--navy); border-radius: 999px; padding: 0 .45rem; font-size: .8rem; }

/* ---------- POS layout */
.pos { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr); gap: 1rem; padding: 1rem; height: calc(100vh - 58px); height: calc(100dvh - 58px); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.catalog, .cart { display: flex; flex-direction: column; min-height: 0; }
.catalog-head { padding: .75rem; border-bottom: 1px solid var(--line); }
.search { position: relative; }
.search input { min-height: 52px; font-size: 1.1rem; padding-left: 2.6rem; }
.search::before { content: ""; position: absolute; left: .9rem; top: 50%; width: 15px; height: 15px; margin-top: -9px; border: 2.5px solid #8892a6; border-radius: 50%; }
.search::after { content: ""; position: absolute; left: 1.95rem; top: 50%; width: 7px; height: 2.5px; margin-top: 5px; background: #8892a6; transform: rotate(45deg); }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-top: .6rem; scrollbar-width: thin; }
.chip { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .35rem .8rem; cursor: pointer; font-weight: 600; font-size: .85rem; min-height: 34px; }
.chip[aria-pressed=true] { background: var(--navy); color: #fff; border-color: var(--navy); }
.results { overflow-y: auto; padding: .5rem; flex: 1; }
.result { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; width: 100%; text-align: left; padding: .65rem .75rem; border: 1px solid transparent; border-radius: 8px; background: none; cursor: pointer; }
.result:hover, .result:focus-visible { background: #f2f5fb; border-color: var(--line); }
.result .name { font-weight: 650; }
.result .meta { color: var(--muted); font-size: .8rem; }
.result .price { font-weight: 700; text-align: right; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

.cart-head { display: flex; align-items: center; gap: .5rem; padding: .75rem; border-bottom: 1px solid var(--line); }
.cart-lines { flex: 1; overflow-y: auto; }
.line { padding: .6rem .75rem; border-bottom: 1px solid #eef1f6; }
.line-top { display: flex; gap: .5rem; align-items: baseline; }
.line-top .name { font-weight: 650; flex: 1; min-width: 0; }
.line-ctrl { display: grid; grid-template-columns: 110px 96px 1fr auto; gap: .4rem; align-items: center; margin-top: .4rem; }
.line-ctrl input, .line-ctrl select { min-height: 40px; padding: .3rem .5rem; }
.line-note { font-size: .78rem; margin-top: .25rem; }
.totals { padding: .75rem; border-top: 1px solid var(--line); background: #fafbfd; border-radius: 0 0 var(--radius) var(--radius); }
.totals table { width: 100%; border-collapse: collapse; }
.totals td { padding: .15rem 0; }
.totals .grand td { font-size: 1.4rem; font-weight: 800; padding-top: .4rem; }

/* ---------- modal */
.modal-back { position: fixed; inset: 0; background: rgba(8, 18, 38, .55); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: calc(100dvh - 2rem); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(900px, 100%); }
.modal-head { display: flex; align-items: center; gap: .5rem; padding: 1rem 1.1rem .5rem; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: .5rem 1.1rem 1.1rem; }
.modal-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .75rem 1.1rem 1.1rem; flex-wrap: wrap; }

.toast-wrap { position: fixed; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 60; width: min(480px, calc(100% - 2rem)); }
.toast { background: var(--navy); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- auth screens */
.center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: radial-gradient(1200px 600px at 20% -10%, #1b2c5a, var(--navy)); }
.card { background: #fff; border-radius: 14px; padding: 1.5rem; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.card .brand { color: var(--navy); margin-bottom: 1rem; font-size: 1.2rem; }

/* ---------- tables (queue, history, admin) */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: .55rem .5rem; border-bottom: 1px solid #eef1f6; vertical-align: top; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #f6f8fc; }

/* ---------- payments */
.pay-methods { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.pay-methods .btn[aria-pressed=true] { background: var(--navy); color: #fff; border-color: var(--navy); }
.quick-cash { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.big-total { font-size: 2rem; font-weight: 800; text-align: center; padding: .5rem 0; }

/* ---------- receipt */
.receipt { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; line-height: 1.35; width: 80mm; max-width: 100%; margin: 0 auto; padding: 4mm; background: #fff; color: #000; border: 1px dashed #ccc; }
.receipt.w58 { width: 58mm; font-size: 10.5px; }
.receipt .c { text-align: center; }
.receipt .b { font-weight: 700; }
.receipt .r { display: flex; justify-content: space-between; gap: 8px; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; }
.receipt .big { font-size: 1.3em; font-weight: 700; }
.saved-state { text-align: center; margin-bottom: .75rem; }

/* ---------- admin */
.admin { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 54px); }
.side { background: #fff; border-right: 1px solid var(--line); padding: .75rem; }
.side button { display: flex; width: 100%; justify-content: space-between; align-items: center; text-align: left; padding: .6rem .75rem; border: 0; border-radius: 8px; background: none; cursor: pointer; font-weight: 600; min-height: 42px; }
.side button[aria-current=page] { background: var(--info-bg); color: var(--royal); }
.main { padding: 1.25rem; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { padding: .9rem 1rem; }
.kpi .v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.section { padding: 1rem; margin-bottom: 1rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
pre.json { background: #f6f8fc; padding: .6rem; border-radius: 8px; font-size: .8rem; overflow-x: auto; max-height: 260px; }

/* ---------- responsive */
@media (max-width: 900px) {
  .pos { grid-template-columns: 1fr; height: auto; }
  .catalog .results { max-height: 45vh; }
  .admin { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); gap: .25rem; }
  .side button { width: auto; flex: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .topbar .hide-sm { display: none; }
}
@media (max-width: 480px) {
  .line-ctrl { grid-template-columns: 1fr 1fr; }
}

/* ---------- printing: only the receipt */
@media print {
  @page { margin: 0; size: auto; }
  body * { visibility: hidden !important; }
  #print-area, #print-area * { visibility: visible !important; }
  #print-area { position: absolute; left: 0; top: 0; }
  #print-area .receipt { border: 0; }
}

@media screen { #print-area { display: none; } }
