/* Telegram hands the client's palette down as --tg-theme-* custom properties.
 * Every colour below goes through one of them with a fallback, so the panel
 * matches whatever theme the user runs — and still looks deliberate in an
 * ordinary browser, where none of those variables exist. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #77808a);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d1453b);
  --radius: 12px;
}

/* Browser fallback only: inside Telegram the variables above already carry the
 * right values, so these defaults are never the ones that win. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #232e3c);
    --section: var(--tg-theme-section-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #7d8b99);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-secondary);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.muted { color: var(--hint); font-size: 13px; }
.hidden { display: none; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 0 8px;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; }

.refresh {
  border: 0;
  background: var(--section);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 17px;
  cursor: pointer;
}
.refresh:active { opacity: 0.6; }

/* ── Blocks ───────────────────────────────────────────────────────────── */

.card, .list, .facts, .tags {
  background: var(--section);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 14px;
}

.section-title {
  margin: 18px 0 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hint);
}
.screen-title { margin: 8px 0 2px; font-size: 22px; font-weight: 600; }

/* ── Who am I ─────────────────────────────────────────────────────────── */

.who { display: flex; align-items: center; gap: 12px; }
.who__text { flex: 1; min-width: 0; }
.who__name { font-weight: 600; font-size: 16px; }

.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}
.avatar--letter {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 19px;
  font-weight: 600;
}

.badge {
  flex: none;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--hint);
}
.badge--ok { background: var(--accent); color: var(--accent-text); }

/* ── Tiles ────────────────────────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.tile {
  background: var(--section);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tile__value { font-size: 22px; font-weight: 600; line-height: 1.1; }
.tile__label { color: var(--hint); font-size: 12px; margin-top: 3px; }

/* ── Rows ─────────────────────────────────────────────────────────────── */

.list { padding: 0; overflow: hidden; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--bg-secondary);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--bg-secondary); }

.row__emoji { flex: none; font-size: 17px; }
.row__main { flex: 1; min-width: 0; display: block; }
.row__title { display: block; font-weight: 500; }
.row__main .muted { display: block; }
.row__chevron { flex: none; color: var(--hint); font-size: 19px; }

.chip {
  font-size: 11px;
  font-weight: 400;
  color: var(--hint);
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
}
.chip--off { color: var(--danger); }

/* ── Facts and tags ───────────────────────────────────────────────────── */

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin-bottom: 14px; }
.facts dt { color: var(--hint); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
}
.tag--mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.tag--ok { color: var(--link); }
.tag--no { color: var(--danger); }
.tag--muted { color: var(--hint); }

/* The ✕ inside a tag. Padded well past the glyph: the tag is small enough that
 * a finger-sized target is the difference between removing a channel and
 * removing the wrong one. */
.tag__x {
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  padding: 4px 0 4px 8px;
  margin: -4px -4px -4px 2px;
}
.tag__x:active { color: var(--danger); }

/* ── Forms and buttons ────────────────────────────────────────────────── */

.form { display: flex; gap: 8px; margin: 0 0 14px; }
.form input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--section);
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}
.form input[type="text"]::placeholder { color: var(--hint); }

.btn {
  flex: none;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 500;
  padding: 10px 16px;
  cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn--wide { display: block; width: 100%; margin-bottom: 8px; }
.btn--danger { background: var(--danger); color: #fff; }

.switches { margin-bottom: 6px; }

/* ── Notices ──────────────────────────────────────────────────────────── */

.notice {
  background: var(--section);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 11px 14px;
  margin: 0 0 14px;
  font-size: 14px;
}
.notice--error { border-left-color: var(--danger); }
