/**
 * Generador de currículums (CV) en PDF ultra limpio
 * Estilos principales de la aplicación
 */

:root {
  /* Paleta base (Tema oscuro por defecto) */
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #334155;
  --bg-surface-hover: #475569;
  --bg-input: #0f172a;
  --border-color: #334155;
  --border-color-light: #475569;
  --border-color-focus: #38bdf8;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-text: #ffffff;
  
  --accent: #38bdf8;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: rgba(239, 68, 68, 0.15);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  --shadow-paper: 0 12px 30px rgba(0, 0, 0, 0.6);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
  --font-mono: 'JetBrains Mono', monospace;

  --header-height: 64px;
  --preview-toolbar-height: 52px;
}

/* Tema claro */
[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f8fafc;
  --bg-surface-hover: #e2e8f0;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-color-light: #e2e8f0;
  --border-color-focus: #2563eb;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-text: #ffffff;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-paper: 0 10px 25px rgba(0, 0, 0, 0.12);
}

/* Reset y base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Tipografía de títulos */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-main);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ============================================================
   Cabecera principal de la aplicación
   ============================================================ */
.app-header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1920px;
  margin: 0 auto;
  height: 100%;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-logo-box {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-text h1 .badge-free {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  letter-spacing: 0.05em;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ============================================================
   Botones y controles de UI
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
  border-radius: 4px;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-color-light);
}

.btn-success {
  background: #059669;
  color: #ffffff;
}

.btn-success:hover {
  background: #047857;
  box-shadow: 0 4px 10px rgba(5, 150, 105, 0.3);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-color-light);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-bg);
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* ============================================================
   Layout Principal: Split Screen (Editor & Preview)
   ============================================================ */
.app-main {
  flex: 1;
  display: flex;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* Switch móvil para alternar entre edición y vista previa */
.mobile-view-tabs {
  display: none;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.4rem 0.75rem;
  gap: 0.5rem;
  width: 100%;
}

.mobile-view-tabs .tab-toggle {
  flex: 1;
  padding: 0.55rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
}

.mobile-view-tabs .tab-toggle.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Panel Izquierdo: Formulario del Editor */
.editor-panel {
  width: 520px;
  min-width: 420px;
  max-width: 650px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.editor-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.editor-scroll-area::-webkit-scrollbar {
  width: 7px;
}
.editor-scroll-area::-webkit-scrollbar-thumb {
  background: var(--bg-surface-elevated);
  border-radius: 4px;
}
.editor-scroll-area::-webkit-scrollbar-thumb:hover {
  background: var(--bg-surface-hover);
}

/* Barra rápida de navegación de secciones */
.quick-nav-bar {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  white-space: nowrap;
}

.quick-nav-bar::-webkit-scrollbar {
  height: 4px;
}
.quick-nav-bar::-webkit-scrollbar-thumb {
  background: var(--border-color);
}

.quick-nav-item {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-nav-item:hover, .quick-nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Tarjetas colapsables de sección (Acordeones) */
.section-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.section-card:focus-within {
  border-color: var(--accent);
}

.section-header {
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  background: rgba(0, 0, 0, 0.05);
  border-bottom: 1px solid transparent;
}

.section-header:hover {
  background: var(--bg-surface-hover);
}

.section-card.is-open .section-header {
  border-bottom-color: var(--border-color);
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.section-icon-box {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
}

.section-badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  font-weight: 600;
}

.section-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.section-collapse-icon {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.section-card.is-open .section-collapse-icon {
  transform: rotate(180deg);
}

.section-body {
  padding: 1.1rem;
  display: none;
  flex-direction: column;
  gap: 1rem;
}

.section-card.is-open .section-body {
  display: flex;
}

/* ============================================================
   Formularios y controles
   ============================================================ */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
}

.form-grid-full {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.col-span-2 {
  grid-column: span 2;
}

.form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-help {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.form-control::placeholder {
  color: var(--text-dim);
}

textarea.form-control {
  resize: vertical;
  min-height: 75px;
  line-height: 1.45;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 2rem;
}

/* Helper text & tips */
.assistant-tip-box {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.assistant-tip-box svg {
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 0.15rem;
}

/* ============================================================
   Foto de perfil y avatar uploader
   ============================================================ */
.photo-uploader-row {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  background: var(--bg-surface);
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.photo-preview-wrap {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 2px dashed var(--border-color-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.photo-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-preview-placeholder {
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.65rem;
}

.photo-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
}

.photo-shape-toggles {
  display: flex;
  gap: 0.35rem;
}

.btn-shape-toggle {
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  cursor: pointer;
}

.btn-shape-toggle.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* ============================================================
   Repetidores dinámicos (Experiencias, Educación, etc.)
   ============================================================ */
.repeater-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.repeater-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  transition: all 0.15s ease;
}

.repeater-item:hover {
  border-color: var(--border-color-light);
}

.repeater-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.repeater-handle-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repeater-drag-handle {
  cursor: grab;
  color: var(--text-dim);
}

.repeater-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.checkbox-group {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-group input[type="checkbox"] {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
}

/* Lista de viñetas de logros */
.bullets-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.bullet-item-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.bullet-item-row .form-control {
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
}

/* Badges de habilidades en editor */
.skills-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  min-height: 42px;
}

.skill-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.55rem;
  border-radius: 14px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-main);
}

.skill-tag-chip .remove-tag-btn {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1;
}

.skill-tag-chip .remove-tag-btn:hover {
  color: var(--danger);
}

/* ============================================================
   Panel Derecho: Live Preview & Canvas A4
   ============================================================ */
.preview-panel {
  flex: 1;
  background: #090d16;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* Toolbar superior del panel de previsualización */
.preview-toolbar {
  height: var(--preview-toolbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  z-index: 10;
  flex-shrink: 0;
}

.preview-toolbar-left, .preview-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* Selectores de personalización visual */
.customizer-select-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.customizer-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
}

.color-swatches-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--primary);
}

/* Contenedor con zoom y scroll del papel A4 */
.preview-viewport {
  flex: 1;
  overflow: auto;
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(circle at center, #1e293b 0%, #090d16 100%);
  position: relative;
}

/* Contenedor del documento A4 */
.cv-document-wrapper {
  position: relative;
  transition: transform 0.2s ease;
  transform-origin: top center;
}

/* Hoja de papel A4 (Proporción exacta: 210mm x 297mm) */
.cv-paper {
  width: 210mm;
  min-height: 297mm;
  background: #ffffff;
  color: #1f2937;
  box-shadow: var(--shadow-paper);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* Indicador visual de corte de página 1 (297mm) */
.page-break-guide {
  position: absolute;
  top: 297mm;
  left: -20px;
  right: -20px;
  height: 0;
  border-top: 2px dashed rgba(239, 68, 68, 0.7);
  pointer-events: none;
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
}

.page-break-guide::after {
  content: 'Límite de página 1 (A4)';
  background: #ef4444;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  transform: translateY(-50%);
}

/* Barra de estado inferior del preview */
.preview-status-bar {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 0.4rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.page-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  background: var(--bg-surface-elevated);
}

.page-count-badge.is-single-page {
  color: var(--success);
  background: var(--success-bg);
}

.page-count-badge.is-multi-page {
  color: var(--warning);
  background: var(--warning-bg);
}

/* ============================================================
   Utilidades y helpers
   ============================================================ */
.d-none {
  display: none !important;
}

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

.font-mono {
  font-family: var(--font-mono);
}

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #ffffff;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Media Queries & Responsividad
   ============================================================ */
@media (max-width: 1180px) {
  .editor-panel {
    width: 460px;
    min-width: 360px;
  }
}

@media (max-width: 960px) {
  .app-main {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .mobile-view-tabs {
    display: flex;
    position: sticky;
    top: var(--header-height);
    z-index: 40;
  }

  .editor-panel {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    height: auto;
    border-right: none;
  }

  .preview-panel {
    width: 100%;
    height: auto;
    min-height: 80vh;
  }

  .editor-panel.mobile-hidden,
  .preview-panel.mobile-hidden {
    display: none !important;
  }

  .preview-viewport {
    padding: 1rem 0.5rem;
    overflow-x: auto;
  }

  .cv-paper {
    transform: scale(0.65);
    transform-origin: top center;
    margin-bottom: -100mm;
  }
}

@media (max-width: 600px) {
  .header-container {
    padding: 0 0.75rem;
  }
  .brand-text p {
    display: none;
  }
  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .form-group.col-span-2 {
    grid-column: span 1;
  }
  .cv-paper {
    transform: scale(0.48);
    margin-bottom: -150mm;
  }
}
