/* styles.css - the dashboard's only stylesheet: no framework, no build step.
 *
 * Deliberately plain CSS: the page is served by the bot's own FastAPI deployment
 * and opened inside Telegram's in-app browser as often as on a desktop, so it has
 * to be small, self-contained and readable on a phone. Light and dark are both
 * handled from custom properties via prefers-color-scheme.
 */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #22262c;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6fd0;
  --accent-ink: #ffffff;
  --good: #2e9e5b;
  --warn: #d98218;
  --bad: #c2312f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 25, 35, 0.06), 0 4px 14px rgba(20, 25, 35, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1e2126;
    --ink: #e8eaee;
    --muted: #9aa2ae;
    --line: #2c3138;
    --accent: #5b96e8;
    --accent-ink: #10131a;
    --good: #57c98a;
    --warn: #e0a34d;
    --bad: #e56f6d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* An author rule such as `.btn.block { display: block }` or `.field { display: flex }`
 * outranks the user-agent's `[hidden] { display: none }`, so anything toggled with the
 * hidden attribute would stay on screen — a "hidden" Google button that still looked
 * clickable, and both period pickers showing at once. Every hidden toggle in app.js
 * relies on this rule, so it must stay ahead of the rest of the sheet. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.35rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.02rem; margin: 0 0 0.6rem; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.spacer { flex: 1 1 auto; }

/* ── Screens and cards ───────────────────────────────────────────────── */

.screen { max-width: 1180px; margin: 0 auto; padding: 16px; }
.screen[hidden] { display: none; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card.narrow { max-width: 460px; margin: 8vh auto; }

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  /* Cards size to their own content. Stretching them to match the taller neighbour
   * left large empty regions under the charts and the short tables. */
  align-items: start;
}

@media (max-width: 860px) {
  .grid.two { grid-template-columns: 1fr; }
}

/* ── Top bar ─────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 650; letter-spacing: -0.01em; margin-right: 4px; }

.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

select, input[type="month"] {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 100%;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  font: inherit;
  display: inline-block;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
}

.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.block { display: block; width: 100%; margin: 10px 0 0; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ── Banners and hints ───────────────────────────────────────────────── */

.banner {
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 12px;
  border: 1px solid;
}

.banner.error { border-color: var(--bad); color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.banner[hidden] { display: none; }

.hint { font-size: 0.86rem; }
.widget-slot { margin: 4px 0 0; min-height: 0; }

/* ── Link confirmation ───────────────────────────────────────────────── */

.steps { padding-left: 1.2rem; }
.steps li { margin: 6px 0; }

.code-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }

.code-row code {
  font-size: 1.5rem;
  letter-spacing: 0.18em;
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--bg);
}

/* ── KPI tiles ───────────────────────────────────────────────────────── */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.kpi .label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.kpi .value { font-size: 1.4rem; font-weight: 620; margin-top: 2px; letter-spacing: -0.01em; }
.kpi .sub { font-size: 0.8rem; color: var(--muted); }

/* ── Tables and lists ────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.date, th:first-child { white-space: nowrap; }
.note { display: block; font-size: 0.8rem; color: var(--muted); }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.table-wrap { overflow-x: auto; }

.empty { color: var(--muted); padding: 10px 0; }

.filters { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pager { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

/* ── Budget rows ─────────────────────────────────────────────────────── */

.budget { padding: 9px 0; border-bottom: 1px solid var(--line); }
.budget:last-child { border-bottom: 0; }
.budget-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.budget-name { font-weight: 560; }
.budget-meta { font-size: 0.82rem; color: var(--muted); }
.budget-figures {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.budget-bar { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 6px 0 4px; }
.budget-bar > i { display: block; height: 100%; background: var(--good); }
.budget-bar.warn > i { background: var(--warn); }
.budget-bar.bad > i { background: var(--bad); }
.budget-unbudgeted {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* ── Narrow screens ──────────────────────────────────────────────────── */

/* Opened inside Telegram as often as on a desktop, where the sticky top bar and the
 * generous spacing cost more than they give. */
@media (max-width: 640px) {
  .screen { padding: 10px; }
  .card { padding: 12px; margin-bottom: 12px; }
  .topbar { position: static; padding: 10px; gap: 8px; }
  .brand { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px; }
  .kpi .value { font-size: 1.2rem; }
  th, td { padding: 6px 6px; font-size: 0.84rem; }
  .budget-meta, .budget-figures { font-size: 0.78rem; }
  footer { padding-bottom: 16px; }
}

/* ── Charts ──────────────────────────────────────────────────────────── */

#chart-category svg [data-label] { cursor: pointer; }
#chart-category svg [data-label]:hover { opacity: 0.75; }

footer { padding: 4px 2px 24px; }
