/* --- Theme --- */
:root {
  --bg: #070b13;
  --panel: #0f172a;
  --panel-2: #101624;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #5eead4;
  --accent-2: #7c3aed;
  --danger: #f87171;
  --inspector-width: 420px;
  font-family: "Manrope", "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(120% 100% at 20% 20%, rgba(124, 58, 237, 0.22), transparent 45%),
    radial-gradient(120% 90% at 85% 10%, rgba(94, 234, 212, 0.18), transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: var(--accent);
}

#app {
  min-height: 100vh;
  display: flex;
}

/* --- Preview --- */
#preview-pane {
  position: relative;
  flex: 1;
  padding: 12px 16px 20px 16px;
  overflow: auto;
  transition: padding-right 1s ease;
}

#preview-frame {
  width: 100%;
  max-width: 1600px;
  height: calc(100vh - 40px);
  border: 1px solid var(--border);
  border-radius: 0;
  background: #0b1020;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  display: block;
  margin: 0 auto;
}

#remote-exit {
  position: absolute;
  top: 22px;
  left: 28px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transform: translateX(-10px);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#remote-exit.visible {
  opacity: 1;
  transform: translateX(0);
}

/* --- Inspector --- */
#inspector {
  width: var(--inspector-width);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-left: 1px solid var(--border);
  box-shadow: -14px 0 40px rgba(0, 0, 0, 0.32);
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 1s ease, opacity 1s ease;
}

#inspector.hidden {
  transform: translateX(105%);
  opacity: 0;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-bottom: 1px solid var(--border);
}

.tabs button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 14px 8px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tabs button.active {
  color: var(--accent);
  border-color: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

#files-list {
  list-style: none;
  margin: 0;
  padding: 14px;
  overflow-y: auto;
}

#files-list li {
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

#files-list li:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

#files-list li.active {
  background: rgba(94, 234, 212, 0.08);
  border-color: rgba(94, 234, 212, 0.6);
}

#editor-tab {
  padding: 14px;
  gap: 12px;
}

#editor-textarea {
  width: 100%;
  height: 320px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  color: var(--text);
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

#editor-actions {
  display: flex;
  gap: 10px;
}

.btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.btn:hover {
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #0c1020;
  border-color: transparent;
}

#console-tab {
  padding: 14px;
  gap: 10px;
}

#console-output {
  flex: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  overflow-y: auto;
  white-space: pre-wrap;
}

#console-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
select,
textarea {
  outline: none;
}

input#console-command,
input#ai-command {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  padding: 11px 12px;
}

select {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  padding: 10px 12px;
}

#ai-tab {
  padding: 14px;
  gap: 10px;
}

#ai-top-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#ai-step-progress {
  display: grid;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

#ai-step-progress-text {
  color: var(--muted);
  font-size: 13px;
}

#ai-step-progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

#ai-step-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  transition: width 0.5s ease;
}

#session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

#session-link {
  color: var(--text);
  font-size: 13px;
  word-break: break-all;
}

#qr-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  justify-content: center;
}

#qr-panel.hidden {
  display: none;
}

#ai-mode-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
  flex-wrap: wrap;
}

.muted-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.01em;
}

#ai-mode-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.pill {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.btn.pill.active {
  background: rgba(94, 234, 212, 0.14);
  border-color: rgba(94, 234, 212, 0.6);
  color: var(--text);
}

#ai-context-lock {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 2px 4px;
  min-height: 18px;
}

#ai-api-config {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.config-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--muted);
  font-size: 13px;
}

.config-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

#ai-api-base {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  padding: 10px 12px;
}

#ai-api-status {
  color: var(--muted);
}

#ai-log {
  flex: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  overflow-y: auto;
  white-space: pre-wrap;
}

#ai-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 50%;
  min-width: 360px;
  align-self: center;
}

#api-catalog-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-title {
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.catalog-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.catalog-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#api-catalog-details {
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  gap: 6px;
}

#api-catalog-description {
  color: var(--text);
}

#api-functions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.function-chip {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.function-chip:hover {
  border-color: rgba(94, 234, 212, 0.6);
  background: rgba(94, 234, 212, 0.06);
  transform: translateY(-1px);
}

.function-params {
  color: var(--muted);
  font-size: 12px;
}

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

.function-desc {
  color: var(--muted);
  font-size: 12px;
}

.catalog-actions {
  display: flex;
  justify-content: flex-end;
}

/* --- Checkpoints --- */
#checkpoints-tab {
  padding: 14px;
}

#checkpoint-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px;
  height: 100%;
}

#checkpoint-list-container {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-label {
  padding: 10px 12px 6px;
}

#checkpoint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

#checkpoint-list li {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  display: grid;
  gap: 2px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#checkpoint-list li:hover {
  background: rgba(255, 255, 255, 0.04);
}

#checkpoint-list li.active {
  background: rgba(94, 234, 212, 0.08);
  border-color: rgba(94, 234, 212, 0.25);
}

.checkpoint-title {
  font-weight: 600;
  color: var(--text);
}

.checkpoint-meta {
  font-size: 12px;
  color: var(--muted);
}

#checkpoint-viewer {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 10px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  min-height: 0;
}

#checkpoint-meta {
  color: var(--muted);
  font-size: 13px;
}

#checkpoint-preview {
  width: 100%;
  height: calc(100vh - 260px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0b1020;
}

#checkpoint-actions {
  display: flex;
  justify-content: flex-end;
}

.loading-bar {
  height: 4px;
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.loading-bar::after {
  content: "";
  position: absolute;
  left: -40%;
  width: 40%;
  top: 0;
  bottom: 0;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  animation: loading-slide 1s linear infinite;
}

.loading-bar.hidden {
  display: none;
}

@keyframes loading-slide {
  0% { transform: translateX(0); }
  100% { transform: translateX(250%); }
}

#preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 19, 0.6);
  border-radius: 18px;
  z-index: 2;
}

#preview-overlay.hidden {
  display: none;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

#mini-chat {
  position: fixed;
  left: 15%;
  right: 15%;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding: 10px;
  display: grid;
  gap: 8px;
  z-index: 5;
  transform: translateY(0);
  transition: transform 1s ease, opacity 1s ease;
}

#mini-chat.hidden {
  transform: translateY(100%);
  opacity: 0;
}

body.inspector-open #preview-pane {
  padding-right: calc(var(--inspector-width) + 24px);
}

#mini-chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#mini-chat-input {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 10px 12px;
}

.hidden {
  display: none !important;
}

/* --- Scrollbar --- */
#files-list::-webkit-scrollbar,
#ai-log::-webkit-scrollbar,
#console-output::-webkit-scrollbar,
#editor-textarea::-webkit-scrollbar,
#checkpoint-list::-webkit-scrollbar {
  width: 10px;
}

#files-list::-webkit-scrollbar-thumb,
#ai-log::-webkit-scrollbar-thumb,
#console-output::-webkit-scrollbar-thumb,
#editor-textarea::-webkit-scrollbar-thumb,
#checkpoint-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

/* --- Mobile --- */
@media (max-width: 900px) {
  #preview-frame {
    height: 480px;
  }

  #inspector {
    width: 100%;
  }

  body.inspector-open #preview-pane {
    padding-right: 16px;
  }
}
