/* Fase 69D - accessibilita, pagine pubbliche e viste storiche.
   Layer globale caricato per ultimo: migliora focus, tastiera, touch, overflow,
   autenticazione e pagine di errore senza duplicare i fogli delle singole aree. */

:root {
  --a11y-focus-ring: 0 0 0 4px rgba(15, 98, 254, .24);
  --a11y-focus-outline: 3px solid #0f62fe;
  --a11y-content-width: 1480px;
}

html {
  overflow-x: hidden;
}

body {
  min-width: 0;
  overflow-wrap: break-word;
}

main,
section,
article,
aside,
form,
fieldset,
.table-wrap,
.ops-table-wrap,
.phase64-table-wrap,
.phase65-table-wrap,
.phase66-table-wrap,
.catalog-table-scroll {
  min-width: 0;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  z-index: 10000;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--a11y-focus-outline) !important;
  outline-offset: 3px !important;
  box-shadow: var(--a11y-focus-ring) !important;
}

:where(button, input, select, textarea):disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: .62;
}

:where(input, select, textarea)[aria-invalid="true"] {
  border-color: #b42318 !important;
  background: #fff8f7 !important;
  box-shadow: 0 0 0 3px rgba(180, 35, 24, .12) !important;
}

.a11y-field-error {
  display: block;
  margin-top: 4px;
  color: #8f1d14;
  font-size: .82rem;
  font-weight: 700;
}

.a11y-error-summary {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid #f0a7a0;
  border-left: 5px solid #b42318;
  border-radius: 12px;
  background: #fff4f2;
  color: #73170f;
}

.a11y-error-summary strong {
  color: #5d130d;
}

.a11y-error-summary a {
  width: fit-content;
  color: #73170f;
  font-weight: 800;
  text-decoration: underline;
}

.a11y-table-region:focus-visible {
  outline: var(--a11y-focus-outline);
  outline-offset: 2px;
}

.a11y-table-region::after {
  content: "Scorri orizzontalmente per vedere tutte le colonne";
  display: none;
  padding: 8px 10px;
  color: #53657d;
  font-size: .78rem;
  text-align: center;
}

/* Autenticazione e recupero password */
body.phase69d-auth-page .topbar {
  min-height: 92px;
}

body.phase69d-auth-page .container {
  display: grid;
  align-items: center;
  min-height: calc(100dvh - 112px);
  padding-block: clamp(24px, 6vh, 64px);
}

.phase69d-auth-shell {
  width: min(100%, 520px);
  margin-inline: auto;
}

.phase69d-auth-card {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: clamp(20px, 4vw, 32px);
  border-radius: 22px;
  box-shadow: 0 18px 46px rgba(15, 34, 56, .12);
}

.phase69d-auth-card header {
  display: grid;
  gap: 8px;
}

.phase69d-auth-card h2 {
  margin: 0;
  color: #102238;
  font-size: clamp(1.55rem, 4vw, 2rem);
  line-height: 1.14;
}

.phase69d-auth-card .page-subtitle {
  margin: 0;
  line-height: 1.55;
}

.phase69d-auth-card .field {
  grid-column: 1 / -1;
}

.phase69d-auth-card .btn {
  width: 100%;
}

.phase69d-auth-actions {
  display: grid;
  gap: 10px;
}

.phase69d-auth-link {
  margin: 0;
  text-align: center;
}

.phase69d-auth-link a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding-inline: 10px;
  font-weight: 800;
  text-decoration: underline;
}

.phase69d-auth-note {
  padding: 12px 14px;
  border: 1px solid #d7e0ec;
  border-radius: 12px;
  background: #f8fafc;
  color: #475569;
  font-size: .9rem;
}

/* Pagine 400/403/404/500 */
body.phase69d-error-page .container {
  display: grid;
  align-items: center;
  min-height: calc(100dvh - 112px);
  padding-block: clamp(24px, 7vh, 72px);
}

.phase69d-status-page {
  width: min(100%, 760px);
  margin-inline: auto;
}

.phase69d-status-card {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: clamp(22px, 5vw, 40px);
  border-radius: 24px;
  text-align: center;
  box-shadow: 0 18px 48px rgba(15, 34, 56, .13);
}

.phase69d-status-code {
  display: inline-flex;
  width: fit-content;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  margin-inline: auto;
  padding: 6px 12px;
  border-radius: 999px;
  background: #eaf2ff;
  color: #1d4ed8;
  font-weight: 900;
  letter-spacing: .08em;
}

.phase69d-status-card h2 {
  margin: 0;
  color: #102238;
  font-size: clamp(1.65rem, 5vw, 2.45rem);
}

.phase69d-status-card p {
  max-width: 590px;
  margin: 0 auto;
  color: #53657d;
  line-height: 1.6;
}

.phase69d-status-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Viste secondarie storiche */
.settings-hub-card,
.mini-item,
details > summary,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

details > summary {
  min-height: 44px;
  cursor: pointer;
}

.settings-hub-card:focus-visible,
.mini-item:focus-visible {
  transform: translateY(-1px);
}

.page-head,
.ops-page-head,
.phase64-hero,
.phase65-economic-head,
.phase66-page-head {
  scroll-margin-top: 16px;
}

.message[role="status"],
[role="alert"] {
  overflow-wrap: anywhere;
}

@media (max-width: 760px) {
  .container {
    padding: 16px;
  }

  .page-head,
  .ops-page-head,
  .phase64-hero,
  .phase65-economic-head,
  .phase66-page-head {
    align-items: stretch !important;
  }

  .inline-actions,
  .ops-page-actions,
  .phase64-actions,
  .phase65-economic-actions,
  .phase69d-status-actions {
    width: 100%;
  }

  .inline-actions > .btn,
  .inline-actions > form,
  .inline-actions > form .btn,
  .ops-page-actions > .btn,
  .phase64-actions > .btn,
  .phase65-economic-actions > .btn,
  .phase69d-status-actions > .btn {
    flex: 1 1 100%;
    width: 100%;
  }

  .a11y-table-region[data-a11y-overflow="true"]::after {
    display: block;
  }

  body.phase69d-auth-page .topbar,
  body.phase69d-error-page .topbar {
    padding: 14px 16px;
  }

  body.phase69d-auth-page .shell-brand-copy p,
  body.phase69d-error-page .shell-brand-copy p {
    display: none;
  }

  body.phase69d-auth-page .container,
  body.phase69d-error-page .container {
    min-height: calc(100dvh - 82px);
    padding-block: 20px;
  }
}

@media (max-width: 420px) {
  .phase69d-auth-card,
  .phase69d-status-card {
    padding: 18px;
    border-radius: 18px;
  }
}

@media (prefers-contrast: more) {
  :root {
    --ui-border: #8795a8;
    --ui-border-strong: #5b697a;
  }

  .card,
  .section-card,
  .phase64-panel,
  .phase65-table-card,
  .phase66-table-card {
    box-shadow: none !important;
  }

  a {
    text-decoration: underline;
  }
}

@media (forced-colors: active) {
  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid CanvasText !important;
    box-shadow: none !important;
  }

  .btn,
  .pill,
  .badge,
  .mini-badge,
  .phase69d-status-code {
    border: 1px solid CanvasText !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

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