:root {
  --bg: var(--tg-theme-bg-color, #f5f1ea);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --ink: var(--tg-theme-text-color, #1c1710);
  --ink-hint: var(--tg-theme-hint-color, #8a7566);
  --accent: var(--tg-theme-button-color, #b9701f);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(0, 0, 0, 0.08);
  --mint: #2f8f6e;
  --mint-soft: rgba(47, 143, 110, 0.12);
  --critical: #c0432f;
  --critical-soft: rgba(192, 67, 47, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }

#root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  padding: 14px 18px 8px;
  flex-shrink: 0;
}
.topbar .hi { font-size: 13px; color: var(--ink-hint); }
.topbar .name { font-size: 20px; font-weight: 700; margin-top: 2px; }

.body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 90px;
  position: relative;
}

.card {
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.card .label {
  font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-hint); font-weight: 600;
}
.card .big { font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 700; margin-top: 4px; }
.card .delta { font-size: 12.5px; margin-top: 3px; font-family: ui-monospace, Menlo, monospace; }
.card .delta.up { color: var(--mint); }
.card .delta.down { color: var(--critical); }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.warn-banner {
  background: var(--critical-soft); border: 1px solid var(--critical); color: var(--critical);
  border-radius: 14px; padding: 10px 14px; font-size: 13px; margin-bottom: 10px; line-height: 1.4;
  display: flex; gap: 8px; align-items: flex-start;
}

.qa-row { display: flex; gap: 8px; margin: 4px 0 14px; }
.qa-btn {
  flex: 1; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 12px;
  padding: 11px 6px; font-size: 12.5px; font-weight: 600; text-align: center; font-family: inherit;
}
.qa-btn:active { opacity: 0.8; }

.sec-title { font-size: 13px; font-weight: 600; margin: 16px 0 8px; }

.list {
  background: var(--surface); border-radius: 16px; border: 1px solid var(--border); overflow: hidden;
}
.list-row {
  display: flex; justify-content: space-between; align-items: center; padding: 12px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { background: var(--bg); }
.list-row .l-main { font-size: 14px; font-weight: 500; }
.list-row .l-sub { font-size: 12px; color: var(--ink-hint); margin-top: 2px; }
.list-row .l-amt { font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; white-space: nowrap; margin-left: 10px; }
.l-amt.mint { color: var(--mint); }
.l-amt.critical { color: var(--critical); }

.empty-state { text-align: center; color: var(--ink-hint); font-size: 14px; padding: 40px 20px; }

.fab {
  position: fixed; right: 18px; bottom: 82px;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 400; box-shadow: 0 8px 20px -6px rgba(0,0,0,0.4);
  z-index: 10;
}
.fab:active { transform: scale(0.94); }

.tabbar {
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom, 0px)); flex-shrink: 0;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; color: var(--ink-hint); cursor: pointer; user-select: none; background: none; border: none; font-family: inherit; padding: 4px 0; }
.tab .ic { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }

/* --- sheet (форма поверх экрана) --- */
.sheet-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 20;
  display: flex; flex-direction: column;
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sheet-header .title { font-size: 16px; font-weight: 700; }
.sheet-header button { background: none; border: none; font-family: inherit; font-size: 14px; color: var(--accent); font-weight: 600; padding: 6px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-hint); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; font-size: 15px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-family: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field .hint { font-size: 12px; color: var(--ink-hint); margin-top: 5px; }

.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg button { flex: 1; text-align: center; font-size: 13px; padding: 8px 0; border-radius: 7px; color: var(--ink-hint); background: none; border: none; font-family: inherit; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.btn-primary {
  width: 100%; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 12px;
  padding: 14px; font-size: 15px; font-weight: 600; font-family: inherit; margin-top: 6px;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary[disabled] { opacity: 0.5; }
.btn-danger {
  width: 100%; background: var(--critical-soft); color: var(--critical); border: none; border-radius: 12px;
  padding: 14px; font-size: 15px; font-weight: 600; font-family: inherit; margin-top: 10px;
}

.detail-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--ink-hint); }
.detail-row .v { font-weight: 600; font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px;
  font-size: 13.5px; z-index: 30; opacity: 0; transition: opacity 0.2s;
  pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

.spinner { text-align: center; padding: 30px; color: var(--ink-hint); font-size: 13px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  padding: 8px 12px; border-radius: 10px; font-size: 13px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-family: inherit;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- Остатки --- */
.stock-item { margin-bottom: 14px; }
.stock-item .si-top { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 5px; }
.stock-item .si-top .n { color: var(--ink-hint); font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.bar-track { height: 7px; border-radius: 4px; background: var(--border); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--mint); }
.bar-fill.low { background: var(--critical); }

/* --- Отчёты / графики --- */
.data-color { color: #2a78d6; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 14px 10px; margin-bottom: 10px; }
.chart-card .ct { font-size: 12.5px; font-weight: 600; margin-bottom: 10px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; }
.bars .b { flex: 1; background: #2a78d6; border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .bl { display: flex; gap: 6px; margin-top: 6px; }
.bars .bl span { flex: 1; text-align: center; font-size: 9.5px; color: var(--ink-hint); }
.hbar-row { margin-bottom: 10px; }
.hbar-row .hr-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.hbar-track { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; background: #2a78d6; border-radius: 4px; }

/* --- Ещё --- */
.more-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--border); font-size: 14.5px; cursor: pointer; }
.more-row:last-child { border-bottom: none; }
.more-row:active { opacity: 0.7; }
.more-row .arr { color: var(--ink-hint); }
