/* ============================================================
   CODE EDITER π — Flat Dark Minimalist Theme
   Palette: #1a1a1a bg · #252526 panels · #f5f0e8 cream · #6b6b6b muted
   STRICT: no neon, no glow, no gradients, no cyberpunk.
   ============================================================ */

:root {
  --bg-primary: #1a1a1a;
  --bg-secondary: #252526;
  --bg-tertiary: #2d2d30;
  --bg-hover: #3e3e42;
  --bg-active: #37373d;
  --border: #3c3c3c;
  --text-primary: #f5f0e8;
  --text-secondary: #b8b0a4;
  --text-muted: #6b6b6b;
  --accent: #f5f0e8;
  --accent-dim: #d4cfc4;
  --danger: #e06c75;
  --warning: #e5c07b;
  --success: #98c379;
  --info: #61afef;
  --topbar-h: 44px;
  --statusbar-h: 26px;
  --sidebar-w: 240px;
  --tabbar-h: 36px;
  --panel-tabs-h: 34px;
  --radius: 4px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ============ SCROLLBARS ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 5px; border: 2px solid var(--bg-primary); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::-webkit-scrollbar-corner { background: transparent; }

/* ============ TOP BAR ============ */
#topbar {
  height: var(--topbar-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
  user-select: none;
  position: relative;
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 6px; }
.brand-pi {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-tertiary);
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
}
.brand-name { font-weight: 600; letter-spacing: 0.5px; color: var(--text-primary); font-size: 13px; }

.topbar-actions { margin-left: auto; display: flex; gap: 6px; }

/* ============ BUTTONS ============ */
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.small { width: 24px; height: 24px; font-size: 13px; }

.action-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.action-btn:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.action-btn:active { background: var(--bg-active); }
.action-btn.primary { background: var(--accent); color: var(--bg-primary); border-color: var(--accent); font-weight: 600; }
.action-btn.primary:hover { background: var(--accent-dim); }
.action-btn.secondary { background: transparent; }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============ MAIN LAYOUT ============ */
#main-container {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  overflow: hidden;
}

/* ============ SIDEBAR ============ */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
}

#sidebar.hidden { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-header {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
  border-radius: 0;
  transition: background 0.1s;
}
.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--bg-active); color: var(--text-primary); }
.tree-item .tree-icon { font-size: 13px; width: 16px; text-align: center; flex-shrink: 0; }
.tree-item .tree-label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-item .tree-badge {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 3px;
}

.tree-children { margin-left: 14px; border-left: 1px solid var(--border); padding-left: 2px; }
.tree-children.collapsed { display: none; }

.sidebar-footer {
  padding: 6px 12px;
  font-size: 10px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}

/* ============ EDITOR AREA ============ */
#editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

/* ---- Tab Bar ---- */
.tab-bar {
  height: var(--tabbar-h);
  background: var(--bg-secondary);
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
  user-select: none;
}
.tab-bar::-webkit-scrollbar { height: 3px; }

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
  border-top: 2px solid transparent;
  transition: background 0.1s;
  flex-shrink: 0;
}
.tab:hover { background: var(--bg-hover); }
.tab.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-top-color: var(--accent);
}
.tab .tab-close {
  font-size: 14px;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px;
  color: var(--text-muted);
}
.tab .tab-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.tab .tab-dirty { color: var(--warning); font-size: 14px; }
.tab .tab-dirty.hidden { display: none; }

/* ---- Monaco Container ---- */
#editor-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ============ BOTTOM PANEL ============ */
#bottom-panel {
  height: 240px;
  min-height: 100px;
  max-height: 70vh;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

#bottom-panel.hidden { display: none; }

.drag-handle {
  height: 4px;
  cursor: row-resize;
  background: transparent;
  position: absolute;
  top: -2px; left: 0; right: 0;
  z-index: 10;
  transition: background 0.15s;
}
.drag-handle:hover, .drag-handle.dragging { background: var(--accent); }

.panel-tabs {
  height: var(--panel-tabs-h);
  display: flex;
  align-items: center;
  padding: 0 6px;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  user-select: none;
}
.panel-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 6px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
}
.panel-tab:hover { color: var(--text-primary); }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-spacer { flex: 1; }

.panel-content { flex: 1; min-height: 0; position: relative; }
.panel-page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.panel-page.active { display: flex; }

#terminal-container { flex: 1; padding: 6px 0 0 8px; background: var(--bg-primary); }
#terminal-container .xterm { height: 100%; }

#preview-frame {
  flex: 1;
  border: none;
  background: #ffffff;
  width: 100%;
}

.problems-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.8;
}
.problem-item { display: flex; gap: 8px; padding: 3px 0; cursor: pointer; }
.problem-item:hover { color: var(--text-primary); }
.problem-item .p-icon { flex-shrink: 0; }
.problem-item.error .p-icon { color: var(--danger); }
.problem-item.warning .p-icon { color: var(--warning); }

/* ============ STATUS BAR ============ */
#statusbar {
  height: var(--statusbar-h);
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}
#statusbar span { white-space: nowrap; }
#status-lang { color: var(--accent); font-weight: 600; }
.status-spacer { flex: 1; }
#status-pwa { color: var(--success); }

/* ============ CONTEXT MENU ============ */
.context-menu {
  position: fixed;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
  z-index: 1000;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.context-menu.hidden { display: none; }
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 7px 12px;
  cursor: pointer;
  border-radius: 3px;
}
.context-menu button:hover { background: var(--bg-hover); }
.context-menu button[data-action="delete"] { color: var(--danger); }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  width: 340px;
  max-width: 90vw;
}
.modal-box h3 { font-size: 14px; margin-bottom: 14px; color: var(--text-primary); font-weight: 600; }
.modal-box input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius);
  outline: none;
  margin-bottom: 16px;
}
.modal-box input:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ============ MONACO THEME OVERRIDES ============ */
.monaco-editor .margin { background: var(--bg-primary) !important; }
.monaco-editor, .monaco-editor-background { background-color: var(--bg-primary) !important; }

/* ============================================================
   RESPONSIVE — MOBILE / TOUCH
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }

  .topbar-actions .action-btn { padding: 5px 8px; font-size: 11px; }
  #btn-new-folder { display: none; }
  .brand-name { display: none; }

  #sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: var(--statusbar-h);
    left: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  #sidebar.hidden { margin-left: calc(-1 * var(--sidebar-w) - 20px); }
  #sidebar-overlay.visible { display: block; }

  #bottom-panel { height: 200px; max-height: 55vh; }
  .panel-tab { padding: 6px 8px; font-size: 10px; }

  .tree-item { padding: 8px 10px; font-size: 14px; }
  .icon-btn { width: 40px; height: 40px; font-size: 18px; }
  .icon-btn.small { width: 32px; height: 32px; font-size: 15px; }

  #statusbar { gap: 8px; padding: 0 8px; font-size: 10px; }
  #status-indent, #status-encoding { display: none; }
}

@media (max-width: 480px) {
  .topbar-actions { gap: 4px; }
  .action-btn { padding: 4px 7px; font-size: 10px; }
  #btn-run { font-size: 0; }
  #btn-run::after { content: "▶"; font-size: 14px; }
  #btn-save { font-size: 0; }
  #btn-save::after { content: "💾"; font-size: 14px; }
  #btn-new-file { font-size: 0; }
  #btn-new-file::after { content: "＋"; font-size: 14px; }
}
