/* ═══════════════════════════════════════════════════════════════
   Web Coder — IDE-style layout for admin code assistant
   3-panel: File Explorer | Main Content (Chat/Editor) | Status
   ═══════════════════════════════════════════════════════════════ */

.webcoder {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  min-height: 400px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-bg);
}

/* ── Header ────────────────────────────────────────────────── */

.webcoder__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  gap: 12px;
  flex-shrink: 0;
}

.webcoder__header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.webcoder__header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.webcoder__title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
}

.webcoder__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
  flex-shrink: 0;
}

.webcoder__status-dot--connected {
  background: var(--color-accent);
}

.webcoder__status-dot--streaming {
  background: #f59e0b;
  animation: webcoder-pulse 1.5s ease-in-out infinite;
}

@keyframes webcoder-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Panel Tabs ────────────────────────────────────────────── */

.webcoder__tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  flex-shrink: 0;
  overflow-x: auto;
}

.webcoder__tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

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

.webcoder__tab--active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.webcoder__tab svg {
  width: 14px;
  height: 14px;
}

/* ── Body (3 panels) ───────────────────────────────────────── */

.webcoder__body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── File Sidebar ──────────────────────────────────────────── */

.webcoder__sidebar {
  width: 260px;
  min-width: 200px;
  max-width: 400px;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  background: var(--color-bg-secondary);
  flex-shrink: 0;
}

.webcoder__sidebar--collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

.webcoder__sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
}

.webcoder__sidebar-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.webcoder__sidebar-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.webcoder__sidebar-toggle:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.webcoder__file-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
}

.webcoder__file-search input {
  width: 100%;
  padding: 6px 10px;
  font-size: var(--font-size-xs);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  outline: none;
}

.webcoder__file-search input:focus {
  border-color: var(--color-primary);
}

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

.webcoder__tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  line-height: 1.6;
}

.webcoder__tree-item:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.webcoder__tree-item--active {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary);
}

.webcoder__tree-item--dir {
  font-weight: var(--font-weight-medium);
}

.webcoder__tree-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

.webcoder__tree-icon--dir {
  color: #e8a87c;
}

.webcoder__tree-icon--file {
  color: var(--color-text-muted);
}

.webcoder__tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main Content ──────────────────────────────────────────── */

.webcoder__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ── Chat Panel ────────────────────────────────────────────── */

.webcoder__chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.webcoder__chat-sidebar {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
}

.webcoder__conv-list-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-right: 1px solid var(--color-border);
  cursor: pointer;
}

.webcoder__conv-list-toggle:hover {
  color: var(--color-text);
  background: var(--color-hover);
}

.webcoder__conv-new {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
}

.webcoder__conv-new:hover {
  background: var(--color-hover);
}

.webcoder__conv-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-top: none;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.webcoder__conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-light, rgba(0,0,0,0.05));
}

.webcoder__conv-item:hover {
  background: var(--color-hover);
}

.webcoder__conv-item--active {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  color: var(--color-primary);
}

.webcoder__conv-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.webcoder__conv-item-delete {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  opacity: 0;
  flex-shrink: 0;
}

.webcoder__conv-item:hover .webcoder__conv-item-delete {
  opacity: 1;
}

.webcoder__conv-item-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* ── Messages ──────────────────────────────────────────────── */

.webcoder__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.webcoder__msg {
  max-width: 95%;
  font-size: var(--font-size-sm);
  line-height: 1.6;
}

.webcoder__msg--user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
}

.webcoder__msg--assistant {
  align-self: flex-start;
  background: var(--color-bg-secondary);
  padding: 12px 16px;
  border-radius: 4px 16px 16px 16px;
  border: 1px solid var(--color-border);
  width: 100%;
  max-width: 100%;
}

.webcoder__code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: #2d2d3d;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-top: 8px;
  font-size: 11px;
  font-family: monospace;
}

.webcoder__code-path {
  color: #89b4fa;
}

.webcoder__code-lang {
  color: #6c7086;
  text-transform: uppercase;
}

.webcoder__code-open {
  padding: 1px 8px;
  font-size: 10px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

.webcoder__code-open:hover {
  opacity: 0.9;
}

.webcoder__code-header + pre {
  margin-top: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.webcoder__msg--assistant pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0;
}

.webcoder__msg--assistant code {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
}

.webcoder__msg--assistant p code {
  background: var(--color-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.webcoder__msg--assistant h1,
.webcoder__msg--assistant h2,
.webcoder__msg--assistant h3 {
  margin: 12px 0 8px;
  font-weight: var(--font-weight-semibold);
}

.webcoder__msg--assistant h1 { font-size: var(--font-size-lg); }
.webcoder__msg--assistant h2 { font-size: var(--font-size-base); }
.webcoder__msg--assistant h3 { font-size: var(--font-size-sm); }

.webcoder__msg--assistant ul,
.webcoder__msg--assistant ol {
  padding-left: 20px;
  margin: 8px 0;
}

/* ── Tool Calls ────────────────────────────────────────────── */

.webcoder__tool {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin: 4px 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-family: monospace;
  color: var(--color-text-secondary);
}

.webcoder__tool-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.webcoder__tool--running .webcoder__tool-icon {
  color: #f59e0b;
  animation: webcoder-pulse 1s ease-in-out infinite;
}

.webcoder__tool--done .webcoder__tool-icon {
  color: var(--color-accent);
}

.webcoder__tool--error .webcoder__tool-icon {
  color: #ef4444;
}

/* ── Attachments ───────────────────────────────────────── */

.webcoder__attachments {
  display: flex;
  gap: 8px;
  padding: 8px 16px 0;
  flex-wrap: wrap;
}

.webcoder__attachment {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  max-width: 200px;
}

.webcoder__attachment-thumb {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
}

.webcoder__attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  color: var(--color-text-secondary);
}

.webcoder__attachment-remove {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  border-radius: 2px;
  flex-shrink: 0;
}

.webcoder__attachment-remove:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.webcoder__attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 18px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  transition: background 0.15s;
}

.webcoder__attach-btn:hover {
  background: var(--color-hover);
}

.webcoder__tool-name {
  font-weight: 600;
  color: var(--color-text);
}

.webcoder__tool-input {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  opacity: 0.7;
}

/* ── Streaming indicator ───────────────────────────────────── */

.webcoder__streaming {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.webcoder__streaming-dots {
  display: flex;
  gap: 3px;
}

.webcoder__streaming-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: webcoder-bounce 1.4s ease-in-out infinite both;
}

.webcoder__streaming-dots span:nth-child(1) { animation-delay: -0.32s; }
.webcoder__streaming-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes webcoder-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Chat Input ────────────────────────────────────────────── */

.webcoder__input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}

.webcoder__input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.webcoder__input {
  flex: 1;
  min-height: 40px;
  max-height: 200px;
  padding: 10px 14px;
  font-size: var(--font-size-sm);
  font-family: inherit;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  resize: none;
  outline: none;
  line-height: 1.5;
}

.webcoder__input:focus {
  border-color: var(--color-primary);
}

.webcoder__input::placeholder {
  color: var(--color-text-muted);
}

.webcoder__send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.webcoder__send-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-primary) 85%, #000);
}

.webcoder__send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.webcoder__send-btn svg {
  width: 18px;
  height: 18px;
}

.webcoder__stop-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
}

.webcoder__stop-btn:hover {
  background: #dc2626;
}

.webcoder__model-select {
  font-size: var(--font-size-xs);
  padding: 4px 8px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  margin-top: 8px;
}

/* ── Editor Panel ──────────────────────────────────────────── */

.webcoder__editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.webcoder__editor-tabs {
  display: flex;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  flex-shrink: 0;
}

.webcoder__editor-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-right: 1px solid var(--color-border);
  cursor: pointer;
  white-space: nowrap;
  max-width: 180px;
}

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

.webcoder__editor-tab--active {
  background: var(--color-bg);
  color: var(--color-text);
}

.webcoder__editor-tab-close {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 2px;
  line-height: 1;
}

.webcoder__editor-tab-close:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.webcoder__editor-tab-modified {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
}

.webcoder__editor-content {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.webcoder__editor-gutter {
  width: 48px;
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  flex-shrink: 0;
  padding-top: 10px;
}

.webcoder__editor-gutter-line {
  height: 20px;
  line-height: 20px;
  text-align: right;
  padding-right: 8px;
  font-size: 11px;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  color: var(--color-text-muted);
  user-select: none;
}

.webcoder__editor-textarea {
  flex: 1;
  padding: 10px 16px;
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 20px;
  background: var(--color-bg);
  color: var(--color-text);
  border: none;
  resize: none;
  outline: none;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
  min-height: 0;
}

.webcoder__editor-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.webcoder__editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  font-size: 11px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.webcoder__editor-toolbar button {
  padding: 2px 8px;
  font-size: 11px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.webcoder__editor-toolbar button:hover {
  opacity: 0.9;
}

/* ── Search Panel ──────────────────────────────────────────── */

.webcoder__search {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.webcoder__search-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.webcoder__search-bar input {
  flex: 1;
  padding: 8px 12px;
  font-size: var(--font-size-sm);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  outline: none;
}

.webcoder__search-bar input:focus {
  border-color: var(--color-primary);
}

.webcoder__search-bar button {
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.webcoder__search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.webcoder__search-result {
  display: flex;
  flex-direction: column;
  padding: 6px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-light, rgba(0,0,0,0.03));
}

.webcoder__search-result:hover {
  background: var(--color-hover);
}

.webcoder__search-result-file {
  font-size: 12px;
  font-weight: var(--font-weight-medium);
  color: var(--color-primary);
}

.webcoder__search-result-line {
  font-size: 11px;
  color: var(--color-text-muted);
  font-family: monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.webcoder__search-result-num {
  color: var(--color-text-muted);
  margin-right: 8px;
}

/* ── Status Bar ────────────────────────────────────────────── */

.webcoder__statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 12px;
  background: var(--color-primary);
  color: rgba(255,255,255,0.85);
  font-size: 11px;
  flex-shrink: 0;
}

.webcoder__statusbar-left,
.webcoder__statusbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Welcome screen ────────────────────────────────────────── */

.webcoder__welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--color-text-muted);
  padding: 32px;
  text-align: center;
}

.webcoder__welcome h2 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
}

.webcoder__welcome p {
  font-size: var(--font-size-sm);
  max-width: 480px;
  line-height: 1.6;
}

.webcoder__welcome-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.webcoder__welcome-shortcut {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.webcoder__welcome-shortcut kbd {
  padding: 2px 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 10px;
  font-family: monospace;
}

/* ── File Tree Actions (hover-reveal) ─────────────────────── */

.webcoder__tree-actions {
  margin-left: auto;
  display: none;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.webcoder__tree-item:hover .webcoder__tree-actions {
  display: flex;
}

/* ── Tables ────────────────────────────────────────────────── */

.webcoder__table-wrap {
  overflow-x: auto;
  margin: 8px 0;
}

.webcoder__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.webcoder__table th,
.webcoder__table td {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  text-align: left;
}

.webcoder__table th {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}

.webcoder__table td {
  color: var(--color-text-secondary);
}

.webcoder__table tr:hover td {
  background: var(--color-hover);
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {
  .webcoder__sidebar {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
  }

  .webcoder__sidebar--mobile-open {
    position: absolute;
    width: 260px;
    height: 100%;
    z-index: 20;
    border-right: 1px solid var(--color-border);
  }

  .webcoder {
    height: calc(100vh - 140px);
  }
}
