/*
 * Escaleco public pages: shared styles for every page. The landing page adds
 * landing.css on top.
 *
 * Tokens and rules are described in ../DESIGN.md. They follow the app
 * (lib/core/theme/app_theme.dart); the one departure is muted text, darkened
 * from the app's #8F8F8F (3:1) so long legal reading passes WCAG AA.
 *
 * Motion lives only inside `prefers-reduced-motion: no-preference` blocks, and
 * scroll-linked motion only inside `@supports (animation-timeline: …)`, so the
 * resting styles are always the finished, readable state.
 */

/* ─── Tokens ─────────────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  --bg: #f8f8f8;
  --bg-soft: #f1f1f1;
  --surface: #ffffff;
  --text: #171717;
  --muted: #5e5e5e;
  --border: #e6e6e6;
  --border-strong: #d9d9d9;
  --brand: #1677ff;
  --brand-soft: #f1f6fd;
  --brand-softer: #e3eefc;
  --link: #0055cc;
  --action: #111111;
  --action-text: #ffffff;
  --success: #1f7a43;
  --success-soft: #e6f4ec;
  --trade: #6d3fd8;
  --trade-soft: #efe9fd;
  --amber: #ffc24b;
  --note-bg: #fff8e6;
  --note-border: #f1dfab;
  --header-bg: rgba(248, 248, 248, 0.78);
  --wash-a: rgba(22, 119, 255, 0.12);
  --wash-b: rgba(91, 92, 230, 0.1);
  --shadow-lg: 0 30px 60px -24px rgba(16, 24, 40, 0.32);
  --shadow-md: 0 18px 40px -22px rgba(16, 24, 40, 0.3);
  --shadow-sm: 0 12px 28px -16px rgba(16, 24, 40, 0.28);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --radius: 20px;
  --radius-sm: 14px;
  --radius-lg: 28px;
  --measure: 44rem;
  --wide: 84rem;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);
  --header-h: 4rem;
  --space-section: clamp(4.5rem, 10vw, 8.5rem);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1114;
    --bg-soft: #13171c;
    --surface: #171a1e;
    --text: #e9eef3;
    --muted: #a5afba;
    --border: #2a3038;
    --border-strong: #343b44;
    --brand: #3d8bff;
    --brand-soft: #13233d;
    --brand-softer: #182c4d;
    --link: #86b6f9;
    --action: #0066f5;
    --action-text: #ffffff;
    --success: #6fd39b;
    --success-soft: rgba(46, 158, 91, 0.16);
    --trade: #b9a1ff;
    --trade-soft: rgba(139, 92, 246, 0.18);
    --note-bg: #2a2412;
    --note-border: #4a3f1c;
    --header-bg: rgba(14, 17, 20, 0.74);
    --wash-a: rgba(61, 139, 255, 0.16);
    --wash-b: rgba(124, 125, 255, 0.12);
    --shadow-lg: 0 30px 60px -24px rgba(0, 0, 0, 0.7);
    --shadow-md: 0 18px 40px -22px rgba(0, 0, 0, 0.65);
    --shadow-sm: 0 12px 28px -16px rgba(0, 0, 0, 0.6);
  }
}

/* ─── Base ───────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.6 var(--font);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--brand-softer);
  color: var(--text);
}

a {
  color: var(--link);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

img,
svg {
  flex: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -3rem;
  z-index: 60;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

.wrap {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.wrap-wide {
  max-width: calc(var(--wide) + 2 * var(--gutter));
}

/* ─── Icons ──────────────────────────────────────────────────────────── */

.icon {
  width: 1.25rem;
  height: 1.25rem;
  vertical-align: -0.2em;
}

.icon-tile {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.9rem;
  background: var(--brand-soft);
  color: var(--brand);
}

.icon-tile .icon {
  width: 1.4rem;
  height: 1.4rem;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
}

.header-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-right: auto;
  color: var(--text);
  font-weight: 700;
  font-size: 1.1875rem;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.brand img {
  width: 2rem;
  height: 2rem;
  border-radius: 0.55rem;
  box-shadow: 0 4px 10px -4px rgba(22, 119, 255, 0.55);
}

/* The section links fit from tablet width up; on phones the footer carries
   them, so the header keeps just the logo and the call to action. */
.site-nav {
  display: none;
}

@media (min-width: 52rem) {
  .site-nav {
    display: block;
  }
}

.site-nav ul {
  display: flex;
  gap: 0.15rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav li + li {
  margin-top: 0;
}

.site-nav a {
  display: inline-block;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.site-nav a:hover {
  color: var(--text);
  background: var(--bg-soft);
}

.site-nav a[aria-current="page"] {
  color: var(--bg);
  background: var(--text);
}

.header-cta {
  flex: none;
}

/* Reading progress: a hairline of brand blue along the header's lower edge. */
.site-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--brand), #7b6cff);
  transform: scaleX(0);
  transform-origin: 0 50%;
  opacity: 0;
}

/* ─── Type ───────────────────────────────────────────────────────────── */

main {
  position: relative;
  isolation: isolate;
  padding: clamp(2.5rem, 6vw, 4.5rem) 0 var(--space-section);
}

/* A soft wash of the brand colours at the top of every reading page. */
body:not(.landing) main::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 auto 0;
  height: 30rem;
  background:
    radial-gradient(52rem 20rem at 12% -12%, var(--wash-a), transparent 70%),
    radial-gradient(40rem 18rem at 88% -18%, var(--wash-b), transparent 70%);
  pointer-events: none;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 2px;
  height: 0.8rem;
  border-radius: 1px;
  background: var(--brand);
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 1.4rem + 3vw, 3.25rem);
  line-height: 1.06;
  letter-spacing: -0.03em;
  font-weight: 700;
  text-wrap: balance;
}

h2 {
  margin: 3rem 0 0.75rem;
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h3 {
  margin: 1.75rem 0 0.4rem;
  font-size: 1.125rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
  font-weight: 650;
}

p {
  text-wrap: pretty;
}

.updated {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.lede {
  margin: 1.4rem 0 0;
  font-size: 1.1875rem;
  line-height: 1.55;
}

p,
ul,
ol,
dl {
  margin: 0.75rem 0 0;
}

ul,
ol {
  padding-left: 1.35rem;
}

li + li {
  margin-top: 0.4rem;
}

li::marker {
  color: var(--muted);
}

strong {
  font-weight: 650;
}

/* ─── Buttons ────────────────────────────────────────────────────────── */

.button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.9rem;
  padding: 0.7rem 1.35rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--action);
  color: var(--action-text);
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s ease, opacity 0.15s ease;
}

.button:hover {
  box-shadow: 0 12px 24px -12px rgba(16, 24, 40, 0.55);
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0) scale(0.98);
}

.button .icon {
  width: 1.1rem;
  height: 1.1rem;
}

.button-quiet {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.button-quiet:hover {
  box-shadow: 0 10px 22px -14px rgba(16, 24, 40, 0.4);
}

.button-sm {
  min-height: 2.35rem;
  padding: 0.45rem 1rem;
  font-size: 0.9375rem;
}

.button-lg {
  min-height: 3.25rem;
  padding: 0.8rem 1.6rem;
  font-size: 1.0625rem;
}

/* ─── Cards and callouts ─────────────────────────────────────────────── */

.card {
  margin: 1.75rem 0 0;
  padding: 1.35rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.card > :first-child {
  margin-top: 0;
}

.card h2 {
  margin-top: 0;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
}

.summary ul {
  padding-left: 1.2rem;
}

.note {
  margin: 1.25rem 0 0;
  padding: 1rem 1.2rem;
  border: 1px solid var(--note-border);
  border-radius: var(--radius-sm);
  background: var(--note-bg);
}

.note > :first-child {
  margin-top: 0;
}

.contact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.25rem;
}

.contact-text {
  flex: 1 1 16rem;
}

.contact-text h2 {
  margin: 0;
}

.contact-text p {
  margin: 0.25rem 0 0;
}

/* ─── Reading pages with a table of contents (privacy, terms) ────────── */

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

.toc {
  margin: 1.75rem 0 0;
  padding: 1.1rem 1.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.toc-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.toc ol {
  margin-top: 0.6rem;
  padding-left: 1.4rem;
  font-size: 0.9375rem;
}

.toc li + li {
  margin-top: 0.3rem;
}

.toc a {
  color: var(--text);
  text-decoration: none;
}

.toc a:hover {
  color: var(--link);
  text-decoration: underline;
}

@media (min-width: 64rem) {
  .doc {
    /* The text column sits in the middle of the page; the contents hang in
       the left margin, under the logo. */
    grid-template-columns: minmax(12rem, 1fr) minmax(0, var(--measure)) minmax(0, 1fr);
    grid-template-areas:
      "toc head ."
      "toc body .";
    column-gap: 2.5rem;
    align-items: start;
    max-width: calc(var(--wide) + 2 * var(--gutter));
  }

  .doc-head {
    grid-area: head;
  }

  .doc-body {
    grid-area: body;
  }

  .doc-toc {
    grid-area: toc;
    position: sticky;
    top: calc(var(--header-h) + 1.5rem);
    max-width: 16rem;
  }

  .doc-toc .toc {
    margin-top: 0.4rem;
    padding: 0;
    border: 0;
    background: none;
  }

  .doc-toc .toc ol {
    padding-left: 1.2rem;
  }
}

/* Data inventory: one block per kind of data, no sideways scrolling. */
.data-item {
  margin: 1rem 0 0;
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.data-item h3 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0;
}

.data-item h3 .icon {
  color: var(--brand);
}

.data-item dl {
  display: grid;
  grid-template-columns: minmax(7rem, max-content) 1fr;
  gap: 0.4rem 1rem;
  margin-top: 0.7rem;
}

.data-item dt {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9375rem;
}

.data-item dd {
  margin: 0;
}

@media (max-width: 30rem) {
  .data-item dl {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

  .data-item dd + dt {
    margin-top: 0.55rem;
  }
}

/* Numbered steps */
.steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
}

.steps li {
  position: relative;
  padding-left: 2.7rem;
  min-height: 1.95rem;
}

.steps li + li {
  margin-top: 0.85rem;
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.95rem;
  height: 1.95rem;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--link);
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.95rem;
  text-align: center;
}

/* FAQ: native disclosure, no script */
.faq-group {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.faq-group .icon {
  color: var(--brand);
}

.faq {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: clip;
}

.faq details + details {
  border-top: 1px solid var(--border);
}

.faq summary {
  position: relative;
  padding: 1.05rem 3rem 1.05rem 1.3rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  transition: background-color 0.15s ease;
}

.faq summary:hover {
  background: var(--bg-soft);
}

.faq summary::-webkit-details-marker {
  display: none;
}

.faq summary::after {
  content: "";
  position: absolute;
  right: 1.35rem;
  top: 50%;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 0.25s var(--ease-out);
}

.faq details[open] summary::after {
  transform: translateY(-30%) rotate(-135deg);
}

.faq details > :not(summary) {
  margin: 0;
  padding: 0 1.3rem 1.1rem;
}

.faq details > :not(summary) + :not(summary) {
  padding-top: 0;
  margin-top: -0.25rem;
}

/* ─── Footer ─────────────────────────────────────────────────────────── */

.site-footer {
  padding: 3.25rem 0 2.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9375rem;
}

.footer-grid {
  display: grid;
  gap: 1.75rem 2rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 48rem) {
  .footer-grid {
    grid-template-columns: 2fr repeat(3, 1fr);
  }
}

.footer-brand {
  grid-column: 1 / -1;
}

@media (min-width: 48rem) {
  .footer-brand {
    grid-column: auto;
  }
}

.footer-brand .brand {
  margin-right: 0;
}

.footer-brand p {
  margin: 0.6rem 0 0;
}

.footer-title {
  margin: 0;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 650;
}

.site-footer ul {
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.site-footer li + li {
  margin-top: 0.4rem;
}

.site-footer ul a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer ul a:hover {
  color: var(--text);
  text-decoration: underline;
}

.footer-note {
  margin: 2rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

/* ─── Motion ─────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  /* Page to page: a short cross-fade; the header stays put. */
  @view-transition {
    navigation: auto;
  }

  .site-header {
    view-transition-name: site-header;
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.3s;
  }

  /* The top of a reading page settles in on arrival. */
  body:not(.landing) main > .wrap:not(.doc) > :nth-child(-n + 4),
  .doc-head > *,
  .doc-toc {
    animation: settle 0.7s var(--ease-out) both;
  }

  body:not(.landing) main > .wrap:not(.doc) > :nth-child(2),
  .doc-head > :nth-child(2) {
    animation-delay: 0.05s;
  }

  body:not(.landing) main > .wrap:not(.doc) > :nth-child(n + 3),
  .doc-head > :nth-child(n + 3),
  .doc-toc {
    animation-delay: 0.1s;
  }
}

@keyframes settle {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .site-header::after {
      animation: read-progress linear both;
      animation-timeline: scroll(root);
    }
  }
}

@keyframes read-progress {
  from {
    transform: scaleX(0);
    opacity: 1;
  }

  to {
    transform: scaleX(1);
    opacity: 1;
  }
}

@media (forced-colors: active) {
  .site-header::after {
    display: none;
  }
}

/* ─── Print ──────────────────────────────────────────────────────────── */

@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --bg-soft: #fff;
    --surface: #fff;
    --text: #000;
    --muted: #333;
    --border: #bbb;
    --link: #000;
  }

  body {
    background: #fff;
    font-size: 11pt;
  }

  .site-header,
  .skip-link,
  .doc-toc,
  .toc,
  .button,
  .site-footer ul {
    display: none;
  }

  main {
    padding-top: 0;
  }

  main::before {
    display: none;
  }

  .doc {
    display: block;
  }

  .faq details {
    break-inside: avoid;
  }

  a[href^="http"]::after,
  a[href^="mailto:"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
  }
}

/* ─── Inline code (addresses and commands on /assistentes) ──────────── */

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1em 0.4em;
  overflow-wrap: anywhere;
}
