:root {
  color-scheme: light;
  --counter: #dde5e8;
  --paper: #ffffff;
  --ink: #18222d;
  --muted: #55636f;
  --line: #9fb0ba;
  --line-soft: #c9d4da;
  --roll: #b3125a;
  --roll-dark: #8e0c46;
  --void: #8f1d0e;
  --slot: #18222d;
  --gutter: 16px;
  --tab-height: 58px;
  --strip-width: 329px;
  --tooth: 11px;
  --torn-edge:
    linear-gradient(#000 0 0) top / 100% calc(100% - var(--tooth)) no-repeat,
    conic-gradient(from -45deg at 50% 100%, #0000 0deg, #000 1deg 89deg, #0000 90deg)
      bottom / calc(var(--tooth) * 2) var(--tooth) repeat-x;
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--counter);
  color: var(--ink);
  font-family: "Segoe UI", Roboto, "Noto Sans", "Noto Sans Ethiopic", Nyala, system-ui, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1 { margin: 0; font-size: 1.6rem; line-height: 1.2; font-weight: 700; }
h2 { margin: 8px 0 0; font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--roll-dark); }
hr { width: 100%; margin: 28px 0; border: 0; border-top: 1px solid var(--line-soft); }

:focus-visible { outline: 3px solid var(--roll); outline-offset: 2px; }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Frame: tab bar on phones, side rail on wide screens */
.frame { min-height: 100dvh; }
.content { padding: 20px var(--gutter) calc(var(--tab-height) + 28px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 5;
  display: flex;
  background: var(--slot);
  padding-bottom: env(safe-area-inset-bottom);
}
.brand { display: none; }
.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: var(--tab-height);
  padding: 4px 2px;
  color: #cbd6dc;
  font-size: 0.74rem;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  border-top: 3px solid transparent;
}
.tab.current { color: #fff; font-weight: 700; border-top-color: var(--roll); background: #26333f; }
.tab:focus-visible { outline-offset: -3px; }
.wide-only { display: none; }

@media (min-width: 900px) {
  .frame { display: grid; grid-template-columns: 196px minmax(0, 1fr); }
  .tabs {
    position: sticky;
    inset: 0 auto auto 0;
    flex-direction: column;
    height: 100dvh;
    padding: 18px 0;
  }
  .brand {
    display: block;
    padding: 4px 20px 22px;
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
  }
  .tab {
    flex: 0 0 auto;
    justify-content: flex-start;
    min-height: 44px;
    padding: 0 20px;
    font-size: 0.95rem;
    text-align: left;
    border-top: 0;
    border-left: 4px solid transparent;
  }
  .tab.current { border-left-color: var(--roll); }
  .wide-only { display: flex; }
  .content { padding: 28px 32px 48px; }
}

/* Pages */
.page { display: flex; flex-direction: column; gap: 16px; max-width: 920px; margin: 0 auto; }
.page.narrow { max-width: 520px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.split { gap: 28px; }
.split-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.split-paper { min-width: 0; }

@media (min-width: 1040px) {
  .split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--strip-width);
    align-items: start;
    max-width: 1020px;
  }
  .split-side { grid-column: 1; grid-row: 1; }
  .split-paper { grid-column: 2; grid-row: 1; position: sticky; top: 0; }
}

/* The printer: the one bold element, a receipt hanging from its slot */
.printer { width: 100%; max-width: var(--strip-width); margin: 0 auto; padding: 0 8px; }
.slot {
  position: relative;
  z-index: 1;
  height: 16px;
  margin: 0 -8px;
  border-radius: 4px;
  background: var(--slot);
}
.feed { overflow: hidden; padding-bottom: 12px; filter: drop-shadow(0 3px 3px rgb(24 34 45 / 28%)); }
.strip { min-height: 160px; background: var(--paper); mask: var(--torn-edge); }
.strip img { display: block; width: 100%; height: auto; padding-bottom: var(--tooth); }
.feeding .strip { animation: feed-out 1.1s steps(18, end) both; }
@keyframes feed-out {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .feeding .strip { animation: none; }
}
.preview-note { max-width: var(--strip-width); margin: 8px auto 0; color: var(--void); font-size: 0.9rem; }

/* Controls */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 0.88rem; font-weight: 600; }
.field-hint { color: var(--muted); font-size: 0.82rem; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
input:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--roll); }
input[type="checkbox"] { width: 22px; min-height: 22px; margin: 0; accent-color: var(--roll); }

.check { display: flex; align-items: center; gap: 10px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { border-color: var(--ink); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button.primary { border-color: var(--roll); background: var(--roll); color: #fff; }
.button.primary:hover:not(:disabled) { border-color: var(--roll-dark); background: var(--roll-dark); }
.button.danger { border-color: var(--void); background: var(--void); color: #fff; }
.button.quiet-danger {
  align-self: flex-start;
  padding-left: 0;
  border-color: transparent;
  background: none;
  color: var(--void);
}
.button.small { min-height: 36px; padding: 5px 12px; font-size: 0.9rem; }
.button.wide { width: 100%; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .button { flex: 1 1 96px; padding-inline: 8px; }
.actions .button.wide { flex-basis: 100%; }
.settings-link { font-weight: 600; }

.form-error, .notice {
  padding: 10px 12px;
  border-left: 4px solid var(--roll);
  border-radius: 3px;
  background: var(--paper);
  font-size: 0.93rem;
}
.form-error, .notice.danger { border-left-color: var(--void); color: var(--void); font-weight: 600; }

/* Receipt lines: item, quantity, price, remove */
.lines { display: flex; flex-direction: column; gap: 10px; }
.line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px;
  gap: 6px;
}
.line > input:first-child { grid-column: 1 / -1; }
.line-head { display: none; }
.remove {
  width: 40px;
  min-height: 44px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.remove:hover { background: var(--line-soft); color: var(--ink); }

@media (min-width: 620px) {
  .line { grid-template-columns: minmax(0, 1fr) 86px 124px 40px; }
  .line > input:first-child { grid-column: auto; }
  .line-head { display: grid; margin-bottom: -10px; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
  .lines { gap: 6px; }
}

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 620px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.issued-fields { display: flex; gap: 8px; }
.issued-fields input[type="date"] { flex: 1 1 auto; min-width: 0; }
.issued-fields input[type="text"] { flex: 0 0 5.5rem; text-align: center; }

.sums {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  margin: 4px 0;
  padding: 12px 0 0;
  border-top: 1px dashed var(--line);
}
.sums dt, .sums dd { margin: 0; }
.sums dd { text-align: right; }
.sums .sum-total { font-size: 1.25rem; font-weight: 700; }

/* Lists */
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.filters .field:first-child { grid-column: 1 / -1; }
@media (min-width: 620px) {
  .filters { grid-template-columns: minmax(0, 1fr) 160px 160px; }
  .filters .field:first-child { grid-column: auto; }
}

.rows { display: flex; flex-direction: column; background: var(--paper); border-radius: 5px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 9px 12px;
  border-bottom: 1px dashed var(--line-soft);
  color: inherit;
  text-decoration: none;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #f0f4f6; }
.row-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; overflow-wrap: anywhere; }
.row-main .row-sub { flex-basis: 100%; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; text-align: right; }
.row-sub { color: var(--muted); font-size: 0.85rem; }
.hidden-row { opacity: 0.6; }
.tag { padding: 1px 7px; border-radius: 3px; background: var(--line-soft); font-size: 0.78rem; font-weight: 600; }
.tag.void { background: var(--void); color: #fff; }
.empty { padding: 28px 16px; background: var(--paper); border-radius: 5px; text-align: center; }

/* Receipt detail */
.big-total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.big-total strong { font-size: 1.5rem; overflow-wrap: anywhere; white-space: normal; text-align: right; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 16px; margin: 0; font-size: 0.93rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* Sheets */
dialog.sheet {
  width: min(460px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - 32px);
  padding: 18px;
  border: 0;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}
dialog.sheet::backdrop { background: rgb(24 34 45 / 55%); }

/* Login: the card is a receipt coming out of the slot */
.login { display: flex; flex-direction: column; align-items: center; min-height: 100dvh; padding: 12vh var(--gutter) 24px; }
.login-slot { width: min(376px, 100%); height: 16px; border-radius: 4px; background: var(--slot); }
.login-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(344px, calc(100% - 16px));
  padding: 26px 22px 34px;
  background: var(--paper);
  mask: var(--torn-edge);
}
.login-card h1 { text-align: center; font-size: 1.45rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-height) + 14px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 10px 14px;
  border-radius: 5px;
  background: var(--slot);
  color: #fff;
  overflow-wrap: anywhere;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
