/* --- VARIABLES DE TEMA --- */
:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --bg-body: #f8fafc;
  --bg-panel: #ffffff;
  --bg-sidebar: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --code-bg: #1e293b;
  --toast-bg: #0f172a;
  --toast-text: #ffffff;
  --input-placeholder: #94a3b8;
}

[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --bg-body: #020617;
  --bg-panel: #0f172a;
  --bg-sidebar: #1e293b;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --code-bg: #02040a;
  --toast-bg: #ffffff;
  --toast-text: #0f172a;
  --input-placeholder: #475569;
}

* {
  box-sizing: border-box;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: "Inter", sans-serif;
  background: var(--bg-body);
  height: 100vh;
  color: var(--text-main);
  display: flex;
  overflow: hidden;
  transition:
    background 0.3s ease,
    color 0.3s ease;
}

/* --- ESTILOS MÓVILES (APP LIKE) --- */

/* Por defecto, la barra móvil está oculta */
.mobile-nav {
  display: none;
}

@media (max-width: 900px) {
  /* 1. Ajustes del Layout Principal */
  body {
    /* Espacio extra abajo para que la barra no tape el contenido */
    padding-bottom: 80px;
  }

  .actions {
    display: none !important; /* Ocultamos los botones viejos de arriba en móvil */
  }

  /* 2. Barra de Navegación Inferior */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 65px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.05);
    z-index: 999;
    justify-content: space-around; /* Distribuye espacio equitativamente */
    align-items: center;
    padding: 0 10px;
    backdrop-filter: blur(10px); /* Efecto cristal moderno */
  }

  /* Items de la barra */
  .nav-item {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    gap: 4px;
    width: 60px;
    cursor: pointer;
    transition: 0.2s;
  }

  .nav-item i {
    font-size: 1.2rem;
    margin-bottom: 2px;
  }

  .nav-item:active {
    transform: scale(0.9);
    color: var(--primary);
  }

  /* 3. Botón Flotante Central (FAB) */
  .nav-fab-container {
    position: relative;
    top: -25px; /* Elevarlo sobre la barra */
    width: 60px;
    height: 60px;
  }

  .nav-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: 4px solid var(--bg-body); /* Borde para simular recorte */
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(37, 99, 235, 0.4);
    transition: transform 0.2s;
  }

  .nav-fab:active {
    transform: scale(0.95);
  }

  /* Ajuste para modo oscuro en el borde del FAB */
  [data-theme="dark"] .nav-fab {
    border-color: #0f172a; /* Debe coincidir con el fondo oscuro */
  }
}

/* --- ZONA DE PUBLICIDAD SIDEBAR --- */
.ad-zone-container {
  /* Se asegura que quede al final de la barra flex */
  margin-top: auto;
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-body); /* Un tono diferente sutil para separar */
  flex-shrink: 0; /* Evita que se aplaste si falta espacio */
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Estilo para el placeholder (borra esto cuando pongas un anuncio real) */
.ad-placeholder {
  width: 100%;
  max-width: 240px; /* Ancho estándar común */
  height: 240px; /* Alto estándar común */
  background-color: #e2e8f0;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: #64748b;
  font-size: 0.8rem;
  font-weight: 600;
  transition: 0.3s;
}

/* Adaptación al modo oscuro del placeholder */
[data-theme="dark"] .ad-zone-container {
  background: rgba(0, 0, 0, 0.2);
}
[data-theme="dark"] .ad-placeholder {
  background-color: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

/* Ajuste Responsive: ocultar anuncio en móviles si la pantalla es muy corta */
@media (max-height: 600px) and (max-width: 900px) {
  .ad-zone-container {
    display: none;
  }
}

/* --- TOASTS --- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 14px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  animation: slideIn 0.3s forwards;
  font-size: 0.95rem;
  font-weight: 500;
  pointer-events: auto;
  border-left: 5px solid var(--primary);
}
.toast.error {
  border-left-color: #ef4444;
}
@keyframes slideIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
@keyframes fadeOut {
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* --- LAYOUT --- */
.app-wrapper {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* SIDEBAR */
aside {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}

.brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-new {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 1rem;
  transition: background 0.2s;
}
.btn-new:hover {
  background: var(--primary-hover);
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  margin-bottom: 1rem;
}
.file-item {
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-main);
  border: 1px solid transparent;
  transition: all 0.2s;
}
.file-item:hover {
  background: rgba(59, 130, 246, 0.1);
}
.file-item.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--primary);
}
.file-info strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 2px;
}
.file-info small {
  color: var(--text-muted);
  font-size: 0.75rem;
}
.delete-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 8px;
  opacity: 0.6;
}
.file-item:hover .delete-btn {
  opacity: 1;
}

/* NUEVA SECCIÓN DE BACKUP */
.backup-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  display: flex;
  gap: 10px;
}
.btn-backup {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}
.btn-backup:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--text-muted);
}
.btn-backup i {
  font-size: 1rem;
  color: var(--primary);
}

/* MAIN */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  position: relative;
  width: 100%;
}

.top-bar {
  padding: 10px 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-panel);
  height: 65px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text-main);
  cursor: pointer;
  padding: 5px;
}

input.doc-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-main);
  padding: 5px;
  min-width: 0;
}
input.doc-title::placeholder {
  color: var(--input-placeholder);
  font-weight: 400;
}

.actions-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-save {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0 16px;
  height: 40px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.btn-save:hover {
  background: var(--primary-hover);
}

/* WORKSPACE */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#editor {
  flex: 1;
  border: none;
  font-size: 1.05rem;
  background: var(--bg-panel);
  color: var(--text-main);
}

.ql-toolbar {
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  background: var(--bg-panel);
  flex-wrap: wrap;
}
.ql-toolbar .ql-stroke {
  stroke: var(--text-main) !important;
}
.ql-toolbar .ql-fill {
  fill: var(--text-main) !important;
}
.ql-toolbar .ql-picker {
  color: var(--text-main) !important;
}

.ql-snow .ql-picker-options {
  background-color: var(--bg-panel);
}
.code-container {
  width: 40%;
  background: var(--code-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.code-header {
  padding: 10px 15px;
  background: rgba(0, 0, 0, 0.2);
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.code-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  margin-left: 5px;
}

textarea#html-output {
  flex: 1;
  background: var(--code-bg);
  color: #a5b4fc;
  border: none;
  padding: 1.5rem;
  resize: none;
  font-family: "Consolas", monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s;
}
.overlay.open {
  display: block;
  opacity: 1;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  aside {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.2);
  }
  aside.open {
    transform: translateX(0);
    z-index: 1000;
  }
  .menu-toggle {
    display: block;
  }
  .workspace {
    flex-direction: column;
  }
  .editor-container {
    flex: none;
    height: 55%;
  }
  .code-container {
    width: 100%;
    height: 45%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .btn-save span {
    display: none;
  }
  .btn-save {
    padding: 0 12px;
  }
}
@media (max-width: 480px) {
  .ql-toolbar button {
    padding: 3px 5px;
    width: 24px;
  }
  .editor-container {
    height: 50%;
  }
  .code-container {
    height: 50%;
  }
}

/* Estilos específicos para el Plugin */
.cleaner-area {
  width: 100%;
  height: 120px;
  background: var(--bg-body);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: "Fira Code", monospace;
  font-size: 0.85rem;
  resize: vertical;
}
.cleaner-area:focus {
  border-color: var(--primary);
  outline: none;
}

/* Estilos Contador de Palabras */
.word-counter {
  padding: 5px 15px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  font-weight: 600;
}

/* Estilos Selector de Colores */
.color-grid {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 10px 0;
}
.color-swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s;
}
.color-swatch:hover {
  transform: scale(1.1);
  border-color: var(--text-main);
}

/* 1. El contenedor principal se convierte en una columna flexible que no hace scroll */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  height: 100%; /* Ocupa todo el alto disponible */
  overflow: hidden; /* IMPORTANTE: Corta el scroll general */
}

/* 2. El editor (Quill) ocupa el espacio sobrante y maneja su propio scroll */
#editor {
  border: none;
  font-size: 1rem;
  color: var(--text-main);
  flex: 1; /* Ocupa todo el espacio entre la barra y el contador */
  overflow-y: auto; /* AQUÍ es donde ocurre el scroll ahora */
}

/* 3. El contador se queda pegado abajo */
.word-counter {
  padding: 5px 15px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  font-weight: 600;
  flex-shrink: 0; /* Asegura que nunca se encoja ni desaparezca */
  z-index: 10; /* Se asegura de estar por encima */
}

/* Estilo Botón Ko-fi */
.kofi-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background-color: #ff5f5f; /* Color oficial Ko-fi */
  color: white;
  text-decoration: none;
  font-weight: 700;
  padding: 12px 25px;
  border-radius: 50px;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(255, 95, 95, 0.3);
}

.kofi-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 95, 95, 0.4);
  background-color: #ff4545;
}

.kofi-btn i {
  font-size: 1.2rem;
}

/* --- CORRECCIÓN RESPONSIVE --- */
@media (max-width: 900px) {
  /* 1. Ocultar FORZOSAMENTE los botones de arriba */
  .top-bar .actions-right {
    display: none !important;
    width: 0 !important;
    overflow: hidden;
  }

  /* 2. Centrar el título para que se vea mejor */
  input.doc-title {
    text-align: center;
    padding-right: 0;
  }

  /* 3. Asegurar espacio para la barra de abajo */
  body {
    padding-bottom: 80px;
  }

  /* 4. Mostrar la barra móvil */
  .mobile-nav {
    display: flex;
    /* (El resto de estilos de la barra móvil se mantienen igual) */
  }
}

/* Estilos del Dialog Nativo */
dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--bg-panel);
  color: var(--text-main);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
  max-width: 600px;
  width: 90%;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
}

.dialog-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog-header h3 {
  margin: 0;
  font-size: 1.1rem;
}
.close-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
}

.dialog-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dialog-body label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.dialog-footer {
  padding: 15px 20px;
  background: var(--bg-body);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.cleaner-area {
  width: 100%;
  height: 100px;
  background: var(--bg-body);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: "Fira Code", monospace;
  font-size: 0.8rem;
  resize: vertical;
}
.btn-process {
  width: 100%;
  padding: 10px;
  background: var(--primary-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}
.btn-process:hover {
  background: var(--accent);
  color: white;
}

.btn-clear {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  padding: 0 15px;
  cursor: pointer;
  font-size: 1rem;
  transition: 0.2s;
}
.btn-clear:hover {
  background: var(--danger);
  color: white;
}
