/* ==========================================================================
   Phone and tablet layer.

   Loaded last on purpose. site.css declares the same grid selectors several
   times at the top level, and a media query does not raise specificity, so a
   mobile collapse written early in that file is silently defeated by a later
   global declaration of the same selector. Winning on source order is the only
   way to fix that without rewriting a 9k-line stylesheet.

   This layer changes layout and touch ergonomics only. No colour, no type
   scale, no identity change.
   ========================================================================== */

/* ------------------------------------------------------------ safety net */

html,
body {
  /* clip, not hidden: it stops sideways scrolling without turning the body
     into a scroll container, so position: sticky keeps working. */
  overflow-x: clip;
}

img,
svg,
video,
canvas,
iframe,
embed,
object {
  max-width: 100%;
}

/* Long unbroken strings (e-mails, URLs, CNPJ) are a common overflow source. */
p,
li,
dd,
dt,
td,
th,
figcaption,
blockquote,
.alert,
.field small {
  overflow-wrap: anywhere;
}

/* Grid and flex items refuse to shrink below their content by default, which
   is what pushes a page sideways on a narrow screen. */
.container > *,
.admin-body > *,
.card > *,
.ecard > *,
.hcard > * {
  min-width: 0;
}

/* ====================================================================== */
/* <= 1040px : header and the drawer menu                                  */
/* ====================================================================== */

@media (max-width: 1040px) {
  .site-header__inner {
    gap: var(--space-3);
  }

  .nav-toggle {
    display: flex;
    flex: none;
    width: 46px;
    height: 46px;
  }

  /* Opaque drawer hanging off the bottom of the header.

     It cannot be position: fixed here. The header carries a backdrop-filter,
     which makes it the containing block for fixed descendants, so a fixed
     drawer was being clamped to the header's own 83px and showed a single
     menu item. Anchoring it to the header with position: absolute sidesteps
     that entirely. */
  .site-header {
    position: sticky;
  }

  .site-nav {
    position: absolute;
    top: 100%;
    right: 0;
    bottom: auto;
    left: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    margin: 0;
    padding: var(--space-4) var(--gutter) var(--space-7);
    background: var(--surface-0);
    border-top: 1px solid var(--line);
    box-shadow: 0 30px 60px -28px rgba(11, 58, 111, 0.5);
    max-height: calc(100dvh - 82px);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateY(-10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-micro-slow) var(--ease-out), transform var(--t-micro-slow) var(--ease-out);
  }

  .site-nav[data-open='true'] {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  /* The header turns transparent over a photo hero; the drawer must not
     inherit that treatment or its items become unreadable. */
  body:has(.hero--photo) .site-header:not([data-scrolled='true']) .site-nav > a.nav-link,
  body:has(.hero--photo) .site-header:not([data-scrolled='true']) .site-nav > a:not(.btn),
  body:has(.hero--photo) .site-header:not([data-scrolled='true']) .nav-drop__trigger:not(.btn) {
    color: var(--text);
  }

  .site-nav .nav-link,
  .site-nav > a:not(.btn),
  .site-header .nav-drop__trigger:not(.btn) {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--space-2);
    padding: 0.7rem 0.75rem;
    font-size: var(--step-0);
    border-radius: var(--radius-sm);
  }

  .site-header .nav-drop__trigger:not(.btn) {
    justify-content: space-between;
  }

  .nav-drop {
    width: 100%;
  }

  .site-header .nav-drop__item {
    min-height: 48px;
    justify-content: center;
  }

  .site-nav__actions {
    margin: var(--space-4) 0 0;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }

  .site-nav a.btn,
  .site-nav .btn {
    width: 100%;
    min-height: 48px;
    justify-content: center;
    text-align: center;
  }
}

/* ====================================================================== */
/* <= 900px : every two-pane layout becomes one column                     */
/* ====================================================================== */

@media (max-width: 900px) {
  .closing-net__grid,
  .depo-share__grid,
  .depo-voices__main,
  .depo-voices__subgrid,
  .donate-layout,
  .ecard__row,
  .empresa-bar__grid,
  .empresa__grid,
  .essencia__grid,
  .hero2,
  .hero__grid,
  .history-hero__inner,
  .history-method__steps,
  .history-method__top,
  .history-move__grid,
  .history-move__top,
  .news-grid,
  .page-hero-split__grid,
  .program,
  .proj-grid,
  .stories-grid,
  .transp-docs__grid,
  .transp-hero__grid,
  .transp-stats__grid,
  .volbem-card {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Side panels that were pinned next to a main pane must not keep a width
     that no longer fits, nor stay sticky once they are stacked. */
  .donate-layout > *,
  .news-grid > *,
  .proj-grid > *,
  .stories-grid > * {
    position: static;
    max-width: none;
    width: auto;
  }

  .site-footer__grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  }

  /* Decorative overlaps and absolute offsets designed for a wide canvas. */
  .hero2__media,
  .page-hero-split__media,
  .history-hero__media {
    margin-inline: 0;
  }

  /* This figure carries aspect-ratio: 4/3 together with a fixed height, so
     its width was derived from that height and ignored the column it sits
     in. An explicit width puts the column back in charge. */
  .empresa__photo {
    width: 100%;
    max-width: 100%;
  }
}

/* ====================================================================== */
/* <= 640px : phone                                                        */
/* ====================================================================== */

@media (max-width: 640px) {
  .container {
    padding-inline: 1rem;
  }

  .section {
    padding-block: clamp(2.25rem, 9vw, 3.25rem);
  }

  /* --- donation and company option grids ---------------------------- */
  /* Three columns at 390px left the labels clipped mid-word. */
  .hcard__amounts,
  .ecard__opts,
  .freq-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hcard__amounts > *,
  .ecard__opts > *,
  .freq-group > *,
  .hcard__freq > * {
    min-width: 0;
    min-height: 48px;
    overflow-wrap: anywhere;
  }

  .amount-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 96px), 1fr));
  }

  /* --- list rows: the trailing "auto" column was crushed to ~22px ---- */
  .news-side__item,
  .proj-item {
    grid-template-columns: 84px minmax(0, 1fr);
    gap: var(--space-3);
    align-items: start;
  }

  .news-side__item > :nth-child(3),
  .proj-item > :nth-child(3) {
    grid-column: 1 / -1;
    text-align: left;
  }

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

  .transp-doc-item > :nth-child(3) {
    grid-column: 1 / -1;
  }

  .stories-thumbs,
  .depo-share__row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .transp-chart__columns {
    gap: 0.35rem;
  }

  /* --- forms and controls ------------------------------------------- */
  /* 16px is the threshold below which iOS Safari zooms on focus.

     A radio or a checkbox must be left out of this: stretching the control
     itself to 48px centres its dot against a label that is only one line
     tall, which reads as a misalignment. The touch target belongs to the
     label around it, below. */
  input:not([type='radio']):not([type='checkbox']),
  select,
  textarea {
    font-size: 16px;
    min-height: 48px;
  }

  input[type='radio'],
  input[type='checkbox'] {
    min-height: 0;
    flex: none;
  }

  /* The clickable row is what has to be comfortable to hit.

     In these option groups the visible card is the <span>, not the <label>:
     the input is hidden and the span carries the border. So the label stays a
     block that fills its grid cell and the span becomes the 48px target. */
  .ecard__opts label,
  .amount-option,
  .freq-option {
    display: block;
    width: 100%;
  }

  .ecard__opts label > span,
  .amount-option > span,
  .freq-option > span {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* These two do show their control, so they are a row. */
  label.radio,
  label.checkbox {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  textarea {
    min-height: 120px;
  }

  .field {
    min-width: 0;
  }

  /* --- touch targets ------------------------------------------------- */
  .btn,
  .icon-btn,
  .hero2__link,
  .hcard__more,
  .essencia__link,
  .pagination a,
  .pagination button {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
  }

  .btn--sm {
    min-height: 44px;
  }

  /* A row of buttons wraps instead of overflowing. */
  .form-actions,
  .btn-row,
  .card__actions,
  .admin-top__actions,
  .filters__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .form-actions .btn,
  .btn-row .btn {
    flex: 1 1 160px;
  }

  /* --- header --------------------------------------------------------- */
  /* Capping the width alone distorts the mark, because the footer rule gives
     it a fixed height: the two together squash it. Every cap here releases
     the height as well. */
  .site-header .brand__logo,
  .site-header__inner img {
    max-width: 140px;
    height: auto;
  }

  .site-footer .brand__logo,
  .site-footer .brand__logo--light,
  .site-footer .brand__logo--dark {
    max-width: 170px;
    height: auto;
  }

  /* --- footer --------------------------------------------------------- */
  .site-footer__grid {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
  }
}

/* ====================================================================== */
/* <= 420px : small phone                                                  */
/* ====================================================================== */

@media (max-width: 420px) {
  .ecard__opts,
  .freq-group {
    grid-template-columns: minmax(0, 1fr);
  }

  .site-header .brand__logo,
  .site-header__inner img {
    max-width: 118px;
    height: auto;
  }

  .site-footer .brand__logo,
  .site-footer .brand__logo--light,
  .site-footer .brand__logo--dark {
    max-width: 150px;
    height: auto;
  }

  .site-nav {
    max-height: calc(100dvh - 72px);
  }
}

/* ====================================================================== */
/* /EMBONG panel                                                           */
/* ====================================================================== */

@media (max-width: 1080px) {
  /* The sidebar used to stack above the content: sixteen links to scroll
     past before reaching the page. It is a drawer on this breakpoint. */
  .admin {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-side {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(300px, 86vw);
    height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 0 30px 60px -28px rgba(11, 58, 111, 0.5);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--t-micro-slow) var(--ease-out), visibility var(--t-micro-slow);
  }

  .admin-side[data-open='true'] {
    transform: none;
    visibility: visible;
  }

  .admin-scrim {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(8, 42, 82, 0.45);
    border: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-micro-slow) var(--ease-out);
  }

  .admin-scrim[data-open='true'] {
    opacity: 1;
    pointer-events: auto;
  }

  .admin-menu-toggle {
    display: inline-flex;
  }

  .admin-nav a {
    min-height: 46px;
  }
}

@media (min-width: 1081px) {
  /* The drawer controls do not exist on desktop. */
  .admin-menu-toggle,
  .admin-scrim {
    display: none;
  }
}

@media (max-width: 700px) {
  .admin-top {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  /* Menu button and page title share the first row; the account controls
     take the second. */
  .admin-menu-toggle {
    order: 1;
    flex: none;
  }

  .admin-top h1 {
    order: 2;
    flex: 1 1 auto;
    min-width: 0;
    font-size: var(--step-1);
    overflow-wrap: anywhere;
  }

  .admin-top__actions {
    order: 3;
    flex: 1 1 100%;
    margin-left: 0;
    flex-wrap: wrap;
    row-gap: var(--space-2);
  }

  /* The name and role block costs a whole row on a phone; the avatar keeps
     the identity visible. */
  .admin-user > span:not(.admin-user__avatar) {
    display: none;
  }

  .admin-body {
    padding: var(--space-4) var(--space-4) var(--space-7);
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  }

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

  .filters .field {
    min-width: 0;
  }

  /* Section tabs scroll sideways instead of overflowing the page. */
  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .admin-tabs::-webkit-scrollbar {
    display: none;
  }

  .admin-tabs a {
    flex: none;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
  }

  /* Wide tables keep their own scroll area and announce it. */
  .table-wrap {
    position: relative;
    -webkit-overflow-scrolling: touch;
  }

  table.data {
    min-width: 560px;
  }

  table.data th,
  table.data td {
    padding: 0.6rem 0.7rem;
  }

  /* Only figures and dates refuse to break; letting text wrap keeps the
     table close to its minimum width instead of forcing a long swipe. */
  table.data td.num,
  table.data th.num,
  table.data .nowrap {
    white-space: nowrap;
  }

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

  .media-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 120px), 1fr));
  }

  .perm-item {
    min-height: 46px;
  }

  .toast-stack {
    left: var(--space-3);
    right: var(--space-3);
  }

  .toast {
    width: auto;
  }
}

/* ====================================================================== */
/* Labels that were told never to wrap                                     */
/* ====================================================================== */

/* These read fine on a wide canvas but are wider than a phone on their own,
   so they were being cut off at the edge. */
@media (max-width: 640px) {
  .transp-hero__bar-title,
  .transp-badge,
  .transp-card__foot a,
  .proj-stats-bar__item span,
  .proj-stats-bar__item strong {
    white-space: normal;
  }

  .transp-hero__bar {
    padding: 1rem 1.15rem;
    gap: var(--space-3);
  }

  .transp-hero__bar-sep {
    display: none;
  }

  /* The statistics row ran off the right edge because its labels were told
     never to wrap. The two entries cross-fade into each other on a timer, so
     they stay on one row here and the text wraps inside them instead. */
  .proj-stats-bar,
  .proj-stats-bar__grid {
    height: auto;
    min-height: 0;
    gap: var(--space-2);
    padding-block: var(--space-4);
  }

  .proj-stats-bar__item {
    flex: 1 1 0;
    min-width: 0;
  }

  /* Pills sized for a desktop line length. */
  .badge,
  .pill,
  .tag {
    white-space: normal;
    max-width: 100%;
  }

  .transp-card__head {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* Video and audio controls on the testimonials page were 30-39px tall. */
  .depo-hero__watch,
  .depo-hero__sound,
  .depo-voices__watch,
  .transp-tab {
    min-height: 44px;
  }

  .depo-hero__sound,
  .depo-voices__watch {
    min-width: 44px;
  }

  .proj-tcard:not([data-pos='active']) .proj-tcard__btn {
    min-height: 44px;
  }

  /* The strip already wraps on its own; it only needs to stay inside its
     column while doing so. */
  .transp-tabs {
    min-width: 0;
    max-width: 100%;
  }
}

/* ====================================================================== */
/* Projects carousel                                                       */
/* ====================================================================== */

/* Below 980px only the active card is shown, but its neighbours were still
   anchored at left: 0 / left: 100% and kept sticking out past the right
   edge. They are invisible there, so park them behind the active one. */
@media (max-width: 980px) {
  .proj-tcard[data-pos='prev'],
  .proj-tcard[data-pos='next'],
  .proj-tcard[data-pos='out-left'],
  .proj-tcard[data-pos='out-right'] {
    left: 50%;
    width: 100%;
    transform: translate(-50%, -50%);
    visibility: hidden;
  }
}
