/* ==========================================================================
   main.css — PowerPDF Design System
   Tokens, tipografía, layout global, dark mode
   ========================================================================== */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --------------------------------------------------------------------------
   Design Tokens (CSS Custom Properties)
   -------------------------------------------------------------------------- */
:root {
  /* --- Paleta de colores (Light Mode) --- */
  --color-bg-primary:     #f8f9fb;
  --color-bg-secondary:   #ffffff;
  --color-bg-tertiary:    #f1f3f6;
  --color-bg-hover:       #eef0f4;
  --color-bg-overlay:     rgba(255,255,255,0.85);

  --color-surface:        #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-sunken: #f1f3f6;

  --color-border:         #e2e5ea;
  --color-border-light:   #eef0f4;
  --color-border-focus:   #4f6ef7;

  /* Texto */
  --color-text-primary:   #1a1d23;
  --color-text-secondary: #5a6072;
  --color-text-muted:     #9aa0b0;
  --color-text-inverse:   #ffffff;

  /* Acento — Azul índigo */
  --color-accent:         #4f6ef7;
  --color-accent-hover:   #3d5ce5;
  --color-accent-light:   #eef1fe;
  --color-accent-dark:    #2d47c8;

  /* Semánticos */
  --color-success:        #22c55e;
  --color-success-light:  #f0fdf4;
  --color-warning:        #f59e0b;
  --color-warning-light:  #fffbeb;
  --color-danger:         #ef4444;
  --color-danger-light:   #fef2f2;
  --color-info:           #06b6d4;
  --color-info-light:     #ecfeff;

  /* --- Tipografía --- */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;

  --text-xs:    0.75rem;    /* 12px */
  --text-sm:    0.8125rem;  /* 13px */
  --text-base:  0.875rem;   /* 14px */
  --text-md:    1rem;       /* 16px */
  --text-lg:    1.125rem;   /* 18px */
  --text-xl:    1.25rem;    /* 20px */
  --text-2xl:   1.5rem;     /* 24px */

  --font-light:   300;
  --font-regular: 400;
  --font-medium:  500;
  --font-semibold:600;
  --font-bold:    700;

  --leading-tight:  1.3;
  --leading-normal: 1.5;
  --leading-loose:  1.75;

  /* --- Espaciado --- */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* --- Radios --- */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* --- Sombras --- */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);
  --shadow-xl:  0 16px 48px rgba(0,0,0,0.14), 0 8px 16px rgba(0,0,0,0.08);
  --shadow-focus: 0 0 0 3px rgba(79,110,247,0.25);

  /* --- Transiciones --- */
  --transition-fast:   120ms ease;
  --transition-base:   200ms ease;
  --transition-slow:   320ms ease;

  /* --- Layout --- */
  --topbar-height:    56px;
  --sidebar-width:    240px;
  --panel-width:      280px;
}

/* --------------------------------------------------------------------------
   Dark Mode Tokens
   -------------------------------------------------------------------------- */
[data-theme="dark"] {
  --color-bg-primary:     #0f1117;
  --color-bg-secondary:   #1a1d25;
  --color-bg-tertiary:    #242735;
  --color-bg-hover:       #2a2e40;
  --color-bg-overlay:     rgba(26,29,37,0.92);

  --color-surface:        #1a1d25;
  --color-surface-raised: #242735;
  --color-surface-sunken: #0f1117;

  --color-border:         #2e3247;
  --color-border-light:   #242735;
  --color-border-focus:   #4f6ef7;

  --color-text-primary:   #e8eaf0;
  --color-text-secondary: #9aa3bc;
  --color-text-muted:     #5c6280;
  --color-text-inverse:   #0f1117;

  --color-accent:         #667eea;
  --color-accent-hover:   #7b8ff0;
  --color-accent-light:   #1e2240;
  --color-accent-dark:    #4f6ef7;

  --shadow-xs:  0 1px 2px rgba(0,0,0,0.20);
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.30), 0 1px 2px rgba(0,0,0,0.20);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.35), 0 2px 4px rgba(0,0,0,0.20);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.40), 0 4px 8px rgba(0,0,0,0.25);
  --shadow-xl:  0 16px 48px rgba(0,0,0,0.50), 0 8px 16px rgba(0,0,0,0.30);
}

/* --------------------------------------------------------------------------
   CSS Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-regular);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  overflow: hidden;
  height: 100vh;
  transition: background-color var(--transition-slow), color var(--transition-slow);
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover { color: var(--color-accent-hover); }

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

button {
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
}

img { display: block; max-width: 100%; }

/* --------------------------------------------------------------------------
   App Shell — Layout Principal
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Topbar */
#topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  z-index: 100;
  transition: background-color var(--transition-slow), border-color var(--transition-slow);
}

/* Workspace (debajo del topbar) */
#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar de miniaturas */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden; /* Deja que .sidebar-pages maneje el scroll interno */
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-slow), border-color var(--transition-slow);
}

/* Canvas principal */
#canvas-area {
  flex: 1;
  overflow: auto;
  background: var(--color-bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-6);
  gap: var(--space-6);
  transition: background-color var(--transition-slow);
}

/* Panel derecho de propiedades */
#properties-panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-slow), border-color var(--transition-slow);
}

/* --------------------------------------------------------------------------
   Scrollbar personalizado
   -------------------------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* --------------------------------------------------------------------------
   Focus visible
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   Utilidades tipográficas
   -------------------------------------------------------------------------- */
.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-base  { font-size: var(--text-base); }
.text-md    { font-size: var(--text-md); }
.text-lg    { font-size: var(--text-lg); }

.text-primary   { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-muted     { color: var(--color-text-muted); }
.text-accent    { color: var(--color-accent); }

.font-medium   { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold     { font-weight: var(--font-bold); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Utilidades de layout
   -------------------------------------------------------------------------- */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.w-full { width: 100%; }
.h-full { height: 100%; }
.flex-1 { flex: 1; }

/* --------------------------------------------------------------------------
   Animaciones base
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.animate-fade-in    { animation: fadeIn var(--transition-base) both; }
.animate-scale-in   { animation: scaleIn var(--transition-base) both; }
.animate-slide-left { animation: slideInLeft var(--transition-base) both; }

/* --------------------------------------------------------------------------
   Loading spinner
   -------------------------------------------------------------------------- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

/* --------------------------------------------------------------------------
   Drop zone overlay
   -------------------------------------------------------------------------- */
#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(79, 110, 247, 0.08);
  backdrop-filter: blur(4px);
  border: 3px dashed var(--color-accent);
  border-radius: var(--radius-xl);
  margin: var(--space-4);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  animation: scaleIn 200ms both;
  pointer-events: none;
}

#drop-overlay.active {
  display: flex;
}

#drop-overlay .drop-icon {
  font-size: 3rem;
  animation: pulse 1.5s ease-in-out infinite;
}

#drop-overlay .drop-text {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--color-accent);
}
