/* Responsabilidad: campos, labels, ayudas, errores y controles del portal interno. */

.ui-field {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.ui-field--full {
  grid-column: 1 / -1;
}

.ui-field > :where(label, span):first-child,
.ui-field__label {
  color: var(--fg-muted);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* «(opcional)» o «(recomendado)» junto a la etiqueta: minúscula, más chico y liviano, para que no se lea
   como parte del nombre del campo. */
.ui-field > :where(label, span):first-child small,
.ui-field__label small {
  margin-left: 2px;
  color: var(--fg-soft);
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* Obligatorio: asterisco rojo tras la etiqueta, automático para todo campo con [required] (también los que
   el JS vuelve obligatorios). El lector de pantalla ya anuncia «obligatorio» por el atributo, así que el
   asterisco se oculta para él (texto alternativo vacío). En las pantallas de acceso todo es obligatorio:
   ahí no se marca. */
:where(body:not(.auth-page)) .ui-field:has(:is(input, select, textarea)[required]:not([type='hidden'])) > :where(label, span):first-child::after,
:where(body:not(.auth-page)) .ui-field:has(:is(input, select, textarea)[required]:not([type='hidden'])) .ui-field__label::after,
.ui-form-note__mark {
  margin-left: 3px;
  color: var(--accent-fg);
  font-weight: 700;
}

:where(body:not(.auth-page)) .ui-field:has(:is(input, select, textarea)[required]:not([type='hidden'])) > :where(label, span):first-child::after,
:where(body:not(.auth-page)) .ui-field:has(:is(input, select, textarea)[required]:not([type='hidden'])) .ui-field__label::after {
  content: '*' / '';
}

/* Nota al inicio de un formulario largo: «* Campo obligatorio». */
.ui-form-note {
  margin: 0;
  color: var(--fg-soft);
  font-size: 12.5px;
}

.ui-form-note__mark {
  margin: 0 3px 0 0;
}

.ui-field > :where(input, select, textarea) {
  width: 100%;
  min-height: var(--control-h-lg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background-color: var(--surface);
  color: var(--fg);
  font: inherit;
  padding: 11px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

/* Flecha propia del select: la nativa queda pegada al borde derecho. */
.ui-field > select:not([multiple]) {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236c758b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 14px center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  padding-inline-end: 42px;
}

/* Donde el navegador lo permite, la lista desplegable se dibuja con el diseño
   del portal y con el ancho del campo; los demás conservan la lista nativa. */
@supports (appearance: base-select) {
  .ui-field > select:not([multiple]),
  .ui-field > select:not([multiple])::picker(select) {
    appearance: base-select;
  }

  .ui-field > select:not([multiple]) {
    display: flex;
    align-items: center;
    text-box: trim-both cap alphabetic;
  }

  .ui-field > select:not([multiple])::picker-icon {
    display: none;
  }

  .ui-field > select:not([multiple])::picker(select) {
    inline-size: anchor-size(self-inline);
    margin-block: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    box-shadow: var(--shadow-md);
  }

  .ui-field > select:not([multiple]) option {
    padding: 7px 10px;
    border-radius: 6px;
    font-size: inherit;
    white-space: normal;
  }

  .ui-field > select:not([multiple]) option:is(:hover, :focus-visible) {
    background: var(--line-soft);
    outline: none;
  }

  .ui-field > select:not([multiple]) option:checked {
    font-weight: 600;
  }

  .ui-field > select:not([multiple]) option[value=''] {
    color: var(--fg-soft);
    font-weight: 400;
  }

  .ui-field > select:not([multiple]) option::checkmark {
    display: none;
  }
}

/* Texto libre (motivos, notas, observaciones, fundamentos): al tamaño del texto de los paneles, no a los 16 px
   de los campos de una línea. En un panel lateral, un menú o un diálogo, 16 px se veía desproporcionado junto a
   su etiqueta y su nota. Alto mínimo de tres líneas; `rows` lo agranda donde se espera más texto. */
.internal-shell textarea {
  font-size: 13px;
  line-height: 1.5;
}

.ui-field > textarea {
  min-height: calc(3lh + 20px);
  padding: 9px 12px;
  resize: vertical;
}

.ui-field > textarea::placeholder {
  color: var(--fg-soft);
}

/* iOS acerca la página al enfocar un campo de menos de 16 px: solo ahí se conservan los 16 px. */
@supports (-webkit-touch-callout: none) {
  .internal-shell textarea {
    font-size: 16px;
  }
}

.ui-field > :where(input, select, textarea):focus {
  border-color: var(--fg);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--fg) 7%, transparent);
  outline: none;
}

.ui-field > :where(input, select, textarea):disabled {
  background-color: var(--line-soft);
  color: var(--fg-soft);
  cursor: not-allowed;
}

.ui-field > :where(input, select, textarea)[aria-invalid='true'] {
  border-color: var(--alert-fg);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 7%, transparent);
}

.ui-field__feedback,
.ui-field__help {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.ui-field__feedback {
  color: var(--alert-fg);
}

.ui-field__help {
  color: var(--fg-soft);
}

@media (max-width: 760px) {
  .ui-field--full {
    grid-column: auto;
  }
}

/* Grupo obligatorio sin campo de texto (tarjetas de rol): el asterisco va en su título. */
:is(h2, h3, legend) > .ui-form-note__mark {
  margin: 0 0 0 4px;
}

/* ---------- Control segmentado con total ----------
   Vistas de una misma lista (Activos · Cerrados · Todos; Todas · Pide acción · No leídas), cada una con su total;
   la actual, en blanco y levantada. design_system.md §4.7. */
.ui-segmented {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: var(--r-pill);
  background: var(--line-soft);
  /* Si las pestañas no caben en el contenedor, la fila se desliza en vez de ensanchar la página. */
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.ui-segmented__tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 34px;
  padding: 0 var(--space-4);
  border-radius: var(--r-pill);
  color: var(--fg-muted);
  font: 600 13.5px/1 var(--font-sans);
  white-space: nowrap;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.ui-segmented__tab:hover {
  color: var(--fg);
}

/* Como botón (filtros que se aplican en el navegador): sin el aspecto nativo; el activo lleva aria-pressed. */
button.ui-segmented__tab {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.ui-segmented__tab[aria-pressed='true'],
.ui-segmented__tab[aria-selected='true'],
.ui-segmented__tab[aria-current='page'] {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--shadow-color) 10%, transparent), 0 0 0 1px color-mix(in srgb, var(--fg) 6%, transparent);
}

.ui-segmented__tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--fg);
}

/* El total va en una pastilla neutra; en la pestaña actual, en azul de marca (el rojo se lee como alerta). */
.ui-segmented__count {
  min-width: 22px;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--fg-muted);
  font-size: 11.5px;
  line-height: 1.3;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ui-segmented__tab:is([aria-current='page'], [aria-pressed='true'], [aria-selected='true']) .ui-segmented__count {
  background: var(--info-bg);
  color: var(--fg);
}

/* Teléfono: a todo el ancho; si las pestañas no caben, la fila se desliza en vez de ensanchar la página. */
@media (max-width: 720px) {
  .ui-segmented {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
  }

  .ui-segmented__tab {
    flex: 1 0 auto;
    padding: 0 var(--space-3);
  }
}

/* Pista de que hay más pestañas: la orilla del lado donde queda contenido se difumina (solo si la fila se desliza). */
@supports (animation-timeline: scroll(self inline)) {
  .ui-segmented {
    animation: ui-segmented-fade linear both;
    animation-timeline: scroll(self inline);
  }
}

@keyframes ui-segmented-fade {
  from { mask-image: linear-gradient(to right, var(--fg) calc(100% - 32px), transparent); }
  to { mask-image: linear-gradient(to left, var(--fg) calc(100% - 32px), transparent); }
}

/* ---------- Filtro de fecha (pastilla) ----------
   interno/components/_filtro_fecha.html.twig: «Ingreso ‹ valor › ✕» como los selectores en pastilla; el valor abre
   un panel con atajos y desde/hasta. En el encabezado en barra se ve sin borde (layout.css). */
.ui-date-filter {
  position: relative;
  flex: none;
  min-width: 0;
  height: var(--control-h-md);
  padding: 0 var(--space-2) 0 var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.ui-date-filter:has(.ui-date-filter__picker[open]),
.ui-date-filter:focus-within {
  border-color: var(--fg);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--fg) 7%, transparent);
}

/* Pastilla que acota la vista (sede, fecha, día, área, aptitud, espera): fondo azul tenue, sin borde. Se nota que
   filtra sin un contorno oscuro; la etiqueta pasa a --fg-muted, que sobre el tinte sí llega a 4.5:1. */
:is(.case-board__select, .ui-date-filter).is-active,
.internal-page-header--bar .internal-page-header__scope > :is(.case-board__select, .ui-date-filter).is-active {
  border-color: transparent;
  background: var(--info-bg);
  box-shadow: none;
}

:is(.case-board__select, .ui-date-filter).is-active :is(label, .ui-date-filter__label) {
  color: var(--fg-muted);
}

.ui-date-filter__label {
  margin-right: var(--space-1);
  color: var(--fg-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.ui-date-filter__step,
.ui-date-filter__clear {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--fg);
  transition: background-color 0.16s ease, color 0.16s ease;
}

a.ui-date-filter__step:hover,
.ui-date-filter__clear:hover {
  background: var(--line-soft);
}

/* «›» sin destino (la ventana siguiente empieza en el futuro): se ve, para que la pastilla no salte, pero apagado. */
span.ui-date-filter__step {
  color: var(--line);
}

.ui-date-filter__clear {
  margin-left: 2px;
  color: var(--fg-soft);
}

.ui-date-filter__clear:hover {
  color: var(--fg);
}

.ui-date-filter__picker {
  position: static;
  min-width: 0;
}

.ui-date-filter__value {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 30px;
  padding: 0 var(--space-2);
  border-radius: var(--r-pill);
  color: var(--fg);
  cursor: pointer;
  font: 600 13.5px/1 var(--font-sans);
  font-variant-numeric: tabular-nums;
  list-style: none;
  white-space: nowrap;
  transition: background-color 0.16s ease;
}

.ui-date-filter__value::-webkit-details-marker {
  display: none;
}

.ui-date-filter__value svg {
  flex: none;
  color: var(--fg-soft);
  /* Poppins dibuja las letras sobre el centro de su línea: el ícono sube 1px para quedar a la altura del texto. */
  transform: translateY(-1px);
}

.ui-date-filter__value:hover,
.ui-date-filter__picker[open] > .ui-date-filter__value {
  background: var(--line-soft);
}

.ui-date-filter__value:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--fg);
}

.ui-date-filter__panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  z-index: 30;
  width: min(360px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: grid;
  gap: var(--space-4);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.ui-date-filter__presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ui-date-filter__presets .ui-filter-chip {
  min-height: 32px;
  padding: 4px 11px;
}

.ui-date-filter__form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line-soft);
}

.ui-date-filter__field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
}

.ui-date-filter__field small {
  color: var(--fg-soft);
  font-size: var(--text-xs);
  font-weight: 500;
}

.ui-date-filter__field input {
  width: 100%;
  min-width: 0;
  height: var(--control-h-sm);
  padding: 0 var(--space-2) 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--fg);
  font: 600 13.5px/1.2 var(--font-sans);
  font-variant-numeric: tabular-nums;
}

.ui-date-filter__field input:focus-visible {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--fg) 7%, transparent);
}

.ui-date-filter__foot {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.ui-date-filter__foot p {
  margin: 0;
  color: var(--fg-soft);
  font-size: 12px;
}

/* Teléfono: la pastilla ocupa el ancho, con ✕ al extremo, y el panel también. */
@media (max-width: 720px) {
  .ui-date-filter__clear {
    margin-left: auto;
  }

  .ui-date-filter__panel {
    right: 0;
    width: auto;
  }
}

/* Pastilla de un día (interno/components/_filtro_dia.html.twig): «Hoy» para volver y el panel con «Ir a» en una fila. */
.ui-date-filter__today {
  display: inline-flex;
  align-items: center;
  height: 28px;
  margin-left: var(--space-1);
  padding: 0 10px;
  border-left: 1px solid var(--line-soft);
  color: var(--fg);
  font: 600 12.5px/1 var(--font-sans);
  white-space: nowrap;
}

.ui-date-filter__today:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ui-date-filter__form--dia {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.ui-date-filter__form--dia .ui-button {
  grid-column: auto;
  height: var(--control-h-sm);
}

/* ---------- Checkbox del portal (.ui-check) ----------
   En lugar del nativo (cuadrado, de esquina dura y tono del navegador): 16px con radio suave, borde fino; marcado,
   azul oscuro con ✓ blanco; intermedio («Todas» con algunas), con una raya. Mismo anillo de foco que los demás campos. */
.ui-check {
  appearance: none;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.ui-check::after {
  content: "";
  width: 10px;
  height: 10px;
  background: var(--surface);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-5' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-5' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: scale(0);
  transition: transform 0.12s ease;
}

.ui-check:hover {
  border-color: var(--fg-soft);
}

.ui-check:checked,
.ui-check:indeterminate {
  border-color: var(--fill-ink);
  background: var(--fill-ink);
}

.ui-check:checked::after {
  transform: scale(1);
}

.ui-check:indeterminate::after {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 6h6' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 6h6' stroke='%23000' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  transform: scale(1);
}

.ui-check:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 12%, transparent);
}

.ui-check:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
