/* ═══════════════════════════════════════════════════════════════
   canvas.css  —  Draven AI Canvas Panel
   ═══════════════════════════════════════════════════════════════ */

/* ── Backdrop (solo móvil, para cerrar) ─────────────────────── */
#draven-canvas-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

#draven-canvas-backdrop.cv-backdrop-show {
  opacity: 1;
  pointer-events: auto;
}

/* Solo visible en móvil */
@media (min-width: 921px) {
  #draven-canvas-backdrop { display: none !important; }
}

/* ── Panel principal ─────────────────────────────────────────── */
#draven-canvas-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 44%;
  min-width: 340px;
  max-width: 720px;
  height: 100dvh;          /* dynamic viewport height para móvil */
  background: var(--surface, #09090c);
  border-left: 1px solid var(--border, #1e1e24);
  display: flex;
  flex-direction: column;
  z-index: 1101;
  transform: translateX(110%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s;
  box-shadow: none;
  overflow: hidden;
}

#draven-canvas-panel.cv-open {
  transform: translateX(0);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.45);
}

/* Empujar el área de chat en desktop cuando el canvas está abierto */
body.cv-body-open #spa-root,
body.cv-body-open .main-layout,
body.cv-body-open .chat-layout {
  padding-right: 44%;
  transition: padding-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Móvil: pantalla completa */
@media (max-width: 920px) {
  #draven-canvas-panel {
    width: 100%;
    min-width: unset;
    max-width: unset;
    border-left: none;
  }

  body.cv-body-open #spa-root,
  body.cv-body-open .main-layout,
  body.cv-body-open .chat-layout {
    padding-right: 0;
  }
}

/* ── Header ──────────────────────────────────────────────────── */
.cv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 14px;
  height: 52px;
  border-bottom: 1px solid var(--border, #1e1e24);
  flex-shrink: 0;
  gap: 6px;
  background: var(--surface, #09090c);
}

.cv-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.cv-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent-dim, rgba(100, 116, 248, 0.12));
  color: var(--accent, #6474f8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cv-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #eeeef0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cv-header-right {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.cv-tabs {
  display: flex;
  gap: 1px;
  background: var(--surface-3, #161619);
  border-radius: 7px;
  padding: 2px;
  margin-right: 6px;
}

.cv-tab {
  background: transparent;
  border: none;
  padding: 4px 11px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2, #8a8a96);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  line-height: 1;
}

.cv-tab:hover:not(.cv-tab--active) {
  color: var(--text, #eeeef0);
}

.cv-tab--active {
  background: var(--surface-4, #1c1c21);
  color: var(--text, #eeeef0);
}

/* ── Botones de acción ───────────────────────────────────────── */
.cv-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
  line-height: 1;
}

.cv-btn--primary {
  background: var(--accent, #6474f8);
  color: #fff;
  border-color: var(--accent, #6474f8);
}

.cv-btn--primary:hover {
  filter: brightness(1.12);
}

.cv-btn--ghost {
  background: transparent;
  color: var(--text-2, #8a8a96);
  border-color: var(--border-2, #272730);
}

.cv-btn--ghost:hover {
  background: var(--surface-3, #161619);
  color: var(--text, #eeeef0);
}

/* En móvil, ocultar el label "Run" */
@media (max-width: 640px) {
  .cv-btn span { display: none; }
  .cv-btn { padding: 7px 9px; }
}

.cv-close {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-2, #8a8a96);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.14s;
  margin-left: 2px;
}

.cv-close:hover {
  background: var(--surface-3, #161619);
  color: var(--text, #eeeef0);
}

/* ── Body ────────────────────────────────────────────────────── */
.cv-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.cv-code-pane,
.cv-preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── Editor (textarea) ───────────────────────────────────────── */
.cv-editor {
  flex: 1;
  width: 100%;
  padding: 16px 18px;
  background: var(--bg, #020203);
  color: var(--text, #eeeef0);
  border: none;
  outline: none;
  resize: none;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code',
               ui-monospace, 'SFMono-Regular', Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  tab-size: 2;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.cv-editor:focus {
  outline: none;
}

.cv-editor::selection {
  background: var(--accent-dim-2, rgba(100, 116, 248, 0.22));
}

/* ── Preview iframe ──────────────────────────────────────────── */
#cv-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
  display: block;
}

/* ── Botón "Canvas" en bloques de código ─────────────────────── */
.code-canvas-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border-2, #272730);
  background: transparent;
  color: var(--accent, #6474f8);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
  white-space: nowrap;
  line-height: 1.2;
}

.code-canvas-btn:hover {
  background: var(--accent-dim, rgba(100, 116, 248, 0.1));
  border-color: var(--accent, #6474f8);
}

.code-canvas-btn svg {
  flex-shrink: 0;
}

/* ── Tema claro ──────────────────────────────────────────────── */
html.theme-light #draven-canvas-panel,
body.theme-light #draven-canvas-panel {
  background: var(--surface, #ffffff);
  border-left-color: var(--border, rgba(0,0,0,0.08));
}

html.theme-light .cv-editor,
body.theme-light .cv-editor {
  background: var(--bg, #f5f5f7);
  color: var(--text, #1a1a1e);
}

html.theme-light #cv-iframe,
body.theme-light #cv-iframe {
  background: #ffffff;
}
