/*
 * Fyatu Mini App — styles.
 *
 * Fyatu's identity, Telegram's behaviour. The palette below is the app's own
 * (src/theme/colors.ts), NOT Telegram's themeParams: this should read as Fyatu
 * inside Telegram rather than as a generic Telegram app. The only thing taken
 * from the client is whether the user is in light or dark mode.
 *
 * Hand-written and dependency-free on purpose. The whole point of this app is
 * that it arrives over a Congolese mobile connection on every single open, with
 * no install to amortise it — so every kilobyte is a kilobyte the user waits for.
 */

:root {
  /* Fyatu purple — 700 is the brand colour, 500 the lighter step. */
  --brand: #721d5d;
  --brand-500: #a43b8b;
  --brand-100: #e9a6dc;
  --brand-wash: #fdf3fa;
  --accent: #fd7e14;

  --bg: #fafafa;
  --surface: #ffffff;
  --border: #ececec;
  --text: #212121;
  --text-dim: #666666;
  --text-faint: #9a9a9a;

  --ok: #1b7f4f;
  --danger: #b91c1c;
  --danger-wash: #ffebee;

  --radius: 16px;
  --pad: 20px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1a1a1a;
    --border: #2b2b2b;
    --text: rgba(255, 255, 255, 0.87);
    --text-dim: rgba(255, 255, 255, 0.6);
    --text-faint: rgba(255, 255, 255, 0.38);

    --brand-wash: #241021;
    --danger-wash: #2e1414;
  }
}

/* Telegram stamps its own scheme on the root; honour it over the OS setting. */
html[data-tg-scheme="dark"] {
  --bg: #000000;
  --surface: #1a1a1a;
  --border: #2b2b2b;
  --text: rgba(255, 255, 255, 0.87);
  --text-dim: rgba(255, 255, 255, 0.6);
  --text-faint: rgba(255, 255, 255, 0.38);
  --brand-wash: #241021;
  --danger-wash: #2e1414;
}

html[data-tg-scheme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #ececec;
  --text: #212121;
  --text-dim: #666666;
  --text-faint: #9a9a9a;
  --brand-wash: #fdf3fa;
  --danger-wash: #ffebee;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Stops a scroll at the top of a list being read as swipe-to-close. */
  overscroll-behavior-y: none;
}

.screen {
  min-height: 100%;
  padding: var(--pad);
  padding-top: max(var(--pad), env(safe-area-inset-top));
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Loading ─────────────────────────────────────────────────────────────── */

.loading {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand-500);
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.loading-text {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.94rem;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.greeting {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-dim);
}

.greeting strong {
  color: var(--text);
  font-weight: 600;
}

/* ── Balance ─────────────────────────────────────────────────────────────── */

.balance-card {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-500) 100%);
  border-radius: var(--radius);
  padding: 22px var(--pad);
  color: #fff;
}

.balance-label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}

.balance-amount {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  /* Digits line up between renders instead of jittering as values change. */
  font-variant-numeric: tabular-nums;
}

.balance-sub {
  margin: 10px 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

/* ── Generic panel ───────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 1.02rem;
  font-weight: 600;
}

.panel p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.92rem;
}

.panel + .panel {
  margin-top: -4px;
}

/* ── States ──────────────────────────────────────────────────────────────── */

.state {
  margin: auto;
  text-align: center;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.state-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-wash);
  font-size: 26px;
}

.state h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.state p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.94rem;
}

.state code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.82em;
}

.state.error .state-icon {
  background: var(--danger-wash);
}

/* ── Button ──────────────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.98rem;
  padding: 13px 22px;
  cursor: pointer;
  width: 100%;
  max-width: 20rem;
}

.btn:active {
  opacity: 0.85;
}

.btn:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 3px;
}

.btn.secondary {
  background: transparent;
  color: var(--brand-500);
  border: 1px solid var(--border);
}

/* Small print used for the diagnostic detail on the error screen. */
.detail {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-faint);
  word-break: break-word;
}

/* ═══════════════════════════════════════════════════════════════════════════
   App chrome — added for the connected experience.
   ═══════════════════════════════════════════════════════════════════════════ */

/* The screen scrolls; the tab bar is fixed. Padding-bottom keeps the last row
   clear of the bar plus the home indicator on notched devices. */
.screen {
  padding-bottom: calc(76px + max(12px, env(safe-area-inset-bottom)));
}
.screen.boot { padding-bottom: max(var(--pad), env(safe-area-inset-bottom)); }

/* ── Header ──────────────────────────────────────────────────────────────── */

.app-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.head-name, .head-title {
  margin: 2px 0 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  width: 40px; height: 40px;
  font-size: 17px;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { opacity: 0.7; }

.balance-meta { margin-top: 10px; font-size: 0.85rem; opacity: 0.85; font-variant-numeric: tabular-nums; }

/* ── Quick actions ───────────────────────────────────────────────────────── */

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  cursor: pointer;
}
.quick span { font-size: 19px; }
.quick:active { opacity: 0.7; }

/* ── Sections and rows ───────────────────────────────────────────────────── */

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-top: 4px;
}
.section-head h2 { margin: 0; font-size: 1.02rem; font-weight: 600; }

.link-btn {
  appearance: none; border: 0; background: none; padding: 0;
  color: var(--brand-500); font: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer;
}

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 15px;
  cursor: pointer;
}
.row:active { opacity: 0.7; }
.row-main { min-width: 0; }
.row-title {
  margin: 0; font-size: 0.95rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-note { margin: 2px 0 0; font-size: 0.8rem; color: var(--text-dim); }
.row-side { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.row-amount { margin: 0; font-size: 0.95rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.row-amount.pos { color: var(--ok); }
.row-amount.neg { color: var(--text); }

/* ── Pills ───────────────────────────────────────────────────────────────── */

.pill {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.03em;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.pill-ok      { background: #e6f4ec; color: #1b7f4f; }
.pill-pending { background: #fff4e0; color: #96601a; }
.pill-cold    { background: #e6f0fa; color: #285d92; }
.pill-warn    { background: #fdeee0; color: #9a5b08; }
.pill-dead    { background: var(--danger-wash); color: var(--danger); }

html[data-tg-scheme="dark"] .pill-ok      { background: #10281f; color: #5fcba0; }
html[data-tg-scheme="dark"] .pill-pending { background: #2a2013; color: #e0a552; }
html[data-tg-scheme="dark"] .pill-cold    { background: #101f2e; color: #7fb3e8; }
html[data-tg-scheme="dark"] .pill-warn    { background: #2a2013; color: #e0a552; }
html[data-tg-scheme="dark"] .pill-dead    { background: #2e1414; color: #f08078; }

/* ── Detail ──────────────────────────────────────────────────────────────── */

.detail-card {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-500) 100%);
  border-radius: var(--radius); padding: 22px var(--pad); color: #fff;
}
.detail-number { margin: 0; font-size: 1.25rem; font-weight: 600; letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.detail-meta { margin-top: 12px; display: flex; align-items: center; gap: 10px; }
.detail-exp { font-size: 0.82rem; opacity: 0.85; }

.stat { text-align: left; }
.stat-label { margin: 0; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.stat-value { margin: 4px 0 0; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 1.05rem; }

.kv {
  margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--pad);
  font-size: 0.9rem;
}
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; text-align: right; font-weight: 500; }

.fineprint { margin: 0; font-size: 0.78rem; color: var(--text-faint); line-height: 1.5; }

/* ── Empty / loading / error ─────────────────────────────────────────────── */

.empty { text-align: center; padding: 26px 10px; display: flex; flex-direction: column; align-items: center; gap: 9px; }
.empty-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-wash); font-size: 23px; }
.empty-title { margin: 0; font-weight: 600; }
.empty-note { margin: 0; font-size: 0.88rem; color: var(--text-dim); max-width: 20rem; }

.skeleton { display: flex; flex-direction: column; gap: 8px; }
.skeleton-row {
  height: 62px; border-radius: 14px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton-row { animation: none; } }

.load-error { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; text-align: center; }
.load-error p { margin: 0 0 8px; font-size: 0.88rem; color: var(--text-dim); }
.inline-error { margin: 10px 0 0; color: var(--danger); font-size: 0.86rem; }

.btn.danger { background: var(--danger); }

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 9px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-faint); font: inherit;
  position: relative;
}
.tab-icon { font-size: 18px; line-height: 1; }
.tab-label { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.01em; }
.tab.active { color: var(--brand-500); }
/* The active marker mirrors the native tab bar's indicator. */
.tab.active::before {
  content: ''; position: absolute; top: 0; width: 26px; height: 3px;
  border-radius: 0 0 3px 3px; background: var(--brand-500);
}
