/**
 * Estilos principales de la interfaz
 * Generador de Carnets - DAITEC
 */

/* ===========================
   Variables CSS
   =========================== */
:root {
  /* Colores */
  --color-bg: #f4f6fb;
  --color-card: #ffffff;
  --color-border: #e6eaf2;
  --color-text: #101828;
  --color-muted: #667085;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #16a34a;
  --color-error: #dc2626;
  
  /* Sombras */
  --shadow-sm: 0 2px 8px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 6px 24px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 48px rgba(16, 24, 40, 0.1);
  
  /* Bordes */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;
  
  /* Espaciado */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  
  /* Tipografía */
  --font-sans: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: 'Courier New', monospace;
}

/* ===========================
   Accesibilidad
   =========================== */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px 16px;
  z-index: 1000;
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
  top: 0;
}

.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;
}

/* ===========================
   Reset y Base
   =========================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Ocultar texto alt de imágenes que no cargan */
img {
  color: transparent;
}

img::before {
  content: '';
  display: block;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ===========================
   Barra Superior
   =========================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(244, 246, 251, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.topbar__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #dbeafe 0%, #e0f2fe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.topbar__title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.topbar__subtitle {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 2px;
}

.topbar__btn {
  border: 1px solid var(--color-border);
  background: var(--color-card);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  transition: all 0.2s;
}

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

.topbar__back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-text);
  font-weight: 600;
  font-size: 14px;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 6px);
  background-color: #ffffff;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.topbar__back:hover {
  background-color: #f8faff;
  transform: translateX(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.topbar__back svg {
  transition: transform 0.2s ease;
}

.topbar__back:active {
  transform: translateX(-2px) scale(0.96);
}

/* Ocultar en la impresión de carnets */
@media print {
  .topbar__back {
    display: none !important;
  }
}

/* ===========================
   Contenedor Principal
   =========================== */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
}

/* ===========================
   Cards
   =========================== */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.card--center {
  text-align: center;
}

.card__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-lg);
}

.card__content {
  flex: 1;
  max-width: 640px;
}

.card__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-md);
  gap: var(--space-md);
}

.card__title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: 4px;
}

.card__header .card__title {
  margin-bottom: 0;
}

.card__description {
  color: var(--color-muted);
  font-size: 14px;
  line-height: 1.6;
}

.card__meta {
  color: var(--color-muted);
  font-size: 14px;
}

.card__note {
  margin-top: var(--space-md);
  color: var(--color-muted);
  font-size: 13px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

/* ===========================
   Botones
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  
  border: 1px solid var(--color-border);
  background: var(--color-card);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--color-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn--primary {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: white;
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn--large {
  padding: 14px 28px;
  font-size: 16px;
  min-width: 280px;
}

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

/* ===========================
   Dropzone (Zona de carga)
   =========================== */
.dropzone {
  margin-top: var(--space-md);
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-lg);
  text-align: center;
  background: #fbfcff;
  cursor: pointer;
  transition: all 0.3s;
}

.dropzone:hover {
  background: #f0f4ff;
  border-color: #94a3b8;
}

.dropzone--drag {
  background: #e0e7ff;
  border-color: var(--color-primary);
  border-style: solid;
}

.dropzone__icon {
  font-size: 25px;
  margin-bottom: var(--space-sm);
  opacity: 0.8;
}

.dropzone__title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.dropzone__subtitle {
  color: var(--color-muted);
  font-size: 13px;
  margin-bottom: var(--space-md);
}

.dropzone__info {
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: #d1fae5;
  color: var(--color-success);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  display: inline-block;
}

.dropzone__info:empty {
  display: none;
}

.dropzone__error {
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: #fee2e2;
  color: var(--color-error);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}

.dropzone__error:empty {
  display: none;
}

/* ===========================
   Grid de Templates
   =========================== */
/* ===========================
   Ayuda colapsable
   =========================== */
.help-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: #fff;
  color: var(--color-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.help-toggle:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: #eff6ff;
}

.help-toggle--open {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.help-content {
  width: 100%;
  margin-top: var(--space-sm);
  padding: var(--space-md);
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-muted);
  animation: helpSlideDown 0.2s ease;
}

.card__header .help-content {
  flex-basis: 100%;
  order: 2;
}

.help-content p {
  margin: 0 0 6px 0;
}

.help-content p:last-child {
  margin-bottom: 0;
}

@keyframes helpSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===========================
   Templates: fila horizontal deslizable
   =========================== */
.templates-scroll {
  display: flex;
  gap: var(--space-md);
  overflow-x: auto;
  padding-bottom: var(--space-sm);
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.templates-scroll::-webkit-scrollbar {
  height: 6px;
}

.templates-scroll::-webkit-scrollbar-track {
  background: var(--color-border);
  border-radius: 3px;
}

.templates-scroll::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 3px;
}

.template-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-card);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  top: 5px;
}

.template-card:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.template-card--selected {
  border-color: var(--color-primary);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.template-card__preview {
  height: 130px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0px;
  transition: background 0.3s ease;
}

.template-card__preview .carnet-mini {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.template-card__preview .carnet-mini .carnet {
  transform: scale(0.6);
  transform-origin: center center;
  flex-shrink: 0;
}

/* Nombre oculto por defecto, aparece en hover */
.template-card__name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: white;
  font-weight: 600;
  font-size: 12px;
  text-align: center;
  opacity: 0;
  transform: translateY(100%);
  transition: all 0.25s ease;
}

.template-card:hover .template-card__name {
  opacity: 1;
  transform: translateY(0);
}

/* Menú de 3 puntos para diseños custom */
.template-card__menu-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  color: #64748b;
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 10;
}

.template-card:hover .template-card__menu-btn {
  opacity: 1;
}

.template-card__menu-btn:hover {
  background: white;
  color: var(--color-primary);
  transform: scale(1.1);
}

/* Dropdown del menú */
.template-card__dropdown {
  position: absolute;
  top: 40px;
  right: 8px;
  background: white;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s ease;
  z-index: 20;
  min-width: 120px;
}

.template-card__dropdown--open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.template-card__dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}

.template-card__dropdown-item:hover {
  background: #f1f5f9;
}

.template-card__dropdown-item--danger {
  color: var(--color-error);
}

.template-card__dropdown-item--danger:hover {
  background: #fef2f2;
}

/* ===========================
   Área de Vista Previa
   =========================== */
.preview-area {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  justify-content: center;
  min-height: 100px;
}

.preview-area:empty::before {
  content: 'No hay vista previa disponible';
  color: var(--color-muted);
  font-style: italic;
  width: 100%;
  text-align: center;
  padding: var(--space-xl);
}

/* Área de impresión: oculta en pantalla, visible solo al imprimir */
.print-area {
  display: none;
}

/* ===========================
   Modal
   =========================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.modal[hidden] {
  display: none;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal__content {
  position: relative;
  background: var(--color-card);
  border-radius: var(--radius-lg);
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  font-size: 20px;
  font-weight: 800;
}

.modal__close {
  background: none;
  border: none;
  font-size: 32px;
  color: var(--color-muted);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.modal__close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.modal__body {
  padding: var(--space-lg);
}

.modal__body h3 {
  font-size: 16px;
  font-weight: 700;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

.modal__body p {
  margin-bottom: var(--space-md);
  line-height: 1.6;
}

.modal__body ul {
  margin-left: var(--space-lg);
  margin-bottom: var(--space-md);
}

.modal__body li {
  margin-bottom: var(--space-sm);
}

.modal__footer-note {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
}

/* ===========================
   Sección de carga de fotos
   =========================== */
.photos-upload {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.photos-upload__info {
  background: #f9fafb;
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.6;
}

.photos-upload__info p {
  margin: var(--space-sm) 0;
}

.photos-upload__info code {
  background: #e5e7eb;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: #1f2937;
}

.photos-upload__status {
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 14px;
  white-space: pre-line;
  min-height: 40px;
  background: #f9fafb;
}

/* Botón secundario */
.btn--secondary {
  background: #ffffff;
  color: var(--color-text);
  border: 2px solid var(--color-border);
}

.btn--secondary:hover {
  background: #f9fafb;
  border-color: var(--color-primary);
}

/* Botón peligro */
.btn--danger {
  background: #ffffff;
  color: var(--color-error);
  border: 2px solid #fecaca;
}

.btn--danger:hover {
  background: #fef2f2;
  border-color: var(--color-error);
}

/* Fila de botones de fotos */
.photos-upload__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* Dropzone específico para fotos */
.dropzone--fotos {
  padding: var(--space-lg) var(--space-md);
}

.dropzone--fotos .dropzone__icon {
  font-size: 36px;
  margin-bottom: var(--space-xs);
}

/* Galería de fotos cargadas */
.photos-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: var(--space-sm);
  max-height: 300px;
  overflow-y: auto;
  padding: var(--space-xs);
}

.photos-gallery:empty {
  display: none;
}

.photos-gallery__item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--color-border);
  aspect-ratio: 1;
  background: #f9fafb;
}

.photos-gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photos-gallery__item-dni {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photos-gallery__item--matched {
  border-color: var(--color-success);
}

.photos-gallery__item--unmatched {
  border-color: #f59e0b;
}

/* Contador de coincidencias */
.photos-upload__match-info {
  font-size: 13px;
  color: var(--color-muted);
  padding: var(--space-sm) 0;
}


/* ===========================
   Utilidades
   =========================== */
.hidden {
  display: none !important;
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .card__row {
    flex-direction: column;
    align-items: stretch;
  }

  .template-card {
    flex: 0 0 170px;
  }
  
  .btn--large {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .template-card {
    flex: 0 0 150px;
  }
}

/* Botones de acción en template cards custom */
.template-card__actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: center;
}

.template-card__edit-btn,
.template-card__delete-btn {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--color-border);
  background: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.template-card__edit-btn:hover {
  border-color: var(--color-primary);
  background: #eff6ff;
}

.template-card__delete-btn:hover {
  border-color: var(--color-error);
  background: #fef2f2;
}