:root {
  color-scheme: light;
  --bg: #eef4f8;
  --bg-alt: #f8fbfd;
  --panel: rgba(255, 255, 255, 0.82);
  --text: #182026;
  --muted: #65727e;
  --line: rgba(141, 157, 171, 0.32);
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --primary-soft: rgba(234, 88, 12, 0.12);
  --danger: #b42318;
  --ok: #1c7c54;
  --shadow: 0 16px 40px rgba(18, 27, 38, 0.12);
  --radius: 16px;
  --touch: 44px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #120c08;
  --bg-alt: #1b140f;
  --panel: rgba(32, 24, 18, 0.88);
  --text: #eef6fb;
  --muted: #c4b4a8;
  --line: rgba(224, 196, 180, 0.2);
  --primary: #fb923c;
  --primary-dark: #fdba74;
  --primary-soft: rgba(251, 146, 60, 0.16);
  --danger: #ff8a80;
  --ok: #4ecb8f;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #120c08;
    --bg-alt: #1b140f;
    --panel: rgba(32, 24, 18, 0.88);
    --text: #eef6fb;
    --muted: #c4b4a8;
    --line: rgba(224, 196, 180, 0.2);
    --primary: #fb923c;
    --primary-dark: #fdba74;
    --primary-soft: rgba(251, 146, 60, 0.16);
    --danger: #ff8a80;
    --ok: #4ecb8f;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

body {
  background: linear-gradient(160deg, rgba(234, 88, 12, 0.16), transparent 42%),
    linear-gradient(180deg, var(--bg), var(--bg-alt));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--primary-dark); }

.hidden { display: none !important; }

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 18px; margin: 0; }
.sub, .muted { color: var(--muted); font-size: 13px; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }

button, .tab {
  font: inherit;
  min-height: var(--touch);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.lg { width: 100%; font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; }

.tabs { display: flex; gap: 8px; margin: 0 0 16px; }
.tab { flex: 1; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
}
.item strong { display: block; margin-bottom: 4px; }
.when { font-size: 13px; color: var(--muted); }

label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}
textarea { resize: vertical; min-height: 96px; }

.suggest { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.suggest:empty { display: none; }
.suggest button { width: 100%; border-radius: 0; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.picked { min-height: 1.2em; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }

#sign {
  width: 100%;
  max-width: 100%;
  height: 180px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  touch-action: none;
  background: #fff;
}
:root[data-theme="dark"] #sign { background: #1a1410; }

.centered { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { text-align: center; max-width: 420px; }
.eyebrow { letter-spacing: 0.08em; text-transform: uppercase; font-size: 12px; color: var(--primary-dark); margin-bottom: 0; }
.err { color: var(--danger); font-size: 14px; }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--primary-soft); border: 1px solid var(--line); margin-bottom: 14px; }
.with-eye { position: relative; }
.with-eye input { padding-right: 48px; }
.eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; min-height: 36px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; box-shadow: var(--shadow); max-width: 90vw; z-index: 20;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }

.bill-line {
  display: grid;
  grid-template-columns: 1fr auto 4.6rem auto 2.6rem;
  gap: 8px;
  align-items: center;
}
.bill-name { font-size: 14px; line-height: 1.3; }
.bill-price, .bill-total { font-size: 13px; white-space: nowrap; }
.bill-price small, .bill-total small { color: var(--muted); font-size: 11px; }
.bill-qty { width: 4.6rem; padding: 8px; min-height: 40px; text-align: center; }
.bill-del {
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--danger);
}
@media (max-width: 560px) {
  .bill-line {
    grid-template-columns: 1fr auto 2.6rem;
    grid-template-areas:
      "name name del"
      "price qty total";
  }
  .bill-name { grid-area: name; }
  .bill-price { grid-area: price; }
  .bill-qty { grid-area: qty; }
  .bill-total { grid-area: total; justify-self: end; }
  .bill-del { grid-area: del; justify-self: end; }
}
