/* ── Tokens ─────────────────────────────────────────────── */
:root {
  --bg:       #f5f6f8;
  --surface:  #ffffff;
  --border:   rgba(17,24,39,0.09);
  --border2:  rgba(17,24,39,0.13);
  --soft:     rgba(17,24,39,0.04);
  --muted:    #6b7280;
  --text:     #111827;
  --accent:   #0078d4;
  --accent-h: #006abc;
  --accent-s: rgba(0,120,212,0.08);
  --accent-b: rgba(0,120,212,0.18);
  --danger:   #dc2626;
  --warn:     #d97706;
  --ok:       #16a34a;
  --radius:   14px;
  --mono:     'DM Mono', ui-monospace, monospace;
  --head:     'Syne', sans-serif;
  --body:     'Figtree', ui-sans-serif, system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────── */
.app { max-width: 1220px; margin: 0 auto; padding: 24px 18px 60px; }

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 10px; }

.brand h1 {
  font-family: var(--head);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand .badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-s);
  color: var(--accent);
  border: 1px solid var(--accent-b);
  border-radius: 20px;
  padding: 2px 9px;
  letter-spacing: .03em;
}

.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* pill toggle */
.pillset {
  display: flex; gap: 4px; padding: 3px;
  background: var(--soft); border: 1px solid var(--border);
  border-radius: 12px;
}
.pill {
  padding: 6px 14px; border-radius: 10px;
  border: 1px solid transparent;
  font-family: var(--body); font-weight: 700; font-size: 12px;
  cursor: pointer; background: transparent; color: var(--muted);
  transition: all .15s;
}
.pill.active { background: var(--surface); border-color: var(--border); color: var(--text); }

/* save toggle */
.save-toggle {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  cursor: pointer; user-select: none;
}
.toggle-track {
  width: 34px; height: 18px; border-radius: 9px;
  background: var(--border2); position: relative;
  transition: background .2s; flex-shrink: 0;
}
.toggle-track.on { background: var(--accent); }
.toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 7px;
  background: #fff; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-track.on .toggle-thumb { transform: translateX(16px); }

/* ── Grid ───────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  align-items: start;
}

/* ── Card ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 6px 20px rgba(0,0,0,.04);
  overflow: hidden;
}

.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}

.card-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }

.card-body { padding: 14px 16px; }
.card-section { padding: 14px 16px; border-top: 1px solid var(--border); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 13px; border-radius: 10px;
  border: 1px solid var(--border2); background: var(--surface);
  font-family: var(--body); font-weight: 700; font-size: 12px;
  color: var(--text); cursor: pointer; white-space: nowrap;
  transition: all .13s;
}
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-h); }

.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--soft); color: var(--text); }

.btn.sm { padding: 5px 10px; font-size: 11px; border-radius: 8px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Inputs ─────────────────────────────────────────────── */
.input {
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--border2); background: var(--surface);
  font-family: var(--body); font-size: 13px; color: var(--text);
  outline: none; width: 100%;
  transition: border-color .15s;
}
.input:focus { border-color: rgba(0,120,212,.4); box-shadow: 0 0 0 3px rgba(0,120,212,.07); }
.input.mono { font-family: var(--mono); font-size: 12px; }

textarea.input { resize: vertical; min-height: 100px; white-space: pre; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ── Notes ──────────────────────────────────────────────── */
.note { font-size: 12px; color: var(--muted); line-height: 1.5; }
.note code {
  font-family: var(--mono); font-size: 11px;
  background: var(--soft); padding: 1px 5px;
  border-radius: 5px; border: 1px solid var(--border);
}
.note.err { color: var(--danger); }

/* ── Toolbar ────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: rgba(245,246,248,.6);
}

.toolbar-sep { width: 1px; height: 22px; background: var(--border2); margin: 0 2px; }

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px;
  padding: 40px 20px; text-align: center;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 36px; opacity: .35; }
.empty-state .empty-title { font-weight: 700; font-size: 14px; color: var(--text); opacity: .5; }
.empty-state .empty-sub { font-size: 12px; max-width: 240px; line-height: 1.5; }

/* ── Tree ───────────────────────────────────────────────── */
.tree { display: flex; flex-direction: column; gap: 3px; padding: 10px 14px; min-height: 80px; }

/* ── Node ───────────────────────────────────────────────── */
.node-wrap { display: flex; flex-direction: column; }

.node {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  position: relative; cursor: pointer;
  transition: background .12s, border-color .12s;
  user-select: none;
}

.node:hover { background: rgba(0,120,212,.03); border-color: var(--border); }

.node.selected {
  background: var(--accent-s);
  border-color: var(--accent-b);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}

.node.drag-over { background: rgba(0,120,212,.07); border-color: var(--accent); border-style: dashed; }
.node.dragging { opacity: .4; }

/* drag handle */
.drag-handle {
  color: var(--border2); font-size: 13px; cursor: grab;
  padding: 0 2px; flex-shrink: 0; line-height: 1;
  transition: color .1s;
}
.node:hover .drag-handle { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }

/* expand toggle */
.expand-btn {
  width: 18px; height: 18px; border-radius: 5px;
  border: none; background: transparent; cursor: pointer;
  font-size: 10px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); flex-shrink: 0; padding: 0;
  transition: background .1s, transform .15s;
}
.expand-btn:hover { background: var(--soft); }
.expand-btn.open { transform: rotate(90deg); }
.expand-btn-spacer { width: 18px; flex-shrink: 0; }

/* favicon / icon */
.node-icon {
  width: 18px; height: 18px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; overflow: hidden;
}
.node-icon img { width: 14px; height: 14px; object-fit: contain; }
.node-icon.folder { font-size: 14px; }

/* name */
.node-name {
  flex: 1; min-width: 0;
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* url pill */
.node-url-pill {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex-shrink: 0;
}

/* validation dot */
.vdot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.vdot.ok    { background: var(--ok); }
.vdot.warn  { background: var(--warn); }
.vdot.empty { display: none; }

/* node actions (shown on hover/select) */
.node-actions {
  display: flex; gap: 4px; flex-shrink: 0;
  opacity: 0; transition: opacity .12s;
}
.node:hover .node-actions,
.node.selected .node-actions { opacity: 1; }

.node-btn {
  padding: 4px 7px; border-radius: 7px; border: 1px solid transparent;
  background: transparent; cursor: pointer; font-size: 11px; font-weight: 700;
  color: var(--muted); line-height: 1; transition: all .1s;
}
.node-btn:hover { background: var(--surface); border-color: var(--border2); color: var(--text); }
.node-btn.danger:hover { color: var(--danger); border-color: rgba(220,38,38,.2); background: rgba(220,38,38,.04); }

/* inline editor (shown when selected) */
.node-editor {
  display: none;
  padding: 8px 10px 10px 54px;
  gap: 6px;
  flex-direction: column;
}
.node-editor.open { display: flex; }
.node-editor .input { font-size: 12px; padding: 6px 9px; }
.node-editor .input.mono { font-family: var(--mono); }
.editor-row { display: flex; gap: 6px; align-items: center; }
.editor-row label { font-size: 11px; font-weight: 700; color: var(--muted); width: 38px; flex-shrink: 0; }

/* move-to dropdown */
.move-dropdown {
  position: relative; display: inline-block;
}
.move-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.1);
  min-width: 160px; z-index: 100; overflow: hidden;
  animation: menuIn .12s ease;
}
.move-menu.open { display: block; }
.move-menu-item {
  padding: 8px 12px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: background .1s;
}
.move-menu-item:hover { background: var(--soft); }
.move-menu-item.root { color: var(--muted); font-style: italic; }

@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* folder children */
.folder-children {
  margin-left: 22px;
  border-left: 1px solid var(--border);
  padding-left: 8px;
  margin-top: 3px;
  display: flex; flex-direction: column; gap: 3px;
}
.folder-children.collapsed { display: none; }

/* ── Output panel ───────────────────────────────────────── */
.output-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.output-tab {
  padding: 10px 16px; font-size: 12px; font-weight: 700;
  cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent;
  transition: all .13s; background: transparent; border-top: none; border-left: none; border-right: none;
  font-family: var(--body);
}
.output-tab:hover { color: var(--text); }
.output-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.output-panel { display: none; }
.output-panel.active { display: block; }

pre.code {
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  padding: 14px; background: #f9fafb;
  border-radius: 0; white-space: pre; overflow: auto;
  max-height: 42vh; color: var(--text);
}

.outline-view {
  font-family: var(--mono); font-size: 12px; line-height: 1.8;
  padding: 14px; background: #f9fafb;
  max-height: 42vh; overflow: auto; color: var(--text);
}

.outline-folder { font-weight: 700; color: var(--text); }
.outline-link   { color: var(--muted); }
.outline-link a { color: var(--accent); text-decoration: none; font-size: 11px; }
.outline-link a:hover { text-decoration: underline; }

/* ── Undo toast ─────────────────────────────────────────── */
.undo-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: #fff; border-radius: 12px;
  padding: 10px 18px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transition: transform .25s cubic-bezier(.34,1.56,.64,1);
  z-index: 999; white-space: nowrap;
}
.undo-toast.show { transform: translateX(-50%) translateY(0); }
.undo-btn-inline {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 7px; padding: 3px 10px;
  font-size: 12px; font-weight: 700; cursor: pointer; font-family: var(--body);
}
.undo-btn-inline:hover { background: rgba(255,255,255,.25); }

/* ── Watermark ──────────────────────────────────────────── */
.watermark { font-size: 11px; color: var(--muted); text-align: right; padding: 8px 14px; border-top: 1px solid var(--border); }

/* ── Divider label ──────────────────────────────────────── */
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); padding: 12px 16px 6px;
}

/* ── Import error ───────────────────────────────────────── */
.import-err { display: none; font-size: 12px; color: var(--danger); padding: 6px 0 0; }

@media (max-width: 920px) {
  .grid { grid-template-columns: 1fr; }
  pre.code, .outline-view { max-height: 260px; }
}