:root {
  --bg: #0a0e13;
  --panel: #0f1419;
  --panel-2: #151b23;
  --panel-3: #1a212a;
  --border: #242b36;
  --border-light: #2d3640;
  --text: #e6edf3;
  --text-secondary: #c9d1d9;
  --muted: #8b949e;
  --primary: #58a6ff;
  --primary-hover: #79c0ff;
  --primary-900: #0969da;
  --accent: #a5a5ff;
  --accent-hover: #b8b8ff;
  --success: #3fb950;
  --success-hover: #56d364;
  --warning: #d29922;
  --danger: #f85149;
  --danger-hover: #ff6b6b;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.5);
  --gradient-primary: linear-gradient(135deg, var(--primary), var(--accent));
  --gradient-panel: linear-gradient(180deg, var(--panel), var(--panel-2));
}

* { 
  box-sizing: border-box; 
  margin: 0;
  padding: 0;
}

html, body, #app { 
  height: 100%; 
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--panel);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--gradient-panel);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  box-shadow: 0 1px 3px var(--shadow);
  position: relative;
  z-index: 100;
}

.brand { 
  font-weight: 700; 
  font-size: 16px;
  letter-spacing: -0.02em; 
  display: flex; 
  align-items: center; 
  gap: 10px;
  color: var(--text);
}

.brand i { 
  color: var(--accent); 
  font-size: 18px;
  filter: drop-shadow(0 0 8px rgba(165, 165, 255, 0.3));
}

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

.btn { 
  background: var(--panel-2); 
  color: var(--text); 
  border: 1px solid var(--border); 
  border-radius: 8px; 
  height: 36px; 
  padding: 0 12px; 
  display: inline-flex; 
  align-items: center; 
  gap: 8px; 
  cursor: pointer; 
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--panel-3);
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px var(--shadow);
}

.btn.small { 
  height: 30px; 
  padding: 0 10px; 
  font-size: 12px;
}

.btn.primary { 
  background: var(--gradient-primary); 
  color: white; 
  border: none; 
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3);
}

.btn.primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--accent-hover));
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(88, 166, 255, 0.4);
}

.btn:disabled { 
  opacity: 0.5; 
  cursor: not-allowed; 
  transform: none;
  box-shadow: none;
}

.btn:active {
  transform: translateY(0);
}

.workspace { 
  display: grid; 
  grid-template-columns: 280px 1fr 400px; 
  height: calc(100% - 56px); 
  min-height: 0; 
  gap: 0;
}

.sidebar { 
  border-right: 1px solid var(--border); 
  background: var(--panel); 
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-header { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  padding: 12px 16px; 
  border-bottom: 1px solid var(--border); 
  color: var(--text-secondary); 
  font-weight: 600;
  font-size: 13px;
  background: var(--gradient-panel);
}

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

.sidebar-header i {
  color: var(--accent);
}

.file-tree { 
  list-style: none; 
  padding: 8px; 
  font-size: 13px; 
  overflow-y: auto;
  flex: 1;
}

.file-item, .folder-item { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  padding: 8px 12px; 
  border-radius: 8px; 
  cursor: pointer; 
  color: var(--text-secondary); 
  transition: all 0.2s ease;
  position: relative;
  margin: 2px 0;
}

.file-item:hover, .folder-item:hover { 
  background: var(--panel-2); 
  color: var(--text);
  transform: translateX(2px);
}

.file-item.active { 
  background: linear-gradient(90deg, var(--primary-900), rgba(88, 166, 255, 0.1)); 
  color: var(--primary);
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}

.file-item i, .folder-item i {
  width: 16px;
  text-align: center;
  opacity: 0.7;
}

.file-item.active i {
  opacity: 1;
  color: var(--primary);
}

.folder-item {
  font-weight: 500;
}

.folder-item > ul {
  margin-left: 16px;
  border-left: 1px solid var(--border);
  padding-left: 8px;
}

.editor-panel { 
  display: flex;
  flex-direction: column;
  background: var(--bg); 
  min-height: 0; 
  border-right: 1px solid var(--border);
}

.editor {
  flex: 1;
}

.tabs { 
  display: flex; 
  align-items: center; 
  gap: 4px; 
  border-bottom: 1px solid var(--border); 
  padding: 6px 12px; 
  overflow-x: auto; 
  background: var(--panel);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab { 
  background: var(--panel-2); 
  border: 1px solid var(--border); 
  border-radius: 8px 8px 0 0; 
  padding: 8px 12px; 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 120px;
  position: relative;
  white-space: nowrap;
}

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

.tab.active { 
  background: var(--bg);
  border-bottom-color: var(--bg);
  color: var(--text);
  border-top: 2px solid var(--primary);
  z-index: 1;
}

.tab .close { 
  opacity: 0.5; 
  padding: 2px;
  border-radius: 4px;
  transition: all 0.2s ease;
  margin-left: auto;
}

.tab .close:hover {
  opacity: 1;
  background: var(--danger);
  color: white;
}

.editor { position: relative; }
#editor { height: 100%; width: 100%; }
.hidden { display: none; }

.ai-panel { 
  background: var(--panel); 
  display: grid; 
  grid-template-rows: 48px 1fr auto; 
  min-height: 0; 
  border-left: 1px solid var(--border);
}

.ai-panel > .chat { 
  min-height: 0; 
}

.ai-header { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  padding: 12px 16px; 
  border-bottom: 1px solid var(--border); 
  color: var(--text-secondary); 
  font-weight: 600;
  font-size: 13px;
  background: var(--gradient-panel);
}

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

.ai-header i {
  color: var(--accent);
  filter: drop-shadow(0 0 6px rgba(165, 165, 255, 0.3));
}

.ai-modes {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat { 
  padding: 16px; 
  overflow-y: auto; 
  overflow-x: hidden; 
  font-size: 13px; 
  line-height: 1.5; 
  display: flex;
  flex-direction: column;
  gap: 12px; 
}

.bubble { 
  max-width: 85%; 
  padding: 12px 16px; 
  border-radius: 16px; 
  position: relative;
  animation: slideIn 0.3s ease;
}

.bubble.user { 
  align-self: flex-end; 
  background: linear-gradient(135deg, var(--primary-900), rgba(88, 166, 255, 0.2)); 
  border: 1px solid rgba(88, 166, 255, 0.3);
  color: var(--text);
}

.bubble.assistant { 
  align-self: flex-start; 
  background: var(--panel-2); 
  border: 1px solid var(--border);
  color: var(--text);
}

.bubble .meta { 
  color: var(--muted); 
  font-size: 11px; 
  font-weight: 600;
  margin-bottom: 6px; 
  line-height: 1; 
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bubble > div:last-child { 
  white-space: pre-wrap; 
  line-height: 1.4; 
}

.edit-tag {
  display: inline-block;
  margin: 4px 0;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.edit-tag.editing {
  background: linear-gradient(135deg, var(--panel-2), #1a2332);
  border-color: var(--primary);
  color: var(--primary);
}
.edit-tag.edited {
  background: linear-gradient(135deg, var(--panel-2), #1a2e1f);
  border-color: var(--success);
  color: var(--success);
}

.edit-card { 
  display: block; 
  margin: 8px 0; 
  padding: 8px 12px; 
  border-radius: 6px; 
  border: 1px solid var(--border);
  background: var(--panel-2);
  transition: all 0.3s ease;
  font-size: 12px;
}
.edit-card.editing { 
  background: linear-gradient(135deg, var(--panel-2), #1a2332);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.edit-card.completed { 
  background: linear-gradient(135deg, var(--panel-2), #1a2e1f);
  border-color: var(--success);
  box-shadow: 0 0 0 1px var(--success);
}
.edit-card-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.edit-icon {
  font-size: 12px;
  width: 14px;
  text-align: center;
}
.edit-card.editing .edit-icon {
  color: var(--primary);
}
.edit-card.completed .edit-icon {
  color: var(--success);
}
.edit-text {
  flex: 1;
  font-weight: 500;
}
.edit-spinner {
  color: var(--primary);
  font-size: 10px;
  animation: spin 1s linear infinite;
}
.edit-card.completed .edit-spinner {
  display: none;
}
.response-text {
  margin: 4px 0;
  line-height: 1.4;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.bubble pre { background: #0c1116; border: 1px solid var(--border); padding: 8px; border-radius: 8px; white-space: pre-wrap; }
.switch { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.switch input { accent-color: var(--accent); }
.ai-input { 
  border-top: 1px solid var(--border); 
  padding: 16px; 
  display: grid; 
  gap: 12px; 
  background: var(--panel);
}

.ai-input textarea { 
  width: 100%; 
  background: var(--panel-2); 
  color: var(--text); 
  border: 1px solid var(--border); 
  border-radius: 12px; 
  padding: 12px 16px; 
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: vertical;
  min-height: 80px;
  transition: all 0.2s ease;
}

.ai-input textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.ai-input textarea::placeholder {
  color: var(--muted);
}

.ai-input-actions { 
  display: flex; 
  gap: 8px; 
  align-items: center; 
  justify-content: flex-end; 
}

.ai-input-actions #stop-ai { 
  display: none; 
  background: var(--danger); 
  border-color: var(--danger); 
  color: white;
}

.ai-input-actions #stop-ai:hover {
  background: var(--danger-hover);
}

.ai-modes #apply-ai { 
  display: none; 
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.ai-modes #apply-ai:hover {
  background: var(--success-hover);
}

.code-block { background: #0c1116; border: 1px solid var(--border); padding: 8px; border-radius: 8px; margin: 8px 0; white-space: pre-wrap; }
.token-file { color: var(--primary); }
.token-added { color: var(--success); }
.token-removed { color: var(--danger); }

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 220px 1fr 320px; }
}
/* Early Testing Popup */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 15, 20, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

.popup-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease;
}

.popup-header {
  padding: 20px 24px 0;
  text-align: center;
}

.popup-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
}

.popup-body {
  padding: 16px 24px;
  color: var(--text);
  line-height: 1.5;
}

.popup-body ul {
  margin: 16px 0;
  padding-left: 20px;
}

.popup-body li {
  margin: 8px 0;
  color: var(--muted);
}

.popup-footer {
  padding: 0 24px 24px;
  text-align: center;
}

.popup-footer .btn {
  min-width: 120px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { 
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to { 
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr 300px 300px; }
  .sidebar { grid-row: 2; }
  .ai-panel { grid-row: 3; }
  .hide-sm { display: none; }
}


/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Context Menu */
.context-menu {
  animation: slideIn 0.2s ease;
}

.context-menu-item:hover {
  background: var(--panel-3) !important;
}

/* Loading States */
.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Enhanced Edit Cards */
.edit-card {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.edit-card.editing {
  animation: slideIn 0.3s ease;
}

.edit-card.completed {
  animation: slideIn 0.3s ease;
}

/* Improved Switch */
.switch input[type="checkbox"] {
  appearance: none;
  width: 40px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: all 0.3s ease;
}

.switch input[type="checkbox"]:checked {
  background: var(--primary);
}

.switch input[type="checkbox"]::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch input[type="checkbox"]:checked::before {
  transform: translateX(20px);
}

/* Enhanced Tabs */
.tab {
  position: relative;
  overflow: hidden;
}

.tab::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s ease;
}

.tab:hover::before {
  left: 100%;
}

/* File Tree Enhancements */
.file-item, .folder-item {
  position: relative;
  overflow: hidden;
}

.file-item::before, .folder-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background: var(--primary);
  transform: scaleY(0);
  transition: transform 0.2s ease;
}

.file-item:hover::before, .folder-item:hover::before {
  transform: scaleY(1);
}

.file-item.active::before {
  transform: scaleY(1);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .workspace { 
    grid-template-columns: 250px 1fr 350px; 
  }
}

@media (max-width: 900px) {
  .workspace { 
    grid-template-columns: 1fr; 
    grid-template-rows: 200px 1fr 250px; 
  }
  
  .sidebar { 
    grid-row: 1; 
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  
  .editor-panel { 
    grid-row: 2; 
    border-right: none;
  }
  
  .ai-panel { 
    grid-row: 3; 
    border-left: none;
    border-top: 1px solid var(--border);
  }
  
  .hide-sm { 
    display: none; 
  }
  
  .topbar {
    padding: 0 12px;
  }
  
  .actions {
    gap: 4px;
  }
  
  .btn {
    padding: 0 8px;
    height: 32px;
  }
}

@media (max-width: 600px) {
  .workspace {
    grid-template-rows: 150px 1fr 200px;
  }
  
  .sidebar-header, .ai-header {
    padding: 8px 12px;
  }
  
  .chat {
    padding: 12px;
  }
  
  .ai-input {
    padding: 12px;
  }
  
  .bubble {
    max-width: 95%;
    padding: 10px 12px;
  }
}

/* Dark mode enhancements */
@media (prefers-color-scheme: dark) {
  body {
    color-scheme: dark;
  }
}

/* Focus styles for accessibility */
.btn:focus-visible,
.file-item:focus-visible,
.folder-item:focus-visible,
.tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.3);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: #ffffff;
    --text: #ffffff;
    --bg: #000000;
    --panel: #1a1a1a;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
