@layer reset, tokens, base, layout, components;

@layer reset {
  :where(html, body, header, nav, main, section, article, aside, footer, div, span, h1, h2, h3, h4, p, ul, ol, li, dl, dt, dd, figure, figcaption, blockquote, a, button, img, svg, details, summary, small, time, hr) {
    box-sizing: border-box;
  }

  :where(body, h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote) {
    margin: 0;
  }

  :where(ul, ol) {
    padding: 0;
    list-style: none;
  }

  img, svg {
    display: block;
    max-inline-size: 100%;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
  }
}

@layer tokens {
  :root {
    --bg-paper: #f6f2ea;
    --bg-stone: #ece6da;
    --bg-surface: #fbf9f4;
    --bg-alert: #f2ebe0;
    --ink: #191816;
    --ink-muted: #4b463e;
    --ink-soft: #645d53;
    --rule: #c8c0b2;
    --rule-strong: #92897b;
    --forest: #1f352c;
    --forest-hover: #14251e;
    --forest-deep: #162620;
    --sage-muted: #5a7a68;
    --clay: #7c5c3b;
    --clay-border: #8d6b47;
    --on-dark: #f6f2ea;
    --on-dark-muted: #d2ccc0;
    --rule-dark: #3b5348;

    --font-serif: 'Newsreader', Georgia, serif;
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --bg-sage-soft: #eaece6;
    --border-sage-soft: #cfd8d1;
    --max-inline: 72rem;
    --gutter: clamp(1.25rem, 4vw, 2.5rem);
  }

  @supports (background-color: color-mix(in srgb, red, blue)) {
    :root {
      --bg-sage-soft: color-mix(in srgb, var(--sage-muted) 11%, var(--bg-paper));
      --border-sage-soft: color-mix(in srgb, var(--sage-muted) 28%, var(--rule));
    }
  }
}

@layer base {
  html {
    scroll-padding-top: 5.5rem;
    background-color: var(--bg-paper);
    color: var(--ink);
    @media (prefers-reduced-motion: no-preference) {
      scroll-behavior: smooth;
    }
  }

  body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.62;
    background-color: var(--bg-paper);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-serif);
    font-weight: 400;
    letter-spacing: -0.02em;
    text-wrap: balance;
  }

  p, blockquote {
    text-wrap: pretty;
  }

  [hidden] {
    display: none !important;
  }

  :where(a:any-link, button, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--forest);
    outline-offset: 3px;
    border-radius: 2px;
  }

  .visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .skip-link:focus {
    position: fixed;
    inset-block-start: 0.75rem;
    inset-inline-start: 0.75rem;
    z-index: 500;
    padding: 0.75rem 1.125rem;
    background-color: var(--forest);
    color: var(--on-dark);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
  }
}

@layer layout {
  .wrap {
    inline-size: min(100% - (var(--gutter) * 2), var(--max-inline));
    margin-inline: auto;
  }

  section[id] {
    scroll-margin-top: 5.25rem;
  }

  .section-block {
    padding-block: clamp(3.5rem, 7vw, 6rem);
  }
}

@layer components {
  /* ─── HEADER ─── */
  .site-header {
    position: sticky;
    inset-block-start: 0;
    z-index: 100;
    background-color: rgba(246, 242, 234, 0.9);
    backdrop-filter: blur(12px) saturate(1.2);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
    border-block-end: 1px solid var(--rule);
    transition: background-color 0.25s ease, box-shadow 0.25s ease;
  }

  .header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding-block: 1.125rem;
    transition: padding-block 0.25s ease;
  }

  .site-header.is-condensed .header-inner {
    padding-block: 0.75rem;
  }

  .site-header.is-condensed {
    box-shadow: 0 2px 18px rgba(25, 24, 22, 0.05);
  }

  @media (prefers-reduced-motion: no-preference) {
    @supports ((animation-timeline: scroll()) and (animation-range: 0% 100%)) {
      @keyframes header-condense {
        to {
          padding-block: 0.75rem;
        }
      }
      @keyframes header-shadow {
        to {
          box-shadow: 0 2px 18px rgba(25, 24, 22, 0.06);
          background-color: rgba(246, 242, 234, 0.96);
        }
      }
      .site-header {
        animation: header-shadow auto linear both;
        animation-timeline: scroll(block root);
        animation-range: 0px 140px;
      }
      .header-inner {
        animation: header-condense auto linear both;
        animation-timeline: scroll(block root);
        animation-range: 0px 140px;
      }
    }
  }

  .brand {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 500;
    letter-spacing: -0.015em;
    white-space: nowrap;
  }

  .nav-desktop {
    display: flex;
    align-items: center;
    gap: 1.75rem;
  }

  .nav-list {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.9rem;
    color: var(--ink-muted);
  }

  .nav-list a {
    display: inline-block;
    padding-block: 0.35rem;
    position: relative;
    white-space: nowrap;
    transition: color 0.2s ease;

    &:hover {
      color: var(--ink);
    }
  }

  .nav-list a[aria-current="page"] {
    color: var(--ink);
    font-weight: 600;

    &::after {
      content: "";
      position: absolute;
      inset-inline: 0;
      inset-block-end: 0;
      block-size: 2px;
      background-color: var(--forest);
    }
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
  }

  .btn-rect {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-block-size: 2.65rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-md);
    background-color: var(--forest);
    color: var(--on-dark);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s ease, transform 0.2s ease;

    &:hover {
      background-color: var(--forest-hover);
    }
  }

  .btn-rect-lg {
    min-block-size: 3.1rem;
    padding: 0.85rem 1.65rem;
    font-size: 0.95rem;
  }

  .btn-mobile-menu {
    display: none;
    align-items: center;
    justify-content: center;
    min-inline-size: 2.65rem;
    min-block-size: 2.65rem;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--ink);
  }

  /* Native Popover mobile menu */
  .mobile-popover {
    position: fixed;
    z-index: 250;
    margin: 0;
    inset: 4.5rem var(--gutter) auto var(--gutter);
    inline-size: auto;
    max-block-size: calc(100dvh - 6rem);
    overflow: auto;
    padding: 1.25rem;
    background-color: var(--bg-surface);
    color: var(--ink);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 18px 40px rgba(25, 24, 22, 0.14);
  }

  .mobile-popover::backdrop {
    background-color: rgba(25, 24, 22, 0.3);
  }

  .mobile-popover-list {
    display: flex;
    flex-direction: column;
  }

  .mobile-popover-list li:not(:last-child) {
    border-block-end: 1px solid var(--rule);
  }

  .mobile-popover-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-block-size: 3rem;
    padding-block: 0.65rem;
    font-size: 1rem;
    font-weight: 500;
  }

  .mobile-popover-list a[aria-current="page"] {
    color: var(--forest);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 2px;
  }

  @supports not selector(:popover-open) {
    [popover]:not(.\:popover-open) {
      display: none;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    @supports selector(:popover-open) {
      .mobile-popover {
        transition: opacity 0.2s ease, translate 0.2s ease, display 0.2s ease, overlay 0.2s ease;
        transition-behavior: allow-discrete;
        opacity: 0;
        translate: 0 -6px;

        &:is(:popover-open, .\:popover-open) {
          opacity: 1;
          translate: 0 0;

          @starting-style {
            opacity: 0;
            translate: 0 -6px;
          }
        }
      }
    }
  }

  /* ─── SHARED TYPOGRAPHY & LINKS ─── */
  .eyebrow {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--clay);
    margin-block-end: 1.35rem;
  }

  .link-underlined {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-block-size: 2.65rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink);
    border-block-end: 1px solid var(--ink);
    padding-block: 0.25rem;
    transition: color 0.2s ease, border-color 0.2s ease;

    &:hover {
      color: var(--forest);
      border-color: var(--forest);
    }
  }

  .section-kicker {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin-block-end: 0.85rem;
  }

  .section-kicker span {
    color: var(--clay);
  }

  .section-title {
    font-size: clamp(1.9rem, 1.35rem + 2.2vw, 2.85rem);
    line-height: 1.12;
    color: var(--ink);
  }

  /* ─── CREDENTIALS LIST & EDITORIAL ROWS ─── */
  .cred-list {
    margin-block-start: 2rem;
    border-block-start: 1px solid var(--rule);
  }

  .cred-list li {
    padding-block: 0.9rem;
    border-block-end: 1px solid var(--rule);
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    gap: 1rem;
    font-size: 0.94rem;
  }

  .cred-tag {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
    padding-block-start: 0.15rem;
  }

  .cred-detail {
    color: var(--ink);
  }

  .editorial-quote {
    padding-inline-start: 1.5rem;
    border-inline-start: 2px solid var(--forest);
  }

  .editorial-quote p {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.55rem);
    line-height: 1.48;
    color: var(--ink);
  }

  .editorial-rows {
    border-block-start: 1px solid var(--rule-strong);
  }

  .editorial-row {
    display: grid;
    grid-template-columns: 4.5rem minmax(12rem, 0.85fr) minmax(0, 1.35fr);
    gap: 1rem 2rem;
    padding-block: clamp(1.5rem, 3vw, 2.25rem);
    border-block-end: 1px solid var(--rule);
    align-items: baseline;
  }

  .row-num {
    font-family: var(--font-serif);
    font-size: 1.35rem;
    color: var(--clay);
  }

  .row-title {
    font-size: clamp(1.25rem, 1.05rem + 0.75vw, 1.6rem);
    line-height: 1.25;
    color: var(--ink);
  }

  .row-body {
    color: var(--ink-muted);
    font-size: 0.97rem;
    line-height: 1.72;
    max-inline-size: 58ch;
  }

  /* ─── CONTACTO & FOOTER (DEEP FOREST CONTRAST BAND) ─── */
  .contact-band {
    background-color: var(--forest);
    color: var(--on-dark);
    padding-block: clamp(3.75rem, 8vw, 6.25rem);
  }

  .contact-band :where(a:any-link, button):focus-visible {
    outline-color: var(--on-dark);
  }

  .contact-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    gap: clamp(2.5rem, 6vw, 5rem);
    align-items: start;
  }

  .contact-kicker {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--on-dark-muted);
    margin-block-end: 0.85rem;
  }

  .contact-title {
    font-size: clamp(2rem, 1.4rem + 2.5vw, 3.2rem);
    line-height: 1.08;
    color: var(--on-dark);
    margin-block-end: 1.25rem;
  }

  .contact-lead {
    color: var(--on-dark-muted);
    font-size: 1.02rem;
    line-height: 1.7;
    max-inline-size: 46ch;
    margin-block-end: 2rem;
  }

  .btn-paper {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-block-size: 3.1rem;
    padding: 0.85rem 1.7rem;
    border-radius: var(--radius-md);
    background-color: var(--bg-paper);
    color: var(--forest);
    font-size: 0.95rem;
    font-weight: 600;
    transition: background-color 0.2s ease, transform 0.2s ease;

    &:hover {
      background-color: #fff;
    }
  }

  .contact-details {
    border-block-start: 1px solid var(--rule-dark);
  }

  .contact-row {
    padding-block: 1.15rem;
    border-block-end: 1px solid var(--rule-dark);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .contact-row dt {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--on-dark-muted);
  }

  .contact-row dd {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--on-dark);
  }

  .contact-row dd a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .site-footer {
    background-color: var(--forest-deep);
    color: var(--on-dark-muted);
    border-block-start: 1px solid var(--rule-dark);
    padding-block: 2rem 2.35rem;
    font-size: 0.86rem;
  }

  .site-footer :where(a:any-link):focus-visible {
    outline-color: var(--on-dark);
  }

  .footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem 2.5rem;
    flex-wrap: wrap;
  }

  .footer-identity {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    color: var(--on-dark);
  }

  .footer-disclaimer {
    font-size: 0.8rem;
    color: var(--on-dark-muted);
  }

  .footer-nav-list {
    display: flex;
    gap: 0.75rem 1.35rem;
    flex-wrap: wrap;
  }

  .footer-nav-list a {
    display: inline-block;
    padding-block: 0.25rem;
    transition: color 0.2s ease;

    &:hover {
      color: var(--on-dark);
    }
  }

  .footer-nav-list a[aria-current="page"] {
    color: var(--on-dark);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
  }

  /* ─── FLOATING WHATSAPP ─── */
  .float-wa {
    position: fixed;
    inset-inline-end: 1.25rem;
    inset-block-end: 1.25rem;
    z-index: 200;
    inline-size: 3.35rem;
    block-size: 3.35rem;
    border-radius: 50%;
    background-color: #187a3d;
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 22px rgba(25, 24, 22, 0.22);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.25s ease, transform 0.25s ease, background-color 0.2s ease;

    &.visible {
      opacity: 1;
      pointer-events: auto;
      transform: translateY(0);
    }

    &:hover {
      background-color: #126130;
      transform: translateY(-2px);
    }
  }

  /* ─── SCROLL REVEALS (Baseline scroll-driven + IO fallback) ─── */
  @media (prefers-reduced-motion: no-preference) {
    @keyframes editorial-reveal {
      from {
        opacity: 0;
        transform: translateY(20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    @supports ((animation-timeline: view()) and (animation-range: entry)) {
      .reveal {
        animation: editorial-reveal auto linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 50%;
      }
    }

    .reveal.io-pending {
      opacity: 0;
      transform: translateY(18px);
      transition: opacity 0.55s ease, transform 0.55s ease;
    }

    .reveal.io-pending.io-visible {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* ─── RESPONSIVE SHARED ─── */
  @media (max-width: 960px) {
    .contact-grid {
      grid-template-columns: 1fr;
    }

    .editorial-row {
      grid-template-columns: 3.25rem minmax(0, 1fr);
    }

    .row-body {
      grid-column: 2;
    }
  }

  @media (max-width: 860px) {
    .nav-desktop {
      display: none;
    }

    .btn-mobile-menu {
      display: inline-flex;
    }
  }

  @media (max-width: 680px) {
    .cred-list li {
      grid-template-columns: 1fr;
      gap: 0.25rem;
    }

    .editorial-row {
      grid-template-columns: 1fr;
      gap: 0.5rem;
    }

    .row-body {
      grid-column: 1;
    }

    .footer-inner {
      flex-direction: column;
      align-items: flex-start;
    }
  }

  @media (max-width: 480px) {
    .header-inner {
      gap: 0.65rem;
    }

    .brand {
      font-size: 1.05rem;
      min-inline-size: 0;
    }

    .header-actions {
      gap: 0.5rem;
    }

    .header-actions .btn-rect {
      padding: 0.55rem 0.85rem;
      font-size: 0.84rem;
      gap: 0.4rem;
    }
  }

  @media (max-width: 380px) {
    .brand {
      font-size: 0.98rem;
    }

    .header-actions .btn-rect {
      padding: 0.55rem 0.7rem;
      font-size: 0.82rem;
    }
  }

  @media (forced-colors: active) {
    .btn-rect,
    .btn-paper,
    .float-wa,
    .btn-mobile-menu {
      border: 1px solid ButtonText;
    }

    .editorial-rows,
    .editorial-row,
    .cred-list,
    .cred-list li,
    .mobile-popover {
      border-color: CanvasText;
    }

    .nav-list a[aria-current="page"]::after {
      background-color: Highlight;
    }

    .mobile-popover-list a[aria-current="page"],
    .footer-nav-list a[aria-current="page"] {
      color: Highlight;
    }
  }
}
