:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #14213d;
  --muted: #5b6475;
  --border: #d9dde5;
  --brand: #14213d;
  --brand-text: #ffffff;
  --accent: #f5a524;
  --good: #137a4b;
  --bad: #b3261e;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --bad-bg: #fde8e6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #1a2130;
    --text: #eef0f4;
    --muted: #a3acbd;
    --border: #323b4d;
    --brand: #f5a524;
    --brand-text: #14213d;
    --good: #4cc38a;
    --bad: #ff8a80;
    --warn-bg: #3a2f10;
    --warn-text: #ffdf91;
    --bad-bg: #3d1a18;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.25rem; }
h2 { margin-bottom: 8px; font-size: 1.05rem; }
h3 { margin-bottom: 4px; font-size: 1rem; }
a { color: inherit; }

.page {
  display: grid;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.page-wide { max-width: 1100px; }

.page-header, .app-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-bar h1 { overflow-wrap: anywhere; }
.app-bar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.app-bar-actions .button { width: auto; min-height: 40px; padding: 6px 12px; margin: 0; }

.card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card > :last-child { margin-bottom: 0; }

.sub-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.stack { display: grid; gap: 12px; min-width: 0; }
.stack > * { margin-bottom: 0; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row .button { flex: 1 1 auto; width: auto; margin: 0; }
.row input { flex: 1 1 140px; width: auto; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row-between .button { flex: none; width: auto; min-height: 40px; padding: 6px 12px; margin: 0; }
.branch-row .input-small { flex: 0 1 80px; }

.muted { color: var(--muted); }
.block { display: block; font-weight: 400; font-size: 0.875rem; }
.preserve { white-space: pre-wrap; margin: 0; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.status { min-height: 1.5em; margin: 0; }

.pill {
  padding: 2px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: 0.875rem;
  white-space: nowrap;
}

.pill[data-state="online"] { color: var(--good); }
.pill[data-state="offline"] { color: var(--bad); }

.button {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button-primary {
  background: var(--brand);
  color: var(--brand-text);
  border-color: var(--brand);
}

.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button + .button { margin-top: 8px; }
.stack > .button + .button,
.row > .button + .button,
.app-bar-actions > .button + .button { margin-top: 0; }

input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

input[type="checkbox"], input[type="radio"] { width: 20px; min-height: 20px; flex: none; }

.field { display: grid; gap: 4px; }
.field-label { font-weight: 600; }
.field-hint { color: var(--muted); font-size: 0.875rem; }
.check { display: flex; align-items: center; gap: 10px; min-height: 32px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); }

.tab {
  flex: none;
  white-space: nowrap;
  min-height: 44px;
  padding: 8px 16px;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 3px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

.list { display: grid; gap: 8px; }

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.banner { margin: 0; padding: 12px; background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; }
.banner-bad { background: var(--bad-bg); color: var(--bad); }
.notice-button { width: 100%; border: 0; font: inherit; font-weight: 600; text-align: left; cursor: pointer; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.pad-key {
  min-height: 56px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
}

.pad-display {
  display: block;
  min-height: 56px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: right;
  overflow-wrap: anywhere;
}

.letter-keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.letter-keys .pad-key { min-height: 44px; font-size: 1rem; }

.dialog {
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog > * + * { margin-top: 12px; }

.sale-columns { display: grid; gap: 16px; align-items: start; }
.cart-line { display: grid; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.cart-line .button { min-height: 40px; padding: 6px 10px; }

.total-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.total-amount { font-size: 1.5rem; }
.change-due { margin: 0; padding: 16px; background: var(--warn-bg); color: var(--warn-text); border-radius: 12px; font-size: 1.5rem; font-weight: 700; text-align: center; }
.logo-preview { max-width: 120px; max-height: 120px; }

@media (min-width: 800px) {
  .sale-columns { grid-template-columns: 1fr 1fr; }
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #14213d;
  color: #ffffff;
  text-align: center;
  transition: opacity 0.3s;
}

.splash[data-done] { opacity: 0; pointer-events: none; }
.splash-business { margin-bottom: 8px; font-size: 1.5rem; font-weight: 600; }
.splash-title { color: #f5a524; font-size: 1rem; letter-spacing: 0.15em; }

@media (prefers-reduced-motion: reduce) {
  .splash { transition: none; }
}

/* Hardware test page */
.choice { display: flex; gap: 16px; margin-bottom: 12px; }
.choice label { display: flex; align-items: center; gap: 6px; min-height: 32px; }

.checks { margin: 0; padding: 0; list-style: none; }
.checks li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }

.scan-result {
  min-height: 48px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace;
  overflow-wrap: anywhere;
}

video { display: block; width: 100%; margin-bottom: 12px; border-radius: 8px; }
video[hidden] { display: none; }

/* Receipts, on screen and on paper */
.receipt { display: none; }

.receipt-body, .receipt {
  font: 13px/1.4 ui-monospace, Consolas, monospace;
}

.receipt-preview { max-width: 340px; width: 100%; margin: 0 auto; background: #ffffff; color: #000000; }
.receipt-center { text-align: center; }
.receipt-title { font-weight: 700; font-size: 1.1em; }
.receipt-row { display: flex; justify-content: space-between; gap: 2mm; }
.receipt-rule { margin: 1.5mm 0; border-top: 1px dashed #000000; }
.receipt-total { font-weight: 700; }
.receipt-logo { display: block; max-width: 50%; max-height: 80px; margin: 0 auto 4px; }

@media print {
  body { background: #ffffff; color: #000000; }
  .page, #app { display: none; }

  .receipt {
    display: block;
    width: var(--receipt-width, 58mm);
    padding: 2mm;
    color: #000000;
    font-size: 11px;
  }

  .receipt .receipt-title { font-size: 13px; }
}
