:root {
  --bg-main: #0d0d0f;
  --bg-panel: rgba(24, 24, 28, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --accent-color: #7c3aed;
  --accent-glow: rgba(124, 58, 237, 0.4);
  --text-main: #e2e8f0;
  --text-dim: #94a3b8;
  --header-height: 56px;
  --mobile-nav-height: 60px;
}

html, body {
  margin: 0;
  height: 100vh;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

.code-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========== TOPBAR ========== */
.code-topbar {
  height: var(--header-height);
  flex-shrink: 0;
  background: rgba(13, 13, 15, 0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

.brand {
  font-weight: 800;
  font-size: 18px;
  background: linear-gradient(135deg, #fff 0%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.top-btn {
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-main);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.top-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.top-btn.primary {
  background: var(--accent-color);
  border: none;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.top-btn.primary:hover {
  background: #6d28d9;
  box-shadow: 0 6px 16px var(--accent-glow);
}

/* ========== DESKTOP BODY LAYOUT ========== */
.code-body {
  flex: 1;
  display: grid;
  grid-template-areas: "explorer editor assistant";
  grid-template-columns: 280px 1fr 320px;
  grid-template-rows: 1fr;
  min-height: 0;
  overflow: hidden;
}

.code-body.with-preview {
  grid-template-areas: "explorer editor preview assistant";
  grid-template-columns: 280px 1fr 1fr 320px;
}

.explorer-panel { grid-area: explorer; }
.editor-panel   { grid-area: editor;   }
.webview-panel  { grid-area: preview;  }
.assistant-panel{ grid-area: assistant; }

/* ========== ALL PANELS (base) ========== */
.explorer-panel,
.assistant-panel,
.editor-panel {
  background: #18181c;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-width: 0;
}

.editor-panel {
  background: #1e1e1e;
}

.editor-host {
  flex: 1;
  min-height: 0;
  width: 100%;
}

.panel-header {
  height: 48px;
  min-height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: #18181c;
  flex-shrink: 0;
}

/* ========== ASSISTANT INPUT AREA ========== */
.assistant-input-area {
  margin-top: auto;
  flex-shrink: 0;
  background: #1a1a20;
  border-top: 1px solid var(--border-color);
  padding: 8px;
}

.assistant-panel .input-wrapper {
  padding: 4px 4px 4px;
  flex-shrink: 0;
}

/* ========== SEARCH & TREE ========== */
.search-container {
  padding: 12px;
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.search-input:focus {
  border-color: var(--accent-color);
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.tree-item {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tree-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.tree-item.active {
  background: rgba(124, 58, 237, 0.15);
  color: #c4b5fd;
  font-weight: 500;
}

/* ========== TABS ========== */
.tabs-bar {
  height: 40px;
  min-height: 40px;
  background: #0d0d0f;
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.tab-item {
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-right: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  background: #141417;
  white-space: nowrap;
}

.tab-item.active {
  background: #101012;
  color: #fff;
  border-bottom: 2px solid var(--accent-color);
}

/* ========== WEBVIEW ========== */
.webview-panel {
  display: none;
  background: #fff;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.code-body.with-preview .webview-panel {
  display: flex;
}
.preview-host {
  flex: 1;
  position: relative;
  min-height: 0;
}
.preview-host iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ========== ASSISTANT CHAT ========== */
.agent-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.agent-msg {
  max-width: 90%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.agent-msg.user {
  align-self: flex-end;
  background: var(--accent-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.agent-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-bottom-left-radius: 4px;
}

.agent-msg.thinking {
  animation: pulse 1.5s infinite;
  color: var(--accent-color);
  font-style: italic;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.ai-prompt {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: #fff;
  padding: 10px 12px;
  resize: none;
  outline: none;
  font-size: 13px;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.ai-prompt:focus {
  border-color: var(--accent-color);
  background: rgba(255, 255, 255, 0.07);
}

/* ========== FILE ICONS ========== */
.bi-filetype-html { color: #f06529; }
.bi-filetype-css  { color: #2965f1; }
.bi-filetype-js   { color: #f7df1e; }
.bi-filetype-php  { color: #777bb4; }
.bi-folder-fill   { color: #fbbf24; }

/* ========== MOBILE NAV (hidden on desktop) ========== */
.mobile-nav {
  display: none;
  height: var(--mobile-nav-height);
  background: #0d0d0f;
  border-top: 1px solid var(--border-color);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3000;
  padding: 0 10px;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-dim);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.15s;
}

.nav-item i { font-size: 20px; }
.nav-item.active { color: var(--accent-color); }

/* ================================================================
   MOBILE RESPONSIVE — max-width: 900px
   Each panel becomes a fixed fullscreen overlay.
   Only the one with .mobile-active is visible.
   ================================================================ */
@media (max-width: 900px) {

  /* Hide desktop top-right buttons (Save, Run, etc.) */
  .top-right {
    display: none;
  }

  /* Remove the grid layout entirely */
  .code-body {
    display: block !important;
    position: relative;
    height: calc(100vh - var(--header-height) - var(--mobile-nav-height));
    overflow: hidden;
  }

  /* ALL panels: hidden by default, fullscreen when active */
  .explorer-panel,
  .assistant-panel,
  .webview-panel,
  .editor-panel {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-height);
    width: 100%;
    height: calc(100vh - var(--header-height) - var(--mobile-nav-height));
    z-index: 2000;
    background: #0d0d0f;
    border: none;
    border-radius: 0;
    box-shadow: none;
    flex-direction: column;
    margin: 0;
    overflow: hidden;
  }

  /* Show only the active tab */
  .explorer-panel.mobile-active,
  .assistant-panel.mobile-active,
  .webview-panel.mobile-active,
  .editor-panel.mobile-active {
    display: flex;
  }

  /* Editor: ensure Monaco fills the space */
  .editor-panel.mobile-active .editor-host {
    flex: 1;
    min-height: 0;
    height: 0; /* let flex handle it */
  }

  /* Assistant: chat fills space, input stays at bottom */
  .assistant-panel.mobile-active {
    overflow: hidden;
  }
  .assistant-panel.mobile-active .agent-chat-history {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
  }
  .assistant-panel.mobile-active .assistant-input-area {
    flex-shrink: 0;
    padding: 8px;
    background: #1a1a20;
    border-top: 1px solid var(--border-color);
  }
  .assistant-panel.mobile-active .ai-prompt {
    height: 50px;
    margin: 0 0 6px 0;
    font-size: 14px;
  }
  .assistant-panel.mobile-active .input-wrapper {
    padding: 0;
  }

  /* Explorer fills the space */
  .explorer-panel.mobile-active {
    overflow: hidden;
  }
  .explorer-panel.mobile-active .file-tree {
    flex: 1;
    overflow-y: auto;
  }

  /* Mobile nav visible */
  .mobile-nav {
    display: flex;
  }

  /* Smaller panel headers on mobile */
  .panel-header {
    height: 40px;
    min-height: 40px;
    font-size: 10px;
  }

  .tabs-bar {
    height: 36px;
    min-height: 36px;
  }
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }