@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #000000;
  --panel-bg: #060606;
  --panel-bg-hover: #1a1a1a;
  --border: #1a1a1a;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #f97316;
  --accent-glow: rgba(249,115,22,0.2);
  --danger: #ff006e;
  --editor-caret: #f97316;
  --editor-bg: #0a0a0a;
  --editor-text: #e8e8e8;
  --btn-secondary-bg: #2a2a2a;
  --btn-secondary-border: #3a3a3a;
  --btn-secondary-hover: #383838;
  --sidebar-width: 150px;
}

body.light-mode {
  --bg: #f5f5f5;
  --panel-bg: #ffffff;
  --panel-bg-hover: #f0f0f0;
  --border: #d0d0d0;
  --text-primary: #1a1a1a;
  --text-secondary: #555555;
  --text-muted: #888888;
  --btn-secondary-bg: #e8e8e8;
  --btn-secondary-border: #ccc;
  --btn-secondary-hover: #ddd;
  --editor-bg: #ffffff;
  --editor-text: #1a1a1a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ─── Header ─── */
header {
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: #FF2F92;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(166, 37, 58, 0.4);
}

.logo-text {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.logo-text span {
  color: #FF2F92;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ─── Buttons ─── */
button {
  font-family: 'Inter', sans-serif;
  font-size: 12px; font-weight: 500;
  padding: 6px 11px; border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent; color: var(--text-primary);
  cursor: pointer; transition: all 0.15s ease;
  display: flex; align-items: center; gap: 5px;
}
button:hover { background: var(--panel-bg-hover); border-color: #333; }
button.primary { background: #f97316; border-color: #f97316; color: #fff; font-weight: 600; }
button.primary:hover { background: #ea580c; border-color: #ea580c; box-shadow: 0 3px 10px rgba(249,115,22,0.3); }
button.ghost { background: var(--btn-secondary-bg); border-color: var(--btn-secondary-border); }
button.ghost:hover { background: var(--btn-secondary-hover); border-color: #4a4a4a; }
button.small { padding: 5px 9px; font-size: 11px; }

.auto-btn.active {
  background: rgba(249,115,22,0.12);
  border-color: rgba(249,115,22,0.4);
  color: #f97316;
}

/* ─── Dropdown ─── */
.dropdown { position: relative; }
.dropdown-trigger { min-width: 100px; justify-content: space-between; }
.dropdown-trigger::after { content: '▾'; font-size: 9px; opacity: 0.6; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px); left: 0;
  min-width: 230px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 6px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  z-index: 9999;
  display: none;
  max-height: 420px; overflow-y: auto;
}
.dropdown-menu.show { display: block; animation: dropIn 0.15s ease; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-category {
  padding: 7px 12px 5px;
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px;
}
.dropdown-category::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.dropdown-item {
  padding: 9px 12px; border-radius: 7px; cursor: pointer;
  font-size: 12px; color: var(--text-secondary);
  transition: all 0.1s ease; display: flex; align-items: center; gap: 10px;
}
.dropdown-item:hover { background: var(--panel-bg-hover); color: var(--text-primary); }
.dropdown-item .icon {
  width: 20px; height: 20px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; flex-shrink: 0;
}
.dropdown-item.cat-basics .icon   { background: rgba(34,197,94,0.2);  color: #22c55e; }
.dropdown-item.cat-layouts .icon  { background: rgba(249,115,22,0.2); color: #f97316; }
.dropdown-item.cat-css_deep .icon { background: rgba(168,85,247,0.2); color: #a855f7; }
.dropdown-item.cat-js_web .icon   { background: rgba(245,158,11,0.2); color: #f59e0b; }

/* ─── Main ─── */
main {
  flex: 1; display: grid;
  grid-template-columns: 1fr 6px 1fr;
  background: var(--border);
  min-height: 0; position: relative;
}

/* Resizer — proper grid column, no position:absolute nonsense */
.resizer {
  background: var(--border);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 100;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.resizer:hover {
  background: #f97316;
}

.resizer::after {
  content: '';
  width: 2px;
  height: 32px;
  background: rgba(255,255,255,0.15);
  border-radius: 1px;
}

/* ─── Panels ─── */
.panel {
  background: var(--panel-bg);
  display: flex; flex-direction: column;
  min-height: 0;
}

/* ═══════════════════════════════════════════════════════════════
   EDITOR PANEL
   ═══════════════════════════════════════════════════════════════ */

.editor-panel {
  /* flex column, min-height 0 — inherited from .panel */
}

/* ─── Toolbar row ─── */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 36px;
  /* overflow visible so dropdown can escape downward */
  overflow: visible;
  position: relative;
  z-index: 20;
}

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

.panel-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-muted);
}

.toolbar-right {
  display: flex; align-items: center; gap: 6px;
  overflow: visible;
  position: relative;
}

.kbd-hint {
  font-size: 10px; color: var(--text-muted);
  display: flex; align-items: center; gap: 3px;
  white-space: nowrap;
}
kbd {
  padding: 1px 5px; background: var(--panel-bg);
  border: 1px solid var(--border); border-radius: 3px;
  font-family: 'Inter', sans-serif; font-size: 9px;
}

/* ─── Editor body: code + sidebar ─── */
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

/* ─── Code area ─── */
.editor-main {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-width: 0;
  overflow: hidden;
}

.line-numbers {
  padding: 16px 10px;
  background: var(--editor-bg); color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; line-height: 1.6;
  text-align: right; user-select: none;
  border-right: 1px solid var(--border);
  min-width: 42px; overflow: hidden; white-space: pre;
}

/* ═══════════════════════════════════════════════════════════════
   VERTICAL FILE SIDEBAR
   ═══════════════════════════════════════════════════════════════ */

.file-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* ─── Scrollable file list ─── */
.sidebar-files {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0 4px;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

/* ─── Individual file tab ─── */
.file-tab {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 8px;
  height: 34px;
  font-size: 12px; font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: color 0.12s, background 0.12s;
  gap: 7px;
  position: relative;
}

.file-tab:hover {
  color: var(--text-secondary);
  background: var(--panel-bg-hover);
  border: none;
}

.file-tab.active {
  color: #f97316;
  background: rgba(249,115,22,0.08);
  border: none;
}

.file-tab-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  padding-left: 0;
}

/* Orange document icon */
.file-tab-icon {
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  opacity: 0.7;
}
.file-tab.active .file-tab-icon { opacity: 1; }

/* Close × — hidden until hover/active */
.file-tab-close {
  display: flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 3px;
  font-size: 13px; line-height: 1;
  color: var(--text-muted);
  background: transparent; border: none;
  cursor: pointer; padding: 0;
  opacity: 0; flex-shrink: 0;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
}
.file-tab:hover .file-tab-close,
.file-tab.active .file-tab-close { opacity: 0.5; }
.file-tab-close:hover { opacity: 1 !important; background: rgba(255,0,110,0.15); color: #ff006e; }

/* Inline rename input */
.file-tab-rename {
  flex: 1;
  font-family: 'Inter', sans-serif;
  font-size: 11px; font-weight: 500;
  background: var(--panel-bg-hover);
  border: 1px solid #f97316;
  border-radius: 3px;
  color: var(--text-primary);
  padding: 1px 4px;
  outline: none;
  min-width: 0;
  margin-left: 6px;
}

/* Add page button */
.file-tab-add {
  display: block;
  width: 100%;
  padding: 7px 8px;
  font-size: 12px; font-weight: 400;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  letter-spacing: 0.2px;
  transition: color 0.12s;
}
.file-tab-add:hover {
  color: #f97316;
  background: transparent;
  border: none;
}

/* ─── Shared pane tabs (CSS / JS) ─── */
.sidebar-panes {
  flex-shrink: 0;
  padding-bottom: 8px;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px 4px;
}

.sidebar-pane-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0 8px;
  height: 32px;
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  letter-spacing: 0.2px;
  transition: color 0.12s, background 0.12s;
}
.sidebar-pane-tab:hover {
  color: var(--text-secondary);
  background: var(--panel-bg-hover);
  border: none;
}
.sidebar-pane-tab.active {
  color: var(--text-primary);
  background: rgba(255,255,255,0.04);
  border: none;
}

.tab-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.html-dot { background: #f97316; }
.css-dot  { background: #38bdf8; }
.js-dot   { background: #facc15; }

.sidebar-pane-name { font-size: 11px; font-weight: 600; }

.all-label {
  font-size: 9px; font-weight: 400;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  padding: 1px 3px;
  letter-spacing: 0.2px;
  margin-left: auto;
  margin-right: 2px;
}
.sidebar-pane-tab.active .all-label { color: var(--text-secondary); }

/* ─── Panel dots ─── */
.orange-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #f97316; box-shadow: 0 0 7px rgba(249,115,22,0.6);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   PREVIEW PANEL
   position:relative is CRITICAL — it scopes #iframe-overlay
   so the overlay only covers the preview, not the editor.
   ═══════════════════════════════════════════════════════════════ */

.preview-panel {
  position: relative;
  overflow: hidden;
}

.panel-header {
  padding: 9px 14px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.panel-header h2 {
  font-size: 10px; font-weight: 600; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-muted); margin: 0; flex: 1;
}
.preview-controls { display: flex; gap: 4px; }

/* iframe overlay — position:absolute, inset:0 scoped to .preview-panel */
#iframe-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  cursor: col-resize;
  background: transparent;
}

#preview {
  flex: 1; width: 100%; border: none;
  background: #ffffff; display: block; min-height: 0;
}

/* ─── Error strip ─── */
.error-strip {
  display: none; align-items: center; gap: 8px;
  padding: 7px 14px;
  background: rgba(255,0,110,0.08);
  border-top: 1px solid rgba(255,0,110,0.25);
  color: #ff5555; font-size: 11px;
  font-family: 'JetBrains Mono', monospace; flex-shrink: 0;
}
.error-strip.show { display: flex; }
.error-strip button { margin-left: auto; color: #ff5555; }

/* ─── Status ─── */
.status {
  padding: 7px 14px; background: var(--bg); border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 7px; flex-shrink: 0;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.status-dot.running { background: #f97316; animation: pulse 1s infinite; }
.status-dot.error   { background: var(--danger); }

@keyframes pulse { 0%,100%{opacity:1;}50%{opacity:0.4;} }

/* ─── Footer ─── */
footer {
  padding: 9px 24px; background: var(--bg); border-top: 1px solid var(--border);
  text-align: center; font-size: 11px; color: var(--text-muted); flex-shrink: 0;
}

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-bg); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 9px; font-size: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4); opacity: 0;
  pointer-events: none; transition: all 0.2s ease; z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Help Modal ─── */
.help-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.8);
  display: none; align-items: center; justify-content: center;
  z-index: 3000; backdrop-filter: blur(4px);
}
.help-modal.show { display: flex; }
.help-content {
  background: var(--panel-bg); border: 1px solid var(--border);
  border-radius: 16px; width: 90%; max-width: 580px; max-height: 82vh;
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}
.help-header {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.help-header h3 { font-size: 15px; font-weight: 600; }
.help-body { padding: 18px 20px; overflow-y: auto; font-size: 13px; line-height: 1.7; }
.help-section { margin-bottom: 18px; }
.help-section h4 {
  font-size: 10px; font-weight: 600; color: #f97316;
  margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;
}
.help-section pre {
  background: var(--bg); padding: 11px 13px; border-radius: 7px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  overflow-x: auto; border: 1px solid var(--border); line-height: 1.6;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr 6px 1fr; }
  .resizer { width: 100%; height: 6px; cursor: row-resize; }
  .resizer::after { width: 32px; height: 2px; }
  .kbd-hint { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   SYNTAX HIGHLIGHTING
   ═══════════════════════════════════════════════════════════════ */

.editor-area {
  flex: 1; position: relative; overflow: hidden;
  display: flex; flex-direction: column; background: var(--editor-bg);
}

#highlight-layer {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  padding: 16px; margin: 0; border: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-wrap: break-word;
  tab-size: 2; -moz-tab-size: 2;
  pointer-events: none; overflow: hidden;
  color: var(--editor-text); z-index: 0;
}
#highlight-layer::-webkit-scrollbar { display: none; }
#highlight-layer { scrollbar-width: none; }

.editor-area textarea {
  flex: 1; position: relative; z-index: 1;
  background: transparent !important; color: transparent !important;
  caret-color: var(--editor-caret) !important;
  padding: 16px; border: none; outline: none; resize: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; line-height: 1.6;
  tab-size: 2; -moz-tab-size: 2; overflow: auto; min-height: 0;
}

#highlight-layer span { line-height: inherit; display: inline; }

/* HTML tokens */
.hl-tag      { color: #3fa9eb; }
.hl-attr     { color: #9cdcfe; }
.hl-attr-val { color: #ede611; }
.hl-bracket  { color: #808080; }
.hl-comment  { color: #788096; font-style: italic; }
.hl-doctype  { color: #bd93f9; }

/* Error highlight — pink, wavy underline */
.hl-error {
  color: #ff006e !important;
  text-decoration: underline wavy #ff006e;
  text-underline-offset: 2px;
}

/* CSS tokens */
.hl-css-sel  { color: #bd93f9; }
.hl-css-prop { color: #9cdcfe; }
.hl-css-val  { color: #ede611; }
.hl-css-at   { color: #cd56d1; }
.hl-css-hex  { color: #fca03d; }

/* JS tokens */
.hl-keyword  { color: #3fa9eb; }
.hl-builtin  { color: #2ade58; }
.hl-string   { color: #ede611; }
.hl-number   { color: #fca03d; }
.hl-literal  { color: #bd93f9; }

/* Light mode */
body.light-mode .hl-tag      { color: #0369a1; }
body.light-mode .hl-attr     { color: #0070c1; }
body.light-mode .hl-attr-val { color: #92400e; }
body.light-mode .hl-bracket  { color: #999; }
body.light-mode .hl-comment  { color: #6b7280; }
body.light-mode .hl-doctype  { color: #7c3aed; }
body.light-mode .hl-css-sel  { color: #7c3aed; }
body.light-mode .hl-css-prop { color: #0070c1; }
body.light-mode .hl-css-val  { color: #92400e; }
body.light-mode .hl-css-at   { color: #9600c8; }
body.light-mode .hl-css-hex  { color: #c2410c; }
body.light-mode .hl-keyword  { color: #0369a1; }
body.light-mode .hl-builtin  { color: #166634; }
body.light-mode .hl-string   { color: #92400e; }
body.light-mode .hl-number   { color: #c2410c; }
body.light-mode .hl-literal  { color: #7c3aed; }
