/*
 * The counter UI.
 *
 * ## Sizing, because three screens have to work from one stylesheet
 *
 * A 15-inch counter monitor is read at arm's length by somebody standing; a 10-inch tablet is
 * held; a phone is used in the stockroom. So the base size is deliberately large — a cashier
 * glancing at a total should not have to lean in — and the layout collapses from a two-column
 * grid to a single column rather than shrinking the text.
 *
 * Dark by default. Counters run all day under shop lighting and a white screen at 9pm is
 * genuinely unpleasant; the manifest's theme colour matches so the installed app does not flash
 * white on launch.
 *
 * `env(safe-area-inset-*)` is honoured so an installed app on an iPhone does not put the tab bar
 * under the home indicator.
 */

:root {
  --ink: #0f172a;
  --ink-soft: #1e293b;
  --paper: #f8fafc;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 12px;
  --gap: 12px;
  --touch: 48px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------------------------------- bar ---------------------------------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px max(12px, env(safe-area-inset-left)) 10px max(12px, env(safe-area-inset-right));
  background: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.bar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.bar__title {
  letter-spacing: 0.01em;
}

.bar__status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.dot--ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgb(22 163 74 / 25%);
}

.dot--off {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgb(245 158 11 / 25%);
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  min-height: 0;
}

.chip.is-alert {
  border-color: var(--bad);
  color: #fecaca;
}

.chip--update {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(70px + env(safe-area-inset-bottom));
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  z-index: 30;
  padding: 10px 16px;
}

/* --------------------------------- tabs ---------------------------------- */

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
}

.tab {
  min-height: var(--touch);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
}

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* --------------------------------- layout -------------------------------- */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap) max(12px, env(safe-area-inset-left)) var(--gap) max(12px, env(safe-area-inset-right));
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

.panel {
  background: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--gap);
}

.panel--narrow {
  max-width: 420px;
  margin: 0 auto 0;
  width: 100%;
}

.panel h2,
.panel h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.foot {
  padding: 8px max(12px, env(safe-area-inset-left)) 12px;
  text-align: center;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.strong {
  font-weight: 700;
}

/* -------------------------------- controls ------------------------------- */

.row {
  display: flex;
  gap: var(--gap);
  align-items: flex-end;
  flex-wrap: wrap;
}

.grow {
  flex: 1 1 200px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field span {
  font-size: 0.82rem;
  color: var(--muted);
}

.input {
  min-height: var(--touch);
  background: var(--ink);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
}

.input:focus-visible,
.button:focus-visible,
.tab:focus-visible,
.ghost:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.input--big {
  font-size: 1.6rem;
  font-family: var(--mono);
  text-align: right;
  min-height: 60px;
}

.button {
  min-height: var(--touch);
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--ink);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.button--wide {
  width: 100%;
  margin-top: 8px;
}

.button--small {
  min-height: 32px;
  font-size: 0.85rem;
  padding: 0 12px;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ghost {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  min-height: 32px;
}

/* --------------------------------- tables -------------------------------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th,
.table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}

.table tfoot th {
  border-bottom: none;
  font-size: 1.05rem;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
}

/* --------------------------------- facts --------------------------------- */

.facts {
  display: grid;
  grid-template-columns: minmax(120px, 40%) 1fr;
  gap: 4px 12px;
  margin: 0;
}

.facts dt {
  color: var(--muted);
  font-size: 0.88rem;
}

.facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------- result -------------------------------- */

.result {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.92rem;
}

.result--ok {
  border-color: var(--ok);
  background: rgb(22 163 74 / 12%);
}

.result--warn {
  border-color: var(--warn);
  background: rgb(245 158 11 / 12%);
}

.result code {
  font-family: var(--mono);
}

.gap {
  margin: 6px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
  border: 1px solid var(--line);
}

.gap--ok {
  border-color: var(--ok);
  background: rgb(22 163 74 / 12%);
}

.gap--off {
  border-color: var(--bad);
  background: rgb(239 68 68 / 14%);
}

/* -------------------------------- banners -------------------------------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.9rem;
}

/* -------------------------------- camera --------------------------------- */

.video {
  width: 100%;
  max-height: 320px;
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

/* ------------------------------ responsive ------------------------------- */

/*
 * The single breakpoint is at 640px: below it the counter tables become cards, because a
 * horizontally scrolling table on a phone is unreadable and gets mis-tapped.
 */
@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  .bar__title {
    display: none;
  }

  .table thead {
    display: none;
  }

  .table tr {
    display: block;
    border-bottom: 1px solid var(--line);
    padding: 6px 0;
  }

  .table td {
    display: flex;
    justify-content: space-between;
    border: none;
    padding: 2px 4px;
  }

  .table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.8rem;
    margin-right: 8px;
  }

  .facts {
    grid-template-columns: 1fr;
  }

  .facts dd {
    margin-bottom: 6px;
  }
}

@media (min-width: 900px) {
  .screen {
    padding-top: 20px;
  }
}

/* Respect a device that has asked for less motion. */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
