/* Кольори бере з теми Telegram, тож панель виглядає рідною і вдень, і вночі. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #14161a);
  --hint: var(--tg-theme-hint-color, #7d838c);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --accent: var(--tg-theme-button-color, #0036fc);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93838);
  --free: #8fbf00;
  --paid: #0036fc;
  --own: #9aa1ab;
  --radius: 14px;
  color-scheme: light dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--hint); margin: 22px 4px 8px; }
h3 { font-size: 17px; margin: 0 0 2px; overflow-wrap: anywhere; }
p { margin: 0; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; }
.logo { height: 12px; width: auto; display: block; }

.chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--line); color: var(--hint); white-space: nowrap; }
.chip.on { background: color-mix(in srgb, var(--free) 22%, transparent); color: color-mix(in srgb, var(--free) 60%, var(--text)); }
.chip.warn { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 2px; padding: 8px 12px; background: var(--bg); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; padding: 8px 12px; border-radius: 10px; color: var(--hint); font-weight: 600; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

main { max-width: 760px; margin: 0 auto; padding: 0 12px; }
.page { min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.hint { color: var(--hint); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--hint); font-size: 13px; }
.stat .s { color: var(--hint); font-size: 12px; margin-top: 4px; }
.meter { height: 5px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--free); }
.meter.hot i { background: var(--danger); }

.seg { display: inline-flex; background: var(--line); border-radius: 9px; padding: 2px; }
.seg button { padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--hint); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 4px 8px; }
.row-head h2 { margin: 0; }

.chart-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.chart-title b { font-size: 15px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .axis { fill: var(--hint); font-size: 10px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .mark { fill: var(--text); opacity: .55; }
.bar-free { fill: var(--free); } .bar-paid { fill: var(--paid); } .bar-own { fill: var(--own); } .bar-one { fill: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--hint); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--c); }
.dot-free { --c: var(--free); } .dot-paid { --c: var(--paid); } .dot-own { --c: var(--own); }
.picked { min-height: 18px; margin-top: 6px; font-size: 13px; color: var(--hint); }

.bars { display: grid; gap: 9px; }
.bars div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; font-size: 14px; }
.bars span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .meter { grid-column: 1 / -1; margin: 0; }
.bars .meter i { background: var(--accent); }

.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 9px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--hint); white-space: nowrap; } .kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); outline: none; }
.search:focus { border-color: var(--accent); }
.list { background: var(--card); border-radius: var(--radius); margin-top: 10px; overflow: hidden; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; width: 100%; text-align: left; padding: 11px 14px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
button.item:active { background: var(--line); }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--hint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .right { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .right small { color: var(--hint); font-weight: 400; font-size: 12px; margin-left: 4px; }
.item .right.sub { font-size: 13px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--line); color: var(--hint); margin-left: 6px; vertical-align: 1px; }
.tag.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.empty { padding: 26px 14px; text-align: center; color: var(--hint); }
.more { display: block; width: 100%; padding: 12px; margin-top: 10px; border-radius: 12px; background: var(--card); color: var(--accent); font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 16px; border-radius: 11px; font-weight: 600; background: var(--line); }
.btn.main { background: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.field { display: flex; gap: 8px; margin-top: 12px; }
.field input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.field input:focus { border-color: var(--accent); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--line); transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--free); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.sheet { width: min(100%, 560px); max-width: 100%; max-height: 88vh; margin: auto auto 0; border: 0; border-radius: 18px 18px 0 0; padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); background: var(--bg); color: var(--text); overflow-y: auto; }
@media (min-width: 620px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.close { width: 32px; height: 32px; border-radius: 50%; background: var(--line); font-size: 18px; line-height: 1; flex: none; }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: #14161a; color: #fff; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgb(0 0 0 / .3); }
.toast.bad { background: #b32626; }
.locked { text-align: center; padding: 60px 20px; }
.locked h2 { text-transform: none; letter-spacing: 0; font-size: 19px; color: var(--text); margin: 0 0 8px; }
.locked p { color: var(--hint); }
.skeleton { height: 120px; border-radius: var(--radius); background: var(--card); opacity: .6; }
