/* Premium dark glass. The panel sets its own theme rather than following
   Telegram's themeParams — the look is deliberate, not inherited. */

:root {
  color-scheme: dark;

  --bg: #0b0d12;
  --surface: #171a21;          /* what the glass averages out to; charts validate against this */

  --glass: rgba(255, 255, 255, .055);
  --glass-strong: rgba(255, 255, 255, .085);
  --glass-press: rgba(255, 255, 255, .13);
  --hairline: rgba(255, 255, 255, .10);
  --highlight: rgba(255, 255, 255, .16);

  --text: #f3f4f6;
  --text-2: rgba(243, 244, 246, .62);
  --text-3: rgba(243, 244, 246, .40);

  --accent: #3987e5;           /* series 1 / sequential — validated on --surface */
  --accent-2: #d95926;         /* second sequential context */
  --danger: #e66767;
  --ok: #199e70;

  --radius: 18px;
  --radius-sm: 12px;
  --blur: blur(24px) saturate(170%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1000px 620px at 12% -8%, rgba(57, 135, 229, .20), transparent 60%),
    radial-gradient(780px 520px at 92% 4%, rgba(138, 92, 232, .16), transparent 62%),
    radial-gradient(900px 700px at 50% 108%, rgba(24, 158, 112, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

main { padding: 12px 16px 24px; }

/* ---------- glass primitives ---------- */

.card, .chat-switch, .sheet, .tile, .chip, button.primary {
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

.card {
  position: relative;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass);
  overflow: hidden;
}

/* the thin specular line along the top edge is what sells the glass */
.card::before, .tile::before, button.primary::before, .sheet::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--highlight), transparent);
  pointer-events: none;
}

/* ---------- top bar ---------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px 16px;
  background: linear-gradient(var(--bg) 40%, transparent);
}

.chat-switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--glass-strong);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.chat-switch:active { background: var(--glass-press); }
.chat-switch #chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-switch .chev { margin-left: auto; color: var(--text-3); }

.badge {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f0c14b, #e0932f);
  color: #2a1c00;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}

.badge.free {
  background: rgba(255, 255, 255, .10);
  color: var(--text-2);
}

/* ---------- structure ---------- */

h1 { margin: 6px 0 18px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }

.section-title {
  margin: 26px 6px 9px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 11px 15px;
  border-top: 1px solid var(--hairline);
}

.row:first-child { border-top: 0; }
.row.tappable { cursor: pointer; }
.row.tappable:active { background: var(--glass-press); }

.row .body { flex: 1; min-width: 0; }
.row .title { display: block; overflow-wrap: break-word; }
.row .sub { display: block; margin-top: 2px; color: var(--text-3); font-size: 13px; }
.row .value { flex: none; color: var(--text-2); }
.row .chev { flex: none; color: var(--text-3); }
.row.locked .body { opacity: .5; }
.row .error { display: block; margin-top: 4px; color: var(--danger); font-size: 13px; }

.hint { margin: 10px 6px 0; color: var(--text-3); font-size: 13px; }
.stack { display: grid; gap: 12px; }

/* ---------- controls ---------- */

.switch { flex: none; width: 52px; height: 32px; position: relative; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  transition: background .22s;
  pointer-events: none;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45);
  transition: transform .22s;
}
.switch input:checked + span { background: linear-gradient(135deg, #34c759, #26a047); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:disabled + span { opacity: .45; }

.stepper { display: flex; align-items: center; gap: 6px; flex: none; }
.stepper button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--glass-strong);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.stepper button:active { background: var(--glass-press); }
.stepper button:disabled { opacity: .35; }
/* input[type] — the generic text-field rule below is just as specific as a
   plain `.stepper input` and comes later, so it used to win: the field went
   width: 100% and ran over the row's label. */
.stepper input[type], .stepper select {
  height: 34px;
  padding: 0 4px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(0, 0, 0, .25);
  color: var(--text);
  font: inherit;
  text-align: center;
}
.stepper input[type] { width: 58px; }
.stepper select { padding: 0 4px; max-width: 74px; }

input[type="text"], input[type="search"], input[type="number"], input[type="time"], textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .25);
  color: var(--text);
  font: inherit;
}

input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { min-height: 104px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.chip {
  padding: 8px 14px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--glass);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.chip:active { background: var(--glass-press); }
.chip.selected { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.chip.danger { color: var(--danger); border-color: rgba(230, 103, 103, .35); }
.chip.removable::after { content: " ✕"; opacity: .55; }

button.primary {
  position: relative;
  width: 100%;
  padding: 15px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #4b93ea, #2f6fcb);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

button.primary:active { filter: brightness(.92); }
button.primary:disabled { opacity: .5; }

button.link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; }
button.link.danger { color: var(--danger); }

/* ---------- stat tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; }

.tile {
  position: relative;
  padding: 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--glass);
}

/* Amounts and wallet addresses get transcribed by hand — monospace so a
   0/O or 1/l mix-up can't cost someone their payment. */
.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.tile .tile-label { color: var(--text-3); font-size: 12px; }
.tile .tile-value { margin-top: 6px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.tile .tile-sub { margin-top: 2px; color: var(--text-3); font-size: 12px; }

/* ---------- charts ---------- */

.chart { padding: 14px 14px 10px; }
.chart-title { font-size: 15px; font-weight: 600; }
.chart-sub { margin-top: 2px; color: var(--text-3); font-size: 12px; }
.chart svg { display: block; width: 100%; margin-top: 12px; overflow: visible; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .grid { stroke: rgba(255, 255, 255, .08); stroke-width: 1; }

.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 96px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(14, 17, 23, .92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 12px;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.chart-tip .tip-date { color: var(--text-3); }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.chart-tip .tip-key { width: 10px; height: 2px; border-radius: 2px; flex: none; }
.chart-tip .tip-value { font-weight: 700; }
.chart-tip .tip-name { color: var(--text-2); }

/* ranked rows — bar behind the label, values aligned for comparison.
   4px rounded data-end, square at the baseline, per the mark spec. */
.rank { display: grid; gap: 8px; padding: 4px 2px; }
.rank-row { position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 12px; }
.rank-fill { position: absolute; inset: 0 auto 0 0; border-radius: 0 4px 4px 0; opacity: .28; }
.rank-name { position: relative; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.rank-value { position: relative; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- sheet (modal) ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade .2s ease-out;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  border: 1px solid var(--hairline);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: rgba(23, 26, 33, .86);
  animation: slide-up .26s cubic-bezier(.22, .9, .3, 1);
}

.sheet h2 { margin: 6px 0 14px; font-size: 19px; font-weight: 700; }
.sheet .grip { width: 38px; height: 4px; margin: -6px auto 12px; border-radius: 99px; background: rgba(255, 255, 255, .22); }

@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

/* ---------- states ---------- */

.center { padding: 56px 16px; text-align: center; color: var(--text-2); }

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 14px;
  border: 3px solid rgba(255, 255, 255, .12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  z-index: 60;
  padding: 11px 18px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: rgba(20, 23, 30, .92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--text);
  font-size: 14px;
  transform: translateX(-50%);
  animation: rise .22s ease-out;
}

.toast.error { border-color: rgba(230, 103, 103, .45); color: #ffd9d9; }

@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* The post form puts a time field next to a chip — keep it chip-sized. */
.chips input[type="time"] { width: auto; min-width: 110px; color-scheme: dark; }

/* ---------- formatting toolbar + preview ---------- */

.fmt-bar { margin-top: 0; }
.chip.fmt { min-width: 40px; padding: 7px 12px; }

.md-preview {
  padding: 12px 14px;
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-sm);
}
.md-preview-label { margin-bottom: 6px; color: var(--text-3); font-size: 12px; }
.md-render { white-space: pre-wrap; overflow-wrap: break-word; }
.md-render code, .md-render pre {
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .35);
  font-family: ui-monospace, monospace;
  font-size: .92em;
}
.md-render pre { display: block; margin: 4px 0; padding: 8px 10px; white-space: pre-wrap; }
.md-render blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.md-render .md-link { color: var(--accent); text-decoration: underline; }
.md-render .md-spoiler { border-radius: 4px; background: rgba(255, 255, 255, .22); color: transparent; cursor: pointer; }
.md-render .md-spoiler.open { background: rgba(255, 255, 255, .08); color: inherit; }
