/*
  Embed page styles. Theme-NEUTRAL — the orchestrator doesn't ship any
  visual identity of its own. Background, default text color, and accent
  come from the app's theme bag (injected as <style id="agentrika-theme">
  by the controller). Defaults below are intentionally bland (white bg,
  near-black text) so an app with NO theme set looks like a clean,
  unbranded form rather than something with strong orchestrator chrome.

  This file owns:
   - the shell layout (full viewport, centered, max-width content well)
   - the loader, error banner, and SSR ↔ hydrate visibility swap
   - hover/focus polish on SSR form elements
*/

* { box-sizing: border-box; }

:root {
  /* Theme-overridable custom properties — the app's <style id="agentrika-theme">
     block sets these. Defaults are neutral light theme. */
  --agentrika-bg: #ffffff;
  --agentrika-text: #0a0a0a;
  --agentrika-muted: #525252;
  --agentrika-accent: #2563eb;
  --agentrika-accent-text: #ffffff;
  --agentrika-loader-bg: var(--agentrika-bg);
  --agentrika-loader-text: var(--agentrika-muted);
  /* Content-well width. Default is a centered 480px mobile column; an app can
     widen it (theme maxWidth) or go full-width (theme layout:full → none). */
  --agentrika-max-width: 480px;
  color-scheme: light;
}

/*
  Neutral DARK fallback for the frame vars, for an EXPLICIT dark choice only
  (user toggle or a dark default-appearance → <html data-appearance="dark">).
  We deliberately do NOT add a prefers-color-scheme media fallback here: a
  light-only app on a dark OS must stay light (its cards are light). System-dark
  only goes dark when the app's own theme bag ships a `dark` variant, whose CSS
  (injected as <style id="agentrika-theme"> AFTER this file) overrides these.
*/
:root[data-appearance="dark"] {
  --agentrika-bg: #0b1220;
  --agentrika-text: #e5e7eb;
  --agentrika-muted: #94a3b8;
  --agentrika-accent: #3c90ff;
  --agentrika-accent-text: #ffffff;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-appearance="light"]):not([data-appearance="dark"]) { color-scheme: dark; }
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--agentrika-bg);
  color: var(--agentrika-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.agentrika-root {
  position: relative;
  width: 100%;
  max-width: var(--agentrika-max-width, 480px);
  min-height: 100vh;
  background: var(--agentrika-bg);
  display: flex;
  flex-direction: column;
}

/* SSR card: real HTML produced by DivkitToHtmlRenderer. Visible until
   embed.js boots DivKit and removes this element. */
.agentrika-ssr {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}
.agentrika-ssr:empty { display: none; }
.agentrika-ssr.handed-off { display: none; }

/* DivKit's hydrated card. Hidden while SSR is showing; shown when JS
   has rendered into it. The .ready class is added by embed.js. */
.agentrika-card {
  flex: 1 1 auto;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.agentrika-card.ready { display: flex; }

/* Loader: only visible when there is NO SSR pre-paint. CSS-only — the
   neighbouring .agentrika-ssr being empty drives the show/hide so we
   don't have to coordinate via JS for the first paint. */
.agentrika-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--agentrika-loader-bg);
  z-index: 10;
  transition: opacity 200ms ease-out;
}
.agentrika-ssr:not(:empty) ~ .agentrika-status { display: none; }
.agentrika-status.hidden {
  opacity: 0;
  pointer-events: none;
}
.agentrika-status.failed { background: #fef2f2; }
.agentrika-status.completed { background: #f0fdf4; }

.status-text {
  margin-top: 16px;
  font-size: 13px;
  color: var(--agentrika-loader-text);
  letter-spacing: 0.3px;
}
.agentrika-status.failed .status-text { color: #dc2626; }
.agentrika-status.completed .status-text {
  color: #15803d;
  font-size: 18px;
  font-weight: 600;
}
.agentrika-status.completed::before {
  content: "✓";
  font-size: 48px;
  color: #15803d;
  margin-bottom: 4px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--agentrika-accent);
  border-radius: 50%;
  animation: agentrika-spin 0.9s linear infinite;
}
.agentrika-status.failed .spinner,
.agentrika-status.completed .spinner {
  display: none;
}

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

.error-banner {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  padding: 12px 16px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 13px;
  z-index: 20;
  display: none;
}
.error-banner.visible { display: block; }

/* SSR-form interactivity — when the inputs/buttons render in the SSR
   layer before JS, hover + focus should still feel polished so the
   pre-hydration moment isn't jarring. */
.agentrika-ssr button,
.agentrika-ssr input {
  font-family: inherit;
}
.agentrika-ssr button:hover {
  filter: brightness(1.08);
}
.agentrika-ssr button:active {
  filter: brightness(0.92);
}
.agentrika-ssr input:focus {
  outline: 2px solid var(--agentrika-accent);
  outline-offset: 2px;
}

/* Built-in light/dark toggle (embed.js injects the button when the app has
   dark mode enabled + showToggle). Uses the theme vars so it re-skins with the
   rest of the page. */
.agentrika-appearance-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--agentrika-muted);
  background: var(--agentrika-bg);
  color: var(--agentrika-text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.65;
  transition: opacity 150ms ease, transform 150ms ease;
}
.agentrika-appearance-toggle:hover { opacity: 1; }
.agentrika-appearance-toggle:active { transform: scale(0.92); }
.agentrika-appearance-toggle:focus-visible {
  outline: 2px solid var(--agentrika-accent);
  outline-offset: 2px;
}
