.ide-page {
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
}

.ide-banner {
  padding: 8px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--card-border);
  color: var(--muted);
  display: flex;
  gap: 16px;
  align-items: center;
}
.ide-banner a { color: var(--primary); }

.ide-grid {
  flex: 1;
  display: grid;
  /* ide.js drags write the --ide-grid-cols custom property (not this
     property directly) so that, at the mobile breakpoint below, the plain
     grid-template-columns override there still wins the cascade instead of
     being shadowed by a leftover inline style. */
  grid-template-columns: var(--ide-grid-cols, 40% 6px 1fr);
  min-height: 0;
}

/* Draggable dividers (desktop only, see the >900px media query below) — one
   between the file sidebar and the editor, one between the editor pane and
   the preview pane. Widths are read/written by ide.js (inline style / grid
   track override), persisted per-browser in localStorage. */
.ide-resizer {
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  width: 6px;
  position: relative;
}
.ide-resizer::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  right: -3px;
}
.ide-resizer:hover, .ide-resizer.ide-resizer-active {
  background: var(--primary);
}
body.ide-resizing {
  cursor: col-resize;
  user-select: none;
}
body.ide-resizing iframe { pointer-events: none; }

.ide-editor-pane, .ide-preview-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Grid items default to min-width:auto (their content's min-content size),
     which stops the track from shrinking below that width. With a fixed-width
     sidebar + toolbar content inside, that min-content easily exceeds a 40%/60%
     track on medium widths, so the overflow spills into and renders on top of
     the next column (looked like the preview "covering" the editor). */
  min-width: 0;
}
.ide-editor-pane { border-right: 1px solid var(--card-border); }

.ide-sidebar-rail {
  flex-shrink: 0;
  width: 28px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
  background: var(--card);
  border-right: 1px solid var(--card-border);
}
.ide-sidebar-rail .ide-icon-btn { font-size: 0.85rem; }
.ide-sidebar-rail .ide-icon-btn.active { background: var(--input-bg); }

.ide-editor-pane-inner.sidebar-collapsed .ide-sidebar,
.ide-editor-pane-inner.sidebar-collapsed #ide-resizer-sidebar {
  display: none;
}

.ide-editor-pane-inner { flex: 1; display: flex; min-height: 0; min-width: 0; }

.ide-sidebar {
  width: var(--ide-sidebar-width, 240px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--card-border);
  overflow-y: auto;
  overflow-x: auto;
}
.ide-sidebar-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--card-border);
}
.ide-sidebar-title {
  flex: 1;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.ide-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 5px;
  color: var(--text);
  border-radius: 4px;
}
.ide-icon-btn:hover { background: var(--input-bg); }

.ide-tree { flex: 1; padding: 4px 0; font-size: 0.85rem; }
.ide-tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 0;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 4px;
}
.ide-tree-row:hover { background: var(--input-bg); }
.ide-tree-row.active { background: var(--primary); color: #fff; }
.ide-tree-toggle { width: 14px; text-align: center; color: var(--muted); flex-shrink: 0; }
.ide-tree-row.active .ide-tree-toggle { color: #fff; }
.ide-tree-icon { flex-shrink: 0; }
.ide-tree-name { overflow: hidden; text-overflow: ellipsis; }
.ide-tree-actions {
  margin-left: auto;
  display: flex;
  gap: 2px;
  opacity: 0;
  flex-shrink: 0;
  padding-right: 4px;
}
.ide-tree-row:hover .ide-tree-actions,
.ide-tree-row:focus-within .ide-tree-actions { opacity: 1; }
.ide-tree-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 1px 3px;
  color: inherit;
  border-radius: 3px;
}
.ide-tree-actions button:hover { background: rgba(128, 128, 128, 0.3); }

.ide-editor-column { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.ide-editor-wrap { flex: 1; min-height: 0; min-width: 0; }
.ide-editor-wrap .CodeMirror { height: 100%; font-size: 0.9rem; }

.ide-tabs {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  flex-shrink: 0;
  background: var(--card);
  border-bottom: 1px solid var(--card-border);
}
.ide-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
  border-right: 1px solid var(--card-border);
  color: var(--muted);
}
.ide-tab:hover { background: var(--input-bg); }
.ide-tab.active { color: var(--text); background: var(--input-bg); box-shadow: inset 0 -2px 0 var(--primary); }
.ide-tab-dirty-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  visibility: hidden;
}
.ide-tab.dirty .ide-tab-dirty-dot { visibility: visible; }
.ide-tab-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 3px;
}
.ide-tab-close:hover { background: rgba(128, 128, 128, 0.3); }

.ide-editor-toolbar, .ide-preview-toolbar {
  padding: 8px;
  background: var(--card);
  border-top: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.ide-preview-toolbar { border-top: none; border-bottom: 1px solid var(--card-border); }

.ide-status { color: var(--muted); font-size: 0.85rem; }

.ide-history-panel {
  border-top: 1px solid var(--card-border);
  background: var(--card);
  padding: 8px 10px;
  max-height: 220px;
  overflow-y: auto;
}
.ide-history-list { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.ide-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 0.82rem;
}
.ide-history-item:hover { background: var(--input-bg); }
.ide-history-item button {
  background: none;
  border: 1px solid var(--card-border);
  color: var(--primary);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.78rem;
  cursor: pointer;
}
.ide-history-empty { color: var(--muted); font-size: 0.82rem; padding: 4px 0; }

#ide-test-output pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.ide-nav-form { flex: 1; min-width: 0; }
.ide-nav-form input[type="text"] {
  width: 100%;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#ide-nav-back, #ide-nav-forward { font-size: 0.75rem; }

.ide-preview-frame-wrap { position: relative; flex: 1; min-height: 0; display: flex; }

#ide-preview-frame {
  flex: 1;
  border: none;
  background: #fff;
  width: 100%;
  min-height: 0;
}

.ide-preview-loading {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-top-color: var(--primary);
  animation: ide-spin 0.7s linear infinite;
}
@keyframes ide-spin { to { transform: rotate(360deg); } }

.ide-help-btn { margin-left: auto; }

.ide-intro-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.ide-intro-overlay[hidden] {
  display: none;
}
.ide-intro-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 28px;
  max-width: 440px;
  width: 100%;
}
.ide-intro-card h2 { margin: 0 0 14px; font-size: 1.2rem; }
.ide-intro-card ul { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 0.9rem; }
.ide-intro-card p { margin: 0 0 18px; color: var(--muted); font-size: 0.88rem; }
.ide-intro-card kbd {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}
.ide-intro-card .btn-primary { margin-top: 0; width: auto; padding-left: 22px; padding-right: 22px; }

.ide-console {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--card-border);
  background: var(--card);
  height: 200px;
}
.ide-console.collapsed { height: auto; }
.ide-console.collapsed .ide-console-body { display: none; }
.ide-console-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.ide-console-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px 10px;
}
.ide-console-empty { color: var(--muted); font-size: 0.85rem; padding: 4px 0; }
.ide-console pre {
  margin: 0 0 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.ide-console-stderr { color: var(--red); }
.ide-console-stdout { color: var(--text); }
.ide-console-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 6px 0 2px;
}

@media (max-width: 900px) {
  .ide-grid { grid-template-columns: 1fr; grid-template-rows: 50% 50%; }
  .ide-editor-pane { border-right: none; border-bottom: 1px solid var(--card-border); }
  .ide-sidebar { width: 180px; }
  .ide-resizer { display: none; }
  .ide-sidebar-rail { display: none; }
  .ide-editor-pane-inner.sidebar-collapsed .ide-sidebar { display: flex; }
}

@media (max-width: 560px) {
  .ide-editor-pane-inner { flex-direction: column; }
  .ide-sidebar {
    width: 100%;
    max-height: 140px;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
  }
  .ide-editor-toolbar, .ide-preview-toolbar { gap: 6px; }
  .ide-help-btn { margin-left: 0; }
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--card-border);
  font-size: 0.9rem;
}
.data-table .actions { display: flex; gap: 12px; align-items: center; }
.link-btn.danger { color: var(--red); }

/* CodeMirror show-hint popup (Arken/Lua autocomplete) -- ships hardcoded white/black by
   default, override to match this app's light/dark theme tokens instead. */
.CodeMirror-hints {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.CodeMirror-hint { color: var(--text); }
li.CodeMirror-hint-active { background: var(--primary); color: #fff; }

/* Database browser page (/ide/database) */
.db-toolbar { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
.db-toolbar h1 { margin: 0; font-size: 1.3rem; flex: 1; }
.db-output {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
}
.db-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; margin-bottom: 24px; }
.db-sidebar {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px;
  align-self: start;
}
.db-table-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.db-table-item {
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
}
.db-table-item:hover { background: var(--input-bg); }
.db-table-item.active { background: var(--primary); color: #fff; }
.db-main {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px;
  min-height: 200px;
}
.db-main h2 { margin-top: 0; font-size: 1.1rem; }
.db-pager { display: flex; align-items: center; gap: 12px; margin: 10px 0; font-size: 0.85rem; }
.db-pager button {
  background: none;
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
.db-pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.db-insert-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.db-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--muted); }
.db-field input { min-width: 120px; }
.db-sql-box {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 32px;
}
.db-sql-box textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
#db-sql-result { margin-top: 12px; overflow-x: auto; }

.db-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--card-border); }
.db-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}
.db-tab.active { color: var(--text); border-bottom-color: var(--primary); }
.db-diagram-hint { margin-bottom: 12px; }
.db-diagram-hint code {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}
.db-diagram-wrap {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px;
  overflow: auto;
  min-height: 200px;
  margin-bottom: 32px;
}
@media (max-width: 760px) {
  .db-layout { grid-template-columns: 1fr; }
}

/* ---- estudos ---- */
.estudos-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  margin-bottom: 40px;
  align-items: start;
}
.estudos-sidebar { max-height: calc(100vh - 160px); overflow-y: auto; position: sticky; top: 16px; }
.estudos-track + .estudos-track { margin-top: 16px; }
.estudos-track-title { margin-bottom: 2px; }
.estudos-lesson-content { display: none; }
.estudos-lesson-content.active { display: block; }
.estudos-explanation { font-size: 0.92rem; line-height: 1.6; }
.estudos-explanation p { margin: 0 0 12px; }
.estudos-explanation code {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}
.estudos-example { margin-top: 18px; }
.estudos-example-title {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
.estudos-example .CodeMirror {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  font-size: 0.85rem;
  height: auto;
}
@media (max-width: 760px) {
  .estudos-layout { grid-template-columns: 1fr; }
  .estudos-sidebar { position: static; max-height: none; }
}
