:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-panel: #162033;
  --border: #2c3a52;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --accent-new: #a855f7;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Barra superior */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.file-badge {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 2px;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.inline-field select {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
}

.pager, .zoom-controls, .export-menu {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-indicator, .zoom-label {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: center;
  color: var(--text);
}

/* Botones */
.btn, .icon-btn, .toggle-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn {
  padding: 7px 13px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 11px 22px;
  font-size: 14px;
}

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

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

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

.btn-secondary:hover:not(:disabled) {
  background: #273549;
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text);
}

.btn-ghost.active {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.4);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
  font-size: 15px;
  padding: 0;
}

.icon-btn:hover:not(:disabled) {
  background: #273549;
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

/* Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.dropzone {
  width: min(560px, 100%);
  padding: 44px 32px;
  border: 2px dashed #3b4f6e;
  border-radius: 16px;
  background: rgba(30, 41, 59, 0.55);
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
  cursor: pointer;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.1);
}

.dropzone-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.dropzone h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.dropzone p {
  margin: 0 auto 22px;
  max-width: 430px;
  color: var(--text-muted);
  line-height: 1.5;
}

.feature-pills {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.feature-pills li {
  font-size: 12px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
}

/* Editor layout */
.editor-layout {
  flex: 1;
  display: flex;
  min-height: 0;
  width: 100%;
}

.canvas-area {
  flex: 1;
  min-width: 0;
  overflow: auto;
  background: #0b1120;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  gap: 12px;
}

.preview-banner, .warning-banner {
  width: min(820px, 100%);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.preview-banner {
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(59, 130, 246, 0.45);
  color: #dbeafe;
}

.warning-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

.page-stage-wrapper {
  display: flex;
  justify-content: center;
  padding-bottom: 40px;
}

.page-stage {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 3px;
  user-select: none;
  flex-shrink: 0;
}

.page-image {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.overlay-layer {
  position: absolute;
  inset: 0;
}

.overlay-layer.hide-boxes .text-box:not(.selected):not(.modified):not(.deleted):not(.is-new) {
  border-color: transparent;
  background: transparent;
}

/* Recuadros interactivos sobre el PDF */
.text-box {
  position: absolute;
  border: 1px dashed rgba(59, 130, 246, 0.55);
  background: rgba(59, 130, 246, 0.06);
  cursor: pointer;
  transition: border-color 0.1s ease, background 0.1s ease;
  overflow: visible;
  border-radius: 2px;
}

.text-box:hover {
  border: 1.5px solid #3b82f6;
  background: rgba(59, 130, 246, 0.14);
  z-index: 15;
}

.text-box.selected {
  border: 2px solid #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
  z-index: 25;
}

.text-box.modified {
  border: 1.5px solid var(--success);
  z-index: 10;
}

.text-box.is-new {
  border: 1.5px solid var(--accent-new);
  cursor: move;
  z-index: 12;
}

.text-box.deleted {
  border: 1.5px dashed var(--danger);
  background: rgba(239, 68, 68, 0.16);
  z-index: 8;
}

.text-box-preview {
  position: absolute;
  inset: 0;
  white-space: pre-wrap;
  line-height: 1.15;
  overflow: visible;
  pointer-events: none;
  padding: 0 1px;
}

.text-box.deleted .text-box-preview {
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.78);
  color: #dc2626;
  font-size: 10px !important;
  font-weight: 700;
  text-decoration: line-through;
}

/* Panel lateral derecho */
.sidebar {
  width: 360px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.stat-modified {
  color: #34d399;
  font-weight: 600;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 10px 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: #60a5fa;
  border-bottom-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
}

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inspector-empty {
  color: var(--text-muted);
  line-height: 1.55;
  padding: 18px 8px;
  text-align: center;
}

.inspector-empty .hint {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 10px;
}

.inspector-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.id-badge {
  font-family: Consolas, monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 3px 7px;
  border-radius: 4px;
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.status-badge.modified {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.status-badge.is-new {
  background: rgba(168, 85, 247, 0.2);
  color: #d8b4fe;
}

.status-badge.deleted {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.field input[type="text"],
.field input[type="number"],
.field input[type="search"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.field textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.4;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
}

.field-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.field-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.style-toggles {
  display: flex;
  gap: 5px;
}

.toggle-btn {
  width: 34px;
  height: 34px;
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
  font-size: 14px;
}

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

.color-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.color-field input[type="color"],
.color-input-row input[type="color"] {
  width: 38px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 2px;
  cursor: pointer;
}

.color-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mono-sm {
  font-family: Consolas, monospace;
  font-size: 12px;
  color: var(--text);
}

.compact-field {
  flex: 1;
}

.advanced-section {
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.advanced-section summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.inspector-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.inspector-actions .btn {
  flex: 1;
  justify-content: center;
}

/* Lista de textos */
.list-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-toolbar input[type="search"] {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.text-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.text-list-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.text-list-item:hover {
  border-color: #475569;
  background: #243247;
}

.text-list-item.selected {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.14);
}

.text-list-item.modified {
  border-left: 3px solid var(--success);
}

.text-list-item.is-new {
  border-left: 3px solid var(--accent-new);
}

.text-list-item.deleted {
  border-left: 3px solid var(--danger);
  opacity: 0.65;
}

.text-list-preview {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-list-item.deleted .text-list-preview {
  text-decoration: line-through;
}

.text-list-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* Buscar y reemplazar */
.search-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-actions .btn {
  width: 100%;
  justify-content: center;
}

.search-status {
  font-size: 12px;
  color: #93c5fd;
  min-height: 18px;
}

/* Toast y carga */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #3b82f6;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 100;
  font-size: 13px;
  font-weight: 500;
}

.toast.error {
  border-color: var(--danger);
  background: #451a1a;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 200;
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

@media (max-width: 960px) {
  .editor-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: 44%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
