/* Developer Toolbox - Global styles (VS Code / Postman inspired) */

/* Default theme (Dark) */
:root,
[data-theme="dark"] {
  --bg-primary: #1e1e1e;
  --bg-secondary: #252526;
  --bg-tertiary: #2d2d30;
  --bg-hover: #2a2d2e;
  --border: #3c3c3c;
  --text: #d4d4d4;
  --text-muted: #858585;
  --accent: #0e639c;
  --accent-hover: #1177bb;
  --scrollbar-thumb: rgba(255, 255, 255, 0.12);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.22);
  --success: #4ec9b0;
  --error: #f48771;
  --warning: #dcdcaa;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --sidebar-width: 220px;
  --header-height: 50px;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-primary);
}

body.extension-popup {
  min-width: 360px;
  max-width: 420px;
  min-height: 400px;
  max-height: 600px;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* Layout: sidebar + main */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.sidebar-section {
  padding: 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  background: none;
  border: none;
  width: 100%;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.sidebar-section-header:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-section-header .chevron {
  font-size: 10px;
  transition: transform 0.2s;
}

.sidebar-section.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-section-content {
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  max-height: 2000px;
}

.sidebar-section.collapsed .sidebar-section-content {
  max-height: 0 !important;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 12px;
  margin: 0;
}

.sidebar-nav-item {
  display: block;
  width: 100%;
  padding: 5px 12px 5px 16px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 400;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav-item:hover {
  background: var(--bg-hover);
}

.sidebar-nav-item.active {
  background: var(--bg-hover);
  border-left-color: var(--accent);
  color: #fff;
}

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

/* Tabs */
.tabs-bar {
  display: flex;
  align-items: center;
  height: 36px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.tabs-bar::-webkit-scrollbar {
  height: 6px;
}

.tabs-bar::-webkit-scrollbar-track {
  background: transparent;
}

.tabs-bar::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

.tabs-bar::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.tab {
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  user-select: none;
}

.tab.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.tabs-bar .tab-drop-indicator {
  width: 2px;
  height: 24px;
  background: var(--accent);
  flex-shrink: 0;
  margin: 0 -1px;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-close {
  margin-left: 6px;
  opacity: 0.6;
  font-size: 14px;
  line-height: 1;
}

.tab-close:hover {
  opacity: 1;
  color: var(--error);
}

.tab.pinned::after {
  content: '📌';
  margin-left: 4px;
  font-size: 10px;
}

.tab.pinned .tab-close {
  display: none;
}

/* Tab context menu */
.tab-context-menu {
  position: fixed;
  min-width: 180px;
  padding: 4px 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1001;
  display: none;
}

.tab-context-menu.show {
  display: block;
}

.tab-context-menu button {
  display: block;
  width: 100%;
  padding: 6px 12px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.tab-context-menu button:hover {
  background: var(--bg-hover);
}

/* Workspace (tool content) */
.workspace {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

/* Header */
.header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
  gap: 8px;
}

.header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.header-search-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
  margin: 0 16px;
}

.header-search {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.header-search:focus {
  outline: none;
  border-color: var(--accent);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
}

.search-results:not([hidden]) {
  display: block;
}

.search-result-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-item small {
  color: var(--text-muted);
  margin-left: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-select {
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

/* Chrome extension popup */
body.extension-popup #app {
  height: 100vh;
  max-height: 100%;
}

body.extension-popup .layout {
  min-height: 0;
  flex: 1;
}

body.extension-popup .sidebar {
  width: 160px;
  min-width: 160px;
  flex-shrink: 0;
}

body.extension-popup .sidebar-section-header {
  padding: 6px 10px 4px;
  font-size: 10px;
}

body.extension-popup .sidebar-nav-item {
  padding: 4px 10px 4px 12px;
  font-size: 11px;
}

body.extension-popup .header {
  height: 61px;
  min-height: 61px;
  padding: 0 8px;
}

body.extension-popup .header-title {
  font-size: 12px;
}

body.extension-popup .header-search-wrap {
  max-width: 140px;
  margin: 0 8px;
}

body.extension-popup .header-search {
  padding: 4px 8px;
  font-size: 11px;
}

body.extension-popup .tabs-bar {
  height: 32px;
}

body.extension-popup .tab {
  padding: 6px 10px;
  font-size: 11px;
}

body.extension-popup .workspace {
  padding: 10px;
  overflow: auto;
  min-height: 0;
}

body.extension-popup .tool-title {
  font-size: 15px;
}

body.extension-popup .tool-desc {
  font-size: 11px;
  margin-bottom: 10px;
}

body.extension-popup .split-row .split-half {
  min-width: 140px;
}

body.extension-popup .io-area .io-content {
  min-height: 60px;
  padding: 6px 8px;
  font-size: 12px;
}

body.extension-popup .pre-block {
  padding: 8px;
  font-size: 11px;
}

body.extension-popup .btn {
  padding: 4px 10px;
  font-size: 11px;
}

body.extension-popup .panel-body {
  padding: 8px;
}

/* Responsive */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 200px;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-section {
    flex: 1;
    min-width: 140px;
  }

  .sidebar-section-title {
    padding: 4px 8px;
  }

  .sidebar-nav-item {
    padding: 4px 8px;
    border-left: none;
    border-bottom: 2px solid transparent;
  }

  .sidebar-nav-item.active {
    border-left: none;
    border-bottom-color: var(--accent);
  }

  .workspace {
    padding: 12px;
  }
}
