/*
 * Estilos de la app (estructura y componentes). Colores y tipografía: /theme.css.
 * Móvil primero; a partir de 640 px se amplían rejillas y espacios.
 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 8px; }
code { font-family: var(--font-mono); font-size: 0.95em; }
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }

/* ---- Utilidades ---------------------------------------------------------- */
.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.container-narrow { max-width: 440px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus {
  left: 16px; top: 8px; z-index: 10; padding: 8px 12px;
  background: var(--color-surface); color: var(--color-text); border-radius: var(--radius-small);
}
.muted { color: var(--color-text-muted); }
.small { font-size: 0.875rem; }
.hint { font-size: 0.875rem; color: var(--color-text-muted); margin: 4px 0 0; }
.stack > * + * { margin-top: 16px; }
.stack > input[type="hidden"] + * { margin-top: 0; } /* los campos ocultos (CSRF) no cuentan */
.prose { overflow-wrap: anywhere; }
.break-all { word-break: break-all; }
.empty { color: var(--color-text-muted); text-align: center; }

/* ---- Cabecera y menú -------------------------------------------------------- */
.site-header {
  background: var(--color-header);
  color: var(--color-header-text);
  padding-top: env(safe-area-inset-top);
}
.header-row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; gap: 12px; }
.brand { font-weight: 700; font-size: 1.05rem; text-decoration: none; }
.logout-form { margin: 0; }
.link-button {
  background: none; border: 0; padding: 8px 0; cursor: pointer;
  color: var(--color-header-muted); font: inherit; text-decoration: underline;
}
.main-nav { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--color-header-muted);
}
.main-nav a:hover { color: var(--color-header-text); }
.main-nav a[aria-current="page"] { background: var(--color-header-text); color: var(--color-header); font-weight: 600; }
.badge-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-header-text); color: var(--color-header); font-size: 0.75rem; font-weight: 700;
}
.main-nav a[aria-current="page"] .badge-count { background: var(--color-header); color: var(--color-header-text); }

/* main lleva también .container: se fija el espaciado vertical sin pisar el lateral */
main.container { padding-top: 20px; padding-bottom: 32px; }
.site-footer { color: var(--color-text-muted); font-size: 0.8125rem; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---- Estructura de página --------------------------------------------------- */
.page-head { margin-bottom: 16px; }
.page-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head-row form { margin: 0; }
.breadcrumb { font-size: 0.875rem; color: var(--color-text-muted); margin-bottom: 4px; overflow-wrap: anywhere; }
.summary { color: var(--color-text-muted); }
.summary strong { color: var(--color-text); }
.section-title { margin-top: 8px; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }
.card-link { display: block; height: 100%; text-decoration: none; }
.card-link:hover { border-color: var(--color-border-strong); }
.card-grid { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 12px; }
.card-grid .card { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* ---- Avisos flash ----------------------------------------------------------- */
.alert {
  margin: 0 0 12px; padding: 12px 14px; border-radius: var(--radius-small);
  background: var(--color-surface); border: 1px solid var(--color-border-strong); border-left-width: 6px;
  overflow-wrap: anywhere;
}
.alert::before { font-weight: 700; margin-right: 6px; }
.alert-error { border-color: var(--color-text); }
.alert-error::before { content: "✕"; }
.alert-success { border-color: var(--color-primary); }
.alert-success::before { content: "✓"; }
.alert-info::before { content: "i"; }

/* ---- Botones ---------------------------------------------------------------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius-small);
  border: 1px solid var(--color-border-strong); background: var(--color-surface); color: var(--color-text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--color-surface-muted); }
.button-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-text); }
.button-primary:hover { background: var(--color-primary-hover); }
.button-ghost { background: transparent; border-color: transparent; }
.button-small { min-height: 36px; padding: 6px 12px; font-size: 0.875rem; }
.button-block { width: 100%; }
.icon-button {
  width: 40px; height: 40px; border-radius: var(--radius-small); cursor: pointer;
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); font-size: 1.1rem;
}
.icon-button:hover { background: var(--color-surface-muted); }
.button:disabled, .icon-button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Formularios ------------------------------------------------------------ */
/* Sin margin vertical: lo pone .stack entre campos */
.field { margin-left: 0; margin-right: 0; padding: 0; border: 0; min-width: 0; }
fieldset.field { margin-bottom: 0; }
.field > label, .field > legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit;
  color: var(--color-text); background: var(--color-surface);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-small);
}
textarea { resize: vertical; }
input[type="file"] { font: inherit; max-width: 100%; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.choice { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; font-weight: 400; cursor: pointer; }
.choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--color-primary); }
.field > .choice { display: inline-flex; margin-bottom: 0; }
.has-error input, .has-error textarea, .has-error select { border: 2px solid var(--color-text); }
.field-error { margin: 6px 0 0; font-size: 0.875rem; font-weight: 600; }
.field-error::before { content: "✕ "; }
.field-error:empty { display: none; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.inline-form label { font-weight: 600; }
.inline-form input, .inline-form select { width: auto; min-width: 0; }

/* ---- Pestañas ----------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--color-border); }
.tab {
  padding: 10px 14px; margin-bottom: -1px; font-weight: 600; text-decoration: none;
  color: var(--color-text-muted); border-bottom: 3px solid transparent;
}
.tab[aria-current="page"] { color: var(--color-text); border-bottom-color: var(--color-text); }

/* ---- Cola ----------------------------------------------------------------- */
.task-list { list-style: none; margin: 0 0 16px; padding: 0; }
.task-card { display: flex; gap: 12px; align-items: flex-start; }
.task-rank {
  flex: 0 0 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-surface-muted); font-weight: 700;
}
.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 1.0625rem; margin-bottom: 6px; overflow-wrap: anywhere; }
.task-title a { text-decoration: none; }
.task-title a:hover { text-decoration: underline; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.task-forecast { margin: 0; font-weight: 600; }
.task-move { display: flex; flex-direction: column; gap: 6px; }
.task-move form { margin: 0; }
.is-private .task-title { color: var(--color-text-muted); font-style: italic; }
.queue-cta { text-align: center; }

.tag {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  background: var(--color-surface-muted); font-size: 0.8125rem; font-weight: 600;
}
.tag-outline { background: transparent; border: 1px solid var(--color-border-strong); }

/* Estados: texto + icono + estilo, nunca solo el tono */
.status {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px;
  border-radius: 999px; border: 1px solid transparent; font-size: 0.8125rem; font-weight: 700;
}
.status-icon::before { display: inline-block; width: 1em; text-align: center; }
.status-pending { background: var(--status-pending-bg); border: 1px dashed var(--status-pending-border); }
/* Pendiente y En curso: círculos dibujados con CSS (no dependen de la fuente del móvil) */
.status-pending .status-icon::before,
.status-in_progress .status-icon::before {
  content: ""; width: 0.75em; height: 0.75em; border-radius: 50%; border: 2px solid currentColor;
}
.status-in_progress { background: var(--status-progress-bg); color: var(--status-progress-text); }
.status-in_progress .status-icon::before { background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
.status-done { background: var(--status-done-bg); color: var(--status-done-text); }
.status-done .status-icon::before { content: "✓"; }
.status-rejected { background: var(--status-closed-bg); color: var(--status-closed-text); border-color: var(--color-border-strong); }
.status-rejected .status-icon::before { content: "✕"; }
.status-cancelled { background: var(--status-closed-bg); color: var(--status-closed-text); }
.status-cancelled .status-icon::before { content: "⊘"; }

/* ---- Detalle -------------------------------------------------------------- */
.meta-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 0; }
.meta-list > div { min-width: 0; }
.meta-list dt { font-size: 0.8125rem; color: var(--color-text-muted); }
.meta-list dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.meta-wide { grid-column: 1 / -1; }
.meta-list-fields { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--color-border); }
.attachment-list { list-style: none; margin: 0; padding: 0; }
.attachment-list li { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-top: 1px solid var(--color-border); }
.attachment-list li:first-child { border-top: 0; }
.attachment-list a { font-weight: 600; overflow-wrap: anywhere; }
.attachment-list-inline { margin-top: 6px; }
.attachment-list-inline li { padding: 2px 0; border: 0; }
.admin-panel { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--color-border-strong); }
.panel-label {
  margin: 0; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-text-muted);
}
details > summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.reject-box form { margin-top: 12px; }

/* Historial */
.timeline { list-style: none; margin: 0 0 16px 6px; padding: 0; border-left: 2px solid var(--color-border); }
.timeline-item { position: relative; padding: 0 0 16px 18px; }
.timeline-item::before {
  content: ""; position: absolute; left: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--color-surface); border: 2px solid var(--color-border-strong);
}
.timeline-comment::before, .timeline-attachment::before { background: var(--color-primary); border-color: var(--color-primary); }
.timeline-head { margin: 0; overflow-wrap: anywhere; }
.timeline-head time { display: block; }
.timeline-text {
  margin-top: 6px; padding: 10px 12px; border-radius: var(--radius-small);
  background: var(--color-surface-muted); overflow-wrap: anywhere;
}
.comment-form { padding-top: 16px; border-top: 1px solid var(--color-border); }

/* ---- Listas del panel admin ------------------------------------------------ */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.item.is-muted { opacity: 0.7; }
.field-editor { padding: 12px 0; border-top: 1px solid var(--color-border); }
.field-editor form { margin-top: 12px; }

/* ---- Avisos ------------------------------------------------------------------- */
.notification-list { list-style: none; margin: 0; padding: 0; }
.notification-list form { margin: 0; }
.notification {
  width: 100%; display: flex; flex-direction: column; gap: 4px;
  text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.notification:hover { border-color: var(--color-border-strong); }
.notification.is-unread { border-left: 6px solid var(--color-primary); font-weight: 600; }
.notification-message { overflow-wrap: anywhere; }

/* ---- Acceso y errores --------------------------------------------------------- */
.auth-card { margin-top: 24px; }
.error-page { text-align: center; }
.error-code { margin: 0; font-size: 3rem; font-weight: 800; color: var(--color-text-muted); }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 12px; }
.secret code {
  display: inline-block; padding: 8px 12px; border-radius: var(--radius-small);
  background: var(--color-surface-muted); font-size: 1.125rem; letter-spacing: 0.08em;
}

/* ---- Acceso con el móvil (QR) --------------------------------------------------- */
.divider { margin: 16px 0; text-align: center; color: var(--color-text-muted); font-size: 0.875rem; }
.qr-box {
  width: 100%; max-width: 260px; margin: 16px auto; padding: 8px;
  background: #ffffff; border: 1px solid var(--color-border); border-radius: var(--radius-small);
}
.qr-box-small { max-width: 200px; margin-left: 0; }
.qr { display: block; width: 100%; height: auto; }
.qr-help { text-align: center; }
.qr-code, .qr-code-inline { font-family: var(--font-mono); font-weight: 800; letter-spacing: 0.12em; }
.qr-code { margin: 4px 0 12px; text-align: center; font-size: 2rem; }
.qr-code-input { font-family: var(--font-mono); font-size: 1.25rem; letter-spacing: 0.12em; text-transform: uppercase; }
.qr-status { text-align: center; font-weight: 600; }
.qr-links { text-align: center; }
.qr-login.is-finished .qr-box { opacity: 0.25; }

/* ---- Informe de carga --------------------------------------------------------- */
.kpi-grid { list-style: none; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi-grid .card { margin: 0; }
.kpi-value { display: block; font-size: 1.75rem; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-label { display: block; font-size: 0.875rem; color: var(--color-text-muted); }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.data-table th, .data-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.data-table th { font-size: 0.8125rem; color: var(--color-text-muted); font-weight: 600; white-space: normal; vertical-align: bottom; }
.data-table td:first-child { white-space: normal; overflow-wrap: anywhere; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tfoot td { font-weight: 700; border-bottom: 0; }

/* ---- Escritorio -------------------------------------------------------------- */
@media (min-width: 640px) {
  h1 { font-size: 1.75rem; }
  .card { padding: 20px; }
  .card-grid { grid-template-columns: 1fr 1fr; }
  .meta-list { grid-template-columns: repeat(3, 1fr); }
  .timeline-head time { display: inline; margin-left: 6px; }
  .queue-cta .button-block { width: auto; min-width: 240px; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

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