.app {
  display: none;
  /* ðŸ”’ OCULTO POR DEFECTO - Se desbloquea con /api/css/unlock */
  grid-template-rows: auto 1fr 28px;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--titlebar-bg);
  flex-wrap: wrap;
  row-gap: 6px;
  overflow: visible;
  min-height: 54px;
}
.topbar .brand { flex: 0 0 auto; }
.topbar > .topbar-drawer { display: contents; }

.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 14px;
  color: #cccccc;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Evita que el header se desajuste al cargar un proyecto:
   los toolbars dentro del topbar nunca envuelven sus items a otra línea,
   y los items individuales (user-menu, botones, selects) no se rompen. */
.topbar { min-width: 0; }
.topbar > * { min-width: 0; }
.topbar .toolbar {
  flex-wrap: nowrap;
  min-width: 0;
  overflow: visible;
}
.topbar .toolbar > * { flex-shrink: 0; }
.topbar #entrySelect { max-width: 180px; }
.topbar .user-menu,
.topbar .user-menu-toggle { flex-shrink: 0; flex-wrap: nowrap; }

/* Download dropdown (desktop) - el menú flota sobre el header */
.download-dropdown { position: relative; display: inline-block; }
.download-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 180px;
  background: var(--panel-2, #2b2d30);
  border: 1px solid var(--border, #3c3f41);
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
  z-index: 1000;
  overflow: hidden;
}
.download-dropdown.open .download-dropdown-menu { display: block; }
.download-dropdown-item {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--ink, #ccc);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.download-dropdown-item:hover { background: var(--accent, #1e90ff); color: #fff; }

/* Import dropdown — un único botón que agrupa todas las opciones de importación */
.import-dropdown { position: relative; display: inline-block; }
.import-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 200px;
  background: var(--panel-2, #2b2d30);
  border: 1px solid var(--border, #3c3f41);
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
  z-index: 1000;
  overflow: hidden;
}
.import-dropdown.open .import-dropdown-menu { display: block; }
.import-dropdown-item {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--ink, #ccc);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.import-dropdown-item:hover { background: var(--accent, #1e90ff); color: #fff; }

/* El menú de usuario siempre se ancla a la derecha del topbar */
.topbar #userMenuContainer,
.topbar #authToolbar { margin-left: auto; }

/* Todas las opciones del topbar pegadas a la derecha */
.topbar .topbar-actions { margin-left: auto; }
.topbar .topbar-actions ~ .toolbar,
.topbar .topbar-actions ~ #userMenuContainer,
.topbar .topbar-actions ~ #authToolbar { margin-left: 0; }

button,
select {
  font-family: var(--sans);
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

button:hover,
select:hover {
  border-color: var(--accent);
  background: rgba(90, 93, 94, 0.4);
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover {
  background: #1a8ad4;
}

button.secondary {
  background: var(--panel-2);
}

.workarea {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(280px, 1fr) minmax(280px, 38%);
  gap: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  padding: 12px 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  animation: rise 0.5s ease;
}

.panel-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.file-tree {
  flex: 1;
  overflow: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
  user-select: none;
}

.tree-item:hover {
  background: rgba(44, 49, 55, 0.8);
}

.tree-item.active {
  background: rgba(4, 57, 94, 0.6);
  font-weight: 600;
}

.tree-item.selected {
  background: rgba(4, 57, 94, 0.4);
  outline: 1px solid rgba(30, 120, 200, 0.3);
}

.tree-item.dir {
  cursor: pointer;
  color: var(--muted);
}

.tree-item.dir .tree-chevron {
  display: inline-block;
  width: 16px;
  font-size: 10px;
  text-align: center;
  transition: transform 0.15s ease;
  color: var(--muted);
  flex-shrink: 0;
}

.tree-item.dir.collapsed .tree-chevron {
  transform: rotate(-90deg);
}

.explorer-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
}

.explorer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.explorer-toolbar button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.explorer-toolbar button svg {
  display: block;
  flex-shrink: 0;
}

.explorer-toolbar button:hover {
  background: rgba(90, 93, 94, 0.4);
  color: var(--ink);
}

.tree-inline-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--accent);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 3px;
  outline: none;
  margin-left: 4px;
}

.tree-item .tree-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-item.drag-over {
  background: rgba(0, 120, 212, 0.25) !important;
  outline: 1px dashed var(--accent);
  outline-offset: -1px;
}

.tree-item.dragging {
  opacity: 0.4;
}

.file-tree.drag-over-root {
  background: rgba(0, 120, 212, 0.08);
  outline: 1px dashed rgba(0, 120, 212, 0.3);
  outline-offset: -2px;
}

.tree-icon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-size: 0;
  font-weight: 600;
  text-transform: uppercase;
  background: rgba(75, 156, 211, 0.2);
  color: #75beff;
}
.tree-icon svg, .tree-chevron svg { display: block; }

.tree-icon.asset {
  background: rgba(220, 220, 170, 0.15);
  color: #dcdcaa;
}

.tree-icon.dir {
  background: rgba(133, 133, 133, 0.15);
  color: var(--muted);
}

.sidebar-footer {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto auto 1fr;
  background: var(--panel);
  border-right: 1px solid var(--border);
  animation: rise 0.6s ease;
  overflow: hidden;
  min-height: 0;
}

.editor-head {
  background: var(--panel);
}

.tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--tab-inactive-bg);
  overflow-x: auto;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 0;
  background: var(--tab-inactive-bg);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.tab:hover {
  background: rgba(44, 49, 55, 0.6);
  border-color: var(--border);
}

.tab.active {
  background: var(--tab-active-bg);
  border-bottom: 1px solid var(--tab-active-bg);
  color: #ffffff;
  font-weight: 500;
}

.tab .close {
  font-weight: 700;
  opacity: 0.5;
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.editor-wrapper {
  position: relative;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.editor-code-area {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  contain: layout style;
}

.highlight-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 16px;
  padding-left: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  color: #d4d4d4;
  background: transparent;
  tab-size: 2;
  border: none;
  word-wrap: normal;
  overflow-wrap: normal;
  contain: layout style paint;
}

/* VS Code Dark+ token colors */
.hl-tag {
  color: #569cd6;
}

.hl-attr {
  color: #9cdcfe;
}

.hl-attr-value {
  color: #ce9178;
}

.hl-string {
  color: #ce9178;
}

.hl-comment {
  color: #6a9955;
  font-style: italic;
}

.hl-keyword {
  color: #c586c0;
}

.hl-keyword2 {
  color: #569cd6;
}

.hl-function {
  color: #dcdcaa;
}

.hl-number {
  color: #b5cea8;
}

.hl-operator {
  color: #d4d4d4;
}

.hl-punctuation {
  color: #808080;
}

.hl-property {
  color: #9cdcfe;
}

.hl-selector {
  color: #d7ba7d;
}

.hl-css-prop {
  color: #9cdcfe;
}

.hl-css-value {
  color: #ce9178;
}

.hl-css-unit {
  color: #b5cea8;
}

.hl-doctype {
  color: #808080;
}

.hl-entity {
  color: #569cd6;
}

.hl-special {
  color: #569cd6;
}

.hl-regexp {
  color: #d16969;
}

.hl-template {
  color: #569cd6;
}

.hl-template-expr {
  color: #d4d4d4;
}

.hl-json-key {
  color: #9cdcfe;
}

.hl-boolean {
  color: #569cd6;
}

.hl-null {
  color: #569cd6;
}

.hl-error-line {
  background: rgba(255, 0, 0, 0.12);
  display: inline-block;
  width: 100%;
}

.errors-panel {
  border-top: 1px solid var(--border);
  padding: 0;
  font-size: 12px;
  max-height: 140px;
  overflow: auto;
  display: none;
  background: #1e1e1e;
  font-family: var(--mono);
}

.errors-panel.active {
  display: block;
}

.errors-panel .error-header {
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #cccccc;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.errors-panel .error-count {
  background: #f14c4c;
  color: white;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
}

.errors-panel .error-item {
  padding: 4px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border-bottom: 1px solid rgba(60, 60, 60, 0.4);
  cursor: pointer;
}

.errors-panel .error-item:hover {
  background: rgba(44, 49, 55, 0.6);
}

.errors-panel .error-icon {
  color: #f14c4c;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.errors-panel .error-icon.warning {
  color: #cca700;
}

.errors-panel .error-msg {
  color: #cccccc;
  flex: 1;
}

.errors-panel .error-loc {
  color: #858585;
  flex-shrink: 0;
  font-size: 11px;
}

/* Error indicator in the status bar */
.status-errors {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

.status-errors .err-icon {
  color: #f14c4c;
}

.status-errors .warn-icon {
  color: #cca700;
}

.line-numbers {
  width: 48px;
  min-width: 48px;
  padding: 0;
  text-align: right;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: #858585;
  background: var(--panel);
  border-right: none;
  user-select: none;
  overflow: hidden;
  white-space: pre;
  flex-shrink: 0;
  position: relative;
  contain: layout style paint;
}

.editor-pane textarea#editor {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: none;
  resize: none;
  outline: none;
  padding: 16px;
  padding-left: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  background: transparent;
  color: transparent;
  caret-color: #aeafad;
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  tab-size: 2;
}

.editor-pane textarea#editor::selection {
  background: var(--selection);
  color: transparent;
}

.editor-pane textarea#editor::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.editor-pane textarea#editor::-webkit-scrollbar-track {
  background: transparent;
}

.editor-pane textarea#editor::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 0;
}

.editor-pane textarea#editor::-webkit-scrollbar-corner {
  background: var(--panel);
}

.editor-content {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.media-preview {
  position: absolute;
  inset: 0;
  display: none;
  background: #1e1e1e;
  z-index: 3;
  align-items: center;
  justify-content: center;
  overflow: auto;
  flex-direction: column;
  gap: 16px;
}

.media-preview.visible {
  display: flex;
}

.media-preview img {
  max-width: 100%;
  max-height: 80%;
  object-fit: contain;
  image-rendering: auto;
  border: 1px solid var(--border);
  background: repeating-conic-gradient(#333 0% 25%, #2a2a2a 0% 50%) 50% / 16px 16px;
}

.media-preview video,
.media-preview audio {
  max-width: 95%;
  max-height: 80%;
  border-radius: 4px;
  outline: none;
}

.media-preview .media-info {
  font-family: var(--mono);
  font-size: 12px;
  color: #858585;
  display: flex;
  gap: 16px;
  align-items: center;
}

.media-preview .media-info span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.media-preview .media-filename {
  font-family: var(--sans);
  font-size: 11px;
  color: #858585;
  letter-spacing: 0.02em;
}

.media-preview .media-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.media-preview .media-actions button {
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: #cccccc;
  cursor: pointer;
}

.media-preview .media-actions button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Base64 detected banner (injected dynamically) */
.b64-detected-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: rgba(0, 120, 212, 0.12);
  border-top: 1px solid rgba(0, 120, 212, 0.3);
  font-size: 12px;
  margin-top: 6px;
}

.b64-detected-bar .b64d-badge {
  background: rgba(0, 120, 212, 0.25);
  color: #75beff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.b64-detected-bar .b64d-msg {
  flex: 1;
  color: #cccccc;
  font-size: 12px;
}

.b64-detected-bar .b64d-btn {
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: #cccccc;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--sans);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.b64-detected-bar .b64d-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.b64-detected-bar .b64d-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.b64-detected-bar .b64d-btn.primary:hover {
  background: #1a8ad4;
}

/* Base64 viewer overlay */
.base64-viewer {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: #1e1e1e;
  z-index: 5;
}

.base64-viewer.visible {
  display: flex;
}

.base64-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.base64-viewer-header .b64-title {
  font-size: 12px;
  color: #cccccc;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.base64-viewer-header .b64-size {
  font-size: 11px;
  color: #858585;
  font-family: var(--mono);
}

.base64-viewer-header .b64-actions {
  display: flex;
  gap: 6px;
}

.base64-viewer-body {
  flex: 1;
  overflow: auto;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: #ce9178;
  word-break: break-all;
  white-space: pre-wrap;
  position: relative;
}

.base64-viewer-body::-webkit-scrollbar {
  width: 10px;
}

.base64-viewer-body::-webkit-scrollbar-track {
  background: transparent;
}

.base64-viewer-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
}

.base64-viewer-body .b64-loading {
  color: #858585;
  font-style: italic;
}

.base64-viewer-body .b64-prefix {
  color: #858585;
}

.base64-viewer-body .b64-data {
  color: #ce9178;
}

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 100;
  background: #252526;
  border: 1px solid #454545;
  border-radius: 5px;
  padding: 4px 0;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  font-family: var(--sans);
  font-size: 12px;
  display: none;
}

.ctx-menu.visible {
  display: block;
}

.ctx-menu-item {
  padding: 6px 24px;
  color: #cccccc;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctx-menu-item:hover {
  background: #04395e;
}

.ctx-menu-sep {
  height: 1px;
  background: #454545;
  margin: 4px 0;
}

.editor-empty {
  position: absolute;
  inset: 0;
  display: none;
  padding: 32px;
  color: #5a5a5a;
  font-size: 14px;
  background: var(--panel);
  z-index: 2;
  align-items: center;
  justify-content: center;
}

.editor-empty.visible {
  display: flex;
}

.output-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--panel);
  animation: rise 0.7s ease;
}

.output-tabs {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-bottom: 1px solid var(--border);
  background: var(--tab-inactive-bg);
}

.output-tabs-left {
  display: flex;
  gap: 6px;
}

.output-tabs-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

.external-deps-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.35);
  user-select: none;
  cursor: help;
  white-space: nowrap;
}

.open-in-tab-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1000;
  min-width: 220px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.open-in-tab-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.open-in-tab-menu button:hover {
  background: #374151;
}

.fullscreen-btn {
  font-size: 14px;
  padding: 6px 8px;
  display: none;
}

.fullscreen-btn.visible {
  display: block;
}

.preview-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
  width: 100vw !important;
  height: 100vh !important;
  background: white;
}

.preview-fullscreen iframe {
  width: 100%;
  height: 100%;
}

.output-tabs button {
  border-radius: 8px;
}

.output-tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Scrollbar global para sidebar y file-tree */
.file-tree::-webkit-scrollbar {
  width: 8px;
}

.file-tree::-webkit-scrollbar-track {
  background: transparent;
}

.file-tree::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
}

/* Selects dark */
select {
  background: var(--input-bg);
  color: var(--ink);
}

select option {
  background: #252526;
  color: #cccccc;
}

.output-view {
  display: none;
  height: 100%;
}

.output-view.active {
  display: grid;
  grid-template-rows: 1fr auto auto;
}

#output {
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
  outline: none;
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  background: #1e1e1e;
  color: #d4d4d4;
}

#output::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

#output::-webkit-scrollbar-track {
  background: transparent;
}

#output::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
}

#preview {
  border: none;
  width: 100%;
  height: 100%;
  background: white;
}

.warnings {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12px;
  color: #cca700;
  max-height: 120px;
  overflow: auto;
  display: none;
  background: rgba(204, 167, 0, 0.1);
}

.warnings.active {
  display: block;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--statusbar-text);
  background: var(--statusbar-bg);
  border-top: none;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 120, 212, 0.15);
  border: 2px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  z-index: 10;
  backdrop-filter: blur(3px);
}

.drop-overlay.active {
  display: flex;
}

/* â•â•â• AUTH MODAL & CLOUD STYLES â•â•â• */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.auth-overlay.visible {
  display: flex;
}

.auth-modal {
  background: #252526;
  border: 1px solid #454545;
  border-radius: 8px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.3s ease;
}

.auth-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.auth-modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #cccccc;
}

.auth-modal-close {
  background: none;
  border: none;
  color: #858585;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.auth-modal-close:hover {
  background: rgba(90, 93, 94, 0.4);
  color: #cccccc;
}

.auth-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-field label {
  font-size: 12px;
  color: #858585;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-field input {
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: #cccccc;
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-field input:focus {
  border-color: var(--accent);
}

.auth-error {
  color: #f14c4c;
  font-size: 12px;
  min-height: 16px;
}

.auth-success {
  color: #89d185;
  font-size: 12px;
}

.auth-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auth-switch {
  font-size: 12px;
  color: #858585;
}

.auth-switch a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.user-menu-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
  user-select: none;
}

.user-menu-toggle:hover {
  background: rgba(90, 93, 94, 0.4);
}

.user-menu-toggle .chevron {
  font-size: 10px;
  color: #858585;
  transition: transform 0.2s;
}

.user-menu.open .user-menu-toggle .chevron {
  transform: rotate(180deg);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.user-name {
  font-size: 12px;
  color: #cccccc;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #252526;
  border: 1px solid #454545;
  border-radius: 8px;
  min-width: 240px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 100;
  animation: rise 0.2s ease;
  overflow: hidden;
}

.user-menu.open .user-dropdown {
  display: block;
}

.user-dropdown-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-dropdown-header .dropdown-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.user-dropdown-header .dropdown-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.user-dropdown-header .dropdown-name {
  font-size: 13px;
  color: #cccccc;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dropdown-header .dropdown-email {
  font-size: 11px;
  color: #858585;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dropdown-items {
  padding: 6px 0;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13px;
  color: #cccccc;
  cursor: pointer;
  transition: background 0.12s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
}

.user-dropdown-item:hover {
  background: rgba(90, 93, 94, 0.3);
}

.user-dropdown-item .dd-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.user-dropdown-item.logout-item {
  color: #f14c4c;
}

.user-dropdown-item.logout-item:hover {
  background: rgba(241, 76, 76, 0.12);
}

/* Cloud projects panel */
.cloud-panel {
  position: fixed;
  top: 54px;
  right: 0;
  width: min(460px, 100vw);
  max-width: 100vw;
  height: calc(100vh - 54px - 28px);
  background: #252526;
  border-left: 1px solid var(--border);
  z-index: 50;
  display: none;
  flex-direction: column;
  animation: slideIn 0.2s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
}

.cloud-panel.visible {
  display: flex;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
  }

  to {
    transform: translateX(0);
  }
}

.cloud-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--titlebar-bg);
}

.cloud-panel-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #cccccc;
}

.cloud-project-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  box-sizing: border-box;
  min-width: 0;
}

.cloud-project-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  word-break: break-word;
}

.cloud-project-item:hover {
  background: rgba(44, 49, 55, 0.8);
}

.cloud-project-item .cp-name {
  font-size: 13px;
  color: #cccccc;
  font-weight: 500;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.cloud-project-item .cp-name .cp-num {
  display: inline-block;
  padding: 1px 7px;
  margin-right: 4px;
  border-radius: 10px;
  background: rgba(0, 120, 212, 0.18);
  color: #4fc3f7;
  font-weight: 600;
  font-size: 11px;
  vertical-align: 1px;
}

.cloud-project-item .cp-meta {
  font-size: 11px;
  color: #858585;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.cloud-project-item .cp-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
  max-width: 100%;
}

.cloud-project-item .cp-actions button {
  font-size: 11px;
  padding: 3px 8px;
  flex: 0 0 auto;
  max-width: 100%;
  white-space: nowrap;
}

.cp-publish-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.cp-publish-row .cp-link {
  font-size: 11px;
  color: var(--accent);
  background: rgba(0, 120, 212, 0.1);
  border: 1px solid rgba(0, 120, 212, 0.3);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}

.cp-publish-row .cp-link:hover {
  background: rgba(0, 120, 212, 0.2);
}

.cp-publish-row .cp-copied {
  font-size: 10px;
  color: #89d185;
  opacity: 0;
  transition: opacity 0.2s;
}

.cp-publish-row .cp-copied.show {
  opacity: 1;
}

.cp-actions .cp-publish-btn {
  background: #2ea043;
  border-color: #2ea043;
  color: white;
}

.cp-actions .cp-publish-btn:hover {
  background: #3fb950;
  border-color: #3fb950;
}

.cp-actions .cp-unpublish-btn {
  background: rgba(241, 76, 76, 0.15);
  border-color: rgba(241, 76, 76, 0.4);
  color: #f14c4c;
}

.cp-actions .cp-unpublish-btn:hover {
  background: rgba(241, 76, 76, 0.25);
}

/* ── UUID Badge: ID interno del proyecto para integraciones de Webhooks ── */
.cp-uuid-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.cp-uuid-label {
  font-size: 10px;
  color: #858585;
  letter-spacing: 0.3px;
  flex-shrink: 0;
  user-select: none;
}

.cp-uuid-badge {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11px;
  color: #b0c4de;
  background: rgba(100, 130, 180, 0.10);
  border: 1px solid rgba(100, 130, 180, 0.25);
  border-radius: 4px;
  padding: 2px 7px;
  cursor: pointer;
  letter-spacing: 0.4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s, border-color 0.15s;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cp-uuid-badge:hover {
  background: rgba(100, 130, 180, 0.22);
  border-color: rgba(100, 130, 180, 0.50);
  color: #d0ddf0;
}

.cp-uuid-badge svg {
  opacity: 0.55;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.cp-uuid-badge:hover svg {
  opacity: 0.9;
}

.cp-uuid-copied {
  display: none;
  font-size: 10px;
  color: #89d185;
  flex-shrink: 0;
}

.cp-uuid-copied.show {
  display: inline;
}

/* ── Garantía de contención del panel de proyectos ── */
/* Evita que el contenido se salga del panel sin importar cuántos botones u opciones haya */
.cloud-panel,
.cloud-panel * {
  box-sizing: border-box;
  min-width: 0;
}
.cloud-panel {
  overflow: hidden;
}
.cloud-panel > * {
  max-width: 100%;
}
.cloud-project-list > * {
  max-width: 100%;
}




.cloud-empty {
  padding: 32px 16px;
  text-align: center;
  color: #858585;
  font-size: 13px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}



/* ðŸ“± TABLET LAYOUT (< 820px) */





/* Default hidden */



/* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â• */
/* ðŸŽ¹ EDITOR FEATURES: Find Bar, Quick Open   */
/* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â• */

.ctx-shortcut {
  margin-left: auto;
  padding-left: 24px;
  font-size: 11px;
  color: #666;
  font-family: monospace;
}

.ctx-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.find-bar {
  position: absolute;
  top: 0;
  right: 16px;
  z-index: 100;
  background: #252526;
  border: 1px solid #3c3c3c;
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 8px 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
  min-width: 340px;
}

.find-row,
.replace-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.replace-row {
  margin-bottom: 0;
}

.find-input,
.replace-input {
  flex: 1;
  background: #1e1e1e;
  border: 1px solid #3c3c3c;
  color: #d4d4d4;
  padding: 4px 8px;
  font-size: 13px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  border-radius: 3px;
  outline: none;
}

.find-input:focus,
.replace-input:focus {
  border-color: #0078d4;
}

.find-count {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  min-width: 70px;
  text-align: center;
}

.find-btn {
  background: transparent;
  border: 1px solid #3c3c3c;
  color: #ccc;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s, border-color .15s;
}

.find-btn:hover {
  background: #3c3c3c;
  border-color: #555;
}

.find-close {
  color: #e06c75;
}

.quick-open-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, .5);
  display: flex;
  justify-content: center;
  padding-top: 80px;
}

.quick-open-box {
  background: #252526;
  border: 1px solid #3c3c3c;
  border-radius: 8px;
  width: 500px;
  max-height: 400px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
  display: flex;
  flex-direction: column;
}

.quick-open-input {
  width: 100%;
  background: #1e1e1e;
  border: none;
  border-bottom: 1px solid #3c3c3c;
  color: #d4d4d4;
  padding: 12px 14px;
  font-size: 14px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  outline: none;
  box-sizing: border-box;
}

.quick-open-list {
  overflow-y: auto;
  max-height: 340px;
}

.quick-open-item {
  padding: 8px 14px;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  font-family: monospace;
  transition: background .1s;
}

.quick-open-item:hover,
.quick-open-item.active {
  background: #094771;
  color: #fff;
}







/*  FIX: Editor Visibility Logic  */





/*  FINAL FIX: Hide the empty state overlay completely 
   since we moved the action button to the toolbar. 
   This ensures the editor code is always visible. */
#editorEmpty {
  display: none !important;
  pointer-events: none;
  visibility: hidden;
  height: 0 !important;
  width: 0 !important;
}

/* Ensure editor area is visible */
.editor-code-area {
  display: block !important;
  opacity: 1 !important;
}

/*  EMERGENCY OVERRIDE TO SHOW CODE  */





/*  FIX LAST LINE CLIPPING */



/* ?? FIX FINAL MÓVIL (CLEAN SLATE) ?? */






/* ====================================== */
/* ... existing content ... */

/* =========================================
   DESKTOP LAYOUT FIXES
   Forzar layout completo en PC para evitar zonas muertas en el editor
   ========================================= */
@media (min-width: 769px) {

  html,
  body {
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .app {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    /* Nota: display: grid se maneja vía unlock/JS, no lo forzamos aquí para no romper el boot */
  }

  /* Asegurar cadena de altura completa para el editor */
  .workarea {
    height: 100% !important;
    overflow: hidden !important;
  }

  .editor-pane {
    height: 100% !important;
    /* grid-template-rows se mantiene del original */
  }

  .editor-wrapper {
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 !important;
  }

  .editor-code-area {
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 !important;
    display: block !important;
    /* Asegura block context para relative children */
  }

  /* El textarea debe llenar absolutamente todo */
  .editor-pane textarea#editor {
    height: 100% !important;
    width: 100% !important;
    max-height: none !important;
    min-height: 100% !important;
    /* Forzar min-height */
  }

  /* Asegurar que el highlight layer no interfiera */
  .highlight-layer {
    height: 100% !important;
    pointer-events: none !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   ðŸ”‘ AUTHENTICATION & CLOUD MODALS (RESTORED)
   ══════════════════════════════════════════════════════════════ */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: none;
  background: rgba(0, 0, 0, 0.75);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.auth-overlay.visible {
  display: flex !important;
  opacity: 1;
}

.auth-modal {
  background: #252526;
  width: 380px;
  max-width: 90vw;
  border-radius: 8px;
  border: 1px solid #454545;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px) scale(0.98);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-overlay.visible .auth-modal {
  transform: translateY(0) scale(1);
}

.auth-modal-header {
  padding: 16px 20px;
  background: #2d2d2d;
  border-bottom: 1px solid #3c3c3c;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auth-modal-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #cccccc;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-modal-close {
  background: transparent;
  border: none;
  color: #858585;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.auth-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.auth-modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-field label {
  font-size: 11px;
  color: #858585;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-field input {
  background: #1e1e1e;
  border: 1px solid #3c3c3c;
  color: #cccccc;
  padding: 10px 12px;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field input:focus {
  border-color: #0078d4;
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.2);
}

.auth-error {
  color: #f14c4c;
  font-size: 13px;
  min-height: 20px;
  font-weight: 500;
  display: flex;
  align-items: center;
}

.auth-modal-footer {
  padding: 16px 20px;
  background: #2d2d2d;
  border-top: 1px solid #3c3c3c;
  text-align: center;
  font-size: 13px;
  color: #858585;
}

.auth-switch a {
  color: #0078d4;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  margin-left: 4px;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* Save Cloud Project Extra Styles */
#saveProjectPublic {
  width: 16px;
  height: 16px;
}

/* ══════════════════════════════════════════════════════════════
   📱 MOBILE LAYOUT  — pantallas < 1024px
   ══════════════════════════════════════════════════════════════ */

/* Ocultar barra móvil y toggle en escritorio */
.mobile-nav    { display: none; }
.topbar-toggle { display: none; }

/* En escritorio: drawer es transparente (contents = no genera caja) */
.topbar-drawer { display: contents; }

@media (max-width: 820px) {

  /* Reset global */
  html, body {
    overflow: hidden;
    height: 100%;
    width: 100%;
  }

  /* Grid principal: topbar | workarea | mobile-nav */
  .app {
    display: grid !important;
    grid-template-rows: 50px 1fr 56px !important;
    grid-template-columns: 1fr !important;
    height: 100dvh !important;
    width: 100vw !important;
    overflow: hidden !important;
  }

  /* Ocultar statusbar en móvil (reemplazada por mobile-nav) */
  .app > .statusbar {
    display: none !important;
  }

  /* Topbar compacta: solo brand + toggle */
  .topbar {
    padding: 0 10px !important;
    gap: 8px !important;
    overflow: visible !important;
    flex-wrap: nowrap !important;
    height: 50px;
    min-height: 50px;
    position: relative;
    z-index: 501;
  }

  .brand {
    font-size: 13px !important;
    white-space: nowrap;
    flex: 1;
    flex-shrink: 0;
  }

  /* Botón hamburguesa — siempre en la esquina derecha */
  .topbar-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--border, #444);
    border-radius: 6px;
    color: var(--fg, #ddd);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s;
    margin-left: auto;
    order: 99;
  }
  .topbar-toggle:active { background: rgba(255,255,255,0.08); }

  /* Drawer deslizable desde arriba */
  .topbar-drawer {
    display: flex !important;    /* override display:contents */
    flex-direction: column;
    gap: 8px;
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    background: var(--titlebar-bg, #1a1a2e);
    border-bottom: 2px solid var(--accent, #4f8ef7);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    padding: 12px 10px;
    z-index: 500;
    /* Estado inicial: oculto deslizado hacia arriba */
    transform: translateY(-110%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                opacity  0.28s ease;
    opacity: 0;
    pointer-events: none;
  }

  /* Drawer abierto */
  .topbar-drawer.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  /* Toolbars dentro del drawer: wrap + centrado */
  .topbar-drawer .toolbar {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  /* Workarea: una sola columna con una sola fila */
  .workarea {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
    height: 100% !important;
    overflow: hidden !important;
    position: relative;
  }

  /* Todos los paneles ocultos por defecto */
  .workarea .sidebar,
  .workarea .editor-pane,
  .workarea .output-pane {
    display: none !important;
    height: 100% !important;
    width: 100% !important;
    overflow: hidden;
  }

  /* --- Vista: archivos --- */
  .workarea.view-files .sidebar {
    display: flex !important;
    flex-direction: column;
  }

  /* --- Vista: editor --- */
  .workarea.view-editor .editor-pane {
    display: grid !important;
  }

  /* --- Vista: preview --- */
  .workarea.view-preview .output-pane {
    display: grid !important;
  }

  /* Default al cargar: mostrar archivos */
  .workarea:not(.view-editor):not(.view-preview) .sidebar {
    display: flex !important;
    flex-direction: column;
  }

  /* Sidebar móvil: sin borde derecho, ocupa todo */
  .sidebar {
    border-right: none !important;
    border-bottom: 1px solid var(--border);
  }

  .file-tree {
    flex: 1;
    overflow-y: auto;
  }

  /* Editor pane móvil */
  .editor-pane {
    grid-template-rows: auto auto 1fr !important;
  }

  /* Output pane móvil */
  .output-pane {
    grid-template-rows: auto 1fr !important;
  }

  #preview, .output-view.active {
    height: 100% !important;
  }

  /* Barra de navegación móvil (fija abajo) */
  .mobile-nav {
    display: flex !important;
    align-items: stretch;
    background: var(--titlebar-bg);
    border-top: 1px solid var(--border);
    height: 56px;
    z-index: 300;
    grid-row: 3;
  }

  .mobile-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    border-top: 2px solid transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    transition: color 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav .nav-item.active {
    color: var(--accent);
    border-top-color: var(--accent);
  }

  .mobile-nav .nav-item:active {
    background: rgba(255,255,255,0.05);
  }

  .mobile-nav .nav-icon {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-nav .nav-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
  }

  /* Cloud panel en móvil — ancho completo */
  .cloud-panel {
    width: 100% !important;
    top: 50px !important;
    height: calc(100dvh - 50px - 56px) !important;
  }

  /* Modales en móvil — ancho completo */
  .auth-modal {
    width: 94vw !important;
    max-width: 94vw !important;
  }

  /* Monaco / editor iframe ocupa todo */
  #monaco-container,
  #sandpack-frame {
    width: 100% !important;
    height: 100% !important;
  }

  /* Tabs del editor: scroll horizontal */
  .tabs {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
  }

  /* Ocultar botones de fullscreen en móvil */
  .fullscreen-btn {
    display: none !important;
  }

  /* Editor head compacto */
  .editor-head {
    padding: 6px 8px !important;
    font-size: 11px !important;
  }

  /* Output tabs compactos */
  .output-tabs {
    padding: 4px 6px !important;
  }

}
/* --- Layout: paneles redimensionables y colapsables (concept-inspired) ------ */
.workarea {
  /* Soporta ancho dinámico de sidebar y preview vía variables CSS.
     IMPORTANTE: el editor (columna central) tiene min-width 240px para que
     siempre quepan ↩ ↪ y los bytes del header sin ser tapados. */
  grid-template-columns:
    var(--sidebar-w, minmax(180px, 220px))
    minmax(240px, 1fr)
    var(--preview-w, minmax(280px, 38%));
}
.workarea.preview-collapsed {
  grid-template-columns: var(--sidebar-w, minmax(180px, 220px)) minmax(240px, 1fr) 0px !important;
}
.workarea.sidebar-collapsed {
  grid-template-columns: 0px minmax(240px, 1fr) var(--preview-w, minmax(280px, 38%)) !important;
}
.workarea.sidebar-collapsed.preview-collapsed {
  grid-template-columns: 0px minmax(240px, 1fr) 0px !important;
}

/* IMPORTANTE: NO usar display:none en los paneles colapsados.
   display:none los saca del grid flow y reasigna columnas (lo que hacía
   desaparecer el editor cuando se ocultaba el explorador). En su lugar
   ponemos la columna a 0px y clipeamos. */
.workarea > .sidebar,
.workarea > .editor-pane,
.workarea > .output-pane { min-width: 0; overflow: hidden; }
.workarea.sidebar-collapsed > .sidebar { padding: 0 !important; border: 0 !important; }
.workarea.preview-collapsed > .output-pane { border: 0 !important; }
.workarea.preview-collapsed .preview-resizer,
.workarea.sidebar-collapsed .sidebar-resizer { display: none; }

/* Strip fino redimensionable en el borde izquierdo del preview */
.output-pane { position: relative; }
.preview-resizer {
  position: absolute;
  top: 0;
  left: -2px;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 30;
  background: transparent;
  transition: background 0.15s ease;
}
.preview-resizer:hover,
.preview-resizer.dragging { background: #007acc; }

/* Strip fino redimensionable en el borde derecho del sidebar */
.sidebar { position: relative; }
.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -2px;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 30;
  background: transparent;
  transition: background 0.15s ease;
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging { background: #007acc; }

/* Capa global durante el drag para no perder el cursor sobre el iframe */
.resize-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  cursor: col-resize;
  background: transparent;
}

/* --- Editor head: que se adapte cuando el editor se hace estrecho ---------- */
/* Los botones (↩ ↪ y bytes) se anclan a la derecha con position:absolute,
   así jamás pueden ser tapados aunque el editor sea super estrecho.
   El #activePath siempre tiene padding-right reservado para ellos. */
.editor-head {
  position: relative;
  min-width: 0;
  gap: 6px;
  flex-wrap: nowrap;
  padding-right: 8px !important;
}
.editor-head #activePath {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 160px; /* reservar espacio para los botones absolutos */
}
.editor-head > div:last-child {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--panel);
  padding: 4px 6px 4px 10px;
  z-index: 5;
  display: flex;
  gap: 6px;
  align-items: center;
  /* Sombra suave a la izquierda para separar visualmente del path truncado */
  box-shadow: -8px 0 8px -6px var(--panel);
  border-radius: 4px;
  flex-shrink: 0;
}
.editor-head #activeMeta {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 11px;
}
.editor-head #undoBtn,
.editor-head #redoBtn {
  flex-shrink: 0;
}

/* --- Píldora de toggles de paneles en el header (concept-inspired) ---------- */
.layout-toggles-pill {
  display: inline-flex !important;
  align-items: center;
  gap: 2px !important;
  padding: 3px !important;
  background: #1e1e1e;
  border: 1px solid #3e3e3e;
  border-radius: 6px;
}
.layout-toggle-btn {
  background: transparent;
  border: none;
  color: #888;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  line-height: 0;
}
.layout-toggle-btn:hover { color: #cbd5e1; background: rgba(255,255,255,0.04); }
.layout-toggle-btn.active { color: #4aa3ff; background: #37373d; }

/* --- Toggle Desktop / Mobile en la barra del preview (concept-inspired) ---- */
.device-toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: #1e1e1e;
  border: 1px solid #3e3e3e;
  border-radius: 6px;
}
.device-toggle-btn {
  background: transparent;
  border: none;
  color: #888;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  line-height: 0;
  transition: all 0.15s ease;
}
.device-toggle-btn:hover { color: #cbd5e1; }
.device-toggle-btn.active { color: #4aa3ff; background: #37373d; }

/* --- Modo móvil: marco de teléfono con proporción real (~9:19.5) ----------- */
.output-pane.device-mobile #previewView {
  background: #15171b;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto !important;
}
.output-pane.device-mobile #previewView > iframe {
  display: block !important;
  /* Proporción real de teléfono moderno (~9:19.5) */
  aspect-ratio: 9 / 19.5;
  width: auto !important;
  /* Altura controlada por --mobile-scale (1 = encaja en el viewport) */
  height: calc((100% - 32px) * var(--mobile-scale, 1)) !important;
  max-height: none !important;
  max-width: none !important;
  min-height: 200px;
  border: 10px solid #0a0a0a !important;
  border-radius: 32px !important;
  box-shadow: 0 25px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04) inset;
  background: #fff;
  flex: 0 0 auto;
  cursor: default;
}
/* Forzamos el iframe activo (sandpack-frame) y ocultamos el legacy en móvil */
.output-pane.device-mobile #previewView > iframe#preview { display: none !important; }

