/* Fonts are OFL-licensed and served from /fonts (license: /fonts/OFL.txt). */
@font-face { font-family: Unbounded; src: url(/fonts/unbounded-cyrillic.woff2) format("woff2"); font-weight: 200 900; font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: Unbounded; src: url(/fonts/unbounded-latin.woff2) format("woff2"); font-weight: 200 900; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Manrope; src: url(/fonts/manrope-cyrillic.woff2) format("woff2"); font-weight: 200 800; font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: Manrope; src: url(/fonts/manrope-latin.woff2) format("woff2"); font-weight: 200 800; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* Palette «C»: lilac, night, tomato, butter, leaf, plum. data-theme comes from the theme picker or Telegram. */
:root {
  --bg: #F2F1F7;
  --card: #ffffff;
  --text: #241F3A;
  --soft: #6F6A86;
  --line: #EEEDF4;
  --plum: #5B3FD1;
  --plum-soft: #F7F5FF;
  --on-plum: #ffffff;
  --tomato: #EF5B45;
  --butter: #F6C445;
  --leaf: #4BB27A;
  --night: #241F3A;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17142A; --card: #241F3A; --text: #F2F1F7; --soft: #A9A4C0; --line: #342E52;
    --plum: #8C74FF; --plum-soft: #2E2750; --on-plum: #17142A; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17142A; --card: #241F3A; --text: #F2F1F7; --soft: #A9A4C0; --line: #342E52;
  --plum: #8C74FF; --plum-soft: #2E2750; --on-plum: #17142A; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 16px/1.4 Manrope, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
main#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
}
h1, h2, .sheet > header h2 { font-family: Unbounded, system-ui, sans-serif; }
h1 { font-size: 26px; font-weight: 700; margin: 8px 0; }
h2 { font-size: 17px; font-weight: 500; margin: 22px 0 10px; display: flex; align-items: center; gap: 10px; }
h2 em { font: normal 700 13px Manrope, sans-serif; min-width: 24px; height: 24px; border-radius: 12px; display: grid; place-items: center; padding: 0 7px; color: #fff; }
h2 em.r { background: var(--tomato); }
h2 em.g { background: var(--leaf); }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--soft); margin: 20px 0 8px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.6; }
:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; }

.top { display: flex; align-items: center; gap: 8px; }
.top h1 { flex: 1 1 auto; }
select.place {
  width: auto;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  padding: 8px 32px 8px 14px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0h10L5 6z' fill='%236F6A86'/%3E%3C/svg%3E") no-repeat right 14px center;
  appearance: none;
  font-size: 14px;
  font-weight: 600;
}
.add {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--plum);
  color: var(--on-plum);
  font-size: 26px;
  line-height: 1;
}
input[type="search"] { margin-top: 10px; }

input, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1.5px solid transparent;
  border-radius: 14px;
  background: var(--bg);
}
.sheet input:focus, .sheet select:focus { border-color: var(--plum); outline: none; }
main input[type="search"] { background: var(--card); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--soft); margin: 12px 0; }
label > input, label > select { color: var(--text); font-size: 16px; font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 label { margin: 12px 0 0; }
[hidden] { display: none !important; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.chip { flex: none; border: 0; background: var(--bg); border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; }
.chip.ghost { background: transparent; color: var(--soft); }

/* «Пора использовать»: three tiles in a row */
.urgent { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile { border-radius: 20px; padding: 12px 11px 11px; min-height: 128px; display: flex; flex-direction: column; background: var(--butter); color: var(--night); }
.tile.red { background: var(--tomato); color: #fff; }
.tile .when { font-size: 12px; font-weight: 700; opacity: 0.85; }
.tile .name { all: unset; cursor: pointer; font-size: 15px; font-weight: 700; line-height: 1.2; margin: 5px 0 auto; overflow-wrap: anywhere; }
.tile .qty { font-size: 13px; font-weight: 600; margin: 6px 0 7px; }
.tile .verb { width: 100%; background: #fff; color: var(--night); padding: 8px 0; }

.list { list-style: none; margin: 0; padding: 2px 14px; background: var(--card); border-radius: 20px; }
.sheet .list { background: var(--bg); }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 58px; }
.list li:last-child { border-bottom: 0; }
.list.compact li { min-height: 44px; }
.list li.out .what b, .list li.out .name { color: var(--soft); }
.what, .row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
}
.what b { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.what > span, .sub { color: var(--soft); font-size: 13px; }
.row-main.check { flex-direction: row; align-items: center; gap: 12px; margin: 0; color: var(--text); font-size: 16px; }
.row-main.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--plum); }
.name { font-weight: 600; overflow-wrap: anywhere; }

.digest fieldset { border: 0; padding: 0; margin: 16px 0 0; display: grid; gap: 12px; }
.digest legend { padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--soft); }
.digest .days { grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days label { justify-items: center; margin: 0; color: var(--text); font-size: 14px; }
.days input { width: 22px; height: 22px; min-height: 0; accent-color: var(--plum); }

.verb {
  flex: none;
  border: 0;
  background: var(--bg);
  border-radius: 11px;
  min-height: 36px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.segmented { display: flex; gap: 4px; padding: 4px; background: var(--card); border-radius: 14px; }
.segmented button { flex: 1; min-height: 44px; border: 0; border-radius: 11px; background: none; color: var(--text); font-size: 14px; font-weight: 600; }
.segmented [aria-pressed="true"] { background: var(--plum); color: var(--on-plum); }
.stepper { flex: none; display: flex; align-items: center; background: var(--bg); border-radius: 12px; }
.stepper button { width: 44px; height: 44px; border: 0; background: none; color: var(--text); font-size: 22px; font-weight: 600; border-radius: 12px; }
.stepper span { min-width: 2.5em; text-align: center; font-size: 14px; font-weight: 700; white-space: nowrap; }

/* by-eye level: four steps */
.level { display: flex; gap: 3px; margin-top: 5px; align-items: center; }
.level i { width: 18px; height: 6px; border-radius: 3px; background: var(--line); }
.level.l3 i:nth-child(-n+3), .level.l4 i { background: var(--leaf); }
.level.l2 i:nth-child(-n+2) { background: var(--butter); }
.level.l1 i:nth-child(1) { background: var(--tomato); }
.level small { margin-left: 6px; font-size: 13px; color: var(--soft); }
.level.l1 small, .level.l0 small { color: var(--tomato); font-weight: 700; }

.icon { flex: none; min-width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--soft); font-size: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 10px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--plum);
  color: var(--on-plum);
  font-weight: 700;
  text-decoration: none;
}
.btn.small { min-height: 38px; padding: 6px 14px; border-radius: 11px; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn.big { min-height: 56px; font-size: 17px; border-radius: 18px; }
.btn.ghost { background: var(--bg); color: var(--text); }
.btn.danger { background: transparent; color: var(--tomato); border: 1.5px solid currentColor; }
.link { background: none; border: 0; color: var(--plum); padding: 12px 0; font-weight: 700; }

.inline { display: flex; gap: 8px; margin: 12px 0; }
.inline input { flex: 1; }
main .inline input { background: var(--card); }

/* «Как считать?» */
.q { font-weight: 700; font-size: 15px; margin: 16px 0 8px; }
.mode { display: block; border-radius: 16px; padding: 12px 14px; margin: 0 0 8px; box-shadow: inset 0 0 0 1.5px var(--line); color: var(--text); cursor: pointer; }
.mode.on { box-shadow: inset 0 0 0 2.5px var(--plum); background: var(--plum-soft); }
.mode input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.mode:focus-within { outline: 2px solid var(--plum); outline-offset: 2px; }
.mode b { font-size: 15px; }
.mode p { margin: 2px 0 0; font-size: 13px; font-weight: 500; color: var(--soft); }
.pack { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 14px; font-weight: 600; color: var(--text); }
.pack input { width: 76px; min-height: 40px; padding: 6px 10px; text-align: center; background: var(--card); border-color: var(--plum); }

#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 20px rgba(36, 31, 58, 0.06);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
#tabs button { flex: 1; min-height: 60px; border: 0; background: none; color: var(--soft); font-size: 14px; font-weight: 600; }
#tabs button[aria-current="true"] { color: var(--plum); }
#tabs button b { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--tomato); color: #fff; font-size: 11px; }
#tabs button b:empty { display: none; }

.card { background: var(--bg); border-radius: 18px; padding: 4px 16px 16px; margin: 16px 0; }
.card input, .card select { background: var(--card); }
.card h3 { margin-top: 14px; }
details.card { padding-top: 12px; }
summary { font-weight: 700; cursor: pointer; padding: 4px 0; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 31, 58, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 30px 30px 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  animation: up 0.18s ease-out;
}
.sheet > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: -12px; background: var(--card); padding: 10px 0 4px; z-index: 1; }
.sheet > header h2 { font-size: 18px; margin: 0; }
@keyframes up { from { transform: translateY(24px); opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.scan-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.scan-buttons .btn:only-of-type { grid-column: 1 / -1; }
.scanned { margin: 12px 0; }
.scanned:empty { display: none; }
.list li.batch-row { display: block; padding: 12px 0; }
.batch input, .batch select { background: var(--card); }
.batch-head { display: flex; align-items: center; gap: 8px; }
.batch-head input { flex: 1; min-width: 0; }
.batch-head b { flex: 1; font-weight: 600; }
.batch-row .sub { margin: 4px 0 8px; }
.error { color: var(--tomato); font-size: 13px; font-weight: 600; margin: 8px 0 0; }
.viewfinder { position: relative; border-radius: 18px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder::after { content: ""; position: absolute; inset: 30% 12%; border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 10px; }

.hint { color: var(--soft); font-size: 13px; }
.empty { color: var(--soft); text-align: center; padding: 40px 12px; }
.center { max-width: 420px; margin: 12vh auto 0; text-align: center; padding: 0 16px; }
.logo { border-radius: 22px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--night);
  color: #fff;
  padding: 10px 12px 10px 16px;
  border-radius: 16px;
  font-size: 15px;
  font-weight: 600;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(36, 31, 58, 0.25);
}
#toast button { border: 0; background: var(--butter); color: var(--night); border-radius: 10px; padding: 7px 12px; font-weight: 700; }
:root[data-theme="dark"] #toast { box-shadow: 0 0 0 1px var(--line); }
