:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --warning: #f59e0b;
  --success: #16a34a;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #1f2937;
  --border: #e5e7eb;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: #001226;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  z-index: 100;
}

/* ===== LOGO PERSONALIZADO ===== */
.app-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 0.375rem;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-title i { font-size: 1.75rem; }

.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 2rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.tool-group {
  display: flex;
  gap: 0.25rem;
  padding-right: 1rem;
  border-right: 1px solid var(--border);
  margin-right: 0.5rem;
}

.tool-group:last-child { border-right: none; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-danger {
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover { background: #fef2f2; }

.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.btn-success:hover { background: #15803d; }

input[type="file"] { display: none; }

.main-container {
  display: flex;
  /*height: calc(100vh - 130px);*/
  flex: 1;
  /*height: 100vh;*/
  min-height: 0;
  overflow: hidden;
}

/*.sidebar {
  width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}*/

.sidebar {
  width: 300px;
  background: transparent;
  border-right: none;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.875rem;
}

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.folder-section {
  margin-bottom: 0.5rem;
}

.folder-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.4rem 0.75rem;
  background: #f3f4f6;
  border-radius: 0.375rem;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.file-item {
  padding: 0.55rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: background 0.2s;
  margin-bottom: 0.1rem;
}

.file-item:hover { background: var(--bg); }
.file-item.active { background: #dbeafe; border: 1px solid var(--primary); }
.file-icon { color: var(--danger); font-size: 1rem; }

/*.pages-area {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  background: #e5e7eb;
  min-height: 0;
}*/
.pages-area {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  background: #e5e7eb;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.page-card {
  background: var(--surface);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: grab;
  position: relative;
  user-select: none;
}

.page-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.page-card.dragging { opacity: 0.5; transform: scale(1.05); }

.page-number {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  z-index: 10;
}

.page-actions {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}

.page-card:hover .page-actions { opacity: 1; }

.page-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 0.25rem;
  border: none;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: all 0.2s;
}

.page-action-btn:hover { background: white; transform: scale(1.1); }
.page-action-btn.delete { color: var(--danger); }
.page-action-btn.rotate { color: var(--warning); }

.page-thumbnail {
  width: 100%;
  height: 220px;
  object-fit: contain;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}
.page-thumbnail.landscape {
  height: 160px; /* Menor altura para hojas horizontales */
  object-fit: contain;
}

.page-info {
  padding: 0.75rem;
  font-size: 0.875rem;
  color: #6b7280;
  text-align: center;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 1.5rem;
  width: 90%;
  max-width: 550px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-header {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; }
.form-group input, .form-group select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 1rem;
}

.form-group small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #6b7280;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.9);
  z-index: 2000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.loading-overlay.active { display: flex; }

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  color: white;
  font-weight: 500;
  transform: translateX(150%);
  transition: transform 0.3s;
  z-index: 3000;
}

.toast.show { transform: translateX(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: #9ca3af;
}

.empty-state i { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h3 { color: var(--text); margin-bottom: 0.5rem; }

/* ===== DROPDOWN ===== */
.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
  z-index: 1000;
  min-width: 240px;
  margin-top: 0.25rem;
  overflow: hidden;
}

.dropdown-menu.active { display: block; }

.dropdown-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.dropdown-item:last-child { border-bottom: none; }

.dropdown-item:hover {
  background: #eff6ff;
  color: var(--primary);
}

.dropdown-item i {
  width: 18px;
  text-align: center;
  font-size: 1rem;
}

/* ===== PREVIEW MODAL - ULTRA HD + ZOOM/PAN ===== */
.preview-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 2500;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.preview-overlay.active { display: flex; }

.preview-container {
  position: relative;
  width: 85vw;
  height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.preview-viewport {
  width: 100%;
  height: calc(100% - 70px);
  background: #1a1a2e;
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.7);
  overflow: hidden;
  position: relative;
  cursor: grab;
}

.preview-viewport:active {
  cursor: grabbing;
}

.preview-viewport.panning {
  cursor: grabbing;
}

.preview-canvas-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.1s ease-out;
  will-change: transform;
}

.preview-canvas-layer img {
  display: block;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(31, 41, 55, 0.95);
  padding: 0.5rem 1.25rem;
  border-radius: 2rem;
  color: white;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.preview-toolbar button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 0.95rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.preview-toolbar button:hover:not(:disabled) {
  background: rgba(255,255,255,0.2);
  transform: scale(1.1);
}

.preview-toolbar button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.preview-toolbar .zoom-info {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 70px;
  text-align: center;
  color: #e5e7eb;
}

.preview-page-info {
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 80px;
  text-align: center;
  border-left: 1px solid rgba(255,255,255,0.2);
  border-right: 1px solid rgba(255,255,255,0.2);
  padding: 0 0.75rem;
}

.preview-close {
  position: absolute;
  top: -2.5rem;
  right: 0;
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.preview-close:hover {
  background: rgba(255,255,255,0.3);
}

.preview-hint {
  position: absolute;
  bottom: -2rem;
  color: rgba(255,255,255,0.45);
  font-size: 0.78rem;
  text-align: center;
  width: 100%;
}

/* Spinner de carga en preview */
.preview-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  color: rgba(255,255,255,0.7);
}

.preview-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.preview-loading-text {
  font-size: 0.9rem;
  font-weight: 500;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }


/* ==========================================
   NUEVOS ESTILOS: ÁREA DE CARGA + INDICACIÓN
   ========================================== */

/* ----- Área de carga principal (estilo imagen 1) ----- */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  background: var(--surface);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  max-width: 600px;
  width: 90%;
  margin: auto;
  border: 2px dashed var(--border);
  transition: border-color 0.3s, background 0.3s;
}

.upload-area.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #8A8A8A;
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.upload-subtitle {
  font-size: 1.05rem;
  color: #6b7280;
  margin-bottom: 2rem;
  line-height: 1.5;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 2.5rem;
  background: #e53935; /* Rojo vibrante estilo imagen 1 */
  color: white;
  border: none;
  border-radius: 0.55rem;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(229, 57, 53, 0.35);
  transition: all 0.2s;
}

.upload-btn:hover {
  background: #c62828;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(229, 57, 53, 0.45);
}

.upload-btn i {
  font-size: 1.3rem;
}

.upload-hint {
  font-size: 0.95rem;
  color: #9ca3af;
  margin: 0;
}

/* ----- Indicación al usuario (contenido imagen 2, abajo) ----- */
.user-hint {
  text-align: center;
  padding: 1.5rem 2rem;
  color: #747D87;
  margin-top: auto; /* Empuja hacia abajo */
  padding-bottom: 2rem;
}

.user-hint i {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  color: #cbd5e1;
}

.user-hint h3 {
  color: var(--text);
  margin-bottom: 0.35rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.user-hint p {
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0;
}

.user-hint strong {
  color: #747D87;
}

/* Ocultar upload-area cuando hay documento */
.pages-area.has-document .upload-area,
.pages-area.has-document .user-hint {
  display: none;
}

/* Ajuste del pages-area para soportar la nueva estructura */
/*.pages-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
}*/

/* ===== TOOLBAR: oculta al inicio, visible con documento ===== */
#toolbar {
  display: none;
}
#toolbar.visible {
  display: flex;
}

/* ===== FOOTER COPYRIGHT ===== */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.6rem 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: #9ca3af;
  z-index: 50;
}

/* ===== SIDEBAR REEMPLAZADA POR BANNER ===== */
/*.sidebar {
  width: 300px;
  background: transparent;
  border-right: none;
  padding: 0;
  overflow: hidden;
}*/

.sidebar iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

/* Ocultar elementos legacy de la sidebar que ya no se usan */
.sidebar-header,
.file-list {
  display: none !important;
}