/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:           #0d0f14;
  --bg-1:         #12151c;
  --bg-2:         #181c26;
  --bg-3:         #1f2433;
  --border:       rgba(255,255,255,0.07);
  --border-bright:rgba(255,255,255,0.14);
  --text:         #e8eaf0;
  --text-dim:     #7a8099;
  --text-muted:   #4a5068;
  --accent:       #7c6dfa;
  --accent-hover: #9585ff;
  --accent-2:     #3ecfcf;
  --accent-3:     #f06292;
  --danger:       #f87171;
  --success:      #4ade80;
  --sidebar-w:    260px;
  --toolbar-h:    50px;
  --radius:       8px;
  --font-ui:      'Syne', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 14px; }
input, textarea, button { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ── Layout ────────────────────────────────────────────── */
body { display: flex; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, min-width 0.25s ease, opacity 0.2s;
  overflow: hidden;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  border: none;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

/* ── Sidebar header ────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.btn-new {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-new:hover { background: var(--accent-hover); }

/* ── Sidebar search ────────────────────────────────────── */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px;
  padding: 7px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

/* ── Maps list ─────────────────────────────────────────── */
.maps-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.maps-list::-webkit-scrollbar { width: 4px; }
.maps-list::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 2px; }

.list-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.map-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 1px;
  position: relative;
}

.map-item:hover { background: var(--bg-2); }
.map-item.active { background: rgba(124, 109, 250, 0.12); }
.map-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.map-item-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}
.map-item.active .map-item-icon { color: var(--accent); }

.map-item-info {
  flex: 1;
  min-width: 0;
}

.map-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.map-item.active .map-item-title { color: var(--accent-hover); }

.map-item-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Toolbar ───────────────────────────────────────────── */
#toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 6px; }
.toolbar-center { flex: 1; display: flex; justify-content: center; }

.map-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
}

.map-title-label {
  font-size: 13px;
  font-weight: 600;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-rename { color: var(--text-dim); padding: 2px; }
.btn-rename:hover { color: var(--accent); }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.btn-icon:hover { background: var(--bg-2); color: var(--text); }

/* ── View tabs ─────────────────────────────────────────── */
.view-tabs {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  transition: all 0.15s;
}

.tab:hover { color: var(--text); background: var(--bg-3); }
.tab.active { background: var(--bg-3); color: var(--text); }

/* ── Toolbar buttons ───────────────────────────────────── */
.btn-action {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  border: 1px solid var(--border);
  background: var(--bg-2);
  transition: all 0.15s;
}
.btn-action:hover { color: var(--text); border-color: var(--border-bright); }

.btn-save { color: var(--accent); border-color: rgba(124,109,250,0.3); }
.btn-save:hover { background: rgba(124,109,250,0.1); color: var(--accent-hover); }
.btn-save.saved { color: var(--success); border-color: rgba(74,222,128,0.3); }

.btn-danger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--bg-2);
  transition: all 0.15s;
}
.btn-danger:hover { color: var(--danger); border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.07); }

.save-indicator {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Workspace ─────────────────────────────────────────── */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.empty-icon {
  opacity: 0.5;
  margin-bottom: 8px;
}

.empty-state h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dim);
}

.empty-state p {
  font-size: 13px;
  max-width: 280px;
  line-height: 1.5;
}

.btn-new-lg {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-new-lg:hover { background: var(--accent-hover); }

/* ── Editor pane ───────────────────────────────────────── */
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.editor-header, .preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.editor-actions, .preview-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#editor {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  padding: 18px 20px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  tab-size: 2;
}

#editor::placeholder { color: var(--text-muted); }

/* ── Preview pane ──────────────────────────────────────── */
.preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.preview-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#markmap {
  width: 100%;
  height: 100%;
}

/* ── Modals ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-bright);
  border-radius: 12px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: slideUp 0.2s ease;
}

.modal-wide { width: 480px; }

@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-body label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal-body input[type=text] {
  background: var(--bg-1);
  border: 1px solid var(--border-bright);
  border-radius: 7px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.modal-body input[type=text]:focus { border-color: var(--accent); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
}

.btn-ghost {
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  border: 1px solid var(--border);
  background: none;
  transition: all 0.15s;
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }

.btn-primary {
  padding: 7px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

/* ── Copy fields ───────────────────────────────────────── */
.copy-field {
  display: flex;
  gap: 6px;
  align-items: center;
}

.copy-field input {
  flex: 1;
  background: var(--bg-1);
  border: 1px solid var(--border-bright);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  border: 1px solid var(--border);
  background: var(--bg-3);
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-copy:hover { color: var(--accent); border-color: rgba(124,109,250,0.3); }
.btn-copy.copied { color: var(--success); border-color: rgba(74,222,128,0.3); }

.embed-note {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(62, 207, 207, 0.07);
  border: 1px solid rgba(62, 207, 207, 0.18);
  border-radius: 7px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  svg { flex-shrink: 0; margin-top: 1px; color: var(--accent-2); }
}

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 16px;
  background: var(--bg-3);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  z-index: 2000;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Spinner ───────────────────────────────────────────── */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Markmap overrides ─────────────────────────────────── */
.markmap-node text { font-family: var(--font-ui) !important; }
