/* Pearto fluid layout layer.
 * Loaded after feature styles so public surfaces adapt continuously from small
 * phones to ultrawide displays without replacing each feature's typography.
 *
 * Principle: layout should flow like water, while component-specific visual
 * hierarchy remains owned by the component that knows its context.
 */
:root {
  --fluid-page-pad: clamp(14px, 2.4vw, 38px);
  --fluid-section-gap: clamp(34px, 6vw, 92px);
  --fluid-card-gap: clamp(12px, 1.8vw, 26px);
  --fluid-reading: 72ch;
  --fluid-wide: 1480px;
  --fluid-control-h: clamp(44px, 5.2vw, 52px);
}

html {
  min-width: 280px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 280px;
  /* Hidden is the fallback for older engines; clip prevents a rogue decorative
     element from creating a horizontal page while preserving nested scrollers. */
  overflow-x: hidden;
  overflow-x: clip;
}

img,
video,
canvas,
svg {
  max-inline-size: 100%;
}

img,
video {
  block-size: auto;
}

iframe {
  max-inline-size: 100%;
}

/* Page width behaves like a liquid with a readable ceiling. */
.container,
.nav-inner,
.product-page,
.console-hero > .container {
  width: min(calc(100% - (var(--fluid-page-pad) * 2)), var(--fluid-wide));
  margin-inline: auto;
}

.container-narrow {
  width: min(calc(100% - (var(--fluid-page-pad) * 2)), var(--fluid-reading));
  margin-inline: auto;
}

.section {
  padding-block: var(--fluid-section-gap);
}

.section-tight {
  padding-block: clamp(24px, 4vw, 54px);
}

/* Preserve each feature's type scale. Fluid.css only improves wrapping. */
h1,
h2,
h3 {
  text-wrap: balance;
}

p,
li {
  overflow-wrap: break-word;
  word-break: normal;
}

.prose p,
.prose li,
.lede {
  max-inline-size: var(--fluid-reading);
}

/* Grid primitives grow and collapse based on actual available space. */
.card-grid,
.product-columns,
.console-trust-grid,
.staff-grid,
.studio-grid {
  gap: var(--fluid-card-gap);
}

.card-grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}

.card-grid-2,
.product-columns,
.console-trust-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
}

.card-grid > *,
.product-columns > *,
.console-trust-grid > *,
.field-row > *,
.form-row > *,
.calculator-grid > *,
.tool-input-grid > * {
  min-width: 0;
}

/* Make reusable cards container-aware rather than viewport-only. */
.card,
.tool-card,
.product-group,
.console-demo,
.studio-card,
.calculator-card {
  container-type: inline-size;
}

@container (max-width: 360px) {
  .split,
  .card-actions,
  .tool-card-actions,
  .result-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .button,
  .button-ghost,
  .button-quiet {
    width: 100%;
    justify-content: center;
  }
}

/* Forms and workspaces remain usable at any width. */
form,
fieldset {
  min-width: 0;
}

input,
select,
textarea,
button {
  max-width: 100%;
}

input,
select,
textarea {
  min-height: var(--fluid-control-h);
  box-sizing: border-box;
}

textarea {
  min-height: clamp(110px, 18vh, 220px);
  resize: vertical;
}

.field-row,
.form-row,
.calculator-grid,
.tool-input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: clamp(10px, 1.4vw, 18px);
}

/* Tool/results workspaces use the space they actually receive. */
.calculator-shell,
.tool-workspace,
.product-workspace,
.studio-workspace {
  container: pearto-workspace / inline-size;
  min-width: 0;
}

@container pearto-workspace (min-width: 760px) {
  .workspace-split,
  .calculator-layout,
  .studio-workspace-grid {
    display: grid;
    grid-template-columns: minmax(260px, .82fr) minmax(0, 1.18fr);
    gap: clamp(18px, 2.4vw, 34px);
    align-items: start;
  }
}

@container pearto-workspace (min-width: 1180px) {
  .workspace-three {
    display: grid;
    grid-template-columns: minmax(250px, .72fr) minmax(0, 1.45fr) minmax(270px, .78fr);
    gap: clamp(18px, 2vw, 32px);
  }
}

/* Tables stay tables. Narrow screens scroll the table, not the whole page. */
.table-wrap,
.staff-table-wrap,
.editorial-table,
.product-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

table {
  max-width: 100%;
}

th,
td {
  vertical-align: top;
}

/* Long code/output never widens the whole page. */
pre,
code,
.code-output,
.result-output {
  max-inline-size: 100%;
  overflow-x: auto;
}

/* Navigation can surrender secondary items cleanly before mobile. */
.site-nav .nav-inner {
  gap: clamp(10px, 1.6vw, 24px);
}

.desktop-nav {
  min-width: 0;
  gap: clamp(8px, 1vw, 18px);
}

.nav-actions {
  min-width: 0;
  gap: clamp(8px, 1vw, 14px);
}

.nav-search {
  width: clamp(150px, 15vw, 260px);
}

/* Home/chat composer adapts without fixed-width assumptions. */
.console-hero-heading {
  max-width: min(100%, 1050px);
}

.console-hero-heading h1 {
  line-height: .97;
}

.product-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(8px, 1vw, 12px);
}

.chat-shell,
.chat-composer,
.composer-shell,
.chat-composer-row,
.composer-row {
  min-width: 0;
  max-width: 100%;
}

/* Prefer room-based component changes, then viewport queries for shell/nav. */
@media (max-width: 1120px) {
  .desktop-nav {
    display: none;
  }

  .mobile-nav-toggle {
    display: inline-flex;
  }

  .nav-search {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --fluid-page-pad: clamp(12px, 4.5vw, 22px);
    --fluid-section-gap: clamp(28px, 10vw, 58px);
  }

  /* Avoid iOS zooming a form simply because a feature uses small helper type. */
  input,
  select,
  textarea {
    font-size: max(16px, 1rem);
  }

  .section-head.split,
  .split {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .console-proof {
    flex-wrap: wrap;
  }

  .console-steps,
  .direct-tools {
    grid-template-columns: 1fr;
  }

  .product-quick-actions {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-block-end: 4px;
    scroll-snap-type: x proximity;
  }

  .product-quick-actions > * {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .nav-actions > .product-search-link {
    display: none;
  }
}

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

  .nav-actions {
    gap: 6px;
  }

  .button-small {
    padding-inline: 10px;
  }

  .console-hero-heading p {
    font-size: 1rem;
  }
}

/* Touch gets larger targets; mouse layouts stay compact. */
@media (pointer: coarse) {
  a,
  button,
  summary,
  input[type="checkbox"],
  input[type="radio"] {
    touch-action: manipulation;
  }

  .button,
  .button-ghost,
  .button-quiet,
  .mobile-nav a,
  .desktop-nav a {
    min-height: 44px;
  }
}

/* Accessibility: movement is enhancement, never a requirement. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  .card,
  .tool-card,
  .product-group,
  input,
  select,
  textarea {
    border-width: 2px;
  }
}

/* Print stays useful for result/report pages. */
@media print {
  .site-nav,
  .mobile-nav,
  .chat-widget,
  .product-quick-actions {
    display: none !important;
  }

  .container,
  .container-narrow {
    width: 100%;
    max-width: none;
  }

  body {
    overflow: visible;
  }
}
