/* Цвета берутся из темы Telegram, чтобы приложение выглядело родным в светлой и тёмной теме.
   Свои цвета — только у слоёв полосы прибыли: каждый слой — своя статья. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111214);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7dd4);
  --accent: var(--tg-theme-button-color, #2a7dd4);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.22));
  --header: var(--tg-theme-header-bg-color, var(--bg));
  --destructive: var(--tg-theme-destructive-text-color, #d63c35);

  --gain: #17875c;
  --loss: #d0453b;
  --layer-hold: #e3a13a;   /* удержания площадок */
  --layer-cost: #7e8ea4;   /* себестоимость */
  --layer-loss: #c97b5a;   /* списания и брак */
  --layer-fixed: #9b6db0;  /* постоянные расходы */
  --layer-profit: var(--gain);

  --r: 12px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #111215;
    --section: #1c1d21;
    --text: #f2f3f5;
    --hint: #8b9099;
    --sep: rgba(255, 255, 255, 0.1);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Месяц */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px var(--gutter);
  background: var(--header);
  border-bottom: 1px solid var(--sep);
}
.topbar.hidden { display: none; }
.month-title { font-weight: 600; font-size: 17px; }
.month-nav {
  width: 40px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; font-size: 24px; line-height: 1; color: var(--link); cursor: pointer;
}
.month-nav:disabled { color: var(--hint); opacity: .4; cursor: default; }

.view { padding: 12px 0 24px; max-width: 640px; margin: 0 auto; }

/* Главная цифра */
.hero { padding: 8px var(--gutter) 4px; }
.hero-label { color: var(--hint); font-size: 15px; }
.hero-value { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin-top: 2px; }
.hero-value .unit { font-size: 18px; font-weight: 600; letter-spacing: 0; margin-left: 4px; color: var(--hint); }
.hero-value.gain { color: var(--gain); }
.hero-value.loss { color: var(--loss); }
.hero-note { color: var(--hint); font-size: 14px; margin-top: 4px; }

/* Полоса прибыли из слоёв */
.layers { margin: 14px var(--gutter) 6px; }
.layer-bar {
  position: relative; display: flex; height: 22px; border-radius: 6px; overflow: hidden;
  background: repeating-linear-gradient(90deg, transparent 0 3px, rgba(128,128,128,.08) 3px 4px);
}
.layer-bar > span { height: 100%; }
.layer-bar .edge {
  position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); opacity: .55;
}
.layer-scale { display: flex; justify-content: space-between; color: var(--hint); font-size: 12px; margin-top: 4px; }
.legend { list-style: none; margin: 10px 0 0; padding: 0; }
.legend li { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 15px; }
.legend li + li { border-top: 1px solid var(--sep); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 10px; flex: none; }
.legend .name { display: flex; align-items: center; }
.legend .total { font-weight: 600; }

/* Секции в стиле Telegram */
.section { background: var(--section); margin: 14px var(--gutter) 0; border-radius: var(--r); overflow: hidden; }
.section-title { color: var(--hint); font-size: 14px; margin: 22px calc(var(--gutter) + 12px) 6px; }
.section-title + .section { margin-top: 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  min-height: 48px; color: var(--text);
}
.row + .row { border-top: 1px solid var(--sep); }
a.row:active, button.row:active { background: rgba(128,128,128,.12); }
button.row { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--hint); font-size: 13px; margin-top: 1px; }
.row .side { text-align: right; flex: none; }
.row .side .sub { margin-top: 2px; }
.row .chev { color: var(--hint); font-size: 18px; flex: none; }
.thumb {
  width: 44px; height: 44px; border-radius: 9px; flex: none; object-fit: cover;
  background: rgba(128,128,128,.14); display: grid; place-items: center; color: var(--hint); font-size: 18px;
}
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.hint { color: var(--hint); }
.pill {
  display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px; margin-top: 3px;
  background: rgba(128,128,128,.15); color: var(--hint);
}
.pill.sold { background: rgba(23,135,92,.14); color: var(--gain); }
.pill.cancelled { background: rgba(208,69,59,.12); color: var(--loss); }
.pill.returned { background: rgba(227,161,58,.18); color: #b77810; }
.pill.pending { background: rgba(42,125,212,.12); color: var(--link); }

/* Плитки */
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--sep); }
.pair { background: var(--section); padding: 12px; }
.pair .k { color: var(--hint); font-size: 13px; }
.pair .v { font-size: 18px; font-weight: 600; margin-top: 2px; }
.pair .s { color: var(--hint); font-size: 12px; margin-top: 2px; }

/* Быстрые действия */
.actions { display: flex; gap: 8px; overflow-x: auto; padding: 14px var(--gutter) 2px; scrollbar-width: none; }
.actions::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 8px 14px; font-size: 15px; cursor: pointer;
  background: var(--section); color: var(--text);
}
.chip.primary { background: var(--accent); color: var(--accent-text); }
.chip.on { background: var(--accent); color: var(--accent-text); }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 0 var(--gutter); scrollbar-width: none; }
.filters .chip { font-size: 14px; padding: 6px 12px; }

/* График по месяцам */
.chart { padding: 12px 12px 8px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--hint); font: 11px var(--font); }

/* Детали */
.detail-head { display: flex; gap: 12px; align-items: center; padding: 6px var(--gutter) 0; }
.detail-head .thumb { width: 64px; height: 64px; border-radius: 12px; }
.detail-head h1 { font-size: 20px; margin: 0; line-height: 1.25; }
.detail-head .sub { color: var(--hint); font-size: 14px; margin-top: 2px; }
.gallery { display: flex; gap: 8px; overflow-x: auto; padding: 12px var(--gutter) 0; }
.gallery img { width: 160px; height: 160px; object-fit: cover; border-radius: 12px; flex: none; background: rgba(128,128,128,.12); }
.btn {
  display: block; width: calc(100% - 2 * var(--gutter)); margin: 12px var(--gutter) 0;
  border: 0; border-radius: 12px; padding: 13px; font-size: 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text); text-align: center;
}
.btn.quiet { background: var(--section); color: var(--link); font-weight: 500; }
.btn.danger { background: var(--section); color: var(--destructive); font-weight: 500; }
.voided { opacity: .45; text-decoration: line-through; }

.empty { padding: 36px var(--gutter); text-align: center; color: var(--hint); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.error { margin: 16px var(--gutter); padding: 14px; border-radius: var(--r); background: rgba(208,69,59,.12); color: var(--loss); }
.loading { padding: 40px; text-align: center; color: var(--hint); }

/* Нижнее меню */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--header); border-top: 1px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 6px; font-size: 11px; color: var(--hint);
}
.tabbar a .ico svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.tabbar a.active { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  background: rgba(30,30,32,.94); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; max-width: 90vw; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* строки-расшифровка под «Удержания площадок» */
.legend li.sub { padding-left: 22px; font-size: 13px; color: var(--hint); border-top: none; padding-top: 2px; padding-bottom: 2px; }
