/* sqma — outliner */

:root {
  --bg: #f4efe6;
  --bg-soft: #ede7d8;
  --ink: #1a1a17;
  --ink-soft: #4a4a44;
  --ink-faint: #8a8a82;
  --line: #d6cfbe;
  --line-soft: #e3ddcc;
  --accent: #8a3a1e;
  --tag: #5a6b3a;
  --ref: #3a5a6b;
  --done: #8a8a82;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "EB Garamond", "Iowan Old Style", Georgia, serif;
  --bullet-size: 6px;
  --indent: 28px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  font-feature-settings: "ss01", "ss02", "calt", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

button { font-family: inherit; font-size: inherit; cursor: pointer; background: transparent; border: 0; color: inherit; }
input { font-family: inherit; font-size: inherit; color: inherit; background: transparent; border: 0; outline: none; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }
a:hover { opacity: 0.7; }

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 6px; cursor: pointer; user-select: none; }
.brand .sigma { font-family: var(--serif); font-size: 22px; font-style: italic; line-height: 1; }
.brand .name { font-weight: 500; letter-spacing: 0.02em; }

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  color: var(--ink-faint);
  font-size: 12px;
  overflow: hidden;
}
.crumbs .crumb { cursor: pointer; padding: 2px 4px; border-radius: 2px; }
.crumbs .crumb:hover { color: var(--ink); background: var(--bg-soft); }
.crumbs .sep { color: var(--line); padding: 0 2px; user-select: none; }

.util { display: flex; align-items: center; gap: 4px; }
.util-btn {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 6px 10px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.util-btn:hover { background: var(--bg-soft); color: var(--ink); }
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  display: inline-block;
}
.dot.synced { background: #4a8a4a; }
.dot.dirty { background: #c08a30; }
.dot.error { background: #a83a2a; }
.dot.syncing { background: #3a6ba8; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

#app { flex: 1; display: flex; justify-content: center; padding: 32px 24px 80px; }
.page { width: 100%; max-width: 760px; }

.zoom-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  color: var(--ink);
  word-wrap: break-word;
}
.zoom-title .meta {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 4px;
}
.zoom-title:empty { display: none; }

.tree { margin-top: 16px; }
.node { position: relative; }
.node-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 1px 0;
  position: relative;
}
.node-children { margin-left: var(--indent); position: relative; }
.node-children::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 0;
  bottom: 4px;
  width: 1px;
  background: var(--line-soft);
}

.handle {
  flex: 0 0 auto;
  width: 18px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  color: var(--ink-faint);
  font-size: 10px;
  margin-top: 1px;
  transition: color 0.15s;
}
.handle:hover { color: var(--ink); }
.handle .caret {
  display: inline-block;
  transition: transform 0.15s;
  font-size: 9px;
  width: 10px;
  text-align: center;
}
.node.collapsed > .node-row .handle .caret { transform: rotate(-90deg); }
.node:not(.has-children) > .node-row .handle .caret { visibility: hidden; }

.bullet {
  flex: 0 0 auto;
  width: 18px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}
.bullet::before {
  content: "";
  display: block;
  width: var(--bullet-size);
  height: var(--bullet-size);
  border-radius: 50%;
  background: var(--ink-soft);
  transition: background 0.15s, box-shadow 0.15s, transform 0.15s;
}
.bullet:hover::before { background: var(--accent); transform: scale(1.2); }
.node.collapsed > .node-row .bullet::before { box-shadow: 0 0 0 4px var(--bg-soft); }

.content {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  caret-color: var(--accent);
  line-height: 1.55;
}
.content:empty::before {
  content: attr(data-placeholder);
  color: var(--line);
  pointer-events: none;
}
.node.focused > .node-row .content {
  background: linear-gradient(transparent 60%, rgba(138,58,30,0.08) 60%);
}

.tag { color: var(--tag); cursor: pointer; padding: 0 1px; border-radius: 2px; }
.tag:hover { background: rgba(90,107,58,0.12); }
.ref {
  color: var(--ref);
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
  border-bottom: 1px dashed currentColor;
}
.ref:hover { background: rgba(58,90,107,0.12); }
.ref.broken { color: var(--ink-faint); border-bottom-style: dotted; }

.todo-mark {
  display: inline-block;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.05em;
  padding: 0 4px;
  margin-right: 4px;
  border-radius: 2px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.todo-mark.done { background: transparent; color: var(--done); }
.node.done > .node-row .content { color: var(--done); text-decoration: line-through; text-decoration-color: var(--ink-faint); }

.backlinks {
  margin-top: 64px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.backlinks:empty { display: none; }
.backlinks h3 {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 12px;
}
.backlink {
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.backlink:hover { background: var(--bg-soft); }
.backlink:last-child { border-bottom: 0; }
.backlink-path { font-size: 11px; color: var(--ink-faint); margin-bottom: 2px; }
.backlink-text { font-size: 13px; color: var(--ink); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,26,23,0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 16px 16px;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.overlay[hidden] { display: none; }
.overlay-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 16px 48px rgba(26,26,23,0.18);
  overflow: hidden;
}
.overlay-card input[type=text] {
  width: 100%;
  padding: 16px 20px;
  font-size: 16px;
  border-bottom: 1px solid var(--line);
}
.overlay-hint {
  padding: 8px 20px;
  font-size: 11px;
  color: var(--ink-faint);
  border-top: 1px solid var(--line-soft);
  background: var(--bg-soft);
}
.search-results { max-height: 50vh; overflow-y: auto; }
.search-result {
  padding: 10px 20px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.search-result:hover, .search-result.active { background: var(--bg-soft); }
.search-result .path { font-size: 11px; color: var(--ink-faint); margin-bottom: 2px; }
.search-result .text { font-size: 13px; }
.search-result mark {
  background: rgba(138,58,30,0.18);
  color: var(--ink);
  padding: 0 2px;
  border-radius: 2px;
}

.overlay-card.config { max-width: 520px; }
.config-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.config-head h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-style: italic;
  font-size: 22px;
}
.close {
  font-size: 22px;
  color: var(--ink-faint);
  width: 28px;
  height: 28px;
  border-radius: 3px;
}
.close:hover { background: var(--bg-soft); color: var(--ink); }

.config-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.config-section:last-child { border-bottom: 0; }
.config-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.config-row h3 {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.status { font-size: 11px; color: var(--ink-faint); letter-spacing: 0.05em; }
.status.connected { color: #4a8a4a; }
.status.error { color: #a83a2a; }
.config-help {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
  margin-bottom: 12px;
}

.field { display: block; margin-bottom: 10px; }
.field span {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 13px;
  background: var(--bg);
}
.field input:focus { border-color: var(--ink-soft); }

.config-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.primary, .ghost {
  padding: 8px 14px;
  border-radius: 3px;
  font-size: 12px;
  letter-spacing: 0.02em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.primary { background: var(--ink); color: var(--bg); }
.primary:hover { background: var(--accent); }
.ghost { border: 1px solid var(--line); color: var(--ink-soft); }
.ghost:hover { border-color: var(--ink-soft); color: var(--ink); }
.config-foot { font-size: 11px; color: var(--ink-faint); margin-top: 10px; }
.config-foot.danger { margin-top: 4px; }
.link-danger {
  font-size: 11px;
  color: #a83a2a;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-danger:hover { color: #6a1a0a; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 3px;
  font-size: 12px;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  .topbar { grid-template-columns: auto auto; gap: 8px; padding: 10px 14px; }
  .crumbs {
    grid-column: 1 / -1;
    order: 3;
    width: 100%;
    padding-top: 4px;
    border-top: 1px dashed var(--line-soft);
  }
  .crumbs:empty { display: none; }
  .util-btn { padding: 6px 8px; }
  #app { padding: 20px 12px 80px; }
  :root { --indent: 20px; }
  .zoom-title { font-size: 26px; }
  .overlay { padding-top: 16px; }
}

/* ── dark mode (sistema) ───────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18170f;
    --bg-soft: #22211a;
    --ink: #ebe6d8;
    --ink-soft: #b8b3a4;
    --ink-faint: #6a675e;
    --line: #2e2c24;
    --line-soft: #25241c;
    --accent: #d97a4a;
    --tag: #a8b87a;
    --ref: #7aa8c0;
    --done: #6a675e;
  }
  :root:not([data-theme="light"]) .primary { background: var(--ink); color: var(--bg); }
  :root:not([data-theme="light"]) .primary:hover { background: var(--accent); color: var(--bg); }
}
/* dark mode (manual toggle) */
[data-theme="dark"] {
  --bg: #18170f;
  --bg-soft: #22211a;
  --ink: #ebe6d8;
  --ink-soft: #b8b3a4;
  --ink-faint: #6a675e;
  --line: #2e2c24;
  --line-soft: #25241c;
  --accent: #d97a4a;
  --tag: #a8b87a;
  --ref: #7aa8c0;
  --done: #6a675e;
}
[data-theme="dark"] .primary { background: var(--ink); color: var(--bg); }
[data-theme="dark"] .primary:hover { background: var(--accent); color: var(--bg); }
[data-theme="dark"] .overlay-card { box-shadow: 0 16px 48px rgba(0,0,0,0.5); }

/* ── rich text inline ──────────────────────────────── */
.content strong { font-weight: 700; }
.content em { font-style: italic; }
.inline-code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 1px 4px;
  border-radius: 2px;
}

/* ── sync timestamp ────────────────────────────────── */
.sync-time {
  font-size: 10px;
  color: var(--ink-faint);
  margin-left: 2px;
}

/* ── shortcuts modal ───────────────────────────────── */
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 8px 0;
}
.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 20px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.shortcut-row:last-child { border-bottom: 0; }
.shortcut-row .desc { color: var(--ink-soft); }
.shortcut-row kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 6px;
  color: var(--ink);
  white-space: nowrap;
}

/* ── mobile toolbar ────────────────────────────────── */
.mobile-toolbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 6px 12px;
  padding-bottom: env(safe-area-inset-bottom, 6px);
  z-index: 50;
  gap: 4px;
  justify-content: space-between;
  align-items: center;
}
.mobile-toolbar button {
  flex: 1;
  padding: 10px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  text-align: center;
  transition: background 0.1s;
}
.mobile-toolbar button:active { background: var(--line); }

@media (max-width: 720px) {
  .mobile-toolbar { display: flex; }
  #app { padding-bottom: 72px; }
}
