/* L-Keeper · Mini App. Токены и вид — docs/DESIGN.md, эталон вёрстки — design/prototype.html */
:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #E9EEF4;
  --panel: #D5DEE9;
  --line: #B7C4D4;
  --card: #fff;
  --text: #14202E;
  --muted: #4B5D75;
  --grey: #4B6079;
  --tile: #2F6FB5;
  --link: #2F6FB5;
  --green: #2E7D32;
  --orange: #BF4A00;
  --red: #B3261E;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E2A38;
    --panel: #2B3A4D;
    --line: #3C4D63;
    --card: #16202B;
    --text: #fff;
    --muted: #C9D3DF;
    --grey: #3C4D63;
    --link: #8FC2F0;
  }
}

:root[data-theme="dark"] {
  --bg: #1E2A38;
  --panel: #2B3A4D;
  --line: #3C4D63;
  --card: #16202B;
  --text: #fff;
  --muted: #C9D3DF;
  --grey: #3C4D63;
  --link: #8FC2F0;
}

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 16px Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font: inherit;
  font-weight: 700;
  color: #fff;
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 14px;
  cursor: pointer;
  background: var(--grey);
  touch-action: manipulation;
}

button small { display: block; font-size: 11px; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }

:focus-visible { outline: 3px solid #FFB74D; outline-offset: 2px; }

.g { background: var(--green); }
.r { background: var(--red); }
.o { background: var(--orange); }
.t { background: var(--tile); }
.n { background: var(--grey); }
.sm { min-height: 44px; padding: 0 12px; }

.top {
  background: var(--panel);
  min-height: 56px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 2px solid var(--line);
  flex: none;
}

.top-actions { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }

.top .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar {
  background: var(--panel);
  padding: 10px;
  display: flex;
  gap: 8px;
  border-top: 2px solid var(--line);
  flex: none;
}

.bar button { flex: 1; min-height: 52px; padding: 0 8px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.grid.three { grid-template-columns: repeat(3, 1fr); }

.tile {
  min-height: 92px;
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--tile);
}

.tl {
  min-height: 72px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  line-height: 1.25;
  background: var(--green);
}

.stat {
  border-radius: 8px;
  padding: 12px;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  background: var(--grey);
}

.stat.g { background: var(--green); }

.card { background: var(--card); border-radius: 8px; padding: 4px 12px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}

.row:last-child { border-bottom: 0; }
.row.wrap { flex-wrap: wrap; }
.row.grow > .grow { flex: 1; min-width: 38%; }
.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  color: var(--text);
  font-weight: 400;
  padding: 0;
  border-radius: 0;
  text-align: left;
}

.row.wrap > .user-row { width: auto; flex: 1 1 220px; min-width: 0; }
.uinfo { flex: 1; min-width: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.tglink, .tgid {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.tglink { color: var(--link); font-weight: 600; text-decoration: underline; padding: 0 2px; }
.tgid { font-size: 12px; text-align: right; max-width: 46%; }

.tot { font-size: 20px; font-weight: 700; }
.mut { color: var(--muted); font-size: 13px; }
.lbl { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; }

/* Лента событий: крупнее и построчно, количество — жирным. */
.feed-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; }
.feed-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}
.feed-head .mut { flex: none; font-weight: 400; }
.feed-plain { white-space: pre-line; font-weight: 400; font-size: 15px; }
.feed-group {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--muted);
}
.feed-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
  font-size: 16px;
  line-height: 1.4;
}
.feed-line.chg { justify-content: space-between; }
.feed-line .q { flex: none; font-weight: 700; font-size: 16px; }
.feed-line .nm { min-width: 0; overflow-wrap: anywhere; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: none;
  padding-bottom: 4px;
}

.tabs button { white-space: nowrap; flex: none; min-height: 44px; }

.rec { max-height: 32%; overflow: auto; flex: none; }

.qtybox { display: flex; align-items: center; gap: 6px; }
.qbtn { min-width: 44px; padding: 0; }
.qval { min-width: 24px; text-align: center; }
.sum { min-width: 64px; text-align: right; }

.drop {
  position: absolute;
  top: 56px;
  right: 10px;
  z-index: 5;
  width: 230px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

.drop button { text-align: left; }

.ov {
  position: absolute;
  inset: 0;
  z-index: 9;
  background: rgba(10, 16, 24, .78);
  display: flex;
  align-items: center;
  padding: 24px;
}

.dlg {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dlg .actions { display: flex; gap: 8px; }
.dlg .actions button { flex: 1; }
.dlg .close-x { align-self: flex-end; flex: none; min-width: 44px; padding: 0; }
.dlg .pick { text-align: left; }

input, select {
  min-height: 52px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: 18px Inter, system-ui, sans-serif;
  padding: 0 14px;
  width: 100%;
  box-sizing: border-box;
}

.mark-row { border-radius: 6px; }
.mark-row.on { background: var(--green); color: #fff; margin: 0 -12px; padding: 0 12px; }
.mark-row .pick {
  flex: 1;
  text-align: left;
  background: transparent;
  color: inherit;
  padding: 0;
  min-height: 52px;
}
.mark-row .pick small { font-weight: 400; font-size: 13px; }

.receipt {
  background: #fff;
  color: #111;
  width: 300px;
  max-width: 100%;
  box-sizing: border-box;
  padding: 18px 16px;
  font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
  align-self: center;
}

.receipt hr { border: 0; border-top: 1px dashed #111; margin: 10px 0; }
.receipt .brand { text-align: center; }
.receipt .brand b { font-size: 20px; letter-spacing: 2px; }
.receipt .line { display: flex; justify-content: space-between; gap: 8px; }
.receipt .foot { text-align: center; font-size: 11px; }

.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 90px;
  max-width: 90%;
  background: #111;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  z-index: 20;
  text-align: center;
}

/* Меню как в R-Keeper: две закреплённые ленты, плитки и свёрнутый чек */
.table-main { overflow: hidden; gap: 8px; }

.draftbar {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--card);
  color: var(--text);
  font-weight: 400;
  text-align: left;
  flex: none;
}

.draftbar b { font-weight: 700; }
.dchev { color: var(--muted); font-size: 14px; }
.rec.draft { max-height: 22%; flex: none; scrollbar-width: none; }
.rec.draft::-webkit-scrollbar { display: none; }
.rowline { display: flex; justify-content: space-between; align-items: center; flex: none; }

.menuhead { display: flex; flex-direction: column; gap: 8px; flex: none; min-width: 0; }

.tabs-scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tabs-scroll::-webkit-scrollbar, .cats::-webkit-scrollbar { display: none; }
.tabs-scroll button { min-height: 44px; }

.cats {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: none;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  white-space: nowrap;
  background: var(--grey);
  font-weight: 600;
}

.chip.on { background: var(--orange); }
.cnum { opacity: .72; font-size: 12px; margin-left: 2px; }
.searchinfo { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex: none; }

.menu-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  touch-action: pan-y;
  scrollbar-width: none;
}

.menu-grid::-webkit-scrollbar { display: none; }

.tl { position: relative; }
.tname {
  padding-right: 30px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.qbadge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 0 6px;
  border-radius: 10px;
  background: #fff;
  color: var(--green);
  font-size: 12px;
  line-height: 20px;
  font-weight: 700;
}
.gridnote { grid-column: 1 / -1; padding: 6px 2px; }

.bar.save { padding: 8px 10px; border-top: 0; }
.bar.save button { flex: 1; min-height: 52px; }

/* Предпросмотр чека как в кассе */
.receipt .rc-org { display: block; font-size: 11px; letter-spacing: 1px; }
.receipt .rc-addr { display: block; font-size: 10px; }
.receipt .rc-item { display: flex; gap: 6px; align-items: flex-start; }
.receipt .rc-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.receipt .rc-qty { width: 46px; text-align: right; flex: none; }
.receipt .rc-sum { width: 64px; text-align: right; flex: none; }
.receipt .rc-head { font-weight: 700; }
.receipt .rc-total { font-weight: 700; font-size: 14px; }

/* Мультизаведение и быстрый список */
.venue-select { min-height: 44px; max-width: 190px; flex: 0 0 auto; font-size: 14px; padding: 0 6px; }
.quick { display: flex; flex-direction: column; gap: 4px; flex: none; }
.quick .lbl { padding-left: 2px; }
.quick-chip { background: var(--green); }
.quick-chip.on { background: var(--orange); }

/* Меню выше чека: раскрытый чек растягивает экран, а не перекрывает кнопки */
.table-main { overflow-y: auto; padding: 8px 10px; }
.rec.draft { max-height: none; }
