:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --section: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --accent: var(--tg-theme-button-color, #2a7ae2);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-section-header-text-color, #6d7885);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --good: #1f9d55;
  --warn: #d97706;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg2); }
.top h1 { font-size: 20px; margin: 0; font-weight: 700; }
.icon-btn { border: 0; background: var(--section); border-radius: 50%; width: 36px; height: 36px; font-size: 18px; }
main { padding: 0 12px calc(84px + var(--safe-bottom)); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--section); border-top: 1px solid color-mix(in srgb, var(--hint) 20%, transparent);
  padding-bottom: var(--safe-bottom); }
.tabs button { border: 0; background: none; padding: 7px 0 9px; font-size: 11px; color: var(--hint); display: flex;
  flex-direction: column; align-items: center; gap: 1px; }
.tabs button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); }
.tabs button.active span { filter: none; opacity: 1; }

.card { background: var(--section); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 10px; }
.card.tap:active { opacity: .7; }
.section-title { color: var(--header); font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  margin: 18px 4px 6px; font-weight: 600; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--hint); font-size: 13px; }
.big { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.right { text-align: right; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--danger); } .muted { color: var(--hint); }
.badge { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 10px; margin: 2px 4px 0 0;
  background: var(--bg2); color: var(--hint); }
.badge.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.info { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.qty { font-size: 20px; font-weight: 700; }
.list > .card { margin-bottom: 8px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kpi { background: var(--section); border-radius: var(--radius); padding: 10px 12px; }
.kpi .label { color: var(--hint); font-size: 12px; }
.kpi .value { font-size: 19px; font-weight: 700; margin-top: 2px; }

.search { display: flex; gap: 8px; margin: 4px 0 10px; }
.search input { flex: 1; }
input, select, textarea { width: 100%; border: 1px solid color-mix(in srgb, var(--hint) 30%, transparent);
  background: var(--section); border-radius: 10px; padding: 9px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 60px; resize: vertical; }
label.field { display: block; margin: 0 0 10px; }
label.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 4px 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid color-mix(in srgb, var(--hint) 30%, transparent); background: var(--section);
  border-radius: 16px; padding: 5px 12px; white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 7px 4px; font-size: 14px; }
.seg button.on { background: var(--section); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 12px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); margin: 8px 0; }
.btn.light { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.small { display: inline-block; width: auto; padding: 6px 12px; margin: 0; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.fab { position: fixed; right: 16px; bottom: calc(74px + var(--safe-bottom)); z-index: 9; border: 0; border-radius: 28px;
  padding: 13px 18px; font-weight: 700; background: var(--accent); color: var(--accent-text);
  box-shadow: 0 4px 14px rgba(0,0,0,.18); }

.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg2); overflow-y: auto;
  padding: 0 12px calc(90px + var(--safe-bottom)); animation: up .18s ease-out; }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: 12px 2px 10px; background: var(--bg2); }
.sheet-head h2 { margin: 0; font-size: 18px; flex: 1; }
.sheet .local-main { position: fixed; left: 12px; right: 12px; width: auto; bottom: calc(12px + var(--safe-bottom)); margin: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,.15); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.line-card { position: relative; }
.line-card .x { position: absolute; right: 8px; top: 6px; border: 0; background: none; font-size: 18px; color: var(--hint); }
.cur { display: flex; gap: 6px; }
.cur input { flex: 1; }
.cur button { border: 1px solid color-mix(in srgb, var(--hint) 30%, transparent); background: var(--section);
  border-radius: 10px; width: 46px; font-weight: 700; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t td { padding: 6px 0; border-bottom: 1px solid color-mix(in srgb, var(--hint) 15%, transparent); }
table.t tr:last-child td { border-bottom: 0; }
.bar { height: 6px; border-radius: 3px; background: var(--accent); margin-top: 4px; opacity: .8; }

.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: rgba(20,20,20,.88); color: #fff; padding: 9px 14px; border-radius: 12px; font-size: 14px; z-index: 50;
  opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }

.scanner { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.scanner #reader { flex: 1; }
.scanner #reader video { object-fit: cover; }
.scanner .btn { margin: 12px; width: auto; }
.empty { text-align: center; color: var(--hint); padding: 30px 10px; }
.loading { text-align: center; color: var(--hint); padding: 40px 0; }
