/*
 * Acabado visual compartido de la aplicación.
 * Se carga después de las hojas específicas para armonizar los componentes
 * comunes sin alterar layouts funcionales (calendarios, planificadores o PDFs).
 */

body:not(.login-page):not(.public-message-page) {
  --ui-primary: #2f6fae;
  --ui-primary-strong: #245987;
  --ui-primary-soft: #eaf2fb;
  --ui-teal: #3b837f;
  --ui-amber: #c58a2b;
  --ui-text: #203247;
  --ui-muted: #66788a;
  --ui-border: #dbe5ef;
  --ui-border-soft: #e8eef4;
  --ui-surface: #ffffff;
  --ui-surface-soft: #f5f8fb;
  --ui-radius: 10px;
  --ui-radius-small: 8px;
  --ui-shadow: 0 2px 8px rgba(31, 60, 90, 0.06);
  color: var(--ui-text);
  font-size: 16px;
  height: auto;
  min-height: 100svh;
  overflow-x: hidden;
  overflow-y: auto;
}

body:not(.login-page):not(.public-message-page) .app-shell {
  height: auto;
  min-height: 100svh;
  overflow: visible;
}

body:not(.login-page):not(.public-message-page) .app-main {
  min-height: 100svh;
  height: auto;
  overflow: visible;
  background:
    linear-gradient(180deg, rgba(236, 244, 252, 0.72), rgba(244, 248, 252, 0.88));
}

body:not(.login-page):not(.public-message-page) .app-main > main,
body:not(.login-page):not(.public-message-page) .app-main > .main-container,
body:not(.login-page):not(.public-message-page) .app-main > .container {
  flex: 0 0 auto;
  height: auto;
  min-height: 0;
  overflow: visible;
}

body.modal-open:not(.login-page):not(.public-message-page) {
  overflow: hidden;
}

body:not(.login-page):not(.public-message-page) .header.topbar {
  min-height: 50px;
  border-bottom: 1px solid var(--ui-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 5px rgba(31, 60, 90, 0.04);
  backdrop-filter: blur(10px);
}

body:not(.login-page):not(.public-message-page) .topbar-title__main {
  color: #2d5d8d;
  font-weight: 650;
}

body:not(.login-page):not(.public-message-page) .topbar-meta {
  gap: 8px;
}

body:not(.login-page):not(.public-message-page) .topbar-meta:has(.role-switcher--topbar) .topbar-chip--role {
  display: none;
}

body:not(.login-page):not(.public-message-page) .topbar-chip,
body:not(.login-page):not(.public-message-page) .topbar-date,
body:not(.login-page):not(.public-message-page) .role-switcher--topbar select {
  min-height: 32px;
  border: 1px solid var(--ui-border);
  border-radius: 7px;
  background: #f8fbfe;
  box-shadow: none;
  color: var(--ui-text);
  font-size: 0.78rem;
}

body:not(.login-page):not(.public-message-page) .topbar-chip--role {
  background: var(--ui-primary-soft);
  color: var(--ui-primary-strong);
}

body:not(.login-page):not(.public-message-page) .page-header,
body:not(.login-page):not(.public-message-page) .page-title-strip {
  min-height: 54px;
  border-bottom-color: #72a5dc;
}

body:not(.login-page):not(.public-message-page) .page-title,
body:not(.login-page):not(.public-message-page) .page-title-strip__text {
  color: var(--ui-text);
  font-size: clamp(1.375rem, 2vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

body:not(.login-page):not(.public-message-page) .main-container {
  padding-top: 18px;
}

body:not(.login-page):not(.public-message-page) .main-container .content-wrap.page-stage {
  padding-bottom: 28px;
}

body:not(.login-page):not(.public-message-page) .page-stage__content {
  min-width: 0;
}

/* Los calendarios de guardias viven dentro de .app-main; 96vw sumaba el
   ancho del sidebar y ampliaba el documento en escritorio. */
body:not(.login-page):not(.public-message-page):has(.guardias-page) .main-container {
  width: 100% !important;
  max-width: 100% !important;
}

body:not(.login-page):not(.public-message-page) :where(
  .guardias-calendario-section,
  .guardias-calendario-shell,
  .guardias-tabla-shell,
  .tabla-guardias-wrapper
) {
  min-width: 0;
  max-width: 100%;
}

body:not(.login-page):not(.public-message-page) :where(
  .card,
  .panel,
  .form-card,
  .table-card,
  .summary-card,
  .planning-surface,
  .calendar-card,
  .filters-card,
  .stats-card
) {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
}

body:not(.login-page):not(.public-message-page) :where(
  .card,
  .panel,
  .form-card,
  .table-card,
  .summary-card,
  .filters-card,
  .stats-card
) {
  padding: clamp(16px, 1.6vw, 20px);
}

body:not(.login-page):not(.public-message-page) :where(
  .section-title-card,
  .dashboard-eyebrow,
  .eyebrow,
  .form-label,
  .filter-label
) {
  color: #315e8b;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

body:not(.login-page):not(.public-message-page) :where(
  .card,
  .panel,
  .form-card,
  .table-card,
  .summary-card
) :where(h2, h3) {
  color: var(--ui-text);
  font-size: clamp(1.0625rem, 1.4vw, 1.125rem);
  font-weight: 650;
  line-height: 1.25;
}

body:not(.login-page):not(.public-message-page) :where(p, li, td, th, label, input, select, textarea, button) {
  line-height: 1.4;
}

body:not(.login-page):not(.public-message-page) :where(input, select, textarea) {
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd9e6;
  border-radius: 7px;
  background: #ffffff;
  color: var(--ui-text);
  font: inherit;
  vertical-align: middle;
  box-shadow: none;
}

body:not(.login-page):not(.public-message-page) :where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select
) {
  min-height: 40px;
  padding-block: 0.34rem !important;
  line-height: 1.25 !important;
}

/*
 * Alineación interior uniforme:
 * Los controles compactos globales y algunas pantallas fijan alturas
 * diferentes. Un mismo padding vertical y una línea estable mantienen el
 * texto centrado sin imponer una altura única a editores de tabla.
 */
body:not(.login-page):not(.public-message-page) :where(
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  input[type="url"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="month"],
  input[type="time"],
  input[type="datetime-local"],
  select
) {
  padding-inline: 0.68rem !important;
  text-align: left;
}

body:not(.login-page):not(.public-message-page) :where(
  input[type="date"],
  input[type="month"],
  input[type="time"],
  input[type="datetime-local"]
) {
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

body:not(.login-page):not(.public-message-page) :where(
  input[type="date"],
  input[type="month"],
  input[type="time"],
  input[type="datetime-local"]
)::-webkit-date-and-time-value {
  display: flex;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  align-items: center;
  text-align: left;
  line-height: inherit;
}

body:not(.login-page):not(.public-message-page) :where(
  input[type="date"],
  input[type="month"],
  input[type="time"],
  input[type="datetime-local"]
)::-webkit-datetime-edit {
  display: flex;
  min-height: 0;
  padding: 0;
  align-items: center;
}

body:not(.login-page):not(.public-message-page) :where(
  input[type="date"],
  input[type="month"],
  input[type="time"],
  input[type="datetime-local"]
)::-webkit-calendar-picker-indicator {
  align-self: center;
  margin: 0;
}

body:not(.login-page):not(.public-message-page) :where(input, textarea)::placeholder {
  color: #8291a1;
  line-height: inherit;
  opacity: 1;
}

body:not(.login-page):not(.public-message-page) textarea {
  min-height: 92px;
  padding: 10px 12px;
  line-height: 1.45 !important;
  text-align: left;
  resize: vertical;
}

body:not(.login-page):not(.public-message-page) :where(input, select, textarea):hover {
  border-color: #9cb8d2;
}

body:not(.login-page):not(.public-message-page) :where(input, select, textarea):focus {
  border-color: var(--ui-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 111, 174, 0.17);
}

body:not(.login-page):not(.public-message-page) :where(
  button,
  .btn,
  a.btn,
  input[type="submit"],
  input[type="button"]
) {
  min-height: 40px;
  border-radius: 7px;
  font-size: 0.875rem;
  font-weight: 650;
  line-height: 1.1;
  box-shadow: none;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.12s ease;
}

body:not(.login-page):not(.public-message-page) :where(
  button,
  .btn-primary,
  input[type="submit"]
):not(.btn-secondary):not(.btn-danger):not(.menu-toggle):not(.sidebar-close):not(.nav-link) {
  border-color: #2f6fae;
  background: #78a9de;
  color: #ffffff;
}

body:not(.login-page):not(.public-message-page) :where(
  button,
  .btn-primary,
  input[type="submit"]
):not(.btn-secondary):not(.btn-danger):not(.menu-toggle):not(.sidebar-close):not(.nav-link):hover {
  border-color: var(--ui-primary-strong);
  background: var(--ui-primary);
  color: #ffffff;
}

body:not(.login-page):not(.public-message-page) :where(
  .btn-secondary,
  .btn-outline,
  a.btn-secondary
) {
  border: 1px solid #bcd0e3;
  background: #edf4fb;
  color: var(--ui-primary-strong);
}

body:not(.login-page):not(.public-message-page) :where(
  .btn-secondary,
  .btn-outline,
  a.btn-secondary
):hover {
  border-color: #8eb0cf;
  background: #dfeefa;
  color: #194c7a;
}

body:not(.login-page):not(.public-message-page) :where(
  button,
  .btn,
  a.btn,
  input,
  select,
  textarea,
  summary,
  [tabindex]
):focus-visible {
  outline: 3px solid rgba(47, 111, 174, 0.28);
  outline-offset: 2px;
}

body:not(.login-page):not(.public-message-page) :where(
  button,
  .btn,
  a.btn,
  input[type="submit"],
  input[type="button"]
):active {
  transform: translateY(1px);
}

body:not(.login-page):not(.public-message-page) .table-responsive,
body:not(.login-page):not(.public-message-page) .table-wrap,
body:not(.login-page):not(.public-message-page) .responsive-table {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-small);
  background: #fff;
  overflow-x: auto;
  box-shadow: none;
}

body:not(.login-page):not(.public-message-page) table {
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ui-text);
}

body:not(.login-page):not(.public-message-page) table th {
  background: #edf4fb;
  color: #315e8b;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

body:not(.login-page):not(.public-message-page) table :where(th, td) {
  border-color: var(--ui-border-soft);
}

body:not(.login-page):not(.public-message-page) table tbody tr:nth-child(even) {
  background: rgba(245, 248, 251, 0.6);
}

body:not(.login-page):not(.public-message-page) table tbody tr:hover {
  background: #f0f6fc;
}

body:not(.login-page):not(.public-message-page) :where(
  .badge,
  .status-badge,
  .tag,
  .chip,
  .pill
) {
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
}

body:not(.login-page):not(.public-message-page) :where(
  .empty-state,
  .no-results,
  .empty-message
) {
  border: 0;
  border-radius: var(--ui-radius-small);
  background: var(--ui-surface-soft);
  color: var(--ui-muted);
  box-shadow: none;
}

body:not(.login-page):not(.public-message-page) details {
  border-color: var(--ui-border);
}

body:not(.login-page):not(.public-message-page) summary {
  color: var(--ui-text);
  font-weight: 650;
}

body:not(.login-page):not(.public-message-page) .alert {
  border-radius: var(--ui-radius-small);
  box-shadow: var(--ui-shadow);
}

body:not(.login-page):not(.public-message-page) .footer {
  position: static;
  flex: 0 0 auto;
  margin-top: auto;
  border-top: 1px solid var(--ui-border);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ui-muted);
}

@media (max-width: 900px) {
  body:not(.login-page):not(.public-message-page) .header.topbar {
    min-height: 52px;
  }

  body:not(.login-page):not(.public-message-page) :where(
    .card,
    .panel,
    .form-card,
    .table-card,
    .summary-card,
    .filters-card,
    .stats-card
  ) {
    padding: 16px;
  }
}

@media (max-width: 768px) {
  body:not(.login-page):not(.public-message-page) {
    font-size: 15px;
  }

  body:not(.login-page):not(.public-message-page) .main-container {
    padding-top: 12px;
  }

  body:not(.login-page):not(.public-message-page) .page-header,
  body:not(.login-page):not(.public-message-page) .page-title-strip {
    min-height: 50px;
  }

  body:not(.login-page):not(.public-message-page) .page-title,
  body:not(.login-page):not(.public-message-page) .page-title-strip__text {
    font-size: 1.375rem;
  }

  body:not(.login-page):not(.public-message-page) :where(
    button,
    .btn,
    a.btn,
    input[type="submit"],
    input[type="button"]
  ) {
    min-height: 42px;
  }

  body:not(.login-page):not(.public-message-page) :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select
  ) {
    min-height: 42px;
  }
}

@media (max-width: 480px) {
  /*
   * Refinamiento móvil: la cabecera debe reservar el hueco del botón de menú
   * sin desplazar ni recortar el texto institucional.
   */
  body:not(.login-page):not(.public-message-page) .topbar-inner,
  body:not(.login-page):not(.public-message-page) .topbar-title,
  body:not(.login-page):not(.public-message-page) .topbar-title__text {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  body:not(.login-page):not(.public-message-page) .topbar-title {
    align-items: stretch !important;
    text-align: left !important;
  }

  body:not(.login-page):not(.public-message-page) .topbar-title__main {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    white-space: normal !important;
    overflow: visible !important;
    text-align: left !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere;
  }

  body:not(.login-page):not(.public-message-page) .topbar-meta {
    width: 100% !important;
    min-width: 0 !important;
    justify-content: flex-start !important;
    gap: 6px !important;
  }

  body:not(.login-page):not(.public-message-page) .role-switcher--topbar,
  body:not(.login-page):not(.public-message-page) .role-switcher--topbar select {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* 16 px evita el zoom automático de Safari iOS al enfocar formularios. */
  body:not(.login-page):not(.public-message-page) .app-shell .app-main :where(input, select, textarea),
  body:not(.login-page):not(.public-message-page) .app-shell .sidebar :where(input, select, textarea) {
    min-width: 0 !important;
    max-width: 100% !important;
    font-size: 16px !important;
    line-height: 1.25;
  }

  body:not(.login-page):not(.public-message-page) :where(
    .card,
    .panel,
    .form-card,
    .table-card,
    .summary-card,
    .filters-card,
    .stats-card
  ) {
    border-radius: 9px;
  }

  /* Los meses tenían ancho de viewport mientras el resto de tarjetas usaba
     una canaleta de 8 px, produciendo un salto lateral visible. */
  body:not(.login-page):not(.public-message-page) .mes-grupo {
    width: auto !important;
    margin-right: 8px !important;
    margin-left: 8px !important;
  }

  /* Evita la suma de márgenes y padding de tarjeta + formulario en gestión
     de personal. Mantiene la jerarquía, pero recupera ancho útil. */
  body.users-admin-page:not(.login-page):not(.public-message-page)
    .form-card.request-composer__main > form,
  body.users-admin-page:not(.login-page):not(.public-message-page)
    .form-card.request-composer__main > .users-selector-form {
    margin-right: 8px !important;
    margin-bottom: 12px !important;
    margin-left: 8px !important;
    padding: 14px 10px !important;
    border-radius: 9px !important;
  }

  body.users-admin-page:not(.login-page):not(.public-message-page)
    .form-card.request-composer__main > form:last-child,
  body.users-admin-page:not(.login-page):not(.public-message-page)
    .form-card.request-composer__main > .users-selector-form:last-child {
    margin-bottom: 12px !important;
  }

  /* Formularios apilados: los controles estrechos parecían descentrados aun
     cuando su contenedor sí lo estaba. */
  body:not(.login-page):not(.public-message-page) :where(
    .request-composer,
    .stats-filters,
    .peticiones-shell
  ) :where(.form-item, .form-group) > :where(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ) {
    width: 100% !important;
    min-width: 0 !important;
  }

  body.stats-admin-page:not(.login-page):not(.public-message-page) .stats-checkbox-grid {
    grid-template-columns: 1fr !important;
  }

  body.stats-admin-page:not(.login-page):not(.public-message-page) .stats-checkbox {
    width: 100%;
  }

  /* Reduce cajas concéntricas en compositores complejos sin aplicar padding
     al grid exterior, que estrecharía todas sus columnas. */
  body:not(.login-page):not(.public-message-page) :where(
    .peticiones-shell,
    .rotaciones-shell
  ) .planning-toolbar {
    padding: 0 !important;
  }

  body:not(.login-page):not(.public-message-page) :where(
    .peticiones-shell,
    .rotaciones-shell
  ) :where(.planning-toolbar__main, .planning-toolbar__aside, .planning-surface) {
    padding-right: 10px !important;
    padding-left: 10px !important;
  }

  body.peticiones-page:not(.login-page):not(.public-message-page) .form-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body.peticiones-page:not(.login-page):not(.public-message-page)
    :where(.form-group, .form-item) {
    width: 100%;
    min-width: 0;
  }

  body:not(.login-page):not(.public-message-page) :where(
    .form-actions,
    .button-row,
    .actions-row,
    .filter-actions
  ) {
    align-items: stretch;
    flex-wrap: wrap;
  }
}

/*
 * Safari / WebKit móvil:
 * - iOS amplía la página al enfocar controles con texto menor de 16 px.
 * - el autoajuste de texto puede cambiar anchos después de pintar la página.
 * - date/month conservan un ancho intrínseco aunque su grid pueda encogerse.
 */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 480px) {
    html {
      -webkit-text-size-adjust: 100%;
      text-size-adjust: 100%;
    }

    body:not(.login-page):not(.public-message-page) :where(input, select, textarea) {
      min-width: 0 !important;
      max-width: 100% !important;
      font-size: 16px !important;
      line-height: 1.25;
    }

    body:not(.login-page):not(.public-message-page) :where(
      input[type="date"],
      input[type="month"],
      input[type="time"],
      input[type="datetime-local"]
    ) {
      display: block;
      width: 100% !important;
      inline-size: 100% !important;
      min-inline-size: 0 !important;
      box-sizing: border-box;
    }

    body:not(.login-page):not(.public-message-page) :where(
      .form-item,
      .form-group,
      .split-selects,
      .vision-dia-form__controls
    ) {
      min-width: 0;
    }

    /*
     * Visión General: Safari iOS conserva métricas internas propias en
     * input[type="date"]. Se fija la geometría completa de la primera fila
     * para que las dos flechas y la fecha queden perfectamente simétricas.
     */
    body.admin-vision-dia-page .vision-dia-date-card,
    body.admin-vision-dia-page .vision-dia-form {
      width: 100%;
      min-width: 0;
    }

    body.admin-vision-dia-page .vision-dia-form__controls {
      display: grid !important;
      grid-template-columns: 42px minmax(0, 1fr) 42px !important;
      align-items: stretch !important;
      width: 100% !important;
      min-width: 0 !important;
      column-gap: 8px !important;
      row-gap: 8px !important;
    }

    body.admin-vision-dia-page .vision-dia-form__controls .vision-dia-arrow {
      width: 42px !important;
      min-width: 42px !important;
      max-width: 42px !important;
      height: 42px !important;
      min-height: 42px !important;
      margin: 0 !important;
      padding: 0 !important;
    }

    body.admin-vision-dia-page .vision-dia-form__controls input[type="date"] {
      display: block !important;
      width: 100% !important;
      min-width: 0 !important;
      max-width: none !important;
      height: 42px !important;
      min-height: 42px !important;
      margin: 0 !important;
      padding: 0 12px !important;
      border-radius: 7px !important;
      box-sizing: border-box !important;
      -webkit-appearance: none;
      appearance: none;
      text-align: left;
    }

    body.admin-vision-dia-page
      .vision-dia-form__controls
      input[type="date"]::-webkit-date-and-time-value {
      min-height: 1.25em;
      margin: 0;
      text-align: left;
    }

    body.admin-vision-dia-page .vision-dia-form__controls .vision-dia-today,
    body.admin-vision-dia-page .vision-dia-form__controls button[type="submit"] {
      grid-column: 1 / -1 !important;
      width: 100% !important;
      margin: 0 !important;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  body:not(.login-page):not(.public-message-page) *,
  body:not(.login-page):not(.public-message-page) *::before,
  body:not(.login-page):not(.public-message-page) *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
