:root {
  --bg: #111113;
  --surface: #1a1a1f;
  --surface-raised: #222228;
  --border: #2e2e36;
  --border-subtle: #252530;
  --text: #e4e4e8;
  --text-secondary: #8b8b96;
  --accent: #6e56cf;
  --accent-hover: #7c66d4;
  --accent-text: #f0ecff;
  --console-bg: #0c0c0e;
  --console-text: #b0d4b8;
  --editor-bg: #16161a;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --tab-active: #6e56cf;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
}

button,
select,
textarea {
  font: inherit;
}

/* ── Shell ── */

.shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top bar ── */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.eyebrow {
  display: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.toolbar-label {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-right: 2px;
}

select,
button {
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  transition: border-color 0.15s, background 0.15s;
}

select:hover,
button:hover {
  border-color: #44444e;
  background: #2a2a32;
}

button {
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 500;
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ── Workspace ── */

.workspace {
  display: grid;
  grid-template-columns: 340px 1fr 1fr;
  gap: 2px;
  flex: 1;
  min-height: 0;
  background: var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
}

/* ── Settings popover ── */

.settings-popover {
  position: absolute;
  top: 56px;
  right: 16px;
  z-index: 100;
  width: 320px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-popover[hidden] {
  display: none;
}

.settings-popover label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  margin-top: 6px;
}

.settings-popover input {
  border: 1px solid var(--border);
  background: var(--editor-bg);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.82rem;
}

.settings-popover input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-help {
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.5;
}

.field-help a {
  color: var(--accent-hover);
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ── Chat column ── */

.chat-column {
  min-height: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.left-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: var(--surface);
  flex-shrink: 0;
}

.left-tab {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 16px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  position: relative;
  transition: color 0.15s;
}

.left-tab:hover {
  color: var(--text);
  background: transparent;
  border: none;
}

.left-tab.active {
  color: var(--text);
  background: transparent;
  border: none;
}

.left-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--tab-active);
  border-radius: 2px 2px 0 0;
}

.left-panel {
  display: none;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--border-subtle);
}

.left-panel.active {
  display: flex;
  flex-direction: column;
}

.data-panel {
  padding: 12px 14px;
  overflow-y: auto;
}

.data-panel.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.panel-title h2 {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.upload-button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.72rem;
}

.upload-button:hover {
  border-color: #44444e;
  background: #2a2a32;
}

.data-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.data-item {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.78rem;
}

.data-item-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--text);
  word-break: break-all;
}

.data-item-meta {
  color: var(--text-secondary);
  font-size: 0.7rem;
}

.data-item-warning {
  color: #f0b45b;
  font-size: 0.7rem;
}

.data-item button {
  padding: 2px 8px;
  font-size: 0.68rem;
  flex-shrink: 0;
}

.drop-hint {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-align: center;
}

/* ── Chat panel ── */

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-message {
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 95%;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--surface-raised);
  color: var(--text);
}

.chat-message.progress {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.chat-message.notice {
  align-self: stretch;
  background: rgba(240, 180, 91, 0.08);
  border: 1px solid rgba(240, 180, 91, 0.35);
  color: #f0b45b;
  font-size: 0.76rem;
}

.chat-message.running {
  align-self: flex-start;
  color: var(--text-secondary);
  font-size: 0.76rem;
}

/* ── Execution log ── */

.log-panel {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.log-panel ul {
  list-style: none;
  margin: 0;
  padding: 10px 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Chat form ── */

.chat-form {
  flex-shrink: 0;
  border-top: 1px solid var(--border-subtle);
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-form textarea {
  flex: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--editor-bg);
  padding: 9px 11px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 0.82rem;
  line-height: 1.5;
}

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

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

/* ── Editors ── */

.editors,
.preview-column {
  min-height: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.editor-tabs,
.viewer-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: var(--surface);
  flex-shrink: 0;
}

.editor-tab,
.viewer-tab {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 16px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  position: relative;
  transition: color 0.15s;
}

.editor-tab:hover,
.viewer-tab:hover {
  color: var(--text);
  background: transparent;
  border: none;
}

.editor-tab.active,
.viewer-tab.active {
  color: var(--text);
  background: transparent;
  border: none;
}

.editor-tab.active::after,
.viewer-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--tab-active);
  border-radius: 2px 2px 0 0;
}

/* ── Editor panels ── */

.editor-panel {
  display: none;
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  overflow: hidden;
}

.editor-panel.active {
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.panel-header h2 {
  display: none;
}

.panel-header p {
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.5;
  max-width: 60ch;
}

textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  border: none;
  padding: 16px;
  background: var(--editor-bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
}

textarea::selection {
  background: rgba(110, 86, 207, 0.35);
}

textarea:focus {
  outline: none;
}

/* ── Preview column ── */

.preview-column {
  padding: 0;
  display: flex;
  flex-direction: column;
}

.viewer-panel {
  display: none;
  min-height: 0;
  flex: 1;
}

.viewer-panel.active {
  display: flex;
  flex-direction: column;
}

#preview-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: #fff;
}

/* ── Console ── */

.console-panel {
  background: var(--console-bg);
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.console-header h2 {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.console-header button {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  font-size: 0.72rem;
}

.console-header button:hover {
  color: var(--text);
}

#console-output {
  margin: 0;
  flex: 1;
  padding: 12px 16px;
  overflow: auto;
  color: var(--console-text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ── Responsive ── */

@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: 320px 1fr;
  }

  .preview-column {
    grid-column: 1 / -1;
    min-height: 50vh;
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: start;
  }

  .shell {
    height: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .chat-column,
  .editors {
    min-height: 50vh;
  }

  .preview-column {
    min-height: 50vh;
  }
}
