/* File: /assets/css/components.css
 * Las piezas con las que se arma cualquier pantalla de daClic.
 *
 * Regla del proyecto: si algo se repite en dos módulos, sube aquí. Un módulo
 * que se inventa su propio botón es un botón que mañana no seguirá al tema del
 * admin, y la plataforma empieza a verse de tres colores distintos.
 *
 * Los objetivos táctiles no bajan de 44 px. Buena parte de quien va a usar
 * daClic no tiene veinte años ni pulso de cirujano, y un botón de 32 px en un
 * celular es un botón que se falla.
 */

/* ── Tarjeta ──────────────────────────────────────────────────────────────── */

/* Fondo claro y borde en el tono fuerte: es la seña de identidad visual de
   daClic. El borde hace el trabajo que en otras plataformas hace una sombra
   pesada, y se lee igual de bien en modo noche. */
.card {
  background: var(--surface);
  border: var(--card-border) solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-pad-lg { padding: 26px; }
.card-flush  { padding: 0; overflow: hidden; }

.card-hover {
  transition: border-color .16s ease, transform .16s ease;
}
.card-hover:hover {
  border-color: var(--accent-line);
  transform: translateY(-2px);
}

/* Barra de acento arriba: distingue la tarjeta importante sin gritar. */
.card-accent { border-top: 3px solid var(--accent); }

.card-soft {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title { font-size: 1rem; font-weight: 640; letter-spacing: -.015em; }
.card-sub   { font-size: .84rem; color: var(--text-soft); margin-top: 2px; }

.card-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* ── Encabezado de página ─────────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { flex: 1 1 auto; min-width: 0; }
.page-head .lead { flex-basis: 100%; margin-top: -4px; }

/* ── Botones ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: .93rem;
  font-weight: 560;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled, .btn.is-busy { opacity: .55; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-text); }

.btn-outline {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}
.btn-soft:hover { background: var(--accent); color: var(--accent-text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); color: #fff; }

.btn-plain { padding: 0; min-height: 0; background: none; color: var(--accent); font-weight: 560; }
.btn-plain:hover { text-decoration: underline; }

.btn-sm    { min-height: 36px; padding: 7px 13px; font-size: .85rem; }
.btn-lg    { min-height: 52px; padding: 14px 26px; font-size: 1rem; border-radius: var(--radius); }
.btn-block { display: flex; width: 100%; }

.btn-icon {
  min-height: 42px;
  width: 42px;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn .ic { flex: 0 0 auto; }

/* ── Formularios ──────────────────────────────────────────────────────────── */

.field { margin-bottom: 16px; }

.label {
  display: block;
  margin-bottom: 6px;
  font-size: .86rem;
  font-weight: 560;
  color: var(--text);
}
.label .req { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px; /* 16px justos: por debajo, iOS hace zoom al enfocar */
  transition: border-color .15s, box-shadow .15s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder, .textarea::placeholder { color: var(--text-mute); }

.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }

/* La flecha se dibuja aquí porque la nativa no sigue al tema. El color-scheme
   del :root es lo que hace que el desplegable ABIERTO también salga oscuro:
   ese menú lo pinta el sistema, no el CSS. */
.select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 17px;
}

.field-hint  { margin-top: 6px; font-size: .8rem; color: var(--text-soft); }
.field-error { margin-top: 6px; font-size: .8rem; color: var(--danger); }

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea { border-color: var(--danger); }

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .input-addon {
  display: flex;
  align-items: center;
  padding: 0 13px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft);
  font-size: .88rem;
  white-space: nowrap;
}
.input-group .input-addon:first-child {
  border-left: 1px solid var(--border-strong);
  border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.input-group .input-addon:first-child + .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* Casilla y conmutador */
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  min-height: 44px;
  padding: 8px 0;
}
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: 0 0 auto; }
.check span  { font-size: .92rem; line-height: 1.45; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 46px; height: 26px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  transition: background .18s;
  flex: 0 0 auto;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Opciones tocables. En móvil se prefieren a un <select>: se ve todo de un
   vistazo y se elige con el dedo, sin desplegar nada. */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }

.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.choice:hover { border-color: var(--accent-line); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.choice .ic { color: var(--text-soft); }
.choice.is-selected .ic { color: var(--accent); }

/* ── Insignias ────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-badge);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .01em;
  background: var(--surface-3);
  color: var(--text-soft);
  white-space: nowrap;
}
.badge-accent  { background: var(--accent-soft);  color: var(--accent); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-solid   { background: var(--accent); color: var(--accent-text); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

/* ── Avisos ───────────────────────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: .9rem;
  line-height: 1.5;
}
.alert .ic { flex: 0 0 auto; margin-top: 1px; }

.alert-info    { background: var(--info-soft);    border-color: transparent; color: var(--info); }
.alert-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }

/* ── Avatares ─────────────────────────────────────────────────────────────── */

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-3);
  flex: 0 0 auto;
}
.avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 640;
  font-size: .85rem;
  letter-spacing: .02em;
  user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }
.avatar-lg { width: 60px; height: 60px; font-size: 1.15rem; }
.avatar-xl { width: 96px; height: 96px; font-size: 1.75rem; }

/* ── Tablas ───────────────────────────────────────────────────────────────── */

/* Envoltorio con desplazamiento propio: una tabla ancha NUNCA debe hacer que la
   página entera se mueva de lado. */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 12px 14px; text-align: left; }
.table th {
  font-size: .76rem;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: .045em;
  color: var(--text-mute);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }

/* ── Estado vacío ─────────────────────────────────────────────────────────── */

/* Un vacío nunca se deja en blanco: dice qué falta y ofrece el botón que lo
   resuelve. Una pantalla en blanco es una pregunta sin respuesta. */
.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-soft);
}
.empty .ic { color: var(--text-mute); margin: 0 auto 12px; }
.empty h3  { margin-bottom: 6px; }
.empty p   { max-width: 380px; margin: 0 auto 18px; font-size: .92rem; }

/* ── Cargando ─────────────────────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: sk 1.3s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Avisos flotantes ─────────────────────────────────────────────────────── */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + 16px);
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}
@media (min-width: 992px) {
  .toast-host { bottom: 22px; left: auto; right: 22px; transform: none; }
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 28px rgba(15,23,42,.16);
  font-size: .9rem;
  pointer-events: auto;
  animation: toast-in .22s ease;
}
.toast-success { border-left-color: var(--success); }
.toast-danger  { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ── Pestañas ─────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 15px;
  border-bottom: 2px solid transparent;
  color: var(--text-soft);
  font-size: .89rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }

/* ── Ventana modal ────────────────────────────────────────────────────────── */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(9, 12, 20, .55);
  backdrop-filter: blur(3px);
  z-index: 150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
@media (min-width: 640px) {
  .modal-back { align-items: center; padding: 20px; }
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  /* En celular sube desde abajo y solo redondea arriba: es el gesto que la
     gente ya conoce de las apps, y deja el pulgar cerca de los botones. */
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 22px;
  animation: sheet-up .24s cubic-bezier(.32,.72,0,1);
}
@media (min-width: 640px) {
  .modal { border-radius: var(--radius-lg); animation: fade .18s ease; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }

.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-head h3 { flex: 1; }
.modal-foot { display: flex; gap: 10px; margin-top: 22px; }
.modal-foot .btn { flex: 1; }

/* ── Separadores y listas ─────────────────────────────────────────────────── */

.divider { height: 1px; background: var(--border); margin: 18px 0; }

.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-mute);
  font-size: .8rem;
}
.divider-text::before, .divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }

/* ── Barra de progreso ────────────────────────────────────────────────────── */

.progress {
  height: 7px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .35s ease;
}
.progress-bar.is-warning  { background: var(--warning); }
.progress-bar.is-critical { background: var(--danger); }

/* ── Dato suelto (métricas) ───────────────────────────────────────────────── */

.stat { text-align: center; }
.stat-num {
  font-size: 1.5rem;
  font-weight: 680;
  letter-spacing: -.03em;
  line-height: 1.1;
  color: var(--text);
}
.stat-label {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-mute);
  margin-top: 3px;
}

/* ── Copiar al portapapeles ───────────────────────────────────────────────── */

.copy-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9rem;
  word-break: break-all;
}
.copy-box .fill { user-select: all; }

/* ── Recortador de imagen ──────────────────────────────────────────────────── */
/* Lo usa cualquier pantalla que suba una imagen (DC.crop). Vive aquí y no en el
   CSS de un módulo porque el recortador es del sitio, no de una pantalla. */
.crop-back {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
}
.crop-box {
  width: 100%;
  max-width: 320px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg, 0 18px 50px rgba(0,0,0,.3));
}
.crop-t { margin: 0 0 12px; font-size: .95rem; font-weight: 650; text-align: center; }
/* El tablero de ajedrez detrás: sin él, una imagen con transparencia se ve
   flotando y no se entiende dónde acaba el recorte. */
.crop-stage {
  width: 260px; height: 260px;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background:
    conic-gradient(from 90deg, #e9e9ec 25%, #f7f7f9 0 50%, #e9e9ec 0 75%, #f7f7f9 0) 0 0/16px 16px;
  cursor: grab;
}
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { display: block; touch-action: none; }
.crop-zoom { width: 100%; margin: 14px 0 4px; }
.crop-acts { display: flex; gap: 8px; }
.crop-acts .btn { flex: 1; justify-content: center; }
