/* ==========================================================================
   FILE-UPLOAD.CSS
   Componente corporativo de subida de archivos (input type="file" estilizado).
   --------------------------------------------------------------------------
   - Hereda la paleta de la intranet (variables --accent, --bg-*, --border-color
     y --text-* definidas en :root de admin.css/tickets.css) con fallbacks
     propios, por lo que funciona también fuera de la intranet.
   - Personalizable por contenedor sobrescribiendo las variables --fu-*:
       .mi-upload { --fu-primary:#2563eb; --fu-bg:#fff; --fu-border:#e5e7eb; }
   ========================================================================== */

.fu {
  /* Paleta del componente (hereda del tema con fallbacks seguros) */
  --fu-primary: var(--accent, #7c3aed);
  --fu-primary-soft: rgba(124, 58, 237, .10);
  --fu-primary-soft-strong: rgba(124, 58, 237, .18);
  --fu-bg: var(--bg-input, #f9fafb);
  --fu-bg-hover: var(--bg-hover, #f3f4f6);
  --fu-border: var(--border-color, #d0d5dd);
  --fu-text: var(--text-primary, #111827);
  --fu-muted: var(--text-secondary, #6b7280);
  --fu-danger: var(--er, #dc2626);
  --fu-danger-soft: rgba(220, 38, 38, .10);
  --fu-radius: var(--rs, 10px);
  --fu-ring: 0 0 0 3px rgba(124, 58, 237, .28);

  /* Contenedor de posicionamiento del input oculto: si el navegador hace
     scroll hasta él al enfocarlo, aterriza sobre la propia zona (en pantalla)
     en lugar de desplazarse a una caja suelta más arriba/abajo del documento. */
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  font-family: inherit;
  color: var(--fu-text);
  text-align: left;
}

/* --------------------------------------------------------------------------
   Input nativo: oculto de forma ACCESIBLE.
   No se usa display:none: sigue presente para el lector de pantalla,
   recibe el foco con Tab y acepta Enter/Space (el navegador abre el selector).
   -------------------------------------------------------------------------- */
.fu-input {
  position: absolute !important;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  /* Inerte al puntero: no captura clics sobre la esquina de la zona; el foco
     por teclado (Tab/Enter/Espacio) sigue funcionando. */
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Zona de arrastrar y soltar / botón de selección.
   Es un <label for="id-del-input">: clic y teclado activan el input nativo.
   -------------------------------------------------------------------------- */
.fu-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 26px 20px;
  border: 1.5px dashed var(--fu-border);
  border-radius: var(--fu-radius);
  background: var(--fu-bg);
  color: var(--fu-muted);
  cursor: pointer;
  text-align: center;
  transition: border-color .18s ease, background-color .18s ease, transform .12s ease, box-shadow .18s ease;
}

.fu-drop svg {
  color: var(--fu-primary);
  transition: transform .18s ease;
}

.fu-drop:hover {
  border-color: var(--fu-primary);
  background: var(--fu-bg-hover);
}

.fu-drop:hover svg {
  transform: translateY(-2px);
}

/* Estado ACTIVO de drag & drop (mientras se arrastra un archivo encima) */
.fu-drop.dragover,
.fu-drop.dragover:hover {
  border-style: solid;
  border-color: var(--fu-primary);
  background: var(--fu-primary-soft);
  box-shadow: var(--fu-ring);
}

.fu-drop.dragover svg {
  transform: translateY(-4px) scale(1.08);
}

/* Foco por teclado (Tab): anillo visible sobre la zona, sin cambiar el DOM */
.fu:focus-within .fu-drop {
  border-color: var(--fu-primary);
  box-shadow: var(--fu-ring);
}

.fu-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--fu-text);
}

.fu-hint {
  font-size: .78rem;
  color: var(--fu-muted);
}

/* Estado DISABLED: sin interacción, visualmente atenuado */
.fu.is-disabled .fu-drop {
  cursor: not-allowed;
  opacity: .55;
  pointer-events: none;
}

.fu.is-disabled .fu-title,
.fu.is-disabled .fu-hint {
  color: var(--fu-muted);
}

/* --------------------------------------------------------------------------
   Fila con el/los archivo(s) seleccionado(s): nombre, tamaño y limpiar.
   -------------------------------------------------------------------------- */
.fu-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--fu-border);
  border-radius: var(--fu-radius);
  background: var(--fu-bg);
}

.fu-file svg {
  flex: 0 0 auto;
  color: var(--fu-primary);
}

.fu-file-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}

.fu-file-name {
  font-size: .88rem;
  font-weight: 600;
  color: var(--fu-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fu-file-size {
  font-size: .76rem;
  color: var(--fu-muted);
}

.fu-clear {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--fu-muted);
  cursor: pointer;
  transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}

.fu-clear:hover {
  color: var(--fu-danger);
  background: var(--fu-danger-soft);
  border-color: var(--fu-danger);
}

.fu-clear:focus-visible {
  outline: 2px solid var(--fu-danger);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Mensaje(s) de error de validación (aria role="alert" anunciados por SR).
   -------------------------------------------------------------------------- */
.fu-error {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--fu-danger);
  border-radius: calc(var(--fu-radius) - 2px);
  background: var(--fu-danger-soft);
  color: var(--fu-danger);
  font-size: .82rem;
}

.fu-error ul {
  margin: 0;
  padding-left: 16px;
}

/* Aseguramos que el atributo [hidden] siempre gane a display:flex/block */
.fu-file[hidden],
.fu-error[hidden] {
  display: none !important;
}

/* Respeto a prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .fu-drop,
  .fu-drop svg,
  .fu-clear {
    transition: none;
  }
}

/* ==========================================================
   RESPONSIVE — File Upload
   ========================================================== */

@media (max-width: 768px) {
  .fu-drop {
    padding: 20px 16px;
  }
  .fu-title { font-size: .88rem; }
  .fu-hint { font-size: .72rem; }
  .fu-file { padding: 8px 12px; gap: 10px; }
  .fu-file-name { font-size: .82rem; }
  .fu-clear { width: 28px; height: 28px; }
}

@media (max-width: 480px) {
  .fu-drop { padding: 18px 12px; }
  .fu-file { flex-wrap: wrap; }
  .fu-file-info { min-width: 0; }
}

/* ── Touch targets ── */
@media (hover:none), (pointer:coarse) {
  .fu-clear { min-width: 44px; min-height: 44px; }
  .fu-drop { min-height: 44px; }
}
