:root {
  --bg-main: #0b0f17;
  --bg-panel: #131924;
  --bg-elevated: #1c2433;
  --bg-hover: #253044;
  --border: #2a3548;
  --text-primary: #e6edf3;
  --text-secondary: #8b98ad;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #c084fc;
  --font-sans: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", "Consolas", "Courier New", monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Topbar */
.topbar {
  height: 54px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.brand-logo {
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.18), rgba(192, 132, 252, 0.18));
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent);
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

select, input, textarea, button {
  font-family: inherit;
}

.select-model {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12.5px;
  outline: none;
  cursor: pointer;
}

.btn {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: #3e4e68;
}

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

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-success {
  background: #16a34a;
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #15803d;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.24);
}

.btn-toggle.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.45);
  color: #4ade80;
}

.btn-accent {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--accent);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  display: inline-block;
}

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

/* Main 3-column IDE Grid */
.workspace-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 245px 1fr 45%;
  overflow: hidden;
}

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

.panel-header {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.workspace-path-box {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
}

.workspace-path-text {
  font-family: var(--font-mono);
  color: var(--accent);
  word-break: break-all;
  margin-bottom: 7px;
  font-size: 11px;
}

.sidebar-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.file-item {
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--text-primary);
  user-select: none;
}

.file-item:hover {
  background: var(--bg-elevated);
}

.file-item.active {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
  font-weight: 600;
}

.file-name-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-size: 10.5px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Center Chat Panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.mode-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.mode-pill {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.mode-pill:hover {
  color: var(--text-primary);
  border-color: #4b5b76;
}

.mode-pill.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent);
  color: var(--accent);
}

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

.welcome-card {
  background: linear-gradient(180deg, rgba(28, 36, 51, 0.75), rgba(19, 25, 36, 0.95));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.welcome-card h2 {
  font-size: 17px;
  margin-bottom: 8px;
  color: var(--accent);
}

.welcome-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 12px;
}

.feature-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.ftag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.prompt-chips {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.chip {
  text-align: left;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.msg {
  max-width: 95%;
  padding: 11px 14px;
  border-radius: 10px;
  line-height: 1.6;
  font-size: 13.5px;
  word-wrap: break-word;
}

.msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #0284c7, #1d4ed8);
  color: #fff;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}

.msg-user-imgs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.msg-user-imgs img {
  max-height: 90px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.msg-ai {
  align-self: flex-start;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
  width: 100%;
}

.msg-ai p {
  margin-bottom: 8px;
}

.msg-ai p:last-child {
  margin-bottom: 0;
}

.msg-ai code {
  font-family: var(--font-mono);
  background: rgba(148, 163, 184, 0.18);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.msg-ai pre {
  background: #070a10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}

.msg-ai pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  color: #e2e8f0;
}

/* Tool & Thought logs */
.agent-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

details.step-card {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  overflow: hidden;
}

details.step-card summary {
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  color: var(--text-secondary);
  list-style: none;
}

details.step-card summary::-webkit-details-marker {
  display: none;
}

details.step-card summary:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.step-body {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: #080b11;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 210px;
  overflow-y: auto;
}

.badge-running { color: var(--warning); font-size: 11px; }
.badge-done { color: var(--success); font-size: 11px; }
.badge-thought { color: var(--purple); }
.badge-web { color: var(--accent); }

/* Image Attachment Bar */
.attachment-strip {
  display: none;
  gap: 8px;
  padding: 8px 12px 0 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.attachment-strip.has-items {
  display: flex;
}

.att-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--accent);
}

.att-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.att-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
}

/* Chat Input */
.chat-input-area {
  padding: 10px 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  outline: none;
}

.chat-textarea:focus {
  border-color: var(--accent);
}

/* Right Viewer / Editor / Preview / Terminal Panel */
.viewer-panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  gap: 6px;
  flex-wrap: wrap;
}

.tab-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.tab-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
}

.editor-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #080b11;
}

.code-editor {
  flex: 1;
  width: 100%;
  background: #080b11;
  color: #e2e8f0;
  border: none;
  outline: none;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  resize: none;
  tab-size: 2;
}

.image-viewer-box {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  background: #080b11;
  overflow: auto;
}

.image-viewer-box img {
  max-width: 92%;
  max-height: 78%;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.preview-container {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  background: #1e293b;
  overflow: auto;
}

.preview-iframe {
  border: none;
  width: 100%;
  height: 100%;
  background: #fff;
  transition: width 0.2s ease;
}

.preview-iframe.mobile-mode {
  width: 390px;
  max-width: 100%;
  margin: 12px auto;
  border-radius: 18px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
  height: calc(100% - 24px);
}

/* Integrated Terminal Tab */
.terminal-container {
  flex: 1;
  display: none;
  flex-direction: column;
  background: #06080d;
  overflow: hidden;
}

.terminal-output {
  flex: 1;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #a7f3d0;
  overflow-y: auto;
  white-space: pre-wrap;
}

.terminal-input-row {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
  background: #0d121c;
  padding: 8px 10px;
  gap: 8px;
}

.terminal-prompt {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
}

.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 490px;
  max-width: 92vw;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.modal h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

.modal p, .modal li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal ol {
  margin: 8px 0 14px 20px;
}

.modal a {
  color: var(--accent);
  text-decoration: none;
}

.modal a:hover {
  text-decoration: underline;
}

.modal-input {
  width: 100%;
  background: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font-mono);
  margin-bottom: 14px;
  outline: none;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
