:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #18181b;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --line: #27272a;
    --accent: #14b8a6;
    --accent-text: #042f2e;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}

button, .button-like, input, select {
  font: inherit;
  color: inherit;
}

button, .button-like {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

button:active, .button-like:active { opacity: .7; }

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

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

.icon-btn {
  min-width: 48px;
  padding: 0;
  font-size: 22px;
  border: none;
  background: transparent;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 0 4px;
}

.link-btn.strong { font-weight: 700; }

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
}

.top h1 { margin: 0; font-size: 32px; }

.top-actions { display: flex; gap: 8px; }

/* Card grid */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.tile {
  width: 100%;
  min-height: 96px;
  aspect-ratio: 1.586;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  text-align: left;
  font-weight: 700;
  font-size: 19px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .15);
}

.tile small {
  font-weight: 400;
  font-size: 13px;
  opacity: .85;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}

/* Sheets */
dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  height: 100%;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  border: none;
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
}

dialog::backdrop { background: rgb(0 0 0 / .4); }

.sheet-head, .show-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 12px;
}

.sheet-head > :first-child, .show-head > :first-child { justify-self: start; }
.sheet-head > :last-child, .show-head > :last-child { justify-self: end; }
.sheet-head h2, .show-head h2 { margin: 0; font-size: 18px; text-align: center; }

form label {
  display: block;
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--muted);
}

form label.button-like {
  margin: 0;
  color: var(--text);
  font-size: 17px;
}

form input:not([type=color]):not([type=file]), form select {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px;
}

form input[type=color] {
  display: block;
  width: 72px;
  height: 44px;
  margin-top: 6px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.scan-row, .order-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.edit-extra {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.preview-wrap { margin-top: 18px; }

.preview {
  display: flex;
  justify-content: center;
  padding: 12px;
  border-radius: 12px;
  background: #fff;
  min-height: 40px;
}

.preview:empty { display: none; }
.preview svg { max-width: 100%; height: auto; max-height: 160px; }

.msg { min-height: 1.2em; margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.msg.error { color: var(--danger); }
.hint { color: var(--muted); font-size: 14px; }
.hint.small { font-size: 12px; }
.center { text-align: center; }

/* Barcode view: always white for scanner contrast */
dialog.show {
  background: #fff;
  color: #000;
}

dialog.show .icon-btn { color: #000; }
dialog.show .link-btn { color: #0f766e; }

.show-code {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 45vh;
  padding: 16px 8px;
}

.show-code svg { width: 100%; height: auto; max-height: 60vh; }
.show-code.square svg { width: min(80vw, 360px); }

.show-number {
  text-align: center;
  font: 600 22px/1.3 ui-monospace, Menlo, monospace;
  letter-spacing: .06em;
  word-break: break-all;
  margin: 8px 0;
}

.show-note { text-align: center; color: #52525b; margin: 0; }

/* Scanner */
.scanner video {
  width: 100%;
  border-radius: 12px;
  background: #000;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.menu > button, .menu > .button-like { width: 100%; margin-top: 12px; }

.health {
  list-style: none;
  margin: 0 0 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 15px;
  display: grid;
  gap: 6px;
}
