/*
 * Shared mobile and accessibility foundation.
 * Loaded after styles.css so these safeguards apply across legacy pages.
 */

:root {
  --a11y-focus: #facc15;
  --a11y-target: 48px;
  --a11y-reading-width: 72ch;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-wrap: anywhere;
}

body.a11y-large-text {
  font-size: 118%;
}

body.a11y-high-contrast {
  --bg: #000;
  --panel: #000;
  --panel-strong: #000;
  --muted: #fff;
  --soft: #fff;
  --text: #fff;
  --line: #fff;
  --accent: #7dd3fc;
  --accent-strong: #0369a1;
  background: #000;
}

body.a11y-high-contrast::before {
  display: none;
}

.skip-link {
  position: fixed;
  inset-block-start: 8px;
  inset-inline-start: 8px;
  z-index: 100000;
  transform: translateY(-160%);
  border: 3px solid var(--a11y-focus);
  border-radius: 8px;
  background: #000;
  color: #fff;
  padding: 12px 16px;
  font-weight: 800;
}

.skip-link:focus {
  transform: none;
}

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

:where(button, .btn, input:not([type="checkbox"]):not([type="radio"]), select) {
  min-block-size: var(--a11y-target);
}

:where(button, .btn) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

label {
  line-height: 1.35;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 88%, white);
  opacity: 1;
}

.a11y-toolbar {
  position: fixed;
  z-index: 9000;
  inset-inline-end: 16px;
  inset-block-end: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-inline-size: calc(100vw - 32px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  padding: 8px;
  backdrop-filter: blur(18px);
}

.a11y-toolbar label {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.a11y-toolbar select,
.a11y-toolbar button {
  inline-size: auto;
  min-inline-size: var(--a11y-target);
  margin: 0;
}

.sr-only {
  position: absolute !important;
  inline-size: 1px !important;
  block-size: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.reading-width {
  max-inline-size: var(--a11y-reading-width);
}

[dir="rtl"] .data-table th {
  text-align: right;
}

@media (max-width: 760px) {
  .container,
  .public-order-shell,
  .signup-shell {
    inline-size: 100%;
    padding-inline: 16px;
  }

  .topbar {
    position: static;
  }

  .nav-actions,
  .toolbar,
  .button-row,
  .dashboard-actions,
  .compact-actions {
    display: grid;
    grid-template-columns: 1fr;
    inline-size: 100%;
  }

  .nav-actions :where(a, button),
  .toolbar :where(a, button),
  .button-row :where(a, button),
  .dashboard-actions :where(a, button),
  .compact-actions :where(a, button) {
    inline-size: 100%;
  }

  .card,
  .metric-card,
  .order,
  .glass-panel,
  .signup-section {
    padding: 18px;
  }

  .a11y-toolbar {
    inset-inline: 10px;
    inset-block-end: 10px;
    justify-content: center;
  }

  body {
    padding-block-end: 76px;
  }
}

@media (max-width: 360px) {
  .a11y-toolbar {
    display: grid;
    grid-template-columns: 1fr auto auto;
  }

  .a11y-toolbar select {
    min-inline-size: 0;
    inline-size: 100%;
  }
}

@media (prefers-contrast: more) {
  :root {
    --line: rgba(255, 255, 255, .72);
    --muted: #dbeafe;
  }
}

@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;
  }
}


/* Mobile card width correction: retain a safe gutter without desktop squeeze. */
@media (max-width: 760px) {
  body.center-page {
    align-items: stretch;
    padding: 12px;
  }

  .center-page > .box,
  .center-page > .login-box,
  .center-page > .card,
  .center-page .signup-shell {
    inline-size: 100%;
    max-inline-size: none;
    margin-inline: 0;
  }

  .container,
  .public-order-shell,
  .signup-shell {
    max-inline-size: none;
    padding-inline: 10px;
  }

  .grid,
  .grid-2,
  .metric-grid,
  .dashboard-layout,
  .dashboard-main,
  .dashboard-sidebar,
  .signup-grid,
  .service-mode-grid,
  .public-form-stack {
    grid-template-columns: minmax(0, 1fr);
    inline-size: 100%;
  }

  .card,
  .metric-card,
  .order,
  .glass-panel,
  .signup-section,
  .public-order-card,
  .public-info-card {
    inline-size: 100%;
    max-inline-size: none;
    min-inline-size: 0;
    margin-inline: 0;
  }
}

@media (max-width: 380px) {
  body.center-page {
    padding-inline: 8px;
  }

  .container,
  .public-order-shell,
  .signup-shell {
    padding-inline: 8px;
  }

  .card,
  .metric-card,
  .order,
  .glass-panel,
  .signup-section {
    padding-inline: 16px;
  }
}


/* Portrait-phone containment: no workflow should require landscape orientation. */
@media (max-width: 600px) and (orientation: portrait) {
  html,
  body {
    inline-size: 100%;
    max-inline-size: 100%;
    overflow-x: clip;
  }

  :where(
    main, header, footer, nav, section, article, aside, form, fieldset,
    .app-shell, .topbar, .container, .card, .metric-card, .order,
    .glass-panel, .dashboard-container, .dashboard-layout,
    .dashboard-main, .dashboard-sidebar, .public-order-shell,
    .public-order-card, .public-info-card, .signup-shell, .signup-section,
    .section-title, .nav-actions, .toolbar, .button-row
  ) {
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  :where(img, svg, video, canvas, iframe) {
    max-inline-size: 100%;
    block-size: auto;
  }

  :where(p, li, dd, td, th, a, button, label, small, strong, .value) {
    overflow-wrap: anywhere;
    word-break: normal;
  }

  .topbar,
  .public-order-header,
  .section-title,
  .dashboard-hero,
  .public-brand,
  .public-trustbar {
    align-items: stretch;
    inline-size: 100%;
  }

  .topbar > *,
  .section-title > *,
  .dashboard-hero > *,
  .public-order-header > * {
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .flex-fill,
  .search-input {
    min-inline-size: 0;
    inline-size: 100%;
  }

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

  .data-table {
    table-layout: fixed;
  }

  #map {
    inline-size: 100%;
    block-size: min(62vh, 420px);
  }

  .a11y-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    inline-size: auto;
    max-inline-size: none;
  }

  .a11y-toolbar select {
    grid-column: 1 / -1;
    inline-size: 100%;
    min-inline-size: 0;
  }

  .a11y-toolbar button {
    min-inline-size: 0;
    inline-size: 100%;
    padding-inline: 10px;
    white-space: normal;
  }

  body.a11y-large-text .page-title,
  body.a11y-large-text .brand h1,
  body.a11y-large-text .signup-heading h1,
  body.a11y-large-text .public-card-title h1 {
    font-size: clamp(1.75rem, 9vw, 2.4rem);
  }
}


/* Production mobile correction: centered pages must stack, never share a row. */
body.center-page {
  flex-direction: column;
  inline-size: 100%;
}

.center-page > main,
.center-page > .box,
.center-page > .login-box,
.center-page > .card {
  flex: 0 1 auto;
}

.center-page > .legal-footer {
  flex: 0 0 auto;
  inline-size: 100%;
}

@media (max-width: 600px) {
  body.center-page {
    justify-content: flex-start;
    min-block-size: 100svh;
  }

  .center-page > main,
  .center-page > .box,
  .center-page > .login-box,
  .center-page > .card {
    inline-size: 100%;
    max-inline-size: none;
  }

  .a11y-toolbar {
    position: static;
    order: 10;
    inline-size: calc(100% - 16px);
    margin: 12px 8px 8px;
  }

  body {
    padding-block-end: 0;
  }
}
