/* Цвета берутся из темы Telegram (CSS-переменные выставляет telegram-web-app.js),
   фолбэки — для открытия в обычном браузере. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --plus: #2ea043;
  --minus: #e5534b;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17212b; --bg2: #232e3c; --text: #f5f5f5; --hint: #708499;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; padding: 12px 16px 32px;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}
h3 { margin: 20px 0 8px; font-size: 15px; color: var(--hint); font-weight: 600; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button {
  flex: 1; padding: 9px 4px; border: 0; border-radius: var(--radius);
  background: var(--bg2); color: var(--text); font-size: 14px;
}
.tabs button.active { background: var(--btn); color: var(--btn-text); }

.filters { display: flex; gap: 6px; margin-bottom: 12px; }
.filters select { flex: 1; min-width: 0; }

.tab { display: none; }
.tab.active { display: block; }

.card { background: var(--bg2); border-radius: var(--radius); padding: 12px; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 8px; }
.cards .card .label { color: var(--hint); font-size: 12px; }
.cards .card .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-card { height: 220px; }

.plus { color: var(--plus); }
.minus { color: var(--minus); }

.table .row-item {
  display: grid; grid-template-columns: 1.5fr 0.5fr 1fr 0.9fr 0.8fr; gap: 6px;
  padding: 8px 0; border-bottom: 1px solid var(--bg2); font-variant-numeric: tabular-nums;
}
.table .row-item.head { color: var(--hint); font-size: 12px; }
.table .row-item { font-size: 14px; }
.table .row-item span:not(:first-child) { text-align: right; }

.session {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; margin-bottom: 6px; background: var(--bg2); border-radius: var(--radius);
}
.session .meta { color: var(--hint); font-size: 12px; }
.session .main { flex: 1; min-width: 0; }
.session .profit { font-weight: 700; font-variant-numeric: tabular-nums; }
.session .del {
  margin-left: 10px; padding: 6px 8px; border: 0; border-radius: 8px;
  background: none; color: var(--hint); font-size: 16px; line-height: 1;
}
.empty { color: var(--hint); text-align: center; padding: 40px 0; }

form label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--hint); }
form .row { display: flex; gap: 8px; }
form .row label { flex: 1; min-width: 0; }
input, select, textarea {
  width: 100%; margin-top: 4px; padding: 10px; font: inherit; color: var(--text);
  background: var(--bg2); border: 1px solid transparent; border-radius: 10px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--btn); }
.filters select { margin-top: 0; padding: 8px; }

.seg { display: flex; background: var(--bg2); border-radius: var(--radius); padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; padding: 8px; border: 0; border-radius: 9px; background: none; color: var(--text); font: inherit; }
.seg button.active { background: var(--bg); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }

button.primary, button.secondary, button.danger {
  width: 100%; padding: 12px; border: 0; border-radius: var(--radius); font: inherit; font-weight: 600;
}
button.primary { background: var(--btn); color: var(--btn-text); }
button.secondary { background: var(--bg); color: var(--link); }
button.danger { background: none; color: var(--minus); margin-top: 6px; }

/* Подписка */
.sub-banner {
  margin-bottom: 10px; padding: 9px 12px; border-radius: var(--radius);
  background: var(--bg2); font-size: 13px; color: var(--hint); cursor: pointer;
}
.sub-banner b { color: var(--text); }
.sub-banner .go { color: var(--link); float: right; }
.paywall { text-align: center; padding: 24px 8px; }
.paywall-icon { font-size: 48px; }
.paywall h2 { margin: 8px 0; }
.paywall p { color: var(--hint); }
.paywall ul { text-align: left; margin: 16px auto 20px; padding-left: 20px; max-width: 320px; }
.paywall li { margin: 6px 0; }
.paywall .hint { font-size: 12px; margin: 10px 0 18px; }
.export-btn { margin-bottom: 10px; background: var(--bg2) !important; }

/* Автодополнение рума и лимита */
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  max-height: 240px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--bg2); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.ac-item { padding: 10px 12px; color: var(--text); font-size: 15px; cursor: pointer; }
.ac-item + .ac-item { border-top: 1px solid var(--bg2); }
.ac-item:hover, .ac-item.active { background: var(--bg2); }
.ac-item b { font-weight: 700; }

.profit-preview { text-align: center; font-size: 18px; font-weight: 700; margin: 6px 0 12px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: 16px; padding: 12px;
  background: var(--text); color: var(--bg); border-radius: var(--radius); text-align: center;
}
