/* Reset y variables */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1a1a1a;
  --bg-hover: #252525;
  --border-color: #2a2a2a;
  --text-primary: #e5e5e5;
  --text-secondary: #a0a0a0;
  --text-muted: #6b6b6b;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --code-bg: #1e1e1e;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", sans-serif;
  --font-mono: "SF Mono", "Monaco", "Inconsolata", "Fira Code", "Consolas", monospace;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  line-height: 1.6;
  /* Added smooth transition for theme changes */
  transition: background-color 0.3s ease, color 0.3s ease;
}

body.light-theme {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e5e5e5;
  --bg-hover: #e0e0e0;
  --border-color: #d0d0d0;
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #8a8a8a;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --code-bg: #f0f0f0;
}

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

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.file-controls {
  display: flex;
  gap: 0.5rem;
}

.file-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
}

.file-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.file-btn svg {
  width: 18px;
  height: 18px;
}

.view-controls {
  display: flex;
  gap: 0.5rem;
}

.view-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
}

.view-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.view-btn.active {
  background-color: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.view-btn svg {
  width: 18px;
  height: 18px;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  flex-wrap: wrap;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background-color: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toolbar-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.toolbar-btn:active {
  background-color: var(--bg-tertiary);
}

.toolbar-text {
  font-size: 0.875rem;
  font-weight: 600;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
  margin: 0 0.5rem;
}

/* Theme Toggle Button Styles */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.theme-toggle:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
  position: absolute;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.theme-toggle .sun-icon {
  opacity: 0;
  transform: rotate(-90deg);
}

.theme-toggle .moon-icon {
  opacity: 1;
  transform: rotate(0deg);
}

body.light-theme .theme-toggle .sun-icon {
  opacity: 1;
  transform: rotate(0deg);
}

body.light-theme .theme-toggle .moon-icon {
  opacity: 0;
  transform: rotate(90deg);
}

/* Main content */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.editor-panel,
.preview-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 120px;
}

.editor-panel {
  flex: 1 1 50%;
}

.preview-panel {
  flex: 1 1 50%;
}

.panel-header {
  height: 45px;
  min-height: 45px;
  padding: 0 1rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Resizer between panels */
.panel-resizer {
  width: 5px;
  min-width: 5px;
  background-color: var(--border-color);
  cursor: col-resize;
  position: relative;
  z-index: 5;
  transition: background-color 0.15s ease;
  flex-shrink: 0;
}

.panel-resizer:hover,
.panel-resizer.dragging {
  background-color: var(--accent-primary);
}

.panel-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 40px;
  border-radius: 2px;
  background: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.panel-resizer:hover::after,
.panel-resizer.dragging::after {
  opacity: 1;
  background: white;
}

.panel-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.editor-textarea {
  flex: 1;
  padding: 1.5rem;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.6;
  resize: none;
  overflow-y: auto;
}

.editor-textarea::placeholder {
  color: var(--text-muted);
}

.preview-content {
  flex: 1;
  padding: 1.5rem;
  background-color: var(--bg-primary);
  overflow-y: auto;
}

/* Preview siempre editable */
.preview-content {
  cursor: text;
}

.preview-content:focus {
  outline: none;
}

/* Hover sutil sobre elementos editables */
.preview-content > *:hover {
  background-color: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  transition: background-color 0.15s ease;
}

body.light-theme .preview-content > *:hover {
  background-color: rgba(0, 0, 0, 0.03);
}


/* Estilos para el contenido renderizado */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.preview-content h1 {
  font-size: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.preview-content h2 {
  font-size: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.preview-content h3 {
  font-size: 1.25rem;
}

.preview-content h4 {
  font-size: 1.125rem;
}

.preview-content h5 {
  font-size: 1rem;
}

.preview-content h6 {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.preview-content p {
  margin-bottom: 1rem;
  line-height: 1.6;
}

.preview-content a {
  color: var(--accent-primary);
  text-decoration: none;
}

.preview-content a:hover {
  text-decoration: underline;
}

.preview-content strong {
  font-weight: 600;
}

.preview-content em {
  font-style: italic;
}

.preview-content code {
  padding: 0.2em 0.4em;
  background-color: var(--code-bg);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.875em;
}

.preview-content pre {
  margin: 1rem 0;
  padding: 1rem;
  background-color: var(--code-bg);
  border-radius: 6px;
  overflow-x: auto;
}

.preview-content pre code {
  padding: 0;
  background-color: transparent;
  font-size: 0.875rem;
}

.preview-content ul,
.preview-content ol {
  margin: 1rem 0;
  padding-left: 2rem;
}

.preview-content li {
  margin-bottom: 0.5rem;
}

.preview-content blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 4px solid var(--accent-primary);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
}

.preview-content hr {
  margin: 2rem 0;
  border: none;
  border-top: 1px solid var(--border-color);
}

.preview-content table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
}

.preview-content table th,
.preview-content table td {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.preview-content table th {
  background-color: var(--bg-secondary);
  font-weight: 600;
}

.preview-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1rem 0;
}

/* Scrollbar personalizado */
.editor-textarea::-webkit-scrollbar,
.preview-content::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.editor-textarea::-webkit-scrollbar-track,
.preview-content::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.editor-textarea::-webkit-scrollbar-thumb,
.preview-content::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
}

.editor-textarea::-webkit-scrollbar-thumb:hover,
.preview-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Emoji Picker Styles */
.emoji-picker {
  position: absolute;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-height: 400px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  z-index: 1000;
}

.emoji-picker.active {
  display: flex;
}

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

.emoji-picker-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.emoji-picker-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.emoji-picker-close:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.emoji-picker-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
}

.emoji-tab {
  background: none;
  border: none;
  font-size: 1.5rem;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  opacity: 0.6;
}

.emoji-tab:hover {
  background-color: var(--bg-hover);
  opacity: 1;
}

.emoji-tab.active {
  background-color: var(--bg-hover);
  opacity: 1;
}

.emoji-picker-content {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
  padding: 0.75rem;
  overflow-y: auto;
  max-height: 280px;
}

.emoji-item {
  background: none;
  border: none;
  font-size: 1.5rem;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-item:hover {
  background-color: var(--bg-hover);
  transform: scale(1.2);
}

.emoji-picker-content::-webkit-scrollbar {
  width: 6px;
}

.emoji-picker-content::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.emoji-picker-content::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

.emoji-picker-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Estados de vista */
.main-content.view-editor .preview-panel {
  display: none;
}

.main-content.view-editor .panel-resizer {
  display: none;
}

/* El editor ocupa todo el espacio cuando no hay preview */
.main-content.view-editor .editor-panel {
  flex: 1 !important;
  width: auto !important;
  height: auto !important;
}

.main-content.view-preview .editor-panel {
  display: none;
}

.main-content.view-preview .panel-resizer {
  display: none;
}

/* La preview ocupa todo el espacio cuando no hay editor */
.main-content.view-preview .preview-panel {
  flex: 1 !important;
  width: auto !important;
  height: auto !important;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }

  .header-left {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .file-controls {
    width: 100%;
    justify-content: space-between;
  }

  .file-btn span {
    display: none;
  }

  .view-controls {
    width: 100%;
    justify-content: space-between;
  }

  .view-btn span {
    display: none;
  }

  .toolbar {
    padding: 0.5rem;
  }

  .main-content {
    flex-direction: column;
  }

  .panel-resizer {
    width: 100%;
    height: 5px;
    min-height: 5px;
    min-width: unset;
    cursor: row-resize;
  }

  .panel-resizer::after {
    width: 40px;
    height: 3px;
  }

  .editor-panel {
    border-bottom: none;
  }
}

/* Drop Zone Overlay */
.drop-zone-overlay {
  position: absolute;
  inset: 0;
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.2s ease;
}

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

body.light-theme .drop-zone-overlay {
  background-color: rgba(255, 255, 255, 0.85);
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem 4rem;
  border: 2px dashed var(--accent-primary);
  border-radius: 16px;
  color: var(--text-primary);
  animation: drop-zone-pulse 1.5s ease-in-out infinite;
  pointer-events: none;
}

.drop-zone-content svg {
  color: var(--accent-primary);
  animation: drop-zone-bounce 1s ease-in-out infinite;
}

.drop-zone-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-zone-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

@keyframes drop-zone-pulse {
  0%, 100% {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.1);
  }
  50% {
    border-color: var(--accent-hover);
    box-shadow: 0 0 30px 10px rgba(59, 130, 246, 0.15);
  }
}

@keyframes drop-zone-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

/* ========================================
   Color Swatch Inline Preview
   ======================================== */

.color-swatch-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 4px;
  margin: 0 2px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  vertical-align: baseline;
  transition: all 0.2s ease;
  cursor: default;
}

.color-swatch-inline:hover {
  border-color: var(--accent-primary);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
  transform: translateY(-1px);
}

.color-swatch-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.1),
    inset 0 1px 2px rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.color-swatch-inline:hover .color-swatch-dot {
  transform: scale(1.2);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.15),
    0 2px 6px rgba(0, 0, 0, 0.15),
    inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.color-swatch-code {
  font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
  font-size: 0.82em;
  color: var(--text-secondary);
  background: none !important;
  border: none !important;
  padding: 0 !important;
  letter-spacing: 0.02em;
  font-weight: 500;
}

/* Light theme overrides */
body.light-theme .color-swatch-inline {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-theme .color-swatch-dot {
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.08),
    inset 0 1px 2px rgba(255, 255, 255, 0.5);
}

body.light-theme .color-swatch-code {
  color: #4a5568;
}

/* ========================================
   Font Preview Inline
   ======================================== */

.font-preview-inline {
  display: inline-flex;
  align-items: stretch;
  margin: 4px 2px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  vertical-align: baseline;
  transition: all 0.25s ease;
  cursor: default;
}

.font-preview-inline:hover {
  border-color: var(--accent-primary);
  box-shadow: 0 3px 12px rgba(59, 130, 246, 0.12);
  transform: translateY(-1px);
}

.font-preview-name {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 0.8em;
  font-weight: 600;
  color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
  letter-spacing: 0.01em;
  white-space: nowrap;
  border-right: 1px solid var(--border-color);
}

.font-preview-sample {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  font-size: 1.05em;
  color: var(--text-primary);
  white-space: nowrap;
  letter-spacing: 0.02em;
  transition: font-family 0.3s ease;
}

/* Light theme overrides */
body.light-theme .font-preview-inline {
  background: rgba(0, 0, 0, 0.025);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-theme .font-preview-name {
  background: rgba(59, 130, 246, 0.06);
  color: #3b82f6;
}

body.light-theme .font-preview-sample {
  color: #1a1a2e;
}
