/* Цвета берутся из темы Telegram, так что приложение выглядит «родным» в светлой и тёмной теме. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #6d6d72);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --line: rgba(128, 128, 128, 0.28);
  --ok: #2e9e5b;
  --warn: #d98200;
  --bad: #d64545;
  --info: #2f7fd1;
  --violet: #7a5bd6;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(72px + var(--safe-b));
  -webkit-text-size-adjust: 100%;
}
body.has-selbar { padding-bottom: calc(150px + var(--safe-b)); }
button, input, select, textarea { font: inherit; color: inherit; }
h3 { margin: 18px 16px 8px; font-size: 14px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 8px; }
[hidden] { display: none !important; }

/* ---------- шапка и вкладки ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { font-size: 13px; color: var(--hint); }
.top input[type=date] {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 10px; min-width: 0;
}
.back {
  border: 0; background: none; color: var(--link); font-size: 16px; padding: 6px 0; cursor: pointer;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--bg); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 14px 6px; font-size: 15px; color: var(--hint); cursor: pointer;
  border-top: 3px solid transparent;
}
.tabs button.on { color: var(--btn); font-weight: 600; border-top-color: var(--btn); }

/* ---------- общие элементы ---------- */
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 60px 24px; color: var(--hint); }
.center h2 { color: var(--text); margin: 0 0 8px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--btn); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { padding: 36px 24px; text-align: center; color: var(--hint); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: rgba(128,128,128,.18); color: var(--hint);
}
.st-assigned { background: rgba(47,127,209,.16); color: var(--info); }
.st-picking  { background: rgba(217,130,0,.16);  color: var(--warn); }
.st-picked   { background: rgba(46,158,91,.16);  color: var(--ok); }
.st-scanning { background: rgba(122,91,214,.16); color: var(--violet); }
.st-checked  { background: rgba(46,158,91,.28);  color: var(--ok); }
.st-problem  { background: rgba(214,69,69,.18);  color: var(--bad); }
.st-rejected { background: rgba(128,128,128,.22); color: var(--hint); }
.card.rejected { opacity: .62; }

.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .2s; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; background: var(--btn); color: var(--btn-text);
  font-weight: 600; cursor: pointer; text-align: center;
}
.btn.ghost { background: var(--card); color: var(--text); }
.btn.bad { background: var(--bad); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.big { padding: 16px; font-size: 17px; width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- списки карточек ---------- */
.list { padding: 8px 12px 0; display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; gap: 10px; align-items: stretch; background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer;
}
.card .main { flex: 1; min-width: 0; }
.card .row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .row1 b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .store { font-size: 15px; }
.card .meta { font-size: 13.5px; color: var(--hint); margin-top: 2px; }
.card.static { cursor: default; }
.card.selected { outline: 2px solid var(--btn); }
.card .actions { margin-top: 10px; display: flex; gap: 8px; }
.card .actions .btn { flex: 1; }

.chk { display: flex; align-items: center; padding: 0 4px 0 0; }
.box {
  width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); display: flex; align-items: center;
  justify-content: center; font-size: 15px; color: transparent;
}
.box.on { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: none; border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer;
}
.chip i { font-style: normal; color: var(--hint); margin-left: 4px; }
.chip.on { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.chip.on i { color: var(--btn-text); opacity: .85; }

.toolbar { display: flex; gap: 8px; padding: 10px 12px 0; }
.toolbar input[type=search] {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px;
}
.linkrow { padding: 8px 16px 0; font-size: 14px; }
.linkrow a { color: var(--link); cursor: pointer; }

.selbar {
  position: fixed; left: 0; right: 0; bottom: calc(52px + var(--safe-b)); z-index: 6;
  background: var(--bg); border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 -6px 18px rgba(0,0,0,.08);
}
.selbar .line { display: flex; gap: 8px; align-items: center; }
.selbar select { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px; }

/* ---------- накладная ---------- */
.head { padding: 14px 16px 6px; }
.head h2 { margin: 0 0 2px; font-size: 20px; }
.head .store { font-size: 16px; }
.head .meta { color: var(--hint); font-size: 14px; margin-top: 6px; line-height: 1.5; }
.note { margin: 8px 16px 0; padding: 10px 12px; border-radius: 12px; background: rgba(214,69,69,.12); color: var(--bad); }
.progress { padding: 4px 16px 6px; font-size: 14px; color: var(--hint); }

.items { padding: 4px 12px; display: flex; flex-direction: column; gap: 6px; }
.item {
  display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 12px 14px; min-height: 60px;
}
.item.tap { cursor: pointer; user-select: none; }
.item .info { flex: 1; min-width: 0; }
.item .nm { font-weight: 600; overflow-wrap: anywhere; white-space: pre-line; } /* в названиях из Excel бывают переносы строк */
.item .sub { font-size: 13.5px; color: var(--hint); margin-top: 2px; }
.item .mark { font-size: 22px; width: 34px; text-align: center; color: var(--line); }
.item.s-picked { opacity: .62; }
.item.s-picked .mark { color: var(--ok); }
.item.s-short { background: rgba(217,130,0,.14); }
.item.s-short .mark { color: var(--warn); }
.item.s-short .sub { color: var(--warn); font-weight: 600; }
.item .qty { font-size: 20px; font-weight: 700; white-space: nowrap; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line);
}
.actionbar .btn { flex: 1; }
body.has-actionbar { padding-bottom: calc(96px + var(--safe-b)); }

.panel { margin: 12px 12px 0; padding: 12px 14px; background: var(--card); border-radius: var(--radius); }
.panel .line { display: flex; gap: 8px; margin-top: 8px; }
.panel select { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px; }

details.log { margin: 12px 12px 0; background: var(--card); border-radius: var(--radius); padding: 10px 14px; }
details.log summary { cursor: pointer; font-weight: 600; }
.ev { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.ev:first-of-type { margin-top: 8px; }
.ev time { color: var(--hint); flex: none; width: 44px; }
.ev span { overflow-wrap: anywhere; }
.ev em { color: var(--hint); font-style: normal; }

/* ---------- сводка ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--hint); font-size: 13.5px; }
.tile.bad b { color: var(--bad); }

/* ---------- предпросмотр загрузки из Excel ---------- */
.muted { color: var(--hint); font-size: 13.5px; }
.pvhead { margin: 4px 0 8px; line-height: 1.5; }
.pvlist { max-height: 38vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.pv { padding: 8px 12px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.pv:last-child { border-bottom: 0; }
.pv.skip { opacity: .55; }
.pvwarn { margin: 0 0 8px; padding: 8px 10px; border-radius: 10px; background: rgba(217,130,0,.14); color: var(--warn); font-size: 14px; }
.pvinfo { margin: 0 0 8px; color: var(--hint); font-size: 13.5px; }

/* ---------- модальные окна ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
}
.sheet h3 { margin: 0 0 12px; font-size: 18px; color: var(--text); text-transform: none; letter-spacing: 0; }
.sheet label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--hint); }
.sheet input[type=text], .sheet input[type=number], .sheet textarea, .sheet select {
  display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; padding: 11px 12px; color: var(--text);
}
.sheet textarea { resize: vertical; min-height: 120px; }
.sheet .btns { display: flex; gap: 8px; margin-top: 6px; }
.sheet .btns .btn { flex: 1; }
.sheet .pickrow { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--text); }
.sheet .pickrow small { color: var(--hint); margin-left: auto; }
.sheet .hint { font-size: 13px; color: var(--hint); margin: -4px 0 12px; }
.sheet .menu { display: flex; flex-direction: column; gap: 8px; }

/* ---------- уведомление ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  max-width: 88vw; z-index: 30; padding: 11px 16px; border-radius: 12px; background: #2b2b2e; color: #fff;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
