/* AI Finance — финансовый интерфейс Mini App (mobile-first, тёмная тема) */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1b2028;
  --border: #263041;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --tok-in: #58a6ff;
  --tok-out: #a371f7;
  --tok-cache: #d29922;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: 32px;
}

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  background: linear-gradient(var(--bg) 55%, rgba(13, 17, 23, 0));
  backdrop-filter: blur(6px);
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
.topbar > div { min-width: 0; flex: 1 1 auto; }
.status { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.status.ok { color: var(--green); }
.status.err { color: var(--red); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:not(:disabled):active { transform: translateY(1px); }

main { padding: 0 16px; max-width: 720px; margin: 0 auto; }

.block { margin-top: 20px; }
.block > h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

/* Карточки провайдеров */
.cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card-name { font-weight: 700; font-size: 15px; min-width: 0; overflow-wrap: anywhere; }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.pill-ok { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.pill-muted { background: rgba(139, 148, 158, 0.15); color: var(--muted); }
.pill-error { background: rgba(248, 81, 73, 0.15); color: var(--red); }

.card-body { display: flex; flex-direction: column; gap: 5px; }
.balance-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.balance-cur { font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; }
.balance-val {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.line-muted { font-size: 12px; color: var(--muted); line-height: 1.5; }
.line-warn { font-size: 12px; color: var(--yellow); line-height: 1.5; }

/* Сводка расходов */
.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.summary-cost { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.summary-label { font-size: 13px; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.summary-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: right;
}
.summary-tokens { font-size: 12px; color: var(--muted); font-family: var(--mono); line-height: 1.5; overflow-wrap: anywhere; }

/* Строки расходов */
.prov-group { margin-top: 14px; }
.prov-group:first-of-type { margin-top: 0; }
.prov-head {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin: 0 0 6px 2px;
}
.usage-list { display: flex; flex-direction: column; gap: 8px; }
.usage-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.usage-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.usage-model {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.usage-hint { font-size: 10.5px; color: var(--muted); font-weight: 400; }
.usage-cost {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  white-space: nowrap;
}
.usage-tok {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  line-height: 1.5;
  overflow-wrap: anywhere;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}
.usage-note { font-size: 11.5px; color: var(--yellow); }

/* Пустые / информационные состояния */
.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
}
.empty-title { font-weight: 600; font-size: 14px; }
.empty-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

/* Панель фильтров периода и режима */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}

/* Динамика — столбчатый график по дням */
.chart-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.legend { display: flex; flex-wrap: wrap; gap: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.legend-swatch-in { background: var(--tok-in); }
.legend-swatch-out { background: var(--tok-out); }
.legend-swatch-cache { background: var(--tok-cache); }

.chart-wrap { display: flex; flex-direction: column; gap: 6px; }
.chart-scale { font-size: 11px; color: var(--muted); }

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.chart-plot { display: flex; align-items: flex-end; gap: 12px; min-width: max-content; }
.chart-day { display: flex; flex-direction: column; align-items: center; flex: none; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; }
.chart-col { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none; cursor: pointer; }
.chart-model {
  font-size: 9.5px;
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
  max-width: 46px;
  line-height: 1.2;
}
.chart-bar {
  width: 40px;
  height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-radius: 4px;
  overflow: hidden;
}
.chart-seg { width: 100%; flex: none; }
.chart-seg-in { background: var(--tok-in); }
.chart-seg-out { background: var(--tok-out); }
.chart-seg-cache { background: var(--tok-cache); }
.chart-date { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; }

.chart-tip {
  display: none;
  position: fixed;
  z-index: 100;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  min-width: 160px;
  max-width: 260px;
}
.tip-title { font-weight: 700; margin-bottom: 2px; overflow-wrap: anywhere; }
.tip-row { color: var(--muted); }
.tip-total { color: var(--text); font-weight: 600; margin-top: 2px; }
