/* Turniai — componentes. Se carga después de tokens.css; solo usa sus variables. Prefijo de clases: tn-. */

.tn, .tn *, .tn *::before, .tn *::after { box-sizing: border-box; }
.tn { font-family: var(--font-sans); font-size: 15px; line-height: 22px; color: var(--ink); background: var(--surface-0); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
.tn :focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.tn-muted { color: var(--ink-muted); }
.tn-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.tn-stack { display: flex; flex-direction: column; gap: var(--space-4); }
.tn-icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Botón */
.tn-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--size-control); padding: 0 var(--space-4); border-radius: var(--radius-sm); border: 1px solid transparent; font: 600 15px/22px var(--font-sans); cursor: pointer; white-space: nowrap; text-decoration: none; }
.tn-btn--primary { background: var(--brand); color: var(--on-brand); }
.tn-btn--primary:hover { background: var(--brand-strong); }
.tn-btn--secondary { background: var(--surface-1); color: var(--ink); border-color: var(--line-strong); }
.tn-btn--secondary:hover { background: var(--surface-2); }
.tn-btn--ghost { background: transparent; color: var(--brand); }
.tn-btn--ghost:hover { background: var(--brand-tint); }
.tn-btn--danger { background: var(--surface-1); color: var(--danger); border-color: var(--danger); }
.tn-btn--danger:hover { background: var(--danger-tint); }
.tn-btn--sm { min-height: 32px; padding: 0 var(--space-3); font-size: 13px; }
.tn-btn--block { width: 100%; }
.tn-btn[disabled], .tn-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.tn-btn--busy::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: tn-giro .8s linear infinite; }
@keyframes tn-giro { to { transform: rotate(1turn); } }
@media (pointer: coarse) { .tn-btn { min-height: 44px; } }

/* ---------- Campo */
.tn-field { display: flex; flex-direction: column; gap: var(--space-1); }
.tn-field > label { font-weight: 600; font-size: 13px; line-height: 18px; }
.tn-input, .tn-select { min-height: var(--size-control); padding: 0 var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-1); color: var(--ink); font: 400 15px/22px var(--font-sans); width: 100%; }
.tn-input::placeholder { color: var(--ink-muted); }
.tn-input--data { font-family: var(--font-mono); font-size: 14px; }
.tn-field__help { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.tn-field--error .tn-input, .tn-field--error .tn-select { border-color: var(--danger); }
.tn-field--error .tn-field__help { color: var(--danger); }
.tn-check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.tn-check input { width: 18px; height: 18px; accent-color: var(--brand); }
@media (pointer: coarse) { .tn-input, .tn-select { min-height: 44px; } }

/* ---------- Chip de turno */
.tn-shift { display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px var(--space-2); border-radius: var(--radius-xs); font: 500 12px/14px var(--font-condensed); white-space: nowrap; }
.tn-shift--morning { background: var(--shift-morning); color: var(--shift-morning-ink); }
.tn-shift--afternoon { background: var(--shift-afternoon); color: var(--shift-afternoon-ink); }
.tn-shift--night { background: var(--shift-night); color: var(--shift-night-ink); }
.tn-shift--oncall { background: var(--shift-oncall); color: var(--shift-oncall-ink); }
/* Color elegido para el tipo de turno (paleta shift-c-*): manda sobre el de su franja */
.tn-shift--c-amber { background: var(--shift-c-amber); color: var(--shift-c-amber-ink); }
.tn-shift--c-orange { background: var(--shift-c-orange); color: var(--shift-c-orange-ink); }
.tn-shift--c-red { background: var(--shift-c-red); color: var(--shift-c-red-ink); }
.tn-shift--c-pink { background: var(--shift-c-pink); color: var(--shift-c-pink-ink); }
.tn-shift--c-purple { background: var(--shift-c-purple); color: var(--shift-c-purple-ink); }
.tn-shift--c-indigo { background: var(--shift-c-indigo); color: var(--shift-c-indigo-ink); }
.tn-shift--c-blue { background: var(--shift-c-blue); color: var(--shift-c-blue-ink); }
.tn-shift--c-sky { background: var(--shift-c-sky); color: var(--shift-c-sky-ink); }
.tn-shift--c-teal { background: var(--shift-c-teal); color: var(--shift-c-teal-ink); }
.tn-shift--c-green { background: var(--shift-c-green); color: var(--shift-c-green-ink); }
.tn-shift--c-lime { background: var(--shift-c-lime); color: var(--shift-c-lime-ink); }
.tn-shift--c-gray { background: var(--shift-c-gray); color: var(--shift-c-gray-ink); }
.tn-shift--lg { padding: var(--space-1) var(--space-3); font: 600 13px/18px var(--font-sans); border-radius: var(--radius-sm); }
.tn-shift__hours { font-family: var(--font-mono); font-weight: 400; opacity: .9; }

/* ---------- Insignia de estado (siempre icono + palabra) */
.tn-badge { display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px var(--space-3) 2px var(--space-2); border-radius: var(--radius-pill); font: 600 13px/18px var(--font-sans); white-space: nowrap; }
.tn-badge .tn-icon { width: 14px; height: 14px; stroke-width: 2.25; }
.tn-badge--ok { background: var(--ok-tint); color: var(--ok); }
.tn-badge--warn { background: var(--warn-tint); color: var(--warn); }
.tn-badge--danger { background: var(--danger-tint); color: var(--danger); }
.tn-badge--brand { background: var(--brand-tint); color: var(--brand); }
.tn-badge--neutral { background: var(--surface-2); color: var(--ink-muted); }

/* ---------- Tarjeta */
.tn-card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-1); padding: var(--space-5); }
.tn-card--flush { padding: 0; overflow: hidden; }
.tn-eyebrow { font: 600 12px/16px var(--font-sans); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.tn-kpi { font: 600 28px/32px var(--font-sans); font-variant-numeric: tabular-nums; }
/* Tarjeta de cifra: el tinte de la paleta de fondo y la cifra en la marca (solo las que destacan un número) */
.tn-card--cifra { background: var(--brand-tint); border-color: transparent; box-shadow: none; }
.tn-card--cifra .tn-kpi { color: var(--brand); }
.tn-card--cifra .tn-eyebrow { color: var(--ink); }
.tn-card--cifra .tn-shift { box-shadow: 0 0 0 1px var(--surface-1); }
@media (max-width: 640px) { .tn-card { padding: var(--space-4); } }

/* ---------- Cuadrante (personas × días) */
.tn-roster { width: fit-content; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-1); max-width: 100%; }
.tn-roster table { border-collapse: separate; border-spacing: 0; font: 500 12px/14px var(--font-condensed); }
.tn-roster th, .tn-roster td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: var(--space-1); height: var(--size-row); min-width: var(--size-cell); text-align: center; vertical-align: middle; }
.tn-roster thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-1); font: 600 13px/16px var(--font-condensed); padding: var(--space-2) var(--space-1); }
.tn-roster thead th small { display: block; font: 500 11px/14px var(--font-condensed); color: var(--ink-muted); text-transform: uppercase; }
.tn-roster th[scope="row"] { position: sticky; left: 0; z-index: 1; background: var(--surface-1); text-align: left; padding: 0 var(--space-3); min-width: 160px; font: 600 13px/16px var(--font-condensed); white-space: nowrap; }
.tn-roster thead th:first-child { left: 0; z-index: 3; text-align: left; padding-left: var(--space-3); }
.tn-roster .tn-weekend { background: var(--surface-2); }
.tn-roster thead th.tn-weekend { background: var(--surface-2); }
.tn-roster .tn-holiday, .tn-roster thead th.tn-holiday { background: var(--holiday-tint); }
.tn-roster .tn-holiday small { color: var(--holiday); }
.tn-roster .tn-special, .tn-roster thead th.tn-special { background: var(--special-tint); }
.tn-roster .tn-special small { color: var(--special); }
.tn-roster .tn-bridge, .tn-roster thead th.tn-bridge { background: var(--bridge-tint); }
.tn-roster .tn-bridge small { color: var(--bridge); }
.tn-roster td .tn-prebridge { box-shadow: 0 0 0 2px var(--bridge); border-radius: var(--radius-sm); }
.tn-roster .tn-today { box-shadow: inset 0 -3px 0 var(--alba); }
.tn-roster td.tn-conflict { background: var(--danger-tint); box-shadow: inset 0 0 0 2px var(--danger); }
.tn-roster td.tn-blocked { background-image: repeating-linear-gradient(135deg, transparent 0 5px, var(--line) 5px 6px); }
.tn-roster td.tn-preferred { box-shadow: inset 0 0 0 1px var(--ok); }
.tn-roster td button { all: unset; display: inline-flex; cursor: pointer; border-radius: var(--radius-xs); }
.tn-roster td button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.tn-roster tbody tr:hover th[scope="row"], .tn-roster tbody tr:hover td:not(.tn-conflict) { background-color: var(--brand-tint); }
.tn-roster__slot { display: inline-block; width: 28px; height: 18px; border: 1px dashed var(--line-strong); border-radius: var(--radius-xs); }

/* ---------- Calendario de días (bloquear / preferir) */
.tn-daypicker { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--space-1); max-width: 360px; }
.tn-daypicker__dow { font: 600 11px/14px var(--font-sans); text-transform: uppercase; color: var(--ink-muted); text-align: center; padding: var(--space-1) 0; }
.tn-day { all: unset; box-sizing: border-box; aspect-ratio: 1; display: grid; place-items: center; border-radius: var(--radius-sm); font: 500 14px/1 var(--font-sans); cursor: pointer; border: 1px solid transparent; color: var(--ink); }
.tn-day:hover { background: var(--surface-2); }
.tn-day:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.tn-day--out { color: var(--ink-muted); opacity: .45; cursor: default; }
.tn-day--blocked { background: var(--danger-tint); color: var(--danger); border-color: var(--danger); text-decoration: line-through; }
.tn-day--preferred { background: var(--ok-tint); color: var(--ok); border-color: var(--ok); }
.tn-day--today { box-shadow: inset 0 -3px 0 var(--alba); }
.tn-day--selected { background: var(--brand); color: var(--on-brand); }
.tn-day--selected:hover { background: var(--brand-strong); }
.tn-day:disabled { color: var(--ink-muted); opacity: .45; cursor: not-allowed; background: none; }

/* ---------- Campo de fecha: se escribe (dd/mm/aaaa) o se elige en el calendario, que se abre debajo */
.tn-datefield { position: relative; max-width: 360px; }
.tn-datefield .tn-input { font-family: var(--font-mono); font-size: 14px; padding-right: 48px; }
.tn-datefield__btn { all: unset; box-sizing: border-box; position: absolute; top: 2px; right: 2px; bottom: 2px; width: 40px; display: grid; place-items: center; border-radius: var(--radius-sm); color: var(--brand); cursor: pointer; }
.tn-datefield__btn:hover { background: var(--brand-tint); }
.tn-datefield__btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.tn-calendar { margin-top: var(--space-2); max-width: 360px; padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-1); box-shadow: var(--shadow-1); }
.tn-calendar__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); font-weight: 600; }
.tn-calendar__head span::first-letter { text-transform: uppercase; }
.tn-calendar__nav { all: unset; box-sizing: border-box; width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-sm); color: var(--brand); cursor: pointer; }
.tn-calendar__nav:hover { background: var(--brand-tint); }
.tn-calendar__nav:focus-visible { outline: 2px solid var(--focus-ring); }
.tn-datelist:empty { display: none; }
.tn-datelist { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; margin: 0; padding: 0; }
.tn-datelist li { display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px 2px 2px var(--space-3); border-radius: var(--radius-pill); background: var(--surface-2); font: 500 14px/22px var(--font-mono); }
.tn-datelist button { all: unset; box-sizing: border-box; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-muted); cursor: pointer; }
.tn-datelist button:hover { background: var(--danger-tint); color: var(--danger); }
.tn-datelist button:focus-visible { outline: 2px solid var(--focus-ring); }
@media (pointer: coarse) { .tn-datelist button { width: 32px; height: 32px; } .tn-calendar__nav { width: 44px; height: 44px; } }

/* ---------- Puntuación del optimizador */
.tn-score { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.tn-score__part { border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); background: var(--surface-2); }
.tn-score__part b { display: block; font: 600 24px/28px var(--font-mono); }
.tn-score__part span { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.tn-score__part--danger { background: var(--danger-tint); } .tn-score__part--danger b { color: var(--danger); }
.tn-score__part--warn { background: var(--warn-tint); } .tn-score__part--warn b { color: var(--warn); }
.tn-score__part--ok { background: var(--ok-tint); } .tn-score__part--ok b { color: var(--ok); }

/* ---------- Medidor de equidad */
.tn-meter { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1) var(--space-3); align-items: center; font-size: 13px; line-height: 18px; }
.tn-meter__bar { grid-column: 1 / -1; position: relative; height: 8px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.tn-meter__bar i { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--brand); }
.tn-meter__bar--over i { background: var(--danger); }
.tn-meter__bar--under i { background: var(--warn); }
.tn-meter__target { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.tn-meter__value { font-family: var(--font-mono); }

/* ---------- Progreso de la optimización */
.tn-progress { display: flex; flex-direction: column; gap: var(--space-3); }
.tn-progress__steps { display: flex; gap: var(--space-2); list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 18px; color: var(--ink-muted); flex-wrap: wrap; }
.tn-progress__steps li { display: inline-flex; align-items: center; gap: var(--space-1); }
.tn-progress__steps li::after { content: "›"; margin-left: var(--space-2); color: var(--line-strong); }
.tn-progress__steps li:last-child::after { content: none; }
.tn-progress__steps li[aria-current="step"] { color: var(--ink); font-weight: 600; }
.tn-progress__steps li.tn-done { color: var(--ok); }
.tn-progress__track { height: 8px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.tn-progress__track i { display: block; height: 100%; width: 0; background: var(--alba); border-radius: inherit; transition: width .4s ease; }
.tn-progress__meta { display: flex; justify-content: space-between; gap: var(--space-3); font: 400 13px/18px var(--font-mono); color: var(--ink-muted); }

/* ---------- Restricción explicada */
.tn-constraint { display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-1) var(--space-3); align-items: start; padding: var(--space-4); border-bottom: 1px solid var(--line); }
.tn-constraint:last-child { border-bottom: 0; }
.tn-constraint__title { font-weight: 600; }
.tn-constraint__text { grid-column: 2 / 4; font-size: 13px; line-height: 18px; color: var(--ink-muted); margin: 0; }
.tn-constraint__count { font: 500 13px/18px var(--font-mono); }

/* ---------- Navegación */
.tn-nav { display: flex; flex-direction: column; gap: 2px; width: var(--size-sidebar); padding: var(--space-4) var(--space-3); background: var(--surface-1); border-right: 1px solid var(--line); }
.tn-nav__brand { font: 700 20px/24px var(--font-sans); letter-spacing: -0.02em; padding: var(--space-2) var(--space-3) var(--space-4); color: var(--ink); }
.tn-nav__brand span { color: var(--brand); }
.tn-nav a, .tn-nav button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); color: var(--ink-muted); font-weight: 500; cursor: pointer; }
.tn-nav a:hover, .tn-nav button:hover { background: var(--surface-2); color: var(--ink); }
.tn-nav [aria-current="page"] { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.tn-nav a:focus-visible, .tn-nav button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.tn-tabbar { display: flex; justify-content: space-around; background: var(--surface-1); border-top: 1px solid var(--line); padding: var(--space-1) 0 calc(var(--space-1) + env(safe-area-inset-bottom)); }
.tn-tabbar a, .tn-tabbar button { all: unset; display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1 1 0; min-width: 0; text-align: center; padding: var(--space-1); font: 500 11px/14px var(--font-sans); color: var(--ink-muted); cursor: pointer; border-radius: var(--radius-sm); }
.tn-tabbar [aria-current="page"] { color: var(--brand); font-weight: 600; }
.tn-tabbar .tn-icon { width: 22px; height: 22px; }

/* ---------- Diálogo */
.tn-backdrop { position: fixed; inset: 0; background: rgba(18, 17, 31, .45); display: grid; place-items: center; padding: var(--space-4); z-index: 50; }
.tn-dialog { min-width: 0; width: min(480px, 100%); background: var(--surface-1); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.tn-dialog__head { padding: var(--space-5) var(--space-5) var(--space-2); font: 600 19px/26px var(--font-sans); }
.tn-dialog__body { padding: 0 var(--space-5) var(--space-4); overflow: auto; }
.tn-dialog__foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line); }
@media (max-width: 640px) { .tn-backdrop { place-items: end stretch; padding: 0; } .tn-dialog { width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; } }

/* ---------- Aviso */
.tn-toast { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--surface-1); border: 1px solid var(--line); box-shadow: var(--shadow-2); max-width: 420px; font-size: 14px; line-height: 20px; }
.tn-toast--ok .tn-icon { color: var(--ok); } .tn-toast--danger .tn-icon { color: var(--danger); } .tn-toast--warn .tn-icon { color: var(--warn); }
.tn-toast b { display: block; }

/* ---------- Estado vacío */
.tn-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding: var(--space-6) var(--space-5); border: 1px dashed var(--line-strong); border-radius: var(--radius-md); }
.tn-empty__mark { display: grid; grid-template-columns: repeat(4, 14px); gap: 3px; }
.tn-empty__mark i { height: 14px; border-radius: var(--radius-xs); background: var(--surface-2); }
.tn-empty__mark i:nth-child(3n) { background: var(--shift-night); } .tn-empty__mark i:nth-child(4n+1) { background: var(--shift-morning); }
.tn-empty p { margin: 0; max-width: 36ch; color: var(--ink-muted); }

/* Skeleton: la forma del contenido mientras responde el servidor. Bloques del color de las superficies con un brillo
   que pasa despacio; sin movimiento si la persona lo pide (prefers-reduced-motion). Siempre dentro de un contenedor
   con role="status" y un texto para lectores de pantalla: los bloques son decorativos (aria-hidden). */
.tn-skeleton { display: block; border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-2) 40%, color-mix(in srgb, var(--surface-2) 55%, var(--surface-1)) 50%, var(--surface-2) 60%, var(--surface-2) 100%); background-size: 300% 100%; animation: tn-skeleton 1.6s ease-in-out infinite; }
.tn-skeleton--text { height: .8em; margin: .35em 0; }
.tn-skeleton--title { height: 1.2em; width: 40%; margin: .2em 0 .6em; }
.tn-skeleton--chip { display: inline-block; width: 2.2em; height: 1.6em; border-radius: var(--radius-sm); }
.tn-skeleton--circle { width: 2em; height: 2em; border-radius: 50%; flex: none; }
.tn-skeleton--block { height: 4.5em; border-radius: var(--radius-md); }
.tn-skeleton-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
.tn-skeleton-row > .tn-skeleton--text { flex: 1; margin: 0; }
.tn-skeleton-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tn-skeleton-calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.tn-skeleton-calendar .tn-skeleton { aspect-ratio: 1; border-radius: var(--radius-sm); }
/* Texto solo para lectores de pantalla */
.tn-visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@keyframes tn-skeleton { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .tn-skeleton { animation: none; background: var(--surface-2); } }
