/* ============================================================
   AFSL — RESPONSIVE LAYER
   ------------------------------------------------------------
   Loaded last, so it wins. Inline grid styles cannot be
   overridden by a media query, so every two-column layout in
   the app uses one of these classes instead.

   Breakpoints
     1280  large desktop → desktop
     1024  desktop       → tablet landscape
      860  tablet        → tablet portrait
      600  tablet        → mobile
      380  mobile        → small mobile
   ============================================================ */

/* ═══════════ SPLIT LAYOUTS ═══════════ */

.split-2,
.split-wide,
.split-narrow,
.split-side,
.split-side-sm,
.split-side-lg {
  display: grid;
  gap: var(--s-5);
  align-items: start;
}

.split-2 {
  grid-template-columns: 1fr 1fr;
}

.split-wide {
  grid-template-columns: 1.4fr 1fr;
}

.split-narrow {
  grid-template-columns: 1.1fr .9fr;
}

.split-side {
  grid-template-columns: 320px 1fr;
}

.split-side-sm {
  grid-template-columns: 250px 1fr;
}

.split-side-lg {
  grid-template-columns: 400px 1fr;
}

@media (max-width: 1180px) {

  .split-wide,
  .split-narrow {
    grid-template-columns: 1fr;
  }

  .split-side-lg {
    grid-template-columns: 340px 1fr;
  }
}

@media (max-width: 1024px) {

  .split-side,
  .split-side-sm,
  .split-side-lg {
    grid-template-columns: 1fr;
  }

  /* A sticky side rail has nothing to stick to once stacked */
  .split-side>aside,
  .split-side-sm>aside,
  .split-side-lg>aside,
  .split-side>.panel:first-child,
  .split-side-sm>.panel:first-child {
    position: static !important;
  }
}

@media (max-width: 860px) {
  .split-2 {
    grid-template-columns: 1fr;
  }
}

/* ═══════════ PUBLIC SITE ═══════════ */

@media (max-width: 1024px) {
  .steps-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--s-10) var(--s-5) !important;
  }

  .steps-4::before {
    display: none;
  }
}

@media (max-width: 600px) {
  .steps-4 {
    grid-template-columns: 1fr !important;
  }
}

/* ═══════════ PORTAL SHELL ═══════════ */

@media (max-width: 1024px) {
  .topbar {
    gap: var(--s-3);
  }

  .topbar-title h1 {
    font-size: var(--fs-base);
  }

  .topbar-title p {
    display: none;
  }

  .topbar-actions .btn span:not(.sr-only) {
    display: none;
  }
}

@media (max-width: 600px) {
  :root {
    --topbar-h: 62px;
  }

  .topbar-actions .badge {
    display: none;
  }

  .topbar-actions .btn {
    width: 40px;
    height: 40px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 0;
  }

  .topbar-actions .btn svg {
    width: 18px;
    height: 18px;
  }

  .sb {
    width: min(292px, 86vw);
  }
}

/* ═══════════ STATS ═══════════ */

@media (max-width: 600px) {
  .stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--s-3);
  }

  .stat {
    padding: var(--s-4);
  }

  .stat-value {
    font-size: var(--fs-xl);
  }

  .stat-top .stat-icon {
    width: 32px;
    height: 32px;
  }

  .stat-top .stat-icon svg {
    width: 15px;
    height: 15px;
  }

  .stat-label {
    font-size: 10px;
  }

  .stat-sub {
    font-size: 11px;
  }
}

@media (max-width: 380px) {
  .stats {
    grid-template-columns: 1fr !important;
  }
}

/* ═══════════ TABLES → CARDS ON MOBILE ═══════════ */

@media (max-width: 600px) {
  .tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .tbl {
    min-width: 620px;
  }

  .tbl th,
  .tbl td {
    padding: var(--s-3) var(--s-4);
  }

  .tbl td {
    font-size: var(--fs-xs);
  }

  /* Hint that the table scrolls sideways */
  .tbl-wrap::after {
    content: "";
    position: sticky;
    right: 0;
    top: 0;
    display: block;
    width: 28px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(2, 43, 100, .06));
    pointer-events: none;
  }

  .tbl-foot {
    flex-direction: column;
    align-items: stretch;
    gap: var(--s-3);
  }

  .pager {
    justify-content: center;
  }
}

/* Matrix stays scrollable but shrinks */
@media (max-width: 860px) {

  .matrix td.emp-col,
  .matrix th.emp-col {
    min-width: 130px;
    font-size: 11px;
  }

  .mx {
    width: 19px;
    height: 19px;
  }
}

/* ═══════════ FORMS ═══════════ */

@media (max-width: 860px) {
  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 600px) {

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .recap-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-input {
    font-size: 16px;
  }

  /* stops iOS zooming on focus */
  .field-label {
    font-size: 15px;
  }

  .filters {
    padding: var(--s-4);
    gap: var(--s-3);
  }

  .filters .field {
    flex: 1 1 100%;
  }

  .filters .btn,
  .filters .icon-btn {
    flex: 1;
  }
}

@media (max-width: 380px) {
  .recap-grid {
    grid-template-columns: 1fr;
  }
}

/* ═══════════ WIZARD ═══════════ */

@media (max-width: 900px) {
  .wiz {
    overflow-x: auto;
    padding-bottom: var(--s-2);
    gap: var(--s-2);
  }

  .wiz::-webkit-scrollbar {
    height: 3px;
  }

  .wiz::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 3px;
    border: 0;
  }

  .wiz-step {
    flex: none;
  }

  .wiz-line {
    min-width: 18px;
    flex: none;
  }

  .wiz-label {
    display: none;
  }

  .wiz-step.is-current .wiz-label {
    display: block;
    position: absolute;
    margin-top: 52px;
    font-size: 10.5px;
    white-space: nowrap;
  }

  .wiz-step.is-current {
    position: relative;
  }

  .wiz {
    margin-bottom: var(--s-10);
  }
}

/* ═══════════ KYC STEPPER ═══════════ */

@media (max-width: 600px) {
  .stepper {
    padding: var(--s-5);
  }

  .stepper-list {
    gap: var(--s-2);
  }

  .step-row {
    min-width: 118px;
  }

  .step-meta b {
    font-size: var(--fs-xs);
  }

  .step-meta span {
    font-size: 10px;
  }
}

/* ═══════════ DOCUMENTS ═══════════ */

@media (max-width: 600px) {
  .doc-row {
    padding: var(--s-4);
    gap: var(--s-3);
  }

  .doc-row b {
    font-size: var(--fs-xs);
  }

  .doc-row span {
    font-size: 11px;
  }

  .doc-group-head {
    flex-wrap: wrap;
    gap: var(--s-2);
  }
}

/* ═══════════ REVIEW ═══════════ */

@media (max-width: 600px) {
  .review-row {
    flex-direction: column;
    gap: 3px;
    padding: var(--s-3) 0;
  }

  .review-row dd {
    text-align: left;
    max-width: none;
  }

  .review-head h3 {
    font-size: var(--fs-sm);
  }
}

/* ═══════════ ADMIN REVIEW SPLIT ═══════════ */

@media (max-width: 1180px) {
  .review-split {
    grid-template-columns: 1fr;
  }

  .doc-viewer {
    position: static;
  }

  .doc-stage {
    aspect-ratio: 3/2;
  }
}

@media (max-width: 600px) {
  .doc-stage {
    aspect-ratio: 1;
  }

  .decision {
    padding: var(--s-5);
    position: static;
  }

  .decision-code {
    flex-direction: column;
    align-items: flex-start;
  }

  .decision-code>div:last-child {
    margin-left: 0 !important;
    width: 100%;
  }

  .decision-acts {
    grid-template-columns: 1fr;
  }
}

/* ═══════════ PUNCH CARD ═══════════ */

@media (max-width: 860px) {
  .punch-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .punch-clock {
    text-align: center;
  }

  .punch-side {
    min-width: 0;
  }
}

/* ═══════════ CALENDAR ═══════════ */

@media (max-width: 600px) {
  .cal-grid {
    gap: 3px;
  }

  .cal-cell {
    font-size: 11px;
    border-radius: 6px;
  }

  .cal-cell i {
    width: 4px;
    height: 4px;
  }

  .cal-legend {
    gap: var(--s-3);
  }

  .cal-legend span {
    font-size: 11px;
  }
}

/* ═══════════ MODALS ═══════════ */

@media (max-width: 600px) {
  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-box {
    max-width: none;
    max-height: 92svh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    transform: translateY(100%);
  }

  .modal.is-open .modal-box {
    transform: translateY(0);
  }

  .modal-head {
    padding: var(--s-5);
  }

  .modal-body {
    padding: var(--s-5);
  }

  /* grab handle */
  .modal-box::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 8px;
    width: 38px;
    height: 4px;
    transform: translateX(-50%);
    background: var(--line-strong);
    border-radius: 99px;
    z-index: 2;
  }

  .modal-head {
    padding-top: var(--s-6);
  }
}

/* ═══════════ SLABS ═══════════ */

@media (max-width: 780px) {
  .slab-table {
    min-width: 620px;
  }
}

/* ═══════════ PERMISSIONS ═══════════ */

@media (max-width: 600px) {
  .perm-row {
    gap: var(--s-3);
  }

  .perm-row span {
    font-size: var(--fs-xs);
  }

  .perm-locked {
    padding: var(--s-3) var(--s-4);
  }

  .perm-locked b {
    font-size: var(--fs-xs);
  }

  .perm-locked em {
    font-size: 11px;
  }
}

/* ═══════════ PILLS ═══════════ */

@media (max-width: 600px) {
  .pills {
    margin-inline: calc(-1 * var(--s-4));
    padding-inline: var(--s-4);
  }

  .pill {
    padding: 8px var(--s-4);
    font-size: 11px;
  }
}

/* ═══════════ AUTH ═══════════ */

@media (max-width: 600px) {
  .auth-panel {
    padding: var(--s-6) var(--s-5);
  }

  .auth-head h1 {
    font-size: var(--fs-xl);
  }

  .auth-back {
    margin-bottom: var(--s-6);
  }

  .tabs-btn {
    padding: 11px var(--s-3);
    font-size: var(--fs-xs);
  }
}

/* ═══════════ PUBLIC ═══════════ */

@media (max-width: 600px) {
  .hero-proof-num {
    font-size: var(--fs-xl);
  }

  .growth-label {
    left: var(--s-5);
    bottom: var(--s-5);
  }

  .growth-label b {
    font-size: var(--fs-base);
  }

  .growth-tag {
    right: var(--s-4);
    top: var(--s-4);
    font-size: 9px;
    padding: 6px var(--s-3);
  }

  .quote {
    padding: var(--s-5);
  }

  .prod {
    padding: var(--s-5);
  }

  .earn {
    padding: var(--s-8) var(--s-5);
  }

  .marquee-track {
    gap: var(--s-6);
    padding-right: var(--s-6);
  }

  .marquee-item {
    font-size: var(--fs-xs);
  }

  .acc-head {
    font-size: var(--fs-sm);
    padding: var(--s-5) 0;
    gap: var(--s-3);
  }

  .policy-body h2 {
    font-size: var(--fs-lg);
  }
}

/* ═══════════ TOUCH TARGETS ═══════════ */

@media (hover: none) {

  .icon-btn,
  .btn-sm,
  .pill,
  .tabs-btn,
  .cal-cell {
    min-height: 40px;
  }

  .file-acts button {
    min-height: 38px;
    padding: 9px var(--s-4);
  }

  .slab-del,
  .master-acts .icon-btn {
    min-width: 40px;
    min-height: 40px;
  }

  /* Hover-only effects do nothing useful on touch */
  .spotlight::before,
  .spotlight-dark::before,
  .glow-edge::after,
  .halo::before,
  .sweep::before {
    display: none;
  }
}

/* ═══════════ LANDSCAPE PHONE ═══════════ */

@media (max-height: 480px) and (orientation: landscape) {
  .hero {
    min-height: auto;
    padding-block: var(--s-16);
  }

  .auth-panel {
    align-items: flex-start;
  }

  .modal-box {
    max-height: 96svh;
  }

  .punch-time {
    font-size: 2rem;
  }
}

/* ═══════════ PRINT ═══════════ */

@media print {

  .sb,
  .topbar,
  .nav,
  .drawer,
  .demo-fab,
  .demo-panel,
  .decision,
  .form-nav,
  .aurora,
  .toast-zone {
    display: none !important;
  }

  .main {
    margin-left: 0;
  }

  .page {
    padding: 0;
  }

  .panel {
    box-shadow: none;
    border: 1px solid #ddd;
    break-inside: avoid;
  }

  body {
    background: #fff;
  }
}

/* ============================================================
   FIXES FOUND BY THE HEADLESS AUDIT
   ============================================================ */

/* ═══════════ GRID MIN-CONTENT OVERFLOW ═══════════
   `1fr` resolves to `minmax(auto, 1fr)`, and `auto` means
   min-content. A flex row inside will therefore push the whole
   grid wider than the screen instead of scrolling. Every grid
   track in the app is pinned to `minmax(0, 1fr)`. */

.kyc-shell,
.split-2,
.split-wide,
.split-narrow,
.split-side,
.split-side-sm,
.split-side-lg,
.shell,
.main,
.stats,
.grid-2,
.grid-3,
.prod-grid,
.values,
.quotes,
.recap-grid {
  min-width: 0;
}

.kyc-shell>*,
.split-2>*,
.split-wide>*,
.split-narrow>*,
.split-side>*,
.split-side-sm>*,
.split-side-lg>*,
.stats>*,
.grid-2>*,
.grid-3>* {
  min-width: 0;
}

@media (max-width: 1180px) {
  .kyc-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .stepper {
    max-width: 100%;
    overflow: hidden;
  }

  .stepper-list {
    margin-inline: calc(-1 * var(--s-6));
    padding-inline: var(--s-6);
    scroll-snap-type: x proximity;
  }

  .step-row {
    scroll-snap-align: start;
  }
}

@media (max-width: 1024px) {

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

@media (max-width: 1180px) {

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

@media (max-width: 860px) {
  .split-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {

  .grid-2,
  .grid-3,
  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Last line of defence — nothing may push the page sideways */
html,
body {
  overflow-x: hidden;
  max-width: 100%;
}

/* ═══════════ TOUCH TARGETS ═══════════ */

@media (hover: none) {
  .link-arrow {
    min-height: 40px;
    align-items: center;
    padding-block: 4px;
  }

  .foot-links a,
  .drawer-menu a,
  .policy-nav a {
    min-height: 42px;
    display: flex;
    align-items: center;
  }

  .nav-link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .auth-forgot,
  .auth-alt a,
  .auth-back {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .doc-viewer-tab {
    min-height: 40px;
  }

  .tabs-btn {
    min-height: 42px;
  }

  .check-box {
    width: 22px;
    height: 22px;
  }

  .switch {
    width: 48px;
    height: 27px;
  }

  .switch i::before {
    width: 21px;
    height: 21px;
  }

  .switch input:checked+i::before {
    transform: translateX(21px);
  }
}

/* ═══════════ LEGIBILITY FLOOR ═══════════
   Nothing drops below 11px on a phone. */

@media (max-width: 600px) {

  .cell-sub,
  .stat-sub,
  .field-hint,
  .sheet-file-meta span,
  .tl-time,
  .feed-body time,
  .doc-row span,
  .master-item b,
  .perm-row code,
  .punch-loc,
  .cal-legend span,
  .badge,
  .sb-user-meta span,
  .marquee-item,
  .foot-bottom,
  .crumb {
    font-size: 11px !important;
  }

  .review-nudge,
  .field-sample,
  .field-words {
    font-size: 12px;
  }

  .tbl th {
    font-size: 10.5px;
  }
}

/* ═══════════ SAFE AREAS (notched phones) ═══════════ */

@supports (padding: max(0px)) {
  @media (max-width: 600px) {
    .page {
      padding-inline: max(var(--s-4), env(safe-area-inset-left));
    }

    .topbar {
      padding-inline: max(var(--s-5), env(safe-area-inset-left));
    }

    .wrap {
      padding-inline: max(var(--s-5), env(safe-area-inset-left));
    }

    .modal-box {
      padding-bottom: env(safe-area-inset-bottom);
    }

    .demo-fab {
      bottom: max(var(--s-5), env(safe-area-inset-bottom));
    }

    .drawer-panel {
      padding-bottom: max(var(--s-6), env(safe-area-inset-bottom));
    }
  }
}

/* ═══════════ DYNAMIC VIEWPORT (mobile browser chrome) ═══════════ */

@supports (height: 100dvh) {
  .hero {
    min-height: 100dvh;
  }

  .auth {
    min-height: 100dvh;
  }

  .shell {
    min-height: 100dvh;
  }

  .modal-box {
    max-height: 92dvh;
  }
}

/* ── Legibility floor, second pass ──
   Uppercase micro-labels were sitting at 9–10px. Raised to 10.5px,
   which is the smallest size that still reads cleanly on a phone. */

@media (max-width: 600px) {
  .matrix th {
    font-size: 10.5px;
  }

  .sb-badge {
    font-size: 10.5px;
    min-width: 22px;
    height: 22px;
  }

  .stat-label {
    font-size: 10.5px;
  }

  .growth-tag {
    font-size: 10.5px;
  }

  .doc-expiry {
    font-size: 10.5px;
  }

  .mx {
    font-size: 10.5px;
  }

  .cal-dow {
    font-size: 10.5px;
  }

  .master-item .badge {
    font-size: 10.5px;
  }
}

/* ── Remaining touch targets ── */

@media (hover: none) {
  .field-toggle {
    width: 40px;
    height: 40px;
    top: 11px;
  }

  .sheet-file-x {
    width: 40px;
    height: 40px;
  }

  a:not(.btn):not(.sb-link):not(.nav-logo):not(.foot-social a) {
    /* inline links inside prose get a comfortable strike area */
    padding-block: 2px;
  }
}


/* ── Final legibility floor ──
   One rule, highest specificity, applied last. Nothing on a phone
   renders below 10.5px. The skip link is exempt: it is deliberately
   parked off-screen until it receives keyboard focus. */

@media (max-width: 900px) {
  body :where(span, small, em, b, i, td, th, dt, dd, time, code, label, button, a, p, div, li) {
    font-size: max(10.5px, 1em);
  }
}

/* Anything that set an inline 10px or smaller */
@media (max-width: 600px) {

  [style*="font-size:10px"],
  [style*="font-size: 10px"],
  [style*="font-size:9px"],
  [style*="font-size: 9px"] {
    font-size: 10.5px !important;
  }
}

/* Skip link stays hidden until focused — this is correct behaviour */
.skip-link {
  pointer-events: none;
}

.skip-link:focus {
  pointer-events: auto;
}

/* ── Legibility floor for the announcement and org components ── */

@media (max-width: 900px) {

  .ann-meta,
  .ann-meta span,
  .ann-ttl,
  .bell-panel-head p,
  .bell-count,
  .org-node span,
  .org-node-meta div span,
  .org-badge,
  .quota-body span,
  .channel-pick span,
  .ann-card .ann-meta span,
  .perm-locked em,
  .feed-body time,
  .set-row-body span {
    font-size: 10.5px !important;
  }

  .org-badge {
    min-width: 42px;
  }
}