:root {
  --bg-dark: #080b11;
  --bg-surface: #0f1523;
  --bg-surface-glass: rgba(15, 21, 35, 0.75);
  --bg-card: rgba(22, 31, 51, 0.6);
  --bg-card-hover: rgba(29, 41, 68, 0.7);
  --bg-input: #121929;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(99, 102, 241, 0.4);
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --emerald: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.2);
  --amber: #f59e0b;
  --rose: #f43f5e;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.2);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.05) 0%, transparent 40%);
}

/* App Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Top Navigation Bar */
.top-nav {
  height: 60px;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-orb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--emerald));
  box-shadow: 0 0 10px var(--primary);
  animation: pulse-glow 3s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.15); opacity: 1; box-shadow: 0 0 16px var(--primary); }
}

.logo-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.logo-title span {
  color: var(--primary);
}

.badge-vps {
  font-size: 0.7rem;
  padding: 2px 8px;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid var(--border-active);
  color: #c7d2fe;
  border-radius: var(--radius-full);
  font-weight: 500;
}

/* Telemetry Pills */
.nav-center {
  display: flex;
  align-items: center;
  gap: 10px;
}

.telemetry-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.online {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.status-dot.offline {
  background: var(--rose);
}

.pill-label {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.7rem;
}

.pill-value {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Body Split */
.workspace-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Left Sidebar */
.sidebar {
  width: 270px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 40;
}

.sidebar-header {
  padding: 16px;
}

.sidebar-section-title {
  padding: 8px 16px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.conv-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.conv-item.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--border-active);
  color: var(--text-main);
  font-weight: 500;
}

.conv-item .delete-btn {
  opacity: 0;
  padding: 2px 4px;
  background: none;
  border: none;
  color: var(--rose);
  cursor: pointer;
  border-radius: 4px;
}

.conv-item:hover .delete-btn {
  opacity: 1;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
}

.env-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.env-dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
}

.env-text code {
  color: #a5b4fc;
  font-family: var(--font-mono);
}

/* Chat Main Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* Welcome Hero Screen */
.welcome-hero {
  margin: auto;
  max-width: 680px;
  text-align: center;
  padding: 40px 20px;
}

.hero-icon-wrapper {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(16, 185, 129, 0.2));
  border: 1px solid var(--border-active);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
}

.hero-icon {
  font-size: 2rem;
}

.welcome-hero h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.03em;
}

.welcome-hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 30px;
}

.welcome-hero code {
  font-family: var(--font-mono);
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

.hero-prompts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  text-align: left;
}

.prompt-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prompt-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.prompt-icon {
  font-size: 1.3rem;
}

.prompt-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
}

.prompt-desc {
  font-size: 0.76rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Chat Messages */
.message-row {
  display: flex;
  gap: 16px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.user-row .message-avatar {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: white;
}

.agent-row .message-avatar {
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: white;
}

.message-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.message-bubble {
  font-size: 0.94rem;
  line-height: 1.65;
  color: var(--text-main);
}

.user-bubble {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
}

/* Thought Accordion */
.thought-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 0.82rem;
  transition: all 0.2s;
}

.thought-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  background: rgba(255, 255, 255, 0.02);
}

.thought-header:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.thought-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.thought-content {
  padding: 12px;
  color: #cbd5e1;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 250px;
  overflow-y: auto;
}

/* Tool Execution Terminal Cards */
.tool-card {
  background: #090d16;
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-family: var(--font-mono);
  box-shadow: var(--shadow-sm);
}

.tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(99, 102, 241, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tool-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.tool-name {
  color: #818cf8;
  font-weight: 600;
}

.tool-badge {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 600;
}

.tool-badge.running {
  background: rgba(245, 158, 11, 0.2);
  color: var(--amber);
  animation: pulse-glow 1.5s infinite;
}

.tool-badge.success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--emerald);
}

.tool-badge.error {
  background: rgba(244, 63, 94, 0.2);
  color: var(--rose);
}

.tool-body {
  padding: 10px 12px;
  font-size: 0.76rem;
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.5;
}

.tool-command {
  color: #38bdf8;
  margin-bottom: 6px;
}

.tool-result {
  color: #94a3b8;
  white-space: pre-wrap;
  word-break: break-all;
}

.tool-error {
  color: #fb7185;
  white-space: pre-wrap;
}

/* Interactive Question Card */
.interaction-card {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.interaction-question {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
}

.interaction-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-active);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.option-btn:hover {
  background: var(--primary);
  color: white;
}

/* Markdown Elements */
.message-bubble pre {
  margin: 12px 0;
  background: #090d16;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.message-bubble code:not(pre code) {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: #a5b4fc;
}

.message-bubble p {
  margin-bottom: 10px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

/* Chat Input Bar */
.chat-input-wrapper {
  padding: 16px 24px 20px;
  background: linear-gradient(180deg, transparent 0%, var(--bg-dark) 40%);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-container {
  display: flex;
  align-items: flex-end;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-container:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

#chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.94rem;
  line-height: 1.5;
  resize: none;
  max-height: 180px;
  min-height: 28px;
  padding: 4px 6px;
}

.send-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.input-hints {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 0 4px;
}

.api-key-warning {
  color: var(--amber);
  cursor: pointer;
}

/* Right Drawer: Workspace Explorer */
.workspace-drawer {
  width: 320px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 40;
}

.drawer-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
}

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

.workspace-info-banner {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  color: #c7d2fe;
  line-height: 1.4;
}

.workspace-files-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.file-row:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}

.file-name {
  font-family: var(--font-mono);
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: var(--text-dim);
  font-size: 0.72rem;
  font-family: var(--font-mono);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.file-preview-card {
  max-width: 780px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-body {
  padding: 20px;
}

.code-body {
  flex: 1;
  overflow: auto;
  padding: 0;
  background: #090d16;
}

.code-body pre {
  margin: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.84rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-group input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.input-with-action {
  display: flex;
  gap: 8px;
}

.form-help {
  display: block;
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.4;
}

.form-help a {
  color: #818cf8;
  text-decoration: none;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-active);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  .mobile-only {
    display: flex;
  }
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .nav-center .telemetry-pill:not(#status-pill) {
    display: none;
  }
  .btn-text {
    display: none;
  }
  .workspace-drawer {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 100%;
  }
}
