/* Atlas — design tokens & shell styles */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,500;8..60,600&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Palette — soft modern editorial */
  --bg:        #f7f5ef;
  --bg-2:      #efece3;
  --surface:   #ffffff;
  --surface-2: #fbfaf6;
  --ink:       #1c1b18;
  --ink-2:     #3a3833;
  --muted:     #76736b;
  --faint:     #a4a098;
  --line:      #e6e2d6;
  --line-2:    #d8d3c4;
  --accent:    #b8482e;
  --accent-soft: #f1d8cf;
  --accent-ink:  #7a2c1a;
  --selected:  #a05a4433;
  --selected-ink: inherit;
  --hover:     #ece8da;
  --good:      #4a7a3a;
  --warn:      #b58326;
  --bad:       #a83b2c;

  /* Type */
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans:  'Inter', system-ui, -apple-system, sans-serif;
  --mono:  'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* Radii / shadow */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;
  --shadow-1: 0 1px 0 rgba(28,27,24,0.04), 0 1px 2px rgba(28,27,24,0.04);
  --shadow-2: 0 8px 30px -8px rgba(28,27,24,0.18), 0 2px 6px rgba(28,27,24,0.05);

  /* Density (overridable) */
  --row-h: 30px;
  --pad-x: 12px;
  --font-ui: 13px;
  --font-sm: 12px;
}

[data-density="comfortable"] {
  --row-h: 36px;
  --pad-x: 16px;
  --font-ui: 14px;
  --font-sm: 12px;
}
[data-density="dense"] {
  --row-h: 24px;
  --pad-x: 8px;
  --font-ui: 12px;
  --font-sm: 11px;
}

/* Preview width — set live by drag handle, read by all views */
:root {
  --preview-w: 560px;
  --main-min-w: 360px;
  --preview-col-w: clamp(320px, min(var(--preview-w), calc(100vw - var(--main-min-w))), var(--preview-w));
  --columns-browser-h: 56%;
  --tree-browser-h: 46%;
}

[data-theme="dark"] {
  --bg:        #0a0a0a;
  --bg-2:      #1c1c1c;
  --surface:   #161616;
  --surface-2: #1c1c1c;
  --ink:       #f4f4f4;
  --ink-2:     #e0e0e0;
  --muted:     #a8a8a8;
  --faint:     #6f6f6f;
  --line:      #262626;
  --line-2:    #393939;
  --hover:     #1f1f1f;
  --selected:  #a05a4433;
  --selected-ink: inherit;
  --accent-soft: #2a1a14;
  --accent-ink:  #f1bca8;
  --shadow-1: 0 1px 0 rgba(0,0,0,0.6), 0 1px 2px rgba(0,0,0,0.7);
  --shadow-2: 0 8px 30px -8px rgba(0,0,0,0.9), 0 2px 6px rgba(0,0,0,0.6);
}
[data-theme="dark"] .tok-k { color: #c596e0; }
[data-theme="dark"] .tok-s { color: #9ec888; }
[data-theme="dark"] .tok-n { color: #e0b96a; }
[data-theme="dark"] .tok-fn { color: #84b4e0; }
[data-theme="dark"] .json-str { color: #9ec888; }
[data-theme="dark"] .json-num { color: #e0b96a; }
[data-theme="dark"] .json-bool { color: #c596e0; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit; color: inherit; background: transparent; border: 0; padding: 0; cursor: pointer;
}
input { font: inherit; color: inherit; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  min-width: 0;
}
.brand {
  display: flex; align-items: baseline; gap: 10px;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent);
  position: relative; top: 4px;
}
.brand-name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.brand-tag {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
}

.paradigms {
  display: flex; gap: 0; align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  min-width: 0;
}
.paradigm-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
  transition: background 0.12s ease, color 0.12s ease;
}
.paradigm-btn:hover { color: var(--ink); }
.paradigm-btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}
.paradigm-btn .num {
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0.5;
}
.paradigm-btn[aria-pressed="true"] .num { opacity: 0.6; }

.spacer { flex: 1; }

.topbar-meta {
  display: flex; align-items: center; gap: var(--s-3);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--good);
  display: inline-block;
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex; align-items: center; gap: var(--s-4);
  padding: 6px var(--s-5);
  border-top: 1px solid var(--line);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  overflow-x: auto;
  white-space: nowrap;
}
.statusbar .key {
  display: inline-flex; align-items: center; gap: 4px;
  margin-right: 12px;
}
.statusbar kbd {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--ink-2);
}

/* ---------- Workspace ---------- */
.workspace {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
}

/* Shared row primitives */
.fs-row {
  display: flex; align-items: center;
  height: var(--row-h);
  padding: 0 var(--pad-x);
  gap: 8px;
  font-size: var(--font-ui);
  color: var(--ink);
  cursor: default;
  user-select: none;
  border-radius: var(--r-sm);
}
.fs-row:hover { background: var(--hover); }
.fs-row[data-selected="true"] {
  background: var(--selected);
  color: var(--selected-ink);
}
.fs-row[data-selected="true"] .muted-cell { color: var(--selected-ink); opacity: 0.65; }

.fs-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-row .meta { font-family: var(--mono); font-size: var(--font-sm); color: var(--muted); flex-shrink: 0; }
.fs-row .chev { color: var(--faint); font-size: 10px; }

/* Icons */
.ficon {
  width: 16px; height: 16px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.ficon svg { width: 16px; height: 16px; }

/* Scrollbars */
.scroll {
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* Preview panel (shared across some views) */
.preview {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.preview-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--faint);
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  gap: var(--s-3);
}
.preview-head {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s-3);
}
.preview-title {
  flex: 1;
  min-width: 0;
}
.preview-head .name {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preview-head-modified {
  display: none;
}
.preview-meta {
  display: flex; gap: var(--s-4);
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.preview-meta .pair { display: flex; gap: 4px; }
.preview-meta .pair b { color: var(--ink-2); font-weight: 500; }
.preview-body {
  flex: 1;
  overflow: auto;
  padding: var(--s-5);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre;
  color: var(--ink-2);
}
.preview-body.markdown {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.7;
  white-space: normal;
}
.preview-body.markdown h1 { font-size: 28px; margin: 0 0 16px; font-weight: 500; letter-spacing: -0.01em; }
.preview-body.markdown h2 { font-size: 20px; margin: 24px 0 10px; font-weight: 500; }
.preview-body.markdown h3 { font-size: 16px; margin: 18px 0 8px; font-weight: 600; }
.preview-body.markdown p { margin: 0 0 12px; }
.preview-body.markdown code { font-family: var(--mono); font-size: 12px; background: var(--bg-2); padding: 1px 6px; border-radius: 3px; }
.preview-body.markdown pre { font-family: var(--mono); font-size: 12px; background: var(--bg-2); padding: 14px 16px; border-radius: var(--r-md); overflow: auto; }
.preview-body.markdown pre code { background: transparent; padding: 0; }
.preview-body.markdown ul, .preview-body.markdown ol { padding-left: 22px; margin: 0 0 12px; }
.preview-body.markdown table { border-collapse: collapse; margin: 12px 0; font-family: var(--sans); font-size: 13px; }
.preview-body.markdown th, .preview-body.markdown td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
.preview-body.markdown th { background: var(--bg-2); font-weight: 600; }
.preview-body.markdown a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Level chips — toggle which abstraction levels are shown in the preview body */
.preview-levels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.level-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.level-chip:hover {
  border-color: var(--ink-2);
  color: var(--ink-2);
}
.level-chip[data-active="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.level-chip[data-active="true"] .level-name {
  color: var(--bg);
}
.level-chip .level-name {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.level-chip .level-label {
  font-weight: 500;
}

/* Multi-section preview body — stacks L0 / L1 / L2 sections */
.preview-body-multi {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.preview-section {
  display: flex;
  flex-direction: column;
}
.preview-section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: var(--s-3) var(--s-5) 6px;
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
.preview-section-head .level-name {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.preview-section-head .level-label {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 500;
}
.preview-section-head .level-desc {
  font-family: var(--sans);
  font-size: 10px;
  color: var(--faint);
  font-style: italic;
}
.preview-section-body {
  padding: var(--s-4) var(--s-5);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.65;
}
.preview-section-body.markdown {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.7;
}
.preview-section-body.markdown h1 { font-size: 22px; margin: 0 0 12px; font-weight: 500; letter-spacing: -0.01em; }
.preview-section-body.markdown h2 { font-size: 17px; margin: 18px 0 8px; font-weight: 500; }
.preview-section-body.markdown h3 { font-size: 14px; margin: 14px 0 6px; font-weight: 600; }
.preview-section-body.markdown p { margin: 0 0 10px; }
.preview-section-body.markdown code { font-family: var(--mono); font-size: 12px; background: var(--bg-2); padding: 1px 6px; border-radius: 3px; }
.preview-section-body.markdown pre { font-family: var(--mono); font-size: 12px; background: var(--bg-2); padding: 12px 14px; border-radius: var(--r-md); overflow: auto; }
.preview-section-body.markdown pre code { background: transparent; padding: 0; }
.preview-section-body.markdown ul, .preview-section-body.markdown ol { padding-left: 22px; margin: 0 0 10px; }
.preview-section-body.markdown a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.preview-divider {
  height: 1px;
  background: var(--line);
  margin: 0 var(--s-5);
}
.preview-section-empty {
  padding: var(--s-5);
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

/* Code preview tokens (very light) */
.tok-c { color: var(--muted); font-style: italic; }
.tok-k { color: #6f3a8a; font-weight: 500; }
.tok-s { color: #4a7a3a; }
.tok-n { color: #b58326; }
.tok-fn { color: #2b5a8a; }
/* Gear button */
.gear-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.gear-btn:hover { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.gear-btn + .gear-btn { margin-left: 4px; }
.sort-btn { width: auto; padding: 0 10px; gap: 5px; border-radius: var(--r-md); }
.sort-btn .sort-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; }

/* Settings modal */
.settings-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: grid; place-items: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.settings-modal {
  width: 480px; max-width: 92vw;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.settings-head {
  display: flex; align-items: center;
  padding: 14px 20px;
}
.settings-head h3 {
  flex: 1;
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
}
.settings-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
.settings-close:hover { background: var(--bg-2); color: var(--ink); }
.settings-body { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.settings-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 12px;
  align-items: center;
}
.settings-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.settings-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
}
.settings-input:focus { outline: none; border-color: var(--accent); }
.settings-radio { display: flex; gap: 0; border: 1px solid var(--line-2); border-radius: 999px; padding: 2px; background: var(--bg); }
.settings-radio-btn {
  flex: 1;
  padding: 6px 12px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.settings-radio-btn[data-active="true"] { background: var(--ink); color: var(--bg); }
.settings-status .settings-pill { justify-self: start; }
.settings-pill {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--ink-2);
}
.settings-pill-connected { background: #2f5d50; color: #fff; }
.settings-pill-error { background: #b8482e; color: #fff; }
.settings-pill-connecting { background: #b58326; color: #fff; }
.settings-error { font-size: 11px; color: var(--accent); word-break: break-word; }

/* Hide paradigm-btn .num (kept in CSS, removed from JSX) — also remove brand-name */
.brand-name { display: none; }

/* Resize handle (drag to change preview width) */
.resize-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 6px;
  margin-left: -3px;
  cursor: col-resize;
  z-index: 5;
  background: transparent;
  transition: background 0.12s ease;
}
.resize-handle::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 2px; height: 32px;
  background: var(--line-2);
  border-radius: 1px;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.resize-handle:hover, .resize-handle[data-dragging="true"] {
  background: var(--accent-soft);
}
.resize-handle:hover::after, .resize-handle[data-dragging="true"]::after {
  opacity: 1;
  background: var(--accent);
}
body[data-resizing="true"] {
  cursor: col-resize !important;
  user-select: none !important;
}
body[data-resizing="true"] * {
  cursor: col-resize !important;
  pointer-events: none;
}
body[data-resizing-y="true"] {
  cursor: row-resize !important;
  user-select: none !important;
}
body[data-resizing-y="true"] * {
  cursor: row-resize !important;
  pointer-events: none;
}

@media (max-width: 900px) {
  .topbar {
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
  }
  .paradigm-btn {
    padding: 5px 10px;
  }
  .sort-btn .sort-label {
    display: none;
  }
  .statusbar {
    display: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    gap: var(--s-2);
  }
  .spacer {
    min-width: 0;
  }
  .gear-btn {
    width: 30px;
    height: 30px;
  }
  .preview-head {
    padding: 7px var(--s-3);
    gap: var(--s-2);
  }
  .preview-head .name {
    font-size: 14px;
    line-height: 1.2;
  }
  .preview-head-modified {
    display: block;
    margin-top: 2px;
    font-family: var(--mono);
    font-size: 10px;
    line-height: 1.2;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .preview-meta {
    display: none;
  }
  .preview {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .preview-body,
  .preview-body-multi {
    flex: none;
    min-height: auto;
    overflow: visible;
  }
  .preview-body-multi,
  .preview-section {
    display: block;
  }
  .preview-section-head {
    position: static;
  }
  .resize-handle {
    display: none;
  }
}

/* Empty state shared */
.empty {
  display: grid; place-items: center;
  height: 100%;
  color: var(--faint);
  font-family: var(--serif);
  font-style: italic;
}
