/* ==========================================================================
   Editor de diagramas Mermaid - Estilos visuales
   ========================================================================== */

:root {
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --info-color: #06b6d4;

  --bg-app: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-header: #19243d;
  --bg-input: #0f172a;
  --border-color: #1e293b;
  --border-color-focus: #6366f1;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-heading: 'Outfit', 'Inter', sans-serif;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-header: #f8fafc;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-color-focus: #6366f1;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* Reset básico y Layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

.main-wrapper {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.tool-with-sidebar {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: start;
}

.tool-main-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Hero */
.tool-hero {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.tool-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary-color);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 20px;
  margin-bottom: 12px;
}

.tool-hero h2 {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.tool-hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Barra de herramientas */
.diagram-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

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

.toolbar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-family: var(--font-main);
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.form-select:focus {
  border-color: var(--border-color-focus);
}

.btn-action-sm, .btn-primary-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-family: var(--font-main);
}

.btn-action-sm {
  background: var(--bg-card-header);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-action-sm:hover {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

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

.btn-primary-sm:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Área de trabajo Split */
.diagram-workspace {
  display: grid;
  grid-template-columns: 42% 58%;
  gap: 16px;
  min-height: 560px;
}

.editor-pane, .preview-pane {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.pane-header {
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.editor-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.status-valid {
  background: var(--success-color);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.status-dot.status-error {
  background: var(--danger-color);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.editor-body {
  flex: 1;
  display: flex;
}

.code-textarea {
  width: 100%;
  height: 100%;
  min-height: 480px;
  background: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  padding: 16px;
  border: none;
  resize: none;
  outline: none;
  tab-size: 2;
}

/* Controles de zoom en la vista previa */
.preview-zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
}

.btn-zoom {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  transition: all 0.15s;
}

.btn-zoom:hover {
  background: var(--primary-light);
  color: var(--primary-color);
}

.zoom-level {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0 6px;
  color: var(--text-main);
  min-width: 44px;
  text-align: center;
}

/* Escenario interactivo */
.preview-stage-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(var(--border-color) 1px, transparent 1px);
  background-size: 16px 16px;
  background-color: var(--bg-card);
  min-height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.preview-stage-container.dragging {
  cursor: grabbing;
}

.preview-viewport {
  transform-origin: center center;
  transition: transform 0.05s ease-out;
  padding: 24px;
  display: inline-block;
  user-select: none;
}

.mermaid-target {
  display: flex;
  justify-content: center;
  align-items: center;
}

.mermaid-target svg {
  max-width: none !important;
  height: auto;
}

.drag-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  color: #cbd5e1;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Guía rápida */
.guide-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
}

.guide-card-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.guide-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.guide-item h4 {
  font-size: 0.85rem;
  color: var(--primary-color);
  margin-bottom: 6px;
}

.guide-item code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  line-height: 1.5;
}

/* FAQ */
.faq-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.faq-section h3 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  margin-bottom: 16px;
}

.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-card-header);
}

.faq-question {
  padding: 14px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  user-select: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question svg {
  transition: transform 0.2s;
  color: var(--primary-color);
}

.faq-item[open] .faq-question svg {
  transform: rotate(180deg);
}

.faq-answer {
  padding: 0 16px 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* Sidebar */
.tool-sidebar {
  width: 300px;
}

.ad-sidebar-wrapper {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ad-sidebar-card {
  width: 300px;
  min-height: 600px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-dev-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
}

.ad-size-badge {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-color);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px 18px;
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.5;
}

.modal-footer {
  padding: 12px 18px;
  background: var(--bg-card-header);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  background: var(--primary-color);
  color: #ffffff;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 1024px) {
  .tool-with-sidebar {
    grid-template-columns: 1fr;
  }
  .tool-sidebar {
    width: 100%;
  }
  .ad-sidebar-card {
    width: 100%;
    min-height: 250px;
  }
  .diagram-workspace {
    grid-template-columns: 1fr;
  }
  .code-textarea {
    min-height: 300px;
  }
  .preview-stage-container {
    min-height: 380px;
  }
}
