/* =========================================
   CodeDroid – Main App Styles
   Theme: Monokai Dark
   ========================================= */

:root {
  /* Monokai palette */
  --bg-base:     #272822;
  --bg-panel:    #1e1f1c;
  --bg-surface:  #3e3d32;
  --bg-hover:    #49483e;
  --bg-active:   #75715e33;

  --text-main:   #f8f8f2;
  --text-muted:  #75715e;
  --text-dim:    #90908a;

  --accent-pink:   #f92672;
  --accent-green:  #a6e22e;
  --accent-yellow: #e6db74;
  --accent-orange: #fd971f;
  --accent-blue:   #66d9ef;
  --accent-purple: #ae81ff;
  --accent-teal:   #a1efe4;

  --border:    #3e3d32;
  --border2:   #49483e;

  --topbar-h:  52px;
  --tabs-h:    40px;
  --lang-h:    36px;
  --nav-h:     60px;
  --toolbar-h: 42px;

  --radius:    6px;
  --radius-lg: 12px;
  --font-ui:   -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-code: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Source Code Pro', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ── Welcome Screen ── */
#welcome {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg-panel);
  overflow-y: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px 40px;
}
.wlc-inner {
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column; gap: 24px;
}
.wlc-logo {
  display: flex; align-items: center; gap: 14px;
  padding-top: 12px;
}
.wlc-title {
  font-size: 26px; font-weight: 800; color: var(--text-main);
  letter-spacing: -0.5px;
}
.wlc-sub {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1.5px;
  margin-top: 2px;
}
.wlc-actions {
  display: flex; flex-direction: column; gap: 10px;
}
.wlc-btn {
  width: 100%; padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 15px; font-weight: 600;
  display: flex; align-items: center; gap: 12px;
  transition: opacity 0.15s, transform 0.1s;
}
.wlc-btn:active { transform: scale(0.98); opacity: 0.85; }
.wlc-btn-primary {
  background: var(--accent-pink); color: #fff;
}
.wlc-btn-secondary {
  background: var(--bg-surface); color: var(--text-main);
  border: 1px solid var(--border2);
}
.wlc-guide {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.wlc-guide-title {
  font-size: 14px; font-weight: 700;
  color: var(--text-main); margin-bottom: 14px;
}
.wlc-steps { display: flex; flex-direction: column; gap: 12px; }
.wlc-step {
  display: flex; align-items: flex-start; gap: 12px;
}
.step-num {
  width: 24px; height: 24px; flex-shrink: 0;
  background: var(--accent-pink); color: #fff;
  border-radius: 50%; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.step-text {
  font-size: 13px; color: var(--text-dim); line-height: 1.55;
}
.step-text b { color: var(--text-main); }
kbd {
  display: inline-block; padding: 1px 5px;
  background: var(--bg-surface); border: 1px solid var(--border2);
  border-radius: 3px; font-family: var(--font-code); font-size: 11px;
  color: var(--accent-yellow);
}
.wlc-footer {
  text-align: center; font-size: 11px;
  color: var(--text-muted); letter-spacing: 0.3px;
}

/* ── Splash ── */
#splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--bg-panel);
  z-index: 9999;
  
}
.splash-logo {
  display: flex; align-items: center; gap: 14px;
  font-size: 28px; font-weight: 700; letter-spacing: -0.5px;
  color: var(--text-main);
}
.splash-sub {
  margin-top: 10px; font-size: 13px;
  color: var(--text-muted); letter-spacing: 2px;
  text-transform: uppercase;
}
@keyframes splashFade { to { opacity:0; pointer-events:none; } }

/* ── App Shell ── */
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg-panel);
}

/* ── Top Bar ── */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}
.topbar-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.topbar-btn:hover, .topbar-btn:active { background: var(--bg-hover); color: var(--text-main); }
.topbar-title {
  flex: 1; display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.topbar-title span:first-child {
  font-size: 14px; font-weight: 600;
  color: var(--text-main); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-code);
}
.dirty-dot { color: var(--accent-orange); font-size: 10px; }
.save-toast {
  font-size: 12px;
  font-weight: 600;
  color: #a6e22e;
  background: rgba(166,226,46,0.12);
  border: 1px solid rgba(166,226,46,0.3);
  border-radius: 8px;
  padding: 2px 9px;
  margin-left: 6px;
  opacity: 1;
  transition: opacity 0.5s ease;
  white-space: nowrap;
  pointer-events: none;
}
.save-toast.hidden { display: none; }
.save-toast.fading { opacity: 0; }
.topbar-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ── File Tabs ── */
.tab-bar {
  height: var(--tabs-h);
  display: flex; align-items: center;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-item {
  height: 100%; padding: 0 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
  border-right: 1px solid var(--border);
  white-space: nowrap; flex-shrink: 0;
  position: relative; cursor: pointer;
  font-family: var(--font-code);
  transition: color 0.15s, background 0.15s;
}
.tab-item:hover { background: var(--bg-hover); color: var(--text-main); }
.tab-item.active {
  color: var(--text-main); background: var(--bg-base);
  border-bottom: 2px solid var(--accent-pink);
}
.tab-close {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; font-size: 11px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.tab-close:hover { background: var(--accent-pink); color: #fff; }
.tab-new-btn {
  padding: 0 14px; height: 100%;
  font-size: 18px; color: var(--text-muted);
  flex-shrink: 0;
  transition: color 0.15s;
}
.tab-new-btn:hover { color: var(--accent-green); }

/* ── Lang Tabs ── */
.lang-tabs {
  height: var(--lang-h);
  display: flex; flex-shrink: 0;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border);
}
.lang-tab {
  flex: 1; font-size: 12px; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.5px;
  transition: color 0.15s, border-color 0.15s;
  border-bottom: 2px solid transparent;
}
.lang-tab:hover { color: var(--text-main); }
.lang-tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }

/* ── Main Area ── */
.main-area {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.pane { flex: 1; min-height: 0; overflow: hidden; }
.editor-pane { background: var(--bg-base); display: flex; flex-direction: column; }

/* ── Pane Divider ── */
.pane-divider {
  height: 6px; flex-shrink: 0;
  background: var(--bg-panel);
  display: flex; align-items: center; justify-content: center;
  cursor: row-resize; z-index: 10;
}
.divider-handle {
  width: 40px; height: 3px;
  border-radius: 2px; background: var(--border2);
}
.pane-divider:hover .divider-handle,
.pane-divider:active .divider-handle { background: var(--accent-blue); }

/* ── Right Pane ── */
.right-pane {
  display: flex; flex-direction: column;
  background: var(--bg-panel); min-height: 0;
}
.preview-area {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.preview-topbar {
  height: 32px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.preview-label, .console-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-muted);
}
.preview-actions, .console-actions {
  display: flex; align-items: center; gap: 4px;
}
.preview-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.preview-btn:hover { background: var(--bg-hover); color: var(--text-main); }
#previewFrame {
  flex: 1; border: none;
  background: #fff;
}

/* ── Console ── */
.console-area {
  height: 160px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-top: 1px solid var(--border);
  transition: height 0.2s ease;
}
.console-area.collapsed { height: 32px; }
.console-area.collapsed .console-output,
.console-area.collapsed .console-input-row { display: none; }
.console-topbar {
  height: 32px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.console-count {
  font-size: 10px; padding: 1px 6px;
  background: var(--accent-pink); color: #fff;
  border-radius: 8px; font-weight: 700;
}
.console-output {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 6px 10px;
  font-family: var(--font-code); font-size: 12px;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.console-output::-webkit-scrollbar { width: 4px; }
.console-output::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.log-line { padding: 1px 0; word-break: break-all; }
.log-line.log-log { color: var(--text-main); }
.log-line.log-info { color: var(--accent-blue); }
.log-line.log-warn { color: var(--accent-yellow); background: #2d2a0022; }
.log-line.log-error { color: var(--accent-pink); background: #f9267222; }
.log-line.log-result { color: var(--accent-purple); }
.log-line.log-system { color: var(--text-muted); font-style: italic; }
.log-prefix { color: var(--text-muted); margin-right: 6px; font-size: 10px; }
.console-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}
.console-prompt { color: var(--accent-green); font-family: var(--font-code); font-size: 13px; }
.console-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-family: var(--font-code); font-size: 12px;
  color: var(--text-main);
  user-select: text;
}

/* ── Quick Toolbar ── */
.quick-toolbar {
  height: var(--toolbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 2px;
  padding: 0 6px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
}
.quick-toolbar::-webkit-scrollbar { display: none; }
.qtbtn {
  padding: 6px 10px; border-radius: 4px;
  font-family: var(--font-code); font-size: 13px;
  color: var(--text-dim); flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
  min-width: 34px; text-align: center;
}
.qtbtn:hover, .qtbtn:active { background: var(--bg-hover); color: var(--accent-yellow); }
.qtbtn-action { color: var(--accent-blue); }

/* ── Bottom Nav ── */
.bottom-nav {
  height: var(--nav-h); flex-shrink: 0;
  display: flex;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  color: var(--text-muted);
  font-size: 10px; font-weight: 600; letter-spacing: 0.3px;
  transition: color 0.15s;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn svg { transition: stroke 0.15s; }
.nav-btn.active { color: var(--accent-pink); }
.nav-btn.active svg { stroke: var(--accent-pink); }

/* ── Sidebar ── */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: #0007; z-index: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.sidebar-overlay.open { opacity: 1; pointer-events: all; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(300px, 85vw);
  background: var(--bg-panel);
  border-right: 1px solid var(--border2);
  z-index: 510;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column;
}
.sidebar.open { transform: translateX(0); }
.sidebar-header {
  height: 54px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-size: 15px; font-weight: 700; }
.sidebar-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; color: var(--text-muted);
  transition: background 0.15s;
}
.sidebar-close:hover { background: var(--bg-hover); color: var(--text-main); }
.sidebar-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 10px 6px;
  border-bottom: 1px solid var(--border);
}
.sb-btn {
  padding: 6px 10px; font-size: 12px; border-radius: 4px;
  background: var(--bg-surface); color: var(--text-main);
  transition: background 0.15s;
}
.sb-btn:hover { background: var(--bg-hover); }
.sb-btn-import { color: var(--accent-blue); }
.sb-btn-folder { color: var(--accent-yellow); }
.sb-btn-export { color: var(--accent-green); }
.sidebar-tree {
  flex: 1; overflow-y: auto; padding: 8px 0;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
.sidebar-tree::-webkit-scrollbar { width: 4px; }
.sidebar-tree::-webkit-scrollbar-thumb { background: var(--border2); }
.tree-folder, .tree-file {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; font-size: 13px;
  cursor: pointer; font-family: var(--font-code);
  color: var(--text-dim);
  transition: background 0.1s, color 0.1s;
  user-select: none;
}
.tree-folder:hover, .tree-file:hover { background: var(--bg-hover); color: var(--text-main); }
.tree-file.active { background: var(--bg-active); color: var(--accent-blue); }
.tree-icon { font-size: 14px; flex-shrink: 0; }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-children { padding-left: 16px; }
.tree-folder-toggle { color: var(--text-muted); font-size: 10px; margin-left: auto; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: #0008; z-index: 800;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-surface); border-radius: var(--radius-lg);
  padding: 20px; width: 100%; max-width: 340px;
  border: 1px solid var(--border2);
  box-shadow: 0 20px 60px #0006;
}
.settings-modal { max-width: 360px; }
.modal-title {
  font-size: 15px; font-weight: 700;
  margin-bottom: 14px; color: var(--text-main);
}
.modal-input {
  width: 100%; padding: 10px 12px;
  background: var(--bg-panel); border: 1px solid var(--border2);
  border-radius: var(--radius); outline: none;
  font-size: 14px; color: var(--text-main);
  user-select: text;
}
.modal-input:focus { border-color: var(--accent-blue); }
.modal-actions {
  display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end;
}
.modal-btn {
  padding: 8px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.modal-cancel { background: var(--bg-hover); color: var(--text-dim); }
.modal-cancel:hover { background: var(--border2); }
.modal-ok { background: var(--accent-pink); color: #fff; }
.modal-ok:hover { opacity: 0.85; }

/* ── Context Menu ── */
.ctx-menu {
  position: fixed; z-index: 700;
  background: var(--bg-surface); border: 1px solid var(--border2);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 8px 30px #0006;
  min-width: 160px;
}
.ctx-item {
  display: block; width: 100%;
  padding: 10px 16px; font-size: 13px;
  text-align: left; color: var(--text-main);
  transition: background 0.1s;
}
.ctx-item:hover { background: var(--bg-hover); }

/* ── Settings ── */
.settings-body { display: flex; flex-direction: column; gap: 14px; }
.setting-row {
  display: flex; align-items: center;
  justify-content: space-between;
  font-size: 13px; color: var(--text-main);
}
.setting-control { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sz-btn {
  width: 28px; height: 28px;
  background: var(--bg-hover); border-radius: 4px;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  color: var(--text-main); transition: background 0.1s;
}
.sz-btn:hover { background: var(--accent-pink); }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--bg-hover); border-radius: 24px;
  transition: background 0.2s; cursor: pointer;
}
.slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .slider { background: var(--accent-green); }
.toggle input:checked + .slider::before { transform: translateX(20px); }
.setting-select {
  background: var(--bg-panel); border: 1px solid var(--border2);
  border-radius: 4px; padding: 4px 8px;
  color: var(--text-main); font-size: 12px; outline: none;
}

/* ── Mobile view switching ── */
@media (max-width: 768px) {
  .main-area { flex-direction: column; }
  .pane-divider { display: none; }

  .editor-pane, .right-pane {
    position: absolute; inset: 0; top: 0;
    transition: opacity 0.2s, transform 0.2s;
  }
  .main-area { position: relative; }

  .view-editor .editor-pane  { opacity: 1; transform: none; z-index: 2; pointer-events: all; }
  .view-editor .right-pane   { opacity: 0; transform: translateX(40px); z-index: 1; pointer-events: none; }
  .view-preview .right-pane  { opacity: 1; transform: none; z-index: 2; pointer-events: all; }
  .view-preview .editor-pane { opacity: 0; transform: translateX(-40px); z-index: 1; pointer-events: none; }
  .view-console .right-pane  { opacity: 1; transform: none; z-index: 2; pointer-events: all; }
  .view-console .editor-pane { opacity: 0; z-index: 1; pointer-events: none; }
  .view-files   .editor-pane,
  .view-files   .right-pane  { opacity: 0; pointer-events: none; z-index: 1; }
}

/* Desktop split layout */
@media (min-width: 769px) {
  .main-area { flex-direction: row; position: relative; }
  .editor-pane { width: 50%; height: 100%; }
  .right-pane  { flex: 1; height: 100%; }
  .pane-divider { width: 6px; height: 100%; cursor: col-resize; }
  .divider-handle { width: 3px; height: 40px; }
  .lang-tabs { position: absolute; top: 0; left: 0; right: 50%; z-index: 10; }
  .bottom-nav { display: none; }
  .nav-btn[data-view="files"] ~ * { display: none; }
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }
