/* «Цифры»: цвета из темы Telegram, шрифт Manrope (свой файл) */
:root {
  --bg: var(--tg-theme-secondary-bg-color);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color));
  --text: var(--tg-theme-text-color);
  --hint: var(--tg-theme-hint-color);
  --accent: var(--tg-theme-button-color);
  --on-accent: var(--tg-theme-button-text-color);
  --bad: var(--tg-theme-destructive-text-color);
  --line: var(--tg-theme-section-separator-color, color-mix(in srgb, var(--hint) 22%, transparent));
  --good: #2fa45a;
  --soft: color-mix(in srgb, var(--hint) 14%, transparent);
  --r: 20px;
}
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font: 500 15px/1.35 "Manrope", -apple-system, BlinkMacSystemFont, Roboto, sans-serif; font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; text-wrap: pretty; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app { min-height: var(--app-height, 100svh); padding: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 0 calc(76px + var(--tg-safe-area-inset-bottom, 0px)); }

/* период и строка «за что и когда» */
.bar { position: sticky; top: 0; z-index: 5; padding: 10px 16px 6px; background: var(--bg); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border-radius: 12px; background: var(--soft); }
.seg button { padding: 8px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--hint); transition: background .15s, color .15s; }
.seg button[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.meta { display: flex; justify-content: space-between; gap: 10px; padding: 4px 20px 10px; font-size: 12px; color: var(--hint); }
.meta #updated { white-space: nowrap; }

.screen { padding: 0 12px 16px; display: grid; gap: 10px; }
.card { background: var(--card); border-radius: var(--r); padding: 18px; }
.lab { font-size: 13px; font-weight: 600; color: var(--hint); }
.h { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.big { margin-top: 6px; font-size: 38px; line-height: 1; font-weight: 800; letter-spacing: -0.035em; }
.big.sm { font-size: 30px; }
.big .cur, .k-sum .cur { font-weight: 500; color: var(--hint); letter-spacing: 0; margin-left: .18em; }
.big.neg { color: var(--bad); }

/* сравнение с прошлым периодом */
.delta { font-size: 12px; font-weight: 700; white-space: nowrap; }
.delta:empty { display: none; }
.delta.up, .delta.down, .delta.flat { padding: 3px 7px; border-radius: 7px; }
.delta.up { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.delta.down { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.delta.flat { color: var(--hint); background: var(--soft); }
.delta.warn { color: var(--bad); }

/* три главные цифры */
.kpi { display: grid; grid-template-columns: repeat(3, 1fr); padding: 18px 0; }
.k { padding: 0 14px; display: grid; align-content: start; justify-items: start; gap: 2px; }
.k + .k { border-left: 1px solid var(--line); }
.k-num { font-size: 34px; line-height: 1; font-weight: 800; letter-spacing: -0.03em; }
.k-lab { font-size: 13px; font-weight: 600; color: var(--hint); white-space: nowrap; }
.k-sum { margin: 8px 0 6px; font-size: 15px; font-weight: 700; white-space: nowrap; }

/* чистыми */
.io { margin-top: 14px; display: flex; gap: 22px; }
.io p { display: grid; gap: 1px; }
.io b { font-size: 15px; }
.io .cur { margin-left: .18em; }
.days { position: relative; margin-top: 18px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.days::before { content: ""; position: absolute; left: 0; right: 0; top: var(--z, 76px); border-top: 1px dashed var(--line); }
.day { display: grid; grid-template-rows: 76px auto; justify-items: center; }
.day .plot { position: relative; display: block; width: 100%; max-width: 28px; height: 76px; }
.day .col { position: absolute; left: 0; right: 0; height: var(--h); }
.day.pos .col { bottom: calc(76px - var(--z, 76px)); background: linear-gradient(to top, color-mix(in srgb, var(--good) 55%, transparent), var(--good)); border-radius: 7px 7px 2px 2px; }
.day.neg .col { top: var(--z, 76px); background: linear-gradient(to bottom, color-mix(in srgb, var(--bad) 40%, transparent), color-mix(in srgb, var(--bad) 80%, transparent)); border-radius: 2px 2px 7px 7px; }
.day .col em { display: none; position: absolute; left: 50%; transform: translateX(-50%); font: 700 10px/1 "Manrope", sans-serif; font-style: normal; white-space: nowrap; }
.day.peak.pos .col em { display: block; bottom: calc(100% + 4px); color: var(--good); }
.day.peak.neg .col em { display: block; bottom: calc(100% + 4px); color: var(--bad); } /* над нулевой линией, не налезает на дату */
.day small { margin-top: 6px; font-size: 11px; font-weight: 600; color: var(--hint); min-height: 1.2em; }
.days.many { gap: 2px; }
.days.many .day small { font-size: 10px; }
.days.many .col em { display: none !important; }
.days-empty { margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--hint); }

/* отклики по площадкам */
.resp ul { list-style: none; padding: 0; margin-top: 14px; display: grid; gap: 11px; }
.resp li { display: grid; grid-template-columns: 112px 1fr 30px 52px; align-items: center; gap: 10px; font-size: 14px; }
.resp .nm { display: grid; grid-template-columns: auto 1fr; align-items: center; font-weight: 600; white-space: nowrap; overflow: hidden; }
.resp .nm > span { overflow: hidden; text-overflow: ellipsis; }
.resp .nm i { grid-column: 2; display: block; font-style: normal; font-size: 11px; font-weight: 600; color: var(--bad); }
.resp .tr { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.resp .tr span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.resp .c { text-align: right; font-weight: 700; }
.resp li .delta { justify-self: end; padding: 0; background: none; }

/* общая статистика */
.stats dl { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; }
.stats dt { font-size: 13px; font-weight: 600; color: var(--hint); }
.stats dd .cur { font-weight: 500; color: var(--hint); margin-left: .18em; }
.stats dd { margin: 3px 0 0; display: flex; align-items: baseline; gap: 8px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.stats dd .delta { letter-spacing: 0; }

/* площадки */
.cards { display: grid; gap: 10px; }
.pc { background: var(--card); border-radius: var(--r); padding: 16px 18px; }
.pc-h { display: flex; justify-content: space-between; align-items: baseline; }
.pc-h b { font-size: 17px; font-weight: 800; }
.pc-h span { font-size: 12px; font-weight: 600; color: var(--hint); }
.pc.stale .pc-h span { color: var(--bad); }
.pc dl { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.pc dt { font-size: 12px; font-weight: 600; color: var(--hint); }
.pc dd { margin: 0; font-size: 16px; font-weight: 700; }
.pc.quiet dd { color: var(--hint); }
.pc-note { margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--hint); }
.resp li.off { color: var(--hint); }
.undo { justify-self: center; padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--accent); }

/* заказы */
.list { background: var(--card); border-radius: var(--r); padding: 16px 18px 6px; }
.list ul { list-style: none; padding: 0; margin-top: 4px; }
.list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.o-name { font-weight: 700; }
.o-sum { font-weight: 800; text-align: right; }
.o-meta, .o-due { font-size: 13px; font-weight: 600; color: var(--hint); }
.o-due { text-align: right; white-space: nowrap; }
.o-due.late { color: var(--bad); }
.list .empty { color: var(--hint); font-size: 14px; display: block; }

/* деньги */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: var(--r); padding: 16px 18px; }
.cap { font-size: 13px; font-weight: 600; color: var(--hint); }
.num { margin-top: 4px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.sum { margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--hint); }
.money { width: 100%; border-collapse: collapse; font-size: 14px; }
.money th { font-weight: 600; font-size: 12px; color: var(--hint); text-align: right; padding: 0 0 6px; }
.money td { text-align: right; padding: 9px 0; border-top: 1px solid var(--line); }
.money th:first-child, .money td:first-child { text-align: left; }
.money td.o { color: var(--bad); }
.money td.n { font-weight: 800; }
.money tr.tot td { font-weight: 800; border-top: 2px solid var(--line); }
.add { width: 100%; padding: 14px; border-radius: 14px; background: var(--accent); color: var(--on-accent); font-weight: 700; }
.entry { background: var(--card); border-radius: var(--r); padding: 16px 18px; display: grid; gap: 12px; }
.entry label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--hint); }
.entry select, .entry input { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%; }
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.warn { font-size: 13px; font-weight: 600; color: var(--bad); }
.warn:empty { display: none; }

/* нижние вкладки */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 4px calc(8px + var(--tg-safe-area-inset-bottom, 0px)); background: var(--tg-theme-bottom-bar-bg-color, var(--card)); border-top: 1px solid var(--line); }
.tabs button { display: grid; justify-items: center; gap: 3px; padding: 4px 0; font-size: 11px; font-weight: 600; color: var(--hint); }
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.tabs button[aria-current="page"] { color: var(--accent); }

/* важное */
.tabs button { position: relative; }
.badge { position: absolute; top: 0; left: 50%; margin-left: 6px; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font: 700 11px/17px "Manrope", sans-serif; font-style: normal; text-align: center; }
#att { display: grid; gap: 10px; }
.att { background: var(--card); border-radius: var(--r); padding: 14px 18px 6px; }
.att h2 { font-size: 13px; font-weight: 700; color: var(--hint); }
.att.decision h2, .att.error h2 { color: var(--bad); }
.att ul { list-style: none; padding: 0; margin-top: 4px; }
.att li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.att li:last-child { border-bottom: 0; }
.att .tx { font-size: 15px; font-weight: 600; line-height: 1.35; }
.att .mt { grid-column: 1; font-size: 12px; font-weight: 600; color: var(--hint); }
.att .ok { grid-row: 1 / span 2; grid-column: 2; padding: 6px 10px; border-radius: 9px; background: var(--soft); font-size: 13px; font-weight: 700; color: var(--accent); }
.att-empty { padding: 40px 18px; text-align: center; color: var(--hint); font-weight: 600; }

/* значки площадок */
.mk { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 8px; border-radius: 7px; vertical-align: middle; background: var(--mc); color: #fff; font: 800 9.5px/1 "Manrope", sans-serif; letter-spacing: -0.02em; }
.pc-h .mk { width: 26px; height: 26px; font-size: 11px; border-radius: 8px; vertical-align: -6px; }
.resp li { grid-template-columns: 138px 1fr 30px 52px; }
.resp .tr span { background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 60%, transparent), var(--accent)); }

/* нули приглушены, чтобы взгляд шёл к тому, что есть */
.k.nil .k-num, .k.nil .k-sum { color: color-mix(in srgb, var(--hint) 70%, transparent); }

/* главная сумма крупнее и с мягкой подложкой */
.net { background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 7%, var(--card)), var(--card) 60%); }
.big { font-size: 44px; }

/* переход между вкладками */
.screen.in { animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .screen.in { animation: none; } }
.resp .nm:has(i) .mk { grid-row: 1 / span 2; }

/* «Сейчас»: что горит, наверху главного */
.now { display: grid; gap: 6px; }
.nw { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 14px 12px 16px; border-radius: 14px; background: var(--card); font-size: 14px; font-weight: 700; border-left: 4px solid var(--hint); }
.nw.warn { border-left-color: #f59f00; background: color-mix(in srgb, #f59f00 9%, var(--card)); }
.nw.bad { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 9%, var(--card)); }
.nw b { white-space: nowrap; font-weight: 800; }
.nw b .cur { color: var(--hint); font-weight: 500; margin-left: .15em; }
.nw::after { content: "›"; color: var(--hint); font-size: 18px; margin-left: 2px; }
.nw.calm { border-left-color: var(--good); color: var(--hint); font-weight: 600; }
.nw.calm::after { content: none; }

/* ожидается и график-кнопка */
.exp { margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--hint); }
.exp:empty { display: none; }
.exp b { color: var(--text); }
.exp .cur { margin-left: .15em; }
button.days { width: 100%; padding: 0; text-align: inherit; }
.daytab { padding: 10px 18px 6px; }
.daytab .money td, .daytab .money th { padding-left: 6px; }

/* путь к деньгам */
.funnel ol { list-style: none; padding: 0; margin-top: 12px; display: grid; gap: 10px; }
.funnel li { display: grid; grid-template-columns: 78px 1fr 44px 38px; align-items: center; gap: 10px; font-size: 14px; }
.funnel .fn { font-weight: 600; }
.funnel .fb { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.funnel .fb span { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, color-mix(in srgb, var(--good) 55%, transparent), var(--good)); }
.funnel li b { text-align: right; font-weight: 800; }
.funnel li small { text-align: right; font-size: 12px; font-weight: 700; color: var(--hint); }
.funnel dl { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.funnel dt { font-size: 13px; font-weight: 600; color: var(--hint); }
.funnel dd { margin: 3px 0 0; display: flex; align-items: baseline; gap: 8px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.funnel dd .cur { font-weight: 500; color: var(--hint); margin-left: .18em; }

/* окупаемость площадок */
.pt { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 14px; }
.pt th { font-size: 12px; font-weight: 600; color: var(--hint); text-align: right; padding: 4px 0 6px; }
.pt th:first-child, .pt td:first-child { text-align: left; }
.pt td { padding: 10px 0; border-top: 1px solid var(--line); text-align: right; font-weight: 700; vertical-align: top; }
.pt .pc1 { display: flex; align-items: flex-start; }
.pt .mk { flex: none; margin-top: 1px; }
.pt .pn { display: grid; gap: 2px; font-weight: 700; }
.pt .pn small, .pt .pn i { font-size: 12px; font-weight: 600; font-style: normal; color: var(--hint); }
.pt .pn i.bad { color: var(--bad); }
.pt td.pos { color: var(--good); }
.pt td.neg { color: var(--bad); }
.pt td:nth-child(2), .pt td:nth-child(3) { width: 52px; }
.pt td:nth-child(4) { width: 86px; white-space: nowrap; }
.quiet-p { padding: 14px 18px; }
.quiet-p summary { font-size: 13px; font-weight: 600; color: var(--hint); cursor: pointer; }
.quiet-p ul { list-style: none; padding: 0; margin-top: 10px; display: grid; gap: 10px; font-weight: 600; }
.quiet-p li small { display: block; margin-left: 30px; font-size: 12px; color: var(--hint); }
.o-sum small { display: block; font-size: 12px; font-weight: 600; color: var(--hint); }

/* ошибка связи: старые цифры не стираем */
.err { margin: 0 12px 8px; padding: 9px 14px; border-radius: 12px; background: color-mix(in srgb, var(--bad) 12%, var(--card)); color: var(--bad); font-size: 13px; font-weight: 700; }

/* пока нет данных: серые заглушки вместо нулей */
body.loading .k-num, body.loading .big, body.loading #f-resp { color: transparent; background: var(--soft); border-radius: 8px; min-width: 2.2em; min-height: 1em; animation: pulse 1.2s ease-in-out infinite; }
body.loading .now { display: none; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { body.loading * { animation: none !important; } }

/* узкие экраны (320 px): ничего не вылезает за край */
.list li > * { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 360px) {
  .k { padding: 0 8px; }
  .big { font-size: 34px; }
  .resp li { grid-template-columns: 96px 1fr auto 44px; gap: 8px; }
  .funnel li { grid-template-columns: 70px 1fr auto 34px; gap: 8px; }
  .pt { font-size: 13px; }
}
.pt tr.sub td { border-top: 0; padding: 0 0 10px 30px; text-align: left; font-size: 12px; font-weight: 600; color: var(--hint); }
.pt tr:has(+ tr.sub) td { padding-bottom: 4px; }
