/* ═══════════════════════════════════════════════════════════════
   tine — Black & White Duotone
   ═══════════════════════════════════════════════════════════════ */

/* ── Theme tokens ─────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #0a0a0a;
  --bg-surface:   #111111;
  --bg-cell:      #0e0e0e;
  --bg-input:     #141414;
  --bg-output:    #111111;
  --bg-hover:     #1c1c1c;
  --bg-panel:     #111111;

  --border:       #2a2a2a;
  --border-subtle:#1e1e1e;
  --border-active:#ffffff;

  --fg:           #e8e8e8;
  --fg-2:         #999999;
  --fg-3:         #555555;

  --accent:       #ffffff;
  --accent-dim:   #cccccc;
  --accent-bg:    rgba(255,255,255,0.06);

  --green:        #4ade80;
  --green-bg:     rgba(74,222,128,0.08);
  --red:          #f87171;
  --red-bg:       rgba(248,113,113,0.08);
  --yellow:       #fbbf24;
  --yellow-bg:    rgba(251,191,36,0.08);
  --purple:       #a78bfa;
  --purple-bg:    rgba(167,139,250,0.08);
  --blue:         #60a5fa;

  --cm-bg:        #0e0e0e;
  --cm-cursor:    #ffffff;
  --cm-selection: rgba(255,255,255,0.12);
  --cm-line-hl:   rgba(255,255,255,0.03);
}

[data-theme="light"] {
  --bg:           #ffffff;
  --bg-surface:   #fafafa;
  --bg-cell:      #ffffff;
  --bg-input:     #f5f5f5;
  --bg-output:    #fafafa;
  --bg-hover:     #f0f0f0;
  --bg-panel:     #fafafa;

  --border:       #e0e0e0;
  --border-subtle:#eeeeee;
  --border-active:#000000;

  --fg:           #1a1a1a;
  --fg-2:         #666666;
  --fg-3:         #999999;

  --accent:       #000000;
  --accent-dim:   #333333;
  --accent-bg:    rgba(0,0,0,0.04);

  --green:        #22c55e;
  --green-bg:     rgba(34,197,94,0.06);
  --red:          #ef4444;
  --red-bg:       rgba(239,68,68,0.06);
  --yellow:       #eab308;
  --yellow-bg:    rgba(234,179,8,0.06);
  --purple:       #8b5cf6;
  --purple-bg:    rgba(139,92,246,0.06);
  --blue:         #3b82f6;

  --cm-bg:        #ffffff;
  --cm-cursor:    #000000;
  --cm-selection: rgba(0,0,0,0.08);
  --cm-line-hl:   rgba(0,0,0,0.02);
}

:root {
  --font:       -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  --font-mono:  "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", monospace;
  --radius:     8px;
  --radius-sm:  4px;

  /* Layout */
  --sidebar-w: 280px;
  --sidebar-collapsed-w: 44px;
  --titlebar-h: 56px;
  --titlebar-logo-h: 40px;
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #root {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ───────────────────────────────────────────────── */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app.notebook-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "sidebar main";
}

/* ── Titlebar ─────────────────────────────────────────────────── */
.titlebar {
  grid-area: titlebar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--titlebar-h);
  padding: 0 16px 0 88px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  -webkit-app-region: drag;
  user-select: none;
  z-index: 100;
}

.titlebar.titlebar-project {
  padding-left: 112px;
}

.titlebar-left, .titlebar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  -webkit-app-region: no-drag;
}

.projects-nav-btn {
  margin-left: 10px;
}

.titlebar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  line-height: 0;
}

.titlebar-logo-mark {
  width: auto;
  height: var(--titlebar-logo-h);
  max-width: min(180px, 24vw);
  object-fit: contain;
  display: block;
}

.titlebar-logo-light {
  display: none;
}

[data-theme="light"] .titlebar-logo-dark {
  display: none;
}

[data-theme="light"] .titlebar-logo-light {
  display: block;
}

.logo {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.5px;
  color: var(--accent);
}

@media (max-width: 768px) {
  .titlebar {
    padding-left: 16px;
  }

  .titlebar-logo-mark {
    height: 34px;
    max-width: min(150px, 36vw);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--fg-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  color: var(--fg);
}

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

.btn:disabled:hover {
  background: transparent;
  color: var(--fg-2);
}

.btn svg {
  flex: 0 0 auto;
}

.btn-primary {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--fg);
  font-weight: 600;
}

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

.btn-secondary {
  border-color: var(--border-subtle);
  color: var(--fg-2);
}

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

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

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 9px;
}

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

.btn-wide {
  width: 100%;
}

.btn-danger:hover {
  background: var(--red-bg);
  color: var(--red);
}

.titlebar-btn {
  flex-shrink: 0;
}

.titlebar-btn svg {
  width: 15px;
  height: 15px;
  display: block;
}

.experiment-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.ws-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-3);
}

.ws-indicator.connected {
  background: var(--green);
}

/* ── Main Content Layout ──────────────────────────────────────── */
.main-content {
  grid-area: main;
  position: relative;
  z-index: 1;
  display: flex;
  height: 100%;
  overflow: hidden;
  min-width: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  position: relative;
  z-index: 20;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: visible;
  transition: width 0.18s ease, border-color 0.18s ease;
}

.sidebar-panel {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-toggle {
  position: absolute;
  top: 20px;
  right: -14px;
  transform: none;
  z-index: 30;
  width: 28px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--fg-2);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  transition: all 0.15s ease;
}

.sidebar-toggle:hover {
  color: var(--fg);
  border-color: var(--border);
  background: var(--bg-hover);
}

.sidebar-tabs {
  position: relative;
  z-index: 21;
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-tab {
  flex: 1;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--fg-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-tab:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.sidebar-tab.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.sidebar-content {
  position: relative;
  z-index: 21;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.sidebar-project-header {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 28px 16px 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-back-btn {
  align-self: flex-start;
}

/* ── Experiments Panel ────────────────────────────────────────── */
.new-experiment-btn {
  width: 100%;
  margin-bottom: 16px;
  justify-content: center;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.experiment-group {
  position: relative;
  margin-bottom: 4px;
}

.experiment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
}

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

.experiment-item.active {
  background: var(--accent-bg);
  color: var(--accent);
}

.experiment-item.branch {
  margin-left: 16px;
  font-size: 12px;
}

.experiment-status {
  font-size: 8px;
  line-height: 1;
}

.experiment-status.idle { color: var(--fg-3); }
.experiment-status.running { color: var(--yellow); }
.experiment-status.done { color: var(--green); }
.experiment-status.failed { color: var(--red); }

.experiment-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.experiment-actions {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.experiment-menu-button {
  border: none;
  background: transparent;
  color: var(--fg-3);
  font: inherit;
  cursor: pointer;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  opacity: 0;
  pointer-events: none;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.experiment-item:hover .experiment-menu-button,
.experiment-item.active .experiment-menu-button,
.experiment-menu-button:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.experiment-menu-button:hover {
  color: var(--fg);
  background: var(--bg-hover);
}

.experiment-menu-button svg {
  width: 14px;
  height: 14px;
  display: block;
}

.experiment-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 200;
  min-width: 140px;
}

.experiment-count {
  font-size: 11px;
  color: var(--fg-3);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* ── Files Panel ──────────────────────────────────────────────── */
.files-header {
  margin-bottom: 12px;
}

.files-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.file-item {
  margin-bottom: 2px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
}

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

.file-icon {
  font-size: 14px;
  line-height: 1;
}

.file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-copy {
  opacity: 0;
  margin-left: 4px;
  flex: 0 0 auto;
}

.file-row:hover .file-copy {
  opacity: 1;
}

.file-copy:hover {
  opacity: 1;
}

.file-size {
  font-size: 11px;
  color: var(--fg-3);
}

/* ── File Preview ─────────────────────────────────────────────── */
.file-preview {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.file-preview-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
}

.file-preview-name {
  font-size: 13px;
  font-weight: 500;
}

.file-preview-content {
  flex: 1;
  overflow: auto;
  padding: 12px;
}

.code-preview {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--fg-2);
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius);
  overflow: auto;
}

.csv-preview {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.csv-preview th,
.csv-preview td {
  padding: 6px 8px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.csv-preview th {
  background: var(--bg-hover);
  font-weight: 600;
}

/* ── Notebook Container ───────────────────────────────────────── */
.notebook-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* ── Notebook View ────────────────────────────────────────────── */
.notebook-view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.notebook-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.empty-message {
  text-align: center;
}

.empty-message h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
}

.empty-message p {
  color: var(--fg-2);
  font-size: 14px;
}

.notebook-cells {
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Notebook Cell ────────────────────────────────────────────── */
.cell-shell {
  position: relative;
  margin: 0 28px 20px 0;
}

.notebook-cell {
  background: var(--bg-cell);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.notebook-cell:hover {
  border-color: var(--border);
}

.cell-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: transparent;
}

.cell-number {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 60px;
  flex: 0 0 60px;
}

.cell-name {
  flex: 1;
  color: var(--fg-3);
  font: inherit;
  font-size: 12px;
}

.cell-save-state {
  min-width: 62px;
  text-align: right;
  font-size: 11px;
  color: var(--fg-3);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.cell-save-state.visible {
  opacity: 1;
}

.cell-status {
  font-size: 14px;
  line-height: 1;
  min-width: 16px;
  text-align: center;
}

.cell-toolbar-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--fg-3);
  font-size: 13px;
  line-height: 1;
}

.cell-toolbar-status.running {
  color: var(--yellow);
}

.cell-toolbar-status.done {
  color: var(--green);
}

.cell-toolbar-status.failed {
  color: var(--red);
}

.cell-status-icon {
  display: block;
}

.cell-status-icon.spinning {
  animation: cell-loader-spin 1.1s linear infinite;
  transform-origin: center;
}

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

.cell-code {
  position: relative;
  min-height: 120px;
  padding: 8px 14px 12px;
   background: rgba(255,255,255,0.01);
   border-top: 1px solid rgba(255,255,255,0.03);
   cursor: text;
}

.cell-code:focus-within {
  background: var(--accent-bg);
}

.cell-editor-shell {
  position: relative;
  min-height: 88px;
  border-radius: var(--radius-sm);
}

.cell-editor-shell.empty::before {
  content: attr(data-placeholder);
  position: absolute;
  top: 0;
  left: 0;
  color: var(--fg-3);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  pointer-events: none;
  z-index: 0;
}

.cell-editor-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  overflow: auto;
  pointer-events: none;
  scrollbar-width: none;
}

.cell-editor-highlight::-webkit-scrollbar {
  display: none;
}

.cell-editor-highlight code {
  display: block;
  min-height: 88px;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  tab-size: 4;
  font-variant-ligatures: none;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: anywhere;
}

.cell-editor-input {
  position: relative;
  z-index: 1;
  color: transparent;
  caret-color: var(--fg);
  -webkit-text-fill-color: transparent;
}

.cell-textarea {
   display: block;
   width: 100%;
   min-height: 88px;
   max-height: 520px;
   padding: 0;
   border: none;
   background: transparent;
   font-family: var(--font-mono);
   font-size: 14px;
   line-height: 1.5;
   tab-size: 4;
   font-variant-ligatures: none;
   resize: none;
   overflow: auto;
}

.cell-textarea:focus {
   outline: none;
}

.cell-textarea::placeholder {
   color: transparent;
}

.cell-editor-input::selection {
  background: var(--cm-selection);
}

.cell-editor-highlight .hljs {
  background: transparent;
  color: var(--fg);
}

.cell-editor-highlight .hljs-comment,
.cell-editor-highlight .hljs-quote {
  color: var(--fg-3);
}

.cell-editor-highlight .hljs-keyword,
.cell-editor-highlight .hljs-built_in,
.cell-editor-highlight .hljs-literal,
.cell-editor-highlight .hljs-type {
  color: var(--purple);
}

.cell-editor-highlight .hljs-title,
.cell-editor-highlight .hljs-title.function_,
.cell-editor-highlight .hljs-title.class_ {
  color: var(--blue);
}

.cell-editor-highlight .hljs-string,
.cell-editor-highlight .hljs-regexp {
  color: var(--green);
}

.cell-editor-highlight .hljs-number,
.cell-editor-highlight .hljs-symbol,
.cell-editor-highlight .hljs-bullet {
  color: var(--yellow);
}

.cell-editor-highlight .hljs-meta,
.cell-editor-highlight .hljs-attr,
.cell-editor-highlight .hljs-attribute,
.cell-editor-highlight .hljs-variable,
.cell-editor-highlight .hljs-template-variable {
  color: var(--accent-dim);
}

.cell-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 10px;
  background: transparent;
}

.cell-btn {
  min-width: 0;
}

.cell-btn.run {
}

.cell-action-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg-panel) 86%, transparent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.cell-action-group .cell-btn {
  color: var(--fg-2);
}

.cell-action-group .cell-btn:hover:not(:disabled) {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.05);
}

.cell-btn.delete {
  color: var(--fg-2);
}

.cell-btn.delete:hover {
  color: var(--red);
  background: var(--red-bg);
}

.cell-btn.delete svg {
  display: block;
}

.cell-spacer {
  flex: 1;
}

.branch-plus-btn {
  position: absolute;
  top: 50%;
  right: -22px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  z-index: 2;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.branch-plus-btn:hover {
  border-color: var(--border);
  background: var(--bg-hover);
}

/* ── Cell Output ──────────────────────────────────────────────── */
.cell-output {
  padding: 12px 16px 16px;
  background: var(--bg-output);
  border-top: 1px solid var(--border-subtle);
}

.cell-output-header {
  margin-bottom: 6px;
  opacity: 0.8;
}

.cell-output-content {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

.output-status {
  color: var(--fg-2);
  background: rgba(255,255,255,0.03);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.output-text {
  color: var(--fg-2);
  white-space: pre-wrap;
  margin-bottom: 8px;
}

.output-error {
  color: var(--red);
  background: var(--red-bg);
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.output-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.metric {
  background: var(--accent-bg);
  color: var(--accent);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.metric-key {
  font-weight: 600;
}

.output-image {
  margin-bottom: 8px;
}

.output-image img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.output-html {
  margin-bottom: 8px;
  overflow-x: auto;
}

/* ── Add Cell ─────────────────────────────────────────────────── */
.add-cell-section {
  margin-top: 24px;
  text-align: center;
}

.add-cell-btn {
  min-width: 140px;
}

/* ── Output Log ───────────────────────────────────────────────── */
.output-log {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  transition: height 0.2s ease;
}

.output-log.collapsed {
  height: 40px;
}

.output-log:not(.collapsed) {
  height: 200px;
  display: flex;
  flex-direction: column;
}

.output-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  user-select: none;
}

.output-log-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-2);
}

.output-log-toggle {
  color: var(--fg-3);
  font-size: 12px;
}

.output-log-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
}

.log-line {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 2px;
  color: var(--fg-2);
}

.log-time {
  flex-shrink: 0;
}

.log-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.log-badge {
  display: inline-flex;
  align-items: center;
  padding: 0 6px;
  min-height: 18px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--fg-2);
  font-size: 11px;
}

.log-message {
  color: var(--fg);
  word-break: break-word;
}

.log-line.error .log-message {
  color: var(--red);
}

.log-line.warn .log-message {
  color: var(--yellow);
}

/* ── Project Dashboard ────────────────────────────────────────── */
.project-dashboard {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 48px 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.dashboard-section {
  margin-bottom: 32px;
}

.dashboard-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-2);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.empty-projects {
  text-align: center;
  padding: 24px 0 0;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
}

.empty-hint {
  font-size: 14px;
  color: var(--fg-2);
  margin-bottom: 24px;
}

.create-first-btn {
  min-height: 38px;
  padding-inline: 14px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.project-card {
  padding: 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.project-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.project-card-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
}

.project-card-desc {
  font-size: 14px;
  color: var(--fg-2);
  margin-bottom: 16px;
  line-height: 1.5;
}

.project-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.project-card-date {
  font-size: 12px;
  color: var(--fg-3);
}

.new-project-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 150px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--fg-2);
}

.new-project-card:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.new-project-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.new-project-text {
  font-size: 14px;
  font-weight: 500;
}

.project-create-card {
  width: 100%;
  min-height: 176px;
}

.project-create-dialog {
  max-width: 760px;
  margin: 0 auto;
}

.project-create-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.project-create-header {
  margin-bottom: 18px;
}

.project-create-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 10px;
}

.project-create-title {
  font-size: 24px;
  font-weight: 650;
  color: var(--fg);
  margin-bottom: 8px;
}

.project-create-copy {
  max-width: 520px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--fg-2);
}

.project-create-icon {
  width: 44px;
  height: 44px;
  margin-bottom: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  color: var(--fg);
  flex: 0 0 auto;
}

.new-project-card .new-project-text {
  margin-top: 18px;
  color: var(--fg);
}

.new-project-card:hover .project-create-icon {
  border-color: var(--border);
}

/* ── Project Form ─────────────────────────────────────────────── */
.project-form-card {
  cursor: default;
  border-color: var(--accent);
}

.project-form-card:hover {
  transform: none;
}

.project-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.project-form-shell {
  width: 100%;
  max-width: 640px;
}

.project-form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.project-form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.project-form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.project-form-label-muted {
  color: var(--fg-3);
  font-weight: 500;
}

.project-form-help {
  font-size: 12px;
  line-height: 1.5;
  color: var(--fg-2);
}

.project-location-row {
  display: block;
  width: 100%;
}

.project-location-field {
  display: flex;
  align-items: center;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  overflow: hidden;
}

.project-location-field.invalid {
  border-color: color-mix(in srgb, var(--red) 70%, var(--border));
}

.project-location-input {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.project-location-input:focus {
  border-color: transparent;
}

.project-location-browse {
  flex: 0 0 auto;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  min-width: 132px;
  border: 0;
  border-left: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--fg-2);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.project-location-browse:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.project-path-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 0 0;
}

.project-path-summary-label {
  font-size: 12px;
  color: var(--fg-2);
}

.project-path-summary code {
  color: var(--fg-2);
  font-size: 12px;
  word-break: break-word;
}

.project-field-actions {
  display: flex;
  justify-content: flex-start;
}

.project-form-error {
  font-size: 12px;
  color: var(--red);
}

.project-form-banner {
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--red) 30%, var(--border));
  border-radius: var(--radius-sm);
  background: var(--red-bg);
  color: var(--fg);
  font-size: 12px;
  line-height: 1.5;
}

.project-inline-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.project-inline-link:hover {
  color: var(--fg);
}

.project-path-input {
  font-family:
    ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
}

.project-path-preview {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-input) 80%, transparent);
  min-height: 42px;
  display: flex;
  align-items: center;
}

.project-path-preview code {
  color: var(--fg-2);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.form-input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}

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

.project-form .form-input[aria-invalid="true"] {
  border-color: color-mix(in srgb, var(--red) 70%, var(--border));
}

.form-input::placeholder {
  color: var(--fg-2);
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

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

.form-btn {
  min-width: 88px;
  width: auto;
}

.project-submit-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.project-submit-btn:hover:not(:disabled) {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--bg);
}

.project-submit-btn:disabled {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--fg-3);
}

@media (max-width: 900px) {
  .project-form-label-row,
  .form-row,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-btn {
    width: 100%;
  }
}

.form-btn:disabled {
  opacity: 0.5;
}

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  animation: slideIn 0.2s ease;
}

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

/* ── Stderr Output ───────────────────────────────────────────── */
.out-stderr {
  color: var(--yellow);
  opacity: 0.8;
}

/* ── Traceback ───────────────────────────────────────────────── */
.out-traceback {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--red);
  opacity: 0.8;
}

/* ── CM Warning Banner ───────────────────────────────────────── */
.cm-warning {
  padding: 8px 12px;
  background: var(--yellow-bg);
  color: var(--yellow);
  font-size: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

/* ── Timeout Status ──────────────────────────────────────────── */
.cell.timeout { border-color: var(--yellow); }
.cell.timeout .cell-gutter { border-color: var(--yellow); }

/* ── Canvas container (Phase 2) ──────────────────────────────── */
.canvas-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
}

.canvas-container.dragging {
  cursor: grabbing;
}

.canvas-transform {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ── SVG Connector Lines (Phase 2B) ──────────────────────────── */
.canvas-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.connector-line {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

/* ── Breadcrumb (Phase 2B) ───────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--fg-2);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.breadcrumb-item {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.breadcrumb-item:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.breadcrumb-sep {
  color: var(--fg-3);
}

/* ── Minimap (Phase 2A) ──────────────────────────────────────── */
.minimap {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  height: 100px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 50;
  cursor: pointer;
}

.minimap-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
}

.minimap-viewport {
  position: absolute;
  border: 2px solid var(--blue);
  border-radius: 2px;
  pointer-events: none;
}

/* ── Execution Mode Toggle (Phase 3) ─────────────────────────── */
.exec-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--fg-2);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.exec-mode-toggle:hover {
  border-color: var(--accent);
  color: var(--fg);
}

.exec-mode-toggle .mode-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Comparison Table (Phase 6) ──────────────────────────────── */
.compare-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--accent-bg);
  border-bottom: 1px solid var(--border);
}

.compare-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.compare-btn {
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.compare-clear {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-2);
  font-size: 12px;
  cursor: pointer;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
}

.compare-table th,
.compare-table td {
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.compare-table th {
  background: var(--bg-surface);
  font-weight: 600;
  color: var(--fg-2);
}

.compare-table td {
  font-family: var(--font-mono);
}

/* ── Theme Toggle Button ─────────────────────────────────────── */
.tb-btn[title="Toggle theme"] {
  font-size: 16px;
  padding: 4px 8px;
}

/* ── Canvas Wrapper ──────────────────────────────────────────── */
.canvas-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.notebook-page {
  flex: 1;
  overflow: auto;
  padding: 24px 32px 40px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.notebook-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.notebook-toolbar-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.notebook-toolbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}

.notebook-toolbar-subtitle {
  font-size: 12px;
  color: var(--fg-3);
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.9);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.modal-card {
  width: min(720px, 100%);
  background: rgba(20, 24, 31, 0.98);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.58);
}

.environment-modal {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.environment-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.environment-modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}

.environment-modal-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--fg-3);
}

.environment-modal-status {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-2);
}

.environment-modal-error {
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.environment-modal-note {
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--fg);
}

.environment-packages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.environment-packages-label {
  font-size: 12px;
  color: var(--fg-3);
}

.environment-package-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.environment-package-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--fg);
  font-size: 12px;
  font-family: var(--font-mono);
}

.environment-textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  padding: 14px;
  font: 13px/1.55 var(--font-mono);
  outline: none;
}

.environment-textarea:focus {
  border-color: var(--fg-3);
}

.environment-sync-log-shell {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.environment-sync-log {
  margin: 0;
  min-height: 140px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--fg);
  padding: 12px 14px;
  font: 12px/1.55 var(--font-mono);
  white-space: pre-wrap;
}

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

.rename-modal {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: rgba(16, 18, 24, 0.98);
}

.rename-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rename-modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.rename-modal-input {
  min-height: 40px;
  border-radius: 10px;
}

.rename-modal-actions {
  margin-top: 0;
}

@media (min-width: 769px) {
  .app.notebook-app.sidebar-collapsed {
    grid-template-columns: var(--sidebar-collapsed-w) minmax(0, 1fr);
  }

  .sidebar.collapsed {
    width: var(--sidebar-collapsed-w);
  }

  .sidebar.collapsed .sidebar-panel {
    opacity: 0;
    pointer-events: none;
  }

  .sidebar.collapsed .sidebar-toggle {
    right: 8px;
  }
}

.notebook-doc {
  max-width: 980px;
  margin: 0 auto;
}

.branch-strip {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 28px;
  min-width: fit-content;
  overflow-x: auto;
  padding-bottom: 8px;
  min-height: 100%;
}

.branch-column {
  position: relative;
  flex: 0 0 auto;
}

.branch-linked-column::before {
  content: "";
  position: absolute;
  left: -15px;
  top: 28px;
  width: 15px;
  border-top: 1px dashed var(--border);
}

.branch-linked-column::after {
  content: "";
  position: absolute;
  left: -15px;
  top: 0;
  height: 28px;
  border-left: 1px dashed var(--border);
}

.branch-doc {
  width: min(760px, calc(100vw - 140px));
  max-width: 760px;
  margin: 0;
  padding: 18px 18px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  background: rgba(255,255,255,0.01);
}

.branch-doc.active {
  border-color: var(--accent);
}

.branch-child-doc {
  width: 460px;
  max-width: 460px;
}

.branch-doc-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  padding: 0 4px;
  cursor: pointer;
}

.branch-doc-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.branch-doc-title-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.branch-doc-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.branch-doc-export {
  border: none;
  background: transparent;
  color: var(--fg-3);
  font: inherit;
  cursor: pointer;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.branch-doc-export:hover {
  color: var(--fg);
  background: rgba(255,255,255,0.06);
}

.branch-export-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 200;
  min-width: 140px;
}

.branch-doc-subtitle {
  font-size: 12px;
  color: var(--fg-3);
}

.branch-doc-delete {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.56);
  font: inherit;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.branch-doc-delete:hover {
  background: rgba(255,255,255,0.06);
  color: rgba(255, 255, 255, 0.88);
}

.branch-doc-delete svg {
  width: 16px;
  height: 16px;
  display: block;
}

.branch-node-stack {
  display: flex;
  flex-direction: column;
}

.branch-empty {
  margin: 0 4px 16px;
  padding: 10px 12px;
  border: 1px dashed var(--border-subtle);
  border-radius: 10px;
  color: var(--fg-3);
  font-size: 13px;
}

/* ── Track ────────────────────────────────────────────────────── */
.track {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: visible;
  transition: border-color 0.15s ease;
}

.track:hover {
  border-color: var(--border);
}

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

.track.notebook-track {
  max-width: 980px;
  margin: 0 auto;
}

.track-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  padding: 0 4px 12px;
}

.track-meta-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-meta-info {
  font-size: 11px;
  color: var(--fg-3);
}

.track-cells {
  padding: 16px;
}

/* ── Context Menu ────────────────────────────────────────────── */
.ctx-menu {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  min-width: 120px;
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

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

.ctx-item.danger {
  color: var(--red);
}

.ctx-item.danger:hover {
  background: var(--red-bg);
}
