/* ===================================================
   APEX IDE — Mobile & Cross-Platform Styles
   Loaded after style.css for responsive overrides
   =================================================== */

/* ===== TOUCH TARGETS ===== */
@media (pointer: coarse) {
  .ab-btn { width: 44px; height: 44px; }
  .tree-item { min-height: 32px; padding-top: 6px; padding-bottom: 6px; }
  .tab { min-height: 40px; padding: 0 14px; }
  .bt-tab { height: 36px; padding: 0 16px; }
  .cm-item { padding: 10px 14px; }
  .cp-item { padding: 12px 16px; }
  .setting-row { padding: 12px 0; }
  .setting-toggle { width: 44px; height: 24px; }
  .setting-toggle::after { width: 18px; height: 18px; top: 2px; left: 2px; }
  .setting-toggle.on::after { left: 22px; }
  .ai-send { padding: 8px 18px; }
}

/* ===== MOBILE LAYOUT ===== */
@media (max-width: 600px) {
  :root {
    --titlebar-h: 44px;
    --activitybar-w: 0px;
    --statusbar-h: 26px;
    --bottomPanel-h: 180px;
    --ai-w: 100vw;
  }

  #activitybar { display: none; }
  #sidebar { width: 100vw !important; position: absolute; z-index: 200; left: -100vw; transition: left 0.2s ease; }
  #sidebar.open { left: 0; }

  #titlebar { padding: 0 4px; }
  .menu-bar { display: none; }
  .logo-mark svg { width: 24px; height: 24px; }
  .titlebar-center { display: none; }
  .window-controls { display: none; }
  .tb-btn { padding: 4px 8px; font-size: 11px; }

  #main { flex-direction: column; }
  #editorArea { flex: 1; }

  /* Mobile toolbar overlay */
  #mobileToolbar {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 52px;
    background: var(--bg-2); border-top: 1px solid var(--border);
    z-index: 300; align-items: center; justify-content: space-around;
    padding: 0 8px;
  }
  .mt-btn {
    display: flex; flex-direction: column; align-items: center;
    gap: 2px; padding: 4px 8px; border-radius: 6px;
    color: var(--text-2); font-size: 10px; cursor: pointer;
    transition: all 0.15s;
  }
  .mt-btn svg { width: 20px; height: 20px; }
  .mt-btn:active { background: var(--bg-hover); color: var(--text-0); }

  #bottomPanel { height: 180px; }

  /* Fullscreen AI on mobile */
  #aiPanelRight {
    position: fixed; inset: var(--titlebar-h) 0 var(--statusbar-h) 0;
    z-index: 150; width: 100% !important;
  }

  .welcome-grid { grid-template-columns: 1fr; }
  .welcome-actions { flex-direction: column; align-items: center; }
}

/* ===== TABLET ===== */
@media (min-width: 601px) and (max-width: 1024px) {
  :root {
    --sidebar-w: 200px;
    --ai-w: 300px;
  }
  #mobileToolbar { display: none; }
  .menu-bar { display: none; }
}

/* ===== DESKTOP ===== */
@media (min-width: 1025px) {
  #mobileToolbar { display: none; }
}

/* ===== HIGH DPI ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  * { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
}

/* ===== DARK MODE SYSTEM PREFERENCE ===== */
@media (prefers-color-scheme: light) {
  /* IDE has its own theme system so we only apply light if user hasn't set a theme */
  body.system-theme {
    --bg-0: #fafafa; --bg-1: #f0f0f0; --bg-2: #e8e8e8; --bg-3: #e0e0e0; --bg-4: #d8d8d8;
    --bg-hover: #d0d0d0; --border: #cccccc; --text-0: #1a1a1a; --text-1: #2d2d2d;
    --text-2: #555555; --text-3: #888888;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .splash-fill { transition: none !important; }
  .ai-typing-dots span { animation: none !important; }
}

/* ===== PRINT ===== */
@media print {
  #titlebar, #activitybar, #sidebar, #bottomPanel, #statusbar,
  #aiPanelRight, .resizer, #contextMenu, #commandPalette,
  .modal, #toastContainer, #mobileToolbar { display: none !important; }
  #editorArea { height: 100vh; }
  #monacoContainer .monaco-editor { font-size: 11pt !important; }
}

/* ===== FOCUS VISIBLE ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ===== SELECTION ===== */
::selection { background: var(--accent-dim); color: var(--text-0); }

/* ===== SCROLLBAR (Firefox) ===== */
* { scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }

/* ===== DRAG & DROP OVERLAY ===== */
#dropOverlay {
  position: fixed; inset: 0; z-index: 99999;
  background: rgba(124, 58, 237, 0.15);
  border: 3px dashed var(--accent);
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  color: var(--accent); font-size: 24px; font-weight: 700;
  pointer-events: none;
}
#dropOverlay.active { display: flex; }
#dropOverlay span:last-child { font-size: 14px; color: var(--text-2); font-weight: 400; }

/* ===== SPLIT EDITOR ===== */
.editor-split { display: flex; flex: 1; overflow: hidden; }
.editor-split .monaco-split {
  flex: 1; border-left: 1px solid var(--border);
}

/* ===== DIFF EDITOR ===== */
.diff-header {
  padding: 4px 12px; background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
  display: flex; gap: 16px;
}
.diff-add { color: var(--green); }
.diff-remove { color: var(--red); }

/* ===== CODE LENS ===== */
.apex-codelens {
  display: inline-flex; gap: 8px;
  font-size: 11px; color: var(--text-3);
  padding: 0 4px; cursor: pointer;
}
.apex-codelens span:hover { color: var(--accent); text-decoration: underline; }

/* ===== INLINE COMPLETION ===== */
.apex-ghost-text { color: var(--text-3); font-style: italic; }

/* ===== GUTTER ICONS ===== */
.apex-gutter-error { background: var(--red); border-radius: 50%; width: 8px; height: 8px; }
.apex-gutter-warn { background: var(--yellow); border-radius: 50%; width: 8px; height: 8px; }
.apex-gutter-bp { background: var(--red); border-radius: 50%; width: 10px; height: 10px; }

/* ===== STATUS BAR VARIANTS ===== */
#statusbar.debug-active { background: #1e5f1e; }
#statusbar.error-active { background: #8b1a1a; }
#statusbar.remote-active { background: #0f4f7a; }

/* ===== BREADCRUMB ===== */
#breadcrumb { display: flex; align-items: center; flex-wrap: nowrap; overflow: hidden; }
#breadcrumb span { cursor: pointer; white-space: nowrap; }
#breadcrumb span:hover { text-decoration: underline; color: var(--text-1); }

/* ===== HOVER POPOVER ===== */
.apex-popover {
  position: fixed; z-index: 5000;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; max-width: 320px;
  font-size: 12px; color: var(--text-1); line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: none;
}

/* ===== MINIMAP TOGGLE ===== */
.minimap-visible .monaco-editor .minimap { opacity: 1; }
.minimap-hidden .monaco-editor .minimap { opacity: 0; pointer-events: none; }

/* ===== FIND WIDGET STYLE ===== */
.monaco-editor .find-widget {
  background: var(--bg-3) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
}

/* ===== AUTOCOMPLETE WIDGET ===== */
.monaco-editor .suggest-widget {
  border-radius: 6px !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6) !important;
}

/* ===== PEEK VIEW ===== */
.monaco-editor .peekview-widget .head {
  background: var(--bg-3) !important;
}

/* ===== ANDROID / iOS WebView support ===== */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari specific */
  body { -webkit-text-size-adjust: 100%; }
  #titlebar { padding-top: env(safe-area-inset-top); }
  #statusbar { padding-bottom: env(safe-area-inset-bottom); }
}

/* ===== WINDOWS SPECIFIC ===== */
@media (display-mode: standalone) {
  #titlebar { -webkit-app-region: drag; }
  .window-controls { display: flex; }
}

/* ===== CHROMEBOOK / LINUX ===== */
@media (any-pointer: fine) and (hover: hover) {
  .tree-item { min-height: 22px; }
  .ab-btn { width: 40px; height: 40px; }
}
