/* MaxBridge Mini App — calm, trustworthy, theme-aware.
   Palette derives from Telegram theme params (set on :root by app.js) with sane
   light/dark fallbacks, layered with one disciplined accent. */

:root {
  /* Filled from Telegram.WebApp.themeParams at runtime; these are fallbacks. */
  --tg-bg: #ffffff;
  --tg-text: #11151c;
  --tg-hint: #707a8a;
  --tg-link: #2c7df0;
  --tg-button: #2c7df0;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #f3f5f8;

  --bg: var(--tg-bg);
  --text: var(--tg-text);
  --hint: var(--tg-hint);
  --accent: var(--tg-button);
  --accent-text: var(--tg-button-text);
  --surface: var(--tg-secondary-bg);
  --border: color-mix(in srgb, var(--text) 12%, transparent);
  --warn: #c2410c;
  --warn-surface: color-mix(in srgb, #f97316 16%, var(--bg));
  --ok: #16a34a;
  --bad: #dc2626;
  --idle: var(--hint);

  --radius: 16px;
  --radius-sm: 10px;
  --space: clamp(1rem, 0.6rem + 2vw, 1.5rem);
  --maxw: 34rem;

  --display: clamp(1.6rem, 1.2rem + 2.4vw, 2.3rem);
  --lede: clamp(1rem, 0.95rem + 0.4vw, 1.12rem);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 280ms;

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

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.shell {
  min-height: 100dvh;
  max-width: var(--maxw);
  margin-inline: auto;
  padding: max(var(--space), env(safe-area-inset-top))
           var(--space)
           max(var(--space), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 1rem + 3vw, 2.5rem);
}

/* --- Brand bar ----------------------------------------------------------------- */
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand__mark {
  inline-size: 22px;
  block-size: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--bg) 70%, transparent);
}
.brand__name { font-weight: 650; letter-spacing: -0.01em; }

.pill {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--hint);
}
.pill__dot {
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: currentColor;
}
.pill--ok { color: var(--ok); }
.pill--warn { color: var(--warn); }
.pill--bad { color: var(--bad); }
.pill--idle { color: var(--idle); }
.pill--ok .pill__dot { box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent); }

/* --- Views --------------------------------------------------------------------- */
main { flex: 1; }
.view { display: flex; flex-direction: column; gap: 1rem; animation: rise var(--dur) var(--ease); }
.view[hidden] { display: none; }

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}
.display {
  margin: 0;
  font-size: var(--display);
  line-height: 1.08;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.lede { margin: 0; font-size: var(--lede); color: color-mix(in srgb, var(--text) 88%, var(--bg)); }
.muted { color: var(--hint); }
.fineprint { margin: 0; font-size: 0.8rem; color: var(--hint); }

/* --- Notice / steps ------------------------------------------------------------ */
.notice {
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  background: var(--warn-surface);
  color: color-mix(in srgb, var(--warn) 85%, var(--text));
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  font-size: 0.92rem;
}
.notice strong { color: var(--warn); }

.steps { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.45rem; }
.steps li { color: color-mix(in srgb, var(--text) 85%, var(--bg)); }
.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.05em 0.4em;
}

/* --- Field --------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field__label { font-size: 0.82rem; font-weight: 600; color: var(--hint); }
.field__input {
  width: 100%;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field__input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.error { margin: 0; color: var(--bad); font-size: 0.85rem; font-weight: 500; }
.error[hidden] { display: none; }

/* --- Buttons ------------------------------------------------------------------- */
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.4rem; }
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.2rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
  min-height: 48px;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
    opacity var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); flex: 0 1 auto; }
.btn--ghost:hover { background: var(--surface); }

/* --- Snippet (auto-capture) ---------------------------------------------------- */
.snippet {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.snippet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.5rem 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
.snippet__label { font-size: 0.8rem; color: var(--hint); font-weight: 600; }
.snippet__label b {
  color: var(--accent);
  letter-spacing: 0.14em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.snippet__code {
  display: block;
  padding: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.73rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 8.5rem;
  overflow: auto;
}
.btn--sm { min-height: 34px; padding: 0.35rem 0.85rem; font-size: 0.82rem; flex: 0 0 auto; }

.waiting { display: flex; align-items: center; gap: 0.5rem; margin: 0; color: var(--hint); font-size: 0.9rem; }
.dot-pulse {
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s var(--ease) infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.1); } }

.manual { border-top: 1px solid var(--border); padding-top: 0.4rem; }
.manual summary {
  cursor: pointer;
  color: var(--hint);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.3rem 0;
  list-style-position: inside;
}
.manual summary:hover { color: var(--text); }
.manual[open] summary { margin-bottom: 0.6rem; }
.manual .field { margin-bottom: 0.6rem; }

/* --- Footer -------------------------------------------------------------------- */
.foot { padding-top: 0.5rem; border-top: 1px solid var(--border); font-size: 0.8rem; }

/* --- Spinner ------------------------------------------------------------------- */
.spinner {
  inline-size: 28px;
  block-size: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin: 1rem auto 0.5rem;
}
#view-loading { align-items: center; text-align: center; padding-top: 2rem; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
