:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --key: #f8fafc;
  --key-fn: #e2e8f0;
  --primary: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --topbar: #1f2937;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2937;
    --key: #1f2937;
    --key-fn: #374151;
    --topbar: #030712;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button {
  font: inherit;
  color: inherit;
  border: 1px solid var(--border);
  background: var(--key);
  border-radius: var(--radius);
  padding: .6rem 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.ghost { background: transparent; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .6rem;
  width: 100%;
  user-select: text;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--topbar); color: #fff;
  padding: .5rem 1rem;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.topbar button { color: #fff; border-color: #374151; padding: .4rem .8rem; }
.status { font-size: .8rem; padding: .2rem .6rem; border-radius: 999px; background: #374151; }
.status.ok { background: var(--ok); }
.status.warn { background: var(--warn); }
.status.sim { background: #6b21a8; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  height: calc(100% - 52px);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex; flex-direction: column;
  min-height: 0;
}
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem 0 .5rem; }
.receipt .section-title { margin-top: 0; }

.display {
  background: #0f172a; color: #4ade80;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.display-qty { min-height: 1.2em; font-size: 1rem; color: #a3e635; }
.display-amount { font-size: 2.6rem; font-weight: 700; }

.keypad {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
  margin-top: .75rem;
}
.keypad button { font-size: 1.5rem; font-weight: 600; padding: .9rem 0; }
.keypad .key-fn { background: var(--key-fn); font-size: 1.2rem; }
.keypad .key-clear { background: var(--danger); border-color: var(--danger); color: #fff; }

.categories {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .5rem;
  overflow: auto;
}
.cat {
  --cat: #475569;
  background: var(--cat); border-color: var(--cat); color: #fff;
  min-height: 72px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.05rem;
}
.cat-dep { font-size: .75rem; font-weight: 400; opacity: .85; }

.lines { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.lines li {
  display: grid; grid-template-columns: 10px 1fr auto auto; grid-template-rows: auto auto;
  column-gap: .6rem; align-items: center;
  padding: .5rem 0; border-bottom: 1px dashed var(--border);
}
.lines .dot { width: 10px; height: 10px; border-radius: 50%; grid-row: 1 / 3; }
.lines .desc { font-weight: 600; }
.lines .qty { grid-column: 2; grid-row: 2; font-size: .8rem; color: var(--muted); }
.lines .price { grid-column: 3; grid-row: 1 / 3; font-variant-numeric: tabular-nums; font-weight: 600; }
.lines .remove { grid-column: 4; grid-row: 1 / 3; padding: .2rem .55rem; background: transparent; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; flex: 1; }
.empty[hidden] { display: none; }

.total-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 1.6rem; font-weight: 800;
  border-top: 2px solid var(--text); padding-top: .6rem; margin-top: .5rem;
  font-variant-numeric: tabular-nums;
}
.pay-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .75rem 0 .5rem; }
.pay { font-size: 1.2rem; font-weight: 700; padding: 1.1rem 0; color: #fff; }
.pay.cash { background: var(--ok); border-color: var(--ok); }
.pay.card { background: var(--primary); border-color: var(--primary); }
.danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }

dialog {
  border: none; border-radius: var(--radius); padding: 0;
  background: var(--panel); color: var(--text);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}
dialog:has(.wide) { width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dlg { padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.dlg h2 { margin: 0; font-size: 1.25rem; }
.dlg h3 { margin: .5rem 0 0; font-size: 1rem; }
.dlg label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.dlg label.check { flex-direction: row; align-items: flex-start; gap: .5rem; }
.dlg label.check input { width: auto; margin-top: .2rem; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.dlg pre {
  background: #0f172a; color: #e2e8f0; padding: .75rem; border-radius: 8px;
  font-size: .8rem; overflow: auto; max-height: 50vh; white-space: pre-wrap; word-break: break-all;
  user-select: text;
}
fieldset { border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; gap: .6rem; }
legend { font-weight: 700; padding: 0 .3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.hint { margin: 0; font-size: .85rem; color: var(--muted); }
.row-actions { display: flex; gap: .5rem; }
.cat-editor { display: flex; flex-direction: column; gap: .4rem; }
.cat-row, .pay-row, .vat-row { display: grid; gap: .4rem; align-items: center; }
.cat-row { grid-template-columns: 48px minmax(0, 1fr) 80px 140px 40px; }
.pay-row { grid-template-columns: minmax(0, 1fr) 80px 80px 40px; }
.vat-row { grid-template-columns: 80px 100px minmax(0, 1fr) 40px; }
.cat-row input[type=color] { padding: 2px; height: 40px; }
.pay-row input[type=checkbox] { width: 22px; height: 22px; justify-self: center; }
.cat-row button, .pay-row button, .vat-row button { padding: .4rem; }
.editor-head { font-size: .75rem; color: var(--muted); }
.editor-head.pay-row span:nth-child(3) { text-align: center; }
.pay.span2 { grid-column: 1 / -1; }
.quick-cash { display: flex; flex-wrap: wrap; gap: .4rem; }
.quick-cash button { padding: .5rem .7rem; }
.change { font-size: 1.2rem; margin: 0; }
.report-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.summary div { display: flex; justify-content: space-between; padding: .2rem 0; border-bottom: 1px dashed var(--border); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: #111827; color: #fff; padding: .75rem 1.25rem; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); z-index: 10; max-width: calc(100vw - 32px);
}
.toast.ok { background: var(--ok); }
.toast.warn { background: var(--warn); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .lines { max-height: 40vh; }
  .grid2, .report-buttons { grid-template-columns: 1fr; }
  .cat-row { grid-template-columns: 40px minmax(0, 1fr) 64px 40px; }
  .cat-row .c-vat { grid-column: 2 / 4; }
  .editor-head.cat-row { display: none; }
}

.advanced { border-top: 1px dashed var(--border); padding-top: .6rem; display: flex; flex-direction: column; gap: .6rem; }
.advanced[open] { gap: .6rem; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.advanced > * + * { margin-top: .6rem; }

.link-banner {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  margin: 1rem 1rem 0; padding: .75rem 1rem;
  background: #fef3c7; color: #78350f; border: 1px solid #f59e0b; border-radius: var(--radius);
}
.link-banner[hidden] { display: none; }
.link-banner-actions { display: flex; gap: .5rem; }
.link-banner .ghost { border-color: #d97706; }
@media (prefers-color-scheme: dark) {
  .link-banner { background: #451a03; color: #fde68a; border-color: #b45309; }
}
