/* Dawn palette — must stay in sync with
 * docs/design/new-direct-messages-design/project/stream-v2-dawn.jsx
 * (DAWN const, lines 4-23). The widget renders inside the Vojo chat slot
 * which is itself a Dawn surface; the iframe inherits the same visual
 * canon to feel like a continuation of the host.
 *
 * Identical visual vocabulary to apps/widget-telegram/src/styles.css —
 * the Discord widget keeps fleet-violet (Vojo accent) rather than
 * adopting Discord blurple, per product decision: «used Vojo style». */

:root {
  --bg: #181a20;
  --bg2: #0d0e11;
  --surface: #21232b;
  --surface2: #2a2d36;
  --divider: rgba(255, 255, 255, 0.06);
  --hairline: rgba(255, 255, 255, 0.08);
  --text: #e6e6e9;
  --muted: rgba(230, 230, 233, 0.55);
  --faint: rgba(230, 230, 233, 0.32);
  --fleet: #9580ff;
  --fleet-soft: #a59cff;
  --green: #7dd3a8;
  --amber: #d4b88a;
  --rose: #c08e7b;
  --section-pad-x: 40px;
}

[data-theme='light'] {
  /* Light theme is intentionally a thin remap. Vojo is dark-default; the
   * theme param exists so we don't fight an explicit user/host setting,
   * not because we expect daily light-mode use. */
  --bg: #f5f5f7;
  --bg2: #ffffff;
  --surface: #f0f0f2;
  --surface2: #e8e8ec;
  --divider: rgba(0, 0, 0, 0.08);
  --hairline: rgba(0, 0, 0, 0.1);
  --text: #1a1a1d;
  --muted: rgba(26, 26, 29, 0.62);
  --faint: rgba(26, 26, 29, 0.4);
}

@media (max-width: 600px) {
  :root {
    --section-pad-x: 20px;
  }
}

* {
  box-sizing: border-box;
  /* Kills the translucent grey overlay iOS/Android WebViews paint on top
   * of any tapped element. Web browsers ignore this. */
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, 'Segoe UI', 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 960px;
  margin: 0 auto;
}

/* The hero is OWNED BY THE HOST (BotShellHero). The widget body starts
 * with the active-state section directly. */

/* ── Section ──────────────────────────────────────────────────────── */

.section {
  padding: 24px var(--section-pad-x) 20px;
}

.section + .section {
  padding-top: 4px;
}

/* Status pill — non-interactive (no cursor:pointer, no hover). The pill
 * carries the section's identity for stateful sections. */
.section-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted);
  background: var(--bg2);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 8px 14px;
  margin: 0 0 14px;
  user-select: none;
  white-space: nowrap;
}

.section-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex-shrink: 0;
}

.section-status.connected {
  color: var(--green);
}
.section-status.connected .dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(125, 211, 168, 0.16);
}

.section-status.disconnected {
  color: var(--rose);
}
.section-status.disconnected .dot {
  background: var(--rose);
}

.section-status.checking {
  color: var(--amber);
}
.section-status.checking .dot {
  background: var(--amber);
}

/* Section row: status pill + recovery button (refresh / reconnect /
 * cancel) when the state has no other affordance. Without this row, the
 * user can stare at a «Проверка статуса…» pill forever if the first
 * ping reply dropped on the wire. */
.section-recovery-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.section-recovery-row > .section-status {
  margin-bottom: 0;
}

.recovery-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
:root[data-input='mouse'] .recovery-action:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
  border-color: var(--hairline);
}
.recovery-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.recovery-action svg {
  width: 16px;
  height: 16px;
}

/* ── Command card (action card with name + desc + chevron) ──────── */

.command-card {
  /* `appearance:none` strips native WebView focus paint that otherwise
   * sits ON TOP of our explicit background — see telegram widget for
   * the full debugging trail (Capacitor Android WebView holds native
   * focus paint until focus moves elsewhere). */
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg2);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 0.12s, background 0.12s;
}

/* Hover scoped to mouse-mode sessions only — Capacitor Android WebView
 * reports `(hover: hover)` as TRUE on a pure-touch device, so a media-
 * query gate doesn't work. `[data-input]` is set in main.tsx from the
 * actual `pointerdown.pointerType`. */
:root[data-input='mouse'] .command-card:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--hairline);
}

.command-card:focus {
  outline: none;
}

:root[data-input='mouse'] .command-card:focus-visible {
  outline: 2px solid var(--fleet);
  outline-offset: 2px;
}

.command-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.command-card-body {
  flex: 1;
  min-width: 0;
}

.command-card-name {
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 3px;
}

.command-card-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 19px;
}

.command-card-chevron {
  color: var(--muted);
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.command-card-chevron svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Generic leading-icon slot — every command-card carries a semantic
 * left-side glyph (mirror of the right-side chevron). Picks up
 * `currentColor` from the parent and stays muted by default;
 * `.danger` deliberately does NOT colour the lead icon so the rose
 * accent stays reserved for the title. */
.command-card-lead-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.command-card-lead-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* Spin the leading refresh icon while the card is in its `refreshing`
 * in-flight state. The selector targets the lead slot since the
 * refresh card moved its glyph from the chevron (right) to the lead
 * slot (left) for parity with every other card. */
.command-card.refreshing .command-card-lead-icon svg {
  animation: command-card-spin 0.8s linear infinite;
}
@keyframes command-card-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Transcript ──────────────────────────────────────────────────── */

.transcript {
  background: var(--bg2);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: ui-monospace, 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 12.5px;
  line-height: 1.55;
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}

.transcript::-webkit-scrollbar {
  width: 8px;
}
.transcript::-webkit-scrollbar-track {
  background: transparent;
}
.transcript::-webkit-scrollbar-thumb {
  background: var(--surface2);
  border-radius: 4px;
  border: 2px solid var(--bg2);
  background-clip: padding-box;
}
.transcript::-webkit-scrollbar-thumb:hover {
  background: var(--surface);
  border: 2px solid var(--bg2);
  background-clip: padding-box;
}

.transcript-line {
  padding: 4px 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  white-space: pre-wrap;
  word-break: break-word;
}

.transcript-line + .transcript-line {
  border-top: 1px dashed var(--divider);
}

.transcript-line .ts {
  color: var(--faint);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.transcript-line .body {
  flex: 1;
  min-width: 0;
}

.transcript-line.from-bot .body {
  color: var(--text);
}

.transcript-line.from-user .body {
  color: var(--fleet-soft);
}

.transcript-line.diag .body {
  color: var(--muted);
}

.transcript-line.error .body {
  color: var(--rose);
}

.transcript-empty {
  color: var(--faint);
  text-align: center;
  padding: 16px 0;
  font-style: italic;
}

/* Destructive card — red name marks logout as destructive vs the primary
 * login card. The hover border stays on the generic
 * `:root[data-input='mouse'] .command-card:hover` rule (hairline) so the
 * accent is consistent across touch and mouse modes — a previous
 * `.command-card.danger:hover { border-color: var(--rose) }` override
 * was dead in mouse mode (lower specificity than the input-gated rule)
 * and only fired in the pre-first-pointerdown touch stub, leaking a
 * rose tint that looked amber on the dark surface. */
.command-card.danger .command-card-name {
  color: var(--rose);
}

/* Inline confirm-in-place body for the destructive logout card. */
.command-card-confirm {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.command-card-confirm-prompt {
  font-size: 14px;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

.command-card-confirm-yes,
.command-card-confirm-no,
.btn-primary,
.btn-text {
  font: inherit;
  cursor: pointer;
}

.command-card-confirm-yes {
  background: var(--rose);
  color: #0c0c0e;
  border: none;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}

.command-card-confirm-no {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--divider);
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
}

.command-card-confirm-yes:disabled,
.command-card-confirm-no:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.command-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 10px;
}

/* ── Auth card (QR panel chrome) ─────────────────────────────────── */

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-card.error {
  border-color: var(--rose);
}

.auth-card-title {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-weight: 600;
}

.auth-card-hint {
  font-size: 14px;
  color: var(--muted);
  line-height: 19px;
}

.auth-card-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  background: var(--fleet);
  color: #0c0c0e;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  font-size: 13px;
}
.btn-text:hover:not(:disabled) {
  color: var(--text);
}

.auth-card-error {
  font-size: 13px;
  line-height: 18px;
  color: var(--rose);
}

.auth-card-warn {
  font-size: 13px;
  line-height: 18px;
  color: var(--amber);
}

.auth-card-countdown {
  font-size: 13px;
  color: var(--muted);
  line-height: 18px;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease-out;
}
.auth-card-countdown.expired {
  color: var(--amber);
}

/* ── QR-login panel ─────────────────────────────────────────────── */

/* Override the auth-card row layout — QR panel stacks vertically with the
 * matrix as the visual anchor. */
.auth-card-qr {
  align-items: stretch;
}

/* The QR matrix sits on a hard #fff plate regardless of theme — phone
 * camera scanners need maximum contrast. */
.auth-card-qr-frame {
  align-self: center;
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Lock the inner box to the SVG's rendered size so the placeholder
   * variant doesn't collapse to zero height while the matrix is being
   * computed. */
  min-width: 260px;
  min-height: 260px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06), 0 12px 24px rgba(0, 0, 0, 0.32);
}

.auth-card-qr-placeholder {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: rgba(26, 26, 29, 0.62);
  font-size: 13px;
  line-height: 20px;
  padding: 96px 16px;
}
.auth-card-qr-placeholder .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
}

.auth-card-qr-steps {
  margin: 0;
  padding-left: 1.4em;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  line-height: 19px;
  color: var(--muted);
}
.auth-card-qr-steps li::marker {
  color: var(--faint);
}

/* ── hCaptcha challenge panel ───────────────────────────────────── */

.auth-card-captcha {
  align-items: stretch;
}

/* hCaptcha renders its own iframe inside this host. We just provide a
 * minimum frame height so the layout doesn't collapse during script load,
 * and centre the iframe horizontally. The hCaptcha widget is a fixed-
 * width 304px element by default; on narrow viewports we let it overflow
 * its container's flex line rather than try to scale the iframe (the
 * upstream SDK handles its own responsive variants). */
.auth-card-captcha-frame {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-height: 88px;
}
.auth-card-captcha-host {
  /* hCaptcha injects a 304x78 (normal) or 156x144 (compact) iframe. The
   * default rendering is 'normal' — we size accordingly and let the SDK
   * place its own iframe inside. */
  display: flex;
  justify-content: center;
}

@media (max-width: 600px) {
  .auth-card-row {
    flex-direction: column;
  }
  .btn-primary,
  .btn-text {
    width: 100%;
  }

  .command-card {
    padding: 12px 14px;
    border-radius: 8px;
  }
  .command-card-name {
    font-size: 14px;
    margin-bottom: 2px;
  }
  .command-card-desc {
    font-size: 13px;
    line-height: 17px;
  }

  .command-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-card-qr-frame {
    min-width: 232px;
    min-height: 232px;
    padding: 10px;
  }
  .auth-card-qr-placeholder {
    padding: 80px 12px;
  }
}

/* ── Linkified transcript bodies ─────────────────────────────────── */

.transcript-line a {
  color: var(--fleet-soft);
  text-decoration: underline;
}
.transcript-line a:hover {
  color: var(--text);
}

/* ── Diagnostic banner (pre-bootstrap failure) ───────────────────── */

.error-banner {
  margin: var(--section-pad-x);
  padding: 14px 16px;
  background: rgba(192, 142, 123, 0.08);
  border: 1px solid var(--rose);
  border-radius: 10px;
  color: var(--rose);
  font-size: 13px;
  line-height: 19px;
}

.error-banner strong {
  display: block;
  margin-bottom: 4px;
  color: var(--rose);
  font-weight: 600;
}

.error-banner code {
  background: var(--bg2);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text);
}

/* ── About modal ─────────────────────────────────────────────────── */

.about-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 14, 17, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: about-fade 0.15s ease-out;
}

@keyframes about-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.about-panel {
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.about-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--divider);
}

.about-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.3;
}

.about-close-x {
  background: transparent;
  border: none;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}
.about-close-x:hover {
  background: var(--surface);
  color: var(--text);
}

.about-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.about-body p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}
.about-body a {
  color: var(--fleet-soft);
  text-decoration: underline;
  overflow-wrap: anywhere;
}
.about-body a:hover {
  color: var(--text);
}

.about-footer {
  padding: 12px 18px 16px;
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--divider);
}
