:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #e4e7ec;
  --color-text: #2c2c2c;
  --color-muted: #667085;
  --color-accent: #e67e22;
  --color-accent-dark: #d35400;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  overflow: hidden;
}

body.modal-open {
  overflow: hidden;
}

.app {
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.access-denied {
  margin: auto;
  max-width: 28rem;
  padding: 2rem;
  text-align: center;
  color: var(--color-muted);
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: #fff;
  border-bottom: 3px solid var(--color-accent);
  flex-shrink: 0;
}

.app-kicker {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.app-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: #cbd5e1;
  max-width: 36rem;
}

.app-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-accent-dark);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.status-bar {
  margin: 0;
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  color: var(--color-muted);
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* Layout: catálogo | composición | vista previa (anchos ajustables, 1 scroll por columna) */
.workspace {
  --col-catalog: 260px;
  --col-preview: 300px;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  overflow: hidden;
}

.workspace-resizer {
  flex-shrink: 0;
  width: 7px;
  margin: 0 -3px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 2;
  touch-action: none;
}

.workspace-resizer::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: var(--color-border);
  transition: background 0.15s, width 0.15s;
}

.workspace-resizer:hover::after,
.workspace-resizer.is-dragging::after {
  width: 3px;
  background: var(--color-accent);
}

body.is-resizing-columns {
  cursor: col-resize;
  user-select: none;
}

.panel--preview {
  --preview-scale: 0.4;
  --preview-email-width: 700px;
  width: var(--col-preview);
  flex-shrink: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #eceef1;
  border-right: none;
}

.preview-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem;
}

.preview-viewport {
  width: calc(var(--preview-email-width) * var(--preview-scale));
  margin: 0 auto;
  overflow: hidden;
  position: relative;
}

.preview-scaler {
  width: var(--preview-email-width);
  transform: scale(var(--preview-scale));
  transform-origin: top left;
}

.preview-frame {
  width: var(--preview-email-width);
  height: 800px;
  border: 0;
  display: block;
  background: #fff;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  overflow: hidden;
}

.panel {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}

.panel--catalog {
  width: var(--col-catalog);
  flex-shrink: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel--canvas {
  flex: 1;
  min-width: 280px;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel__head {
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  background: #fff;
  flex-shrink: 0;
}

.panel__head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.panel__hint {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--color-muted);
}

.panel__head--preview {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.btn-preview-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  background: var(--color-accent);
  color: #fff;
  border: none;
}

.btn-preview-refresh:hover {
  background: var(--color-accent-dark);
}

.btn-preview-refresh .material-symbols-outlined {
  font-size: 1.1rem;
}

.btn-preview-refresh.is-loading .material-symbols-outlined {
  animation: preview-refresh-spin 0.8s linear infinite;
}

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

.search-input {
  margin: 0.75rem 1rem 0;
  width: calc(100% - 2rem);
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.search-input:focus {
  outline: 2px solid rgba(230, 126, 34, 0.35);
  border-color: var(--color-accent);
}

.catalog-list {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.catalog-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #fafbfc;
}

.catalog-card__num {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-accent);
}

.catalog-card__name {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
}

.canvas-scroll {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.zone-block {
  padding-top: 1rem;
}

.zone-block--body {
  margin: 0.75rem 0;
  padding: 1rem 0;
  border-top: 1px dashed rgba(230, 126, 34, 0.35);
  border-bottom: 1px dashed rgba(230, 126, 34, 0.35);
}

.zone-block__title {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.zone-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.zone-empty {
  margin: 0;
  padding: 1.5rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-muted);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  background: #fff;
}

/* ── Acordeón ── */
.accordion {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.accordion.is-open {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.12);
}

.accordion.is-fixed .accordion__header {
  background: #fffaf5;
}

.accordion__header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem 0.35rem 0.35rem;
  background: #fafbfc;
  border-bottom: 1px solid transparent;
}

.accordion.is-open .accordion__header {
  border-bottom-color: var(--color-border);
}

.accordion__toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: inherit;
}

.accordion__toggle:hover {
  background: rgba(230, 126, 34, 0.06);
}

.accordion__chevron {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 4px;
  background: #fff4e8;
  position: relative;
}

.accordion__chevron::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 55%;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--color-accent-dark);
  border-bottom: 2px solid var(--color-accent-dark);
  transform: translate(-50%, -60%) rotate(-45deg);
  transition: transform 0.2s;
}

.accordion.is-open .accordion__chevron::before {
  transform: translate(-50%, -30%) rotate(45deg);
}

.accordion__num {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff4e8;
  color: var(--color-accent-dark);
  font-size: 0.75rem;
  font-weight: 700;
}

.accordion__meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.accordion__name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.25;
}

.accordion__snippet {
  font-size: 0.78rem;
  color: var(--color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.accordion__actions {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
  padding-right: 0.25rem;
}

.accordion__fixed {
  padding: 0 0.5rem;
  font-size: 0.85rem;
  opacity: 0.75;
}

.accordion__body {
  padding: 1rem 1.1rem 1.15rem;
  background: #fff;
}

.accordion__empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* ── Campos inline ── */
.edit-fields {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.edit-section {
  margin-top: 0.25rem;
}

.edit-section__title {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-accent-dark);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(230, 126, 34, 0.25);
}

.edit-field-group {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #fafbfc;
  overflow: hidden;
}

.edit-field-group__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: #fff4e8;
  border-bottom: 1px solid var(--color-border);
}

.edit-field-group__title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text);
}

.edit-field-group__body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.85rem;
}

.edit-field-group--articles .edit-field-group__body {
  gap: 0.75rem;
}

.edit-articles {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.edit-article {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.edit-article__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.edit-article__num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-accent-dark);
  background: #fff4e8;
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
}

.edit-article__remove:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.edit-field-group--cards .edit-field-group__body {
  gap: 0.75rem;
}

.edit-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.edit-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.edit-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.edit-card__num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-accent-dark);
  background: #fff4e8;
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
}

.edit-card__remove:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.edit-field__preview--sm {
  width: 88px;
  min-width: 88px;
}

.edit-field__optional {
  font-weight: 400;
  color: var(--color-muted);
  font-size: 0.75rem;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.edit-field__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-muted);
}

.edit-field__input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  background: #fff;
}

.edit-field__input:focus {
  outline: 2px solid rgba(230, 126, 34, 0.3);
  border-color: var(--color-accent);
}

.edit-field__input--title {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.75rem 0.85rem;
}

.edit-field__textarea {
  min-height: 5.5rem;
  resize: vertical;
  line-height: 1.5;
}

/* Material Symbols */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 1.15rem;
  line-height: 1;
  vertical-align: middle;
}

/* Imagen: preview + botón subir debajo, URL a la derecha */
.edit-field--image {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.edit-field__preview-col {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.edit-field__image-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.edit-field__upload-row {
  display: flex;
  width: 100%;
}

.btn-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
  border: none;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(230, 126, 34, 0.35);
}

.btn-upload:hover {
  background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
}

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

.btn-upload .material-symbols-outlined {
  font-size: 1.2rem;
}

.edit-field__upload-input {
  display: none;
}

.edit-field__preview {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: #f8f9fa;
  overflow: hidden;
  display: grid;
  place-items: center;
}

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

.edit-field__preview-empty {
  font-size: 0.8rem;
  color: var(--color-muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  color: var(--color-text);
  cursor: pointer;
}

.icon-btn .material-symbols-outlined {
  font-size: 1.1rem;
}

.icon-btn:hover {
  background: #fff4e8;
  border-color: rgba(230, 126, 34, 0.45);
  color: var(--color-accent-dark);
}

.icon-btn--ghost {
  border-color: transparent;
  background: transparent;
  color: inherit;
}

.icon-btn--ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: transparent;
  color: inherit;
}

.icon-btn--danger:hover {
  background: #fef3f2;
  border-color: #fecdca;
  color: #b42318;
}

.btn-primary .material-symbols-outlined {
  font-size: 1.15rem;
}

/* Modal subida imagen (estilo s3-manager, carpeta fija news/) */
.upload-modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.65);
}

.upload-modal[hidden] {
  display: none;
}

.upload-modal__dialog {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}

.upload-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: #fff;
  border-bottom: 3px solid var(--color-accent);
}

.upload-modal__header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.upload-modal__body {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.upload-modal__preview {
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 1rem;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: #f8f9fa;
}

.upload-modal__preview img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
}

.upload-modal__file-icon {
  font-size: 3rem !important;
  color: var(--color-muted);
}

.upload-modal__hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--color-muted);
  line-height: 1.45;
}

.upload-modal__hint code {
  font-size: 0.76rem;
  background: #f2f4f7;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.upload-modal__details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: #fafbfc;
  border: 1px solid var(--color-border);
}

.upload-modal__details div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.72rem;
  color: var(--color-muted);
}

.upload-modal__details strong {
  font-size: 0.82rem;
  color: var(--color-text);
  font-weight: 600;
}

.upload-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem 1rem;
  border-top: 1px solid var(--color-border);
}

.upload-modal__footer .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.65);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal__dialog {
  width: min(1100px, 100%);
  height: min(92vh, 980px);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal__header h2 {
  margin: 0;
  font-size: 1rem;
}

.modal__frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #eceef1;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #1f2937;
  color: #fff;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
}

.toast[hidden] {
  display: none;
}

.toast[data-type='success'] {
  background: #027a48;
}

.toast[data-type='error'] {
  background: #b42318;
}

@media (max-width: 1100px) {
  .workspace-resizer[data-resize="preview"],
  .panel--preview {
    display: none;
  }

  .panel--canvas {
    min-width: 0;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .workspace {
    flex-direction: column;
    overflow: visible;
  }

  .workspace-resizer {
    display: none;
  }

  .panel--catalog,
  .panel--canvas,
  .panel--preview {
    width: 100% !important;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .catalog-list {
    max-height: 220px;
  }

  .canvas-scroll,
  .preview-scroll {
    overflow: visible;
    flex: none;
  }

  .panel--catalog {
    border-bottom: 1px solid var(--color-border);
  }

  .edit-field--image {
    grid-template-columns: 1fr;
  }

  .upload-modal__details {
    grid-template-columns: 1fr;
  }
}
