/* Sinapse — estilos da interface.
   Tokens primeiro; depois estrutura, componentes e conteúdo. */

@font-face { font-family: "Inter"; src: url("/fonts/Inter-Regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Inter"; src: url("/fonts/Inter-Medium.woff") format("woff"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Inter"; src: url("/fonts/Inter-SemiBold.woff") format("woff"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Lora"; src: url("/fonts/Lora-Variable.woff") format("woff"); font-weight: 400 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Lora"; src: url("/fonts/Lora-Italic-Variable.woff") format("woff"); font-weight: 400 700; font-style: italic; font-display: swap; }

:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eaecf1;
  --surface-3: #dfe2ea;
  --line: #d9dce4;
  --line-soft: #e6e8ee;
  --ink: #1e2230;
  --ink-2: #4b5266;
  --ink-3: #7b8296;
  --focus: #4b5fd6;
  --danger: #c4424f;
  --ok: #2f8a6c;
  --mark: #f6e3a1;
  --code-bg: #eef0f4;
  --graph-line: rgba(30, 34, 48, 0.13);
  --graph-line-hot: rgba(30, 34, 48, 0.55);
  --shadow: 0 1px 2px rgba(20, 24, 36, 0.06), 0 12px 32px -12px rgba(20, 24, 36, 0.22);
  --pc: #8c93a6;

  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --read: "Lora", "Iowan Old Style", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;

  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 12px;
  --rail: 52px;
  --side: 272px;
  --panel: 288px;
  --measure: 70ch;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1f29;
    --surface: #222632;
    --surface-2: #2a2f3d;
    --surface-3: #333949;
    --line: #353b4b;
    --line-soft: #2c3141;
    --ink: #e7e4dc;
    --ink-2: #aab0bf;
    --ink-3: #767d90;
    --focus: #8f9cf5;
    --danger: #ec7782;
    --ok: #6cc8a4;
    --mark: #5c4d1e;
    --code-bg: #262b38;
    --graph-line: rgba(231, 228, 220, 0.12);
    --graph-line-hot: rgba(231, 228, 220, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -14px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1f29;
  --surface: #222632;
  --surface-2: #2a2f3d;
  --surface-3: #333949;
  --line: #353b4b;
  --line-soft: #2c3141;
  --ink: #e7e4dc;
  --ink-2: #aab0bf;
  --ink-3: #767d90;
  --focus: #8f9cf5;
  --danger: #ec7782;
  --ok: #6cc8a4;
  --mark: #5c4d1e;
  --code-bg: #262b38;
  --graph-line: rgba(231, 228, 220, 0.12);
  --graph-line-hot: rgba(231, 228, 220, 0.55);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -14px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-radius: var(--r-sm); }
[hidden] { display: none !important; }
code, kbd, pre { font-family: var(--mono); }
.icon { display: inline-flex; flex: none; }
.spacer { flex: 1; }
.muted { color: var(--ink-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); flex: none; display: inline-block; }
.boot { display: grid; place-items: center; height: 100%; color: var(--ink-3); letter-spacing: 0.02em; }

/* ----- botões e campos ------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
  font-weight: 500; white-space: nowrap; text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-danger-ghost { color: var(--danger); }
.btn-small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; height: 40px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-3);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); font-size: 13px; }
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }

.input {
  width: 100%; height: 36px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
}
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input-small { height: 30px; font-size: 13px; width: auto; }
select.input { padding-right: 28px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.hint { font-size: 12.5px; color: var(--ink-3); margin: -6px 0 14px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 0 0 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); user-select: none; }
.check input { accent-color: var(--ink); }

.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--r-md); background: var(--surface-2); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"], .seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
kbd { font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); color: var(--ink-3); background: var(--surface); }

/* ----- estrutura -------------------------------------------------------- */

.app { display: flex; height: 100%; }
.rail {
  width: var(--rail); flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0; background: var(--bg); border-right: 1px solid var(--line-soft);
}
.rail-brand { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 8px; color: var(--ink); border-radius: var(--r-md); }
.rail-btn { width: 36px; height: 36px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink-3); display: grid; place-items: center; }
.rail-btn:hover { color: var(--ink); background: var(--surface-2); }
.rail-btn[aria-current="true"] { color: var(--ink); background: var(--surface-2); }

.shell { flex: 1; min-width: 0; display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--panel); }
.shell.no-side { grid-template-columns: 0 minmax(0, 1fr) var(--panel); }
.shell.no-panel { grid-template-columns: var(--side) minmax(0, 1fr) 0; }
.shell.no-side.no-panel { grid-template-columns: 0 minmax(0, 1fr) 0; }
.shell > .side { grid-column: 1; grid-row: 1; }
.shell > .center { grid-column: 2; grid-row: 1; }
.shell > .panel { grid-column: 3; grid-row: 1; }
.shell { grid-template-rows: 100%; }
.shell.no-side .side, .shell.no-panel .panel { visibility: hidden; overflow: hidden; border: 0; }

.side { display: flex; flex-direction: column; min-height: 0; background: var(--bg); border-right: 1px solid var(--line-soft); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 46px; padding: 0 10px 0 16px; flex: none; }
.side-title { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.side-tools { display: flex; gap: 2px; }
.side-body { flex: 1; overflow: auto; padding: 2px 8px 24px; }

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.topbar { display: flex; align-items: center; gap: 4px; height: 46px; padding: 0 10px; flex: none; border-bottom: 1px solid var(--line-soft); }
.search-trigger {
  display: flex; align-items: center; gap: 8px; margin-left: 10px;
  height: 30px; width: min(380px, 50%); padding: 0 8px 0 10px;
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
  background: var(--bg); color: var(--ink-3); font-size: 13px;
}
.search-trigger:hover { border-color: var(--line); color: var(--ink-2); }
.search-trigger span:not(.icon) { flex: 1; text-align: left; }
.main { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

.panel { overflow: auto; background: var(--bg); border-left: 1px solid var(--line-soft); padding: 8px 14px 32px; }

/* ----- árvore de arquivos ----------------------------------------------- */

.part { margin-bottom: 10px; }
.part-head {
  position: relative; display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 6px 0 10px; border-radius: var(--r-md);
  cursor: pointer; user-select: none;
}
.part-head:hover { background: var(--surface-2); }
.part-head.drop, .tree-row.drop { background: color-mix(in srgb, var(--pc) 22%, transparent); }
.part-swatch { width: 4px; height: 16px; border-radius: 2px; background: var(--pc); flex: none; }
.part-name { flex: 1; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part-access { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.part-access.private { color: var(--ink-3); opacity: 0.8; }
.part-add { width: 24px; height: 24px; opacity: 0; }
.part-head:hover .part-add, .part-add:focus-visible { opacity: 1; }
.tree-children { position: relative; margin-left: 12px; padding-left: 0; }
.tree-children::before { content: ""; position: absolute; left: 0; top: 2px; bottom: 2px; width: 1.5px; background: color-mix(in srgb, var(--pc) 55%, transparent); border-radius: 1px; }
.tree-row {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 8px 0 calc(10px + var(--depth) * 14px);
  border-radius: var(--r-sm); color: var(--ink-2);
  text-decoration: none; cursor: pointer; user-select: none; font-size: 13.5px;
}
.tree-row:hover { background: var(--surface-2); color: var(--ink); }
.tree-row.active { background: color-mix(in srgb, var(--pc) 18%, var(--surface)); color: var(--ink); font-weight: 500; }
.tree-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-ext { font-size: 10.5px; padding: 0 4px; border-radius: 3px; background: var(--surface-2); color: var(--ink-3); font-weight: 500; }
.tree-icon { color: var(--ink-3); }
.tree-row.active .tree-icon { color: var(--pc); }
.chev { color: var(--ink-3); transition: transform 0.12s; }
.chev.open { transform: rotate(90deg); }
.tree-meta { opacity: 0.7; }
.empty { color: var(--ink-3); padding: 12px; }

/* ----- busca e tags (barra lateral) -------------------------------------- */

.search-box { display: grid; gap: 8px; padding: 2px 4px 12px; }
.search-box select { width: 100%; }
.results { display: grid; gap: 2px; }
.result { display: grid; gap: 2px; padding: 8px 10px; border-radius: var(--r-md); text-decoration: none; }
.result:hover { background: var(--surface-2); }
.result-title { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.result-path { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 15px; }
.result-snippet { margin: 2px 0 0 15px; font-size: 12.5px; color: var(--ink-2); line-height: 1.45; }
.result-snippet mark, .prose mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.tag-list { list-style: none; margin: 0; padding: 0 2px; }
.tag-row { display: flex; justify-content: space-between; width: 100%; padding: 6px 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); }
.tag-row:hover { background: var(--surface-2); color: var(--ink); }
.count { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ----- nota: cabeçalho e modos ------------------------------------------ */

.noteview { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.doc-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 46px; padding: 0 14px 0 20px; flex: none; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; color: var(--ink-3); overflow: hidden; white-space: nowrap; }
.crumb-part { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 500; }
.crumb-part::before { content: ""; width: 4px; height: 14px; border-radius: 2px; background: var(--pc); }
.crumb-sep { opacity: 0.6; }
.crumb { overflow: hidden; text-overflow: ellipsis; }
.doc-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.save-status { font-size: 12px; color: var(--ink-3); min-width: 64px; text-align: right; }
.save-status[data-state="dirty"], .save-status[data-state="saving"] { color: var(--ink-2); }
.save-status[data-state="error"], .save-status[data-state="conflict"] { color: var(--danger); font-weight: 500; }
.banner-host:empty { display: none; }
.banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 20px 8px; padding: 10px 14px; border-radius: var(--r-md); font-size: 13px; }
.banner-warn { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.banner span { flex: 1; min-width: 200px; }

.doc-body { flex: 1; min-height: 0; display: grid; position: relative; }
.doc-body::before {
  /* a "espinha" da partição: a cor diz em que área do cérebro você está */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--pc); opacity: 0.85; z-index: 1;
}
.pane { overflow: auto; min-width: 0; padding: 18px 40px 30vh; }
.measure { max-width: var(--measure); margin: 0 auto; }
.doc-body[data-mode="edit"] .pane-read { display: none; }
.doc-body[data-mode="read"] .pane-edit { display: none; }
.doc-body[data-mode="split"] { grid-template-columns: 1fr 1fr; }
.doc-body[data-mode="split"] .pane-edit { border-right: 1px solid var(--line-soft); }
.doc-body[data-mode="split"] .pane { padding-left: 32px; padding-right: 32px; }

.inline-title {
  font: 600 2.05rem/1.2 var(--read); letter-spacing: -0.01em;
  margin: 18px 0 18px; padding: 0; outline: none; color: var(--ink);
  overflow-wrap: anywhere;
}
.inline-title:not(.static):hover { color: var(--ink); }
.inline-title:not(.static):focus { box-shadow: inset 0 -2px 0 var(--pc); }

/* ----- editor (textarea + camada de realce) ------------------------------- */

.editor { position: relative; }
.editor-surface { position: relative; }
.editor-layer, .editor-input, .editor-measure {
  margin: 0; padding: 0; border: 0;
  font: 400 17px/1.75 var(--read);
  letter-spacing: 0; word-spacing: 0; tab-size: 4;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal;
  font-variant-ligatures: none; font-kerning: normal;
}
.editor-code .editor-layer, .editor-code .editor-input, .editor-code .editor-measure { font: 400 14px/1.65 var(--mono); }
.editor-layer { position: absolute; inset: 0; pointer-events: none; color: var(--ink); overflow: hidden; }
.editor-input {
  position: relative; display: block; width: 100%; min-height: 50vh;
  resize: none; overflow: hidden; background: transparent;
  color: transparent; caret-color: var(--ink); outline: none;
}
.editor-input::selection { background: color-mix(in srgb, var(--focus) 30%, transparent); color: transparent; }
.editor-measure { position: absolute; inset: 0; visibility: hidden; pointer-events: none; }

.md-punct, .md-front, .md-hr { color: var(--ink-3); }
.md-h { color: var(--ink); }
.md-h .md-punct { color: var(--pc); }
.md-h1, .md-h2 { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--pc) 45%, transparent); text-underline-offset: 6px; text-decoration-thickness: 2px; }
.md-strong { color: var(--ink); background: color-mix(in srgb, var(--ink) 7%, transparent); border-radius: 2px; }
.md-em { color: var(--ink-2); }
.md-code, .md-fence { color: #b5567a; background: var(--code-bg); border-radius: 3px; }
:root[data-theme="dark"] .md-code, :root[data-theme="dark"] .md-fence { color: #e59ab6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .md-code, :root:not([data-theme="light"]) .md-fence { color: #e59ab6; } }
.md-wiki { color: var(--pc); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--pc) 40%, transparent); text-underline-offset: 3px; }
.md-link, .md-url { color: var(--focus); }
.md-tag { color: var(--pc); background: color-mix(in srgb, var(--pc) 14%, transparent); border-radius: 3px; }
.md-mark { background: var(--mark); border-radius: 2px; }
.md-quote { color: var(--ink-2); }
.md-list { color: var(--pc); }
.md-task { color: var(--ink-3); }
.md-task.done, .md-done { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-3); }
.md-table { color: var(--ink-2); }

.suggest {
  position: absolute; z-index: 30; width: 320px; max-height: 280px; overflow: auto;
  padding: 4px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow);
}
.suggest-item { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer; color: var(--ink-2); }
.suggest-item .icon { grid-row: span 2; }
.suggest-item.active { background: var(--surface-2); color: var(--ink); }
.suggest-title { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-path { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- leitura (prosa) ---------------------------------------------------- */

.prose { font: 400 17px/1.75 var(--read); color: var(--ink); overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 { font-family: var(--read); font-weight: 600; line-height: 1.3; letter-spacing: -0.005em; margin: 1.7em 0 0.55em; }
.prose h1 { font-size: 1.75em; }
.prose h2 { font-size: 1.38em; padding-bottom: 0.25em; border-bottom: 1.5px solid color-mix(in srgb, var(--pc) 35%, transparent); }
.prose h3 { font-size: 1.15em; }
.prose h4, .prose h5, .prose h6 { font-size: 1em; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose .table-wrap, .prose .codeblock, .prose figure { margin: 0 0 1em; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li { margin: 0.15em 0; }
.prose li::marker { color: var(--pc); }
.prose a { color: var(--focus); text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--focus) 40%, transparent); }
.prose a.wikilink { color: var(--pc); filter: saturate(1.1); text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); }
.prose a.wikilink.unresolved { color: var(--ink-3); text-decoration-style: dashed; }
.prose a.tag, .panel a.tag {
  display: inline-block; font: 500 0.78em/1.6 var(--ui); padding: 0 7px; border-radius: 999px;
  color: var(--ink-2); background: var(--surface-2); text-decoration: none; vertical-align: 0.08em;
}
.prose a.tag:hover, .panel a.tag:hover { color: var(--ink); background: var(--surface-3); }
.prose blockquote { padding: 0.1em 0 0.1em 1.1em; border-left: 3px solid var(--line); color: var(--ink-2); font-style: italic; }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 2em 0; }
.prose code { font-size: 0.84em; padding: 0.12em 0.36em; border-radius: 4px; background: var(--code-bg); }
.prose strong { font-weight: 650; }
.codeblock { border-radius: var(--r-md); background: var(--code-bg); overflow: hidden; }
.codeblock-bar { display: flex; justify-content: space-between; align-items: center; height: 30px; padding: 0 6px 0 12px; font: 12px var(--ui); color: var(--ink-3); }
.copy-code { border: 0; background: transparent; color: var(--ink-3); font: 500 12px var(--ui); padding: 3px 8px; border-radius: var(--r-sm); }
.copy-code:hover { background: var(--surface-3); color: var(--ink); }
.codeblock pre { margin: 0; padding: 4px 14px 14px; overflow: auto; font-size: 13.5px; line-height: 1.6; }
.codeblock code { padding: 0; background: none; font-size: inherit; }
.table-wrap { overflow-x: auto; }
.prose table { border-collapse: collapse; font: 14px/1.5 var(--ui); min-width: 60%; }
.prose th, .prose td { padding: 7px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
.prose th { font-weight: 600; border-bottom-color: var(--line); color: var(--ink-2); }
.prose img { max-width: 100%; height: auto; border-radius: var(--r-md); }
.embed { margin: 0 0 1em; }
.embed figcaption { font: 13px var(--ui); color: var(--ink-3); margin-top: 6px; }
.embed-video video { width: 100%; border-radius: var(--r-md); background: #000; }
.embed-audio audio { width: 100%; }
.embed-pdf iframe { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: var(--r-md); }
.embed-note { border-left: 3px solid var(--pc); padding: 4px 0 4px 16px; }
.embed-title { font: 600 13px var(--ui); text-decoration: none; }
.embed-body { font-size: 0.95em; color: var(--ink-2); }
.embed-missing { color: var(--danger); font: 13px var(--ui); }
.embed-file { font: 500 14px var(--ui); }
.task { list-style: none; position: relative; }
.prose ul:has(> .task) { padding-left: 0.4em; }
.task-box {
  display: inline-grid; place-items: center; vertical-align: -0.12em;
  width: 1.05em; height: 1.05em; margin-right: 0.5em; padding: 0;
  border: 1.5px solid var(--ink-3); border-radius: 4px; background: transparent;
}
.task-box.done { background: var(--pc); border-color: var(--pc); }
.task-box.done::after { content: ""; width: 0.32em; height: 0.55em; border: solid var(--surface); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.task-done { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line); }

.callout { margin: 0 0 1em; padding: 12px 16px; border-radius: var(--r-md); background: color-mix(in srgb, var(--cc, var(--pc)) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cc, var(--pc)) 28%, transparent); }
.callout-title { font: 600 13.5px/1.4 var(--ui); color: color-mix(in srgb, var(--cc, var(--pc)) 75%, var(--ink)); margin-bottom: 4px; }
.callout-body > :last-child { margin-bottom: 0; }
.callout-tip, .callout-success { --cc: #3c9e7e; }
.callout-warning, .callout-important { --cc: #c98a2e; }
.callout-danger { --cc: #d0505e; }
.callout-info, .callout-note, .callout-question, .callout-example, .callout-todo { --cc: #5a73d8; }
.callout-quote { --cc: #8c93a6; }

/* ----- arquivos de mídia --------------------------------------------------- */

.media-wrap { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px; }
.media-view { max-width: 100%; max-height: calc(100vh - 200px); border-radius: var(--r-md); box-shadow: var(--shadow); }
video.media-view { background: #000; }
.media-audio { width: min(560px, 100%); margin-top: 20vh; }
.pdf-view { width: 100%; flex: 1; min-height: 70vh; border: 1px solid var(--line); border-radius: var(--r-md); }
.media-meta { font-size: 12.5px; color: var(--ink-3); }
.media-meta code { font-size: 12px; padding: 1px 5px; background: var(--code-bg); border-radius: 4px; }

.empty-state { margin: auto; max-width: 440px; text-align: center; padding: 40px 20px; color: var(--ink-2); display: grid; gap: 10px; justify-items: center; }
.empty-state h2 { margin: 0; color: var(--ink); font: 600 1.3rem var(--read); }
.empty-state p { margin: 0; }
.loading { margin: auto; color: var(--ink-3); }

/* ----- início ---------------------------------------------------------------- */

.home { overflow: auto; padding: 9vh 40px 60px; max-width: 900px; width: 100%; margin: 0 auto; }
.home-title { font: 600 clamp(1.9rem, 3.6vw, 2.7rem)/1.15 var(--read); letter-spacing: -0.015em; margin: 0 0 22px; }
.home-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 40px; }
.home-parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 44px; }
.home-part {
  display: grid; gap: 6px; text-align: left; padding: 14px 16px 14px 18px;
  border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--bg);
  position: relative; overflow: hidden;
}
.home-part::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--pc); }
.home-part:hover { border-color: var(--line); background: var(--surface-2); }
.home-part-name { font-weight: 600; }
.home-part-desc { font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.home-part-count { font-size: 12px; color: var(--ink-3); }
.home-sub { font: 600 13px var(--ui); color: var(--ink-2); margin: 0 0 8px; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm); text-decoration: none; }
.recent a:hover { background: var(--surface-2); }
.recent-title { font: 500 15px var(--read); }
.recent-path { margin-left: auto; font-size: 12px; color: var(--ink-3); }

/* ----- painel da direita ------------------------------------------------------ */

.panel-sec { padding: 14px 2px; border-bottom: 1px solid var(--line-soft); }
.panel-sec:last-child { border-bottom: 0; }
.panel-title { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font: 600 12.5px var(--ui); color: var(--ink-2); }
.panel-empty { color: var(--ink-3); font-size: 13px; margin: 0; line-height: 1.5; }
.panel-loading { height: 80px; }
.access { position: relative; }
.access-lead { margin: 0 0 10px; font-size: 13px; color: var(--ink); line-height: 1.5; }
.agent-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; }
.agent-chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-soft); font-size: 13px; }
.agent-chip .icon { color: var(--pc); }
.agent-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.access-badge { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.access-badge.write { background: color-mix(in srgb, var(--pc) 22%, var(--surface)); color: var(--ink); }
.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.link-list li { min-width: 0; }
.link-item { min-width: 0; overflow: hidden; display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: var(--r-sm); text-decoration: none; font-size: 13.5px; }
.link-item:hover { background: var(--surface-2); }
.link-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-missing { padding: 5px 6px 5px 22px; font-size: 13px; color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--line); }
.link-hidden { text-decoration: none; font-style: italic; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; }
.panel a.tag { font-size: 12px; }
.props { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.props dt { color: var(--ink-3); }
.props dd { margin: 0; overflow-wrap: anywhere; }
.overview { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.overview li { display: grid; grid-template-columns: auto 1fr; column-gap: 9px; align-items: center; font-size: 13px; }
.ov-name { font-weight: 500; }
.ov-agents { grid-column: 2; color: var(--ink-3); font-size: 12.5px; }

/* ----- grafo ------------------------------------------------------------------ */

.graphview { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.graph-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.graph-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border: 1px solid var(--line-soft); border-radius: 999px; background: var(--surface); font-size: 13px; color: var(--ink); }
.chip.off { color: var(--ink-3); background: transparent; }
.chip.off .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--pc); }
.graph-opts { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.graph-stage { flex: 1; min-height: 0; position: relative; }
.graph-canvas { position: absolute; inset: 0; cursor: grab; touch-action: none; }
.graph-tip { position: absolute; z-index: 5; pointer-events: none; display: grid; gap: 2px; max-width: 320px; padding: 7px 10px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg); font-size: 12.5px; box-shadow: var(--shadow); }
.graph-tip span { opacity: 0.75; font-size: 11.5px; }
.graph-empty { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); color: var(--ink-3); text-align: center; max-width: 340px; }

/* ----- modais, paleta e menus ------------------------------------------------- */

.modal-back { position: fixed; inset: 0; z-index: 100; display: grid; place-items: start center; padding: 12vh 16px 16px; background: rgba(12, 14, 20, 0.55); animation: fade 0.12s ease-out; }
.modal { width: min(460px, 100%); max-height: 80vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); animation: rise 0.16s ease-out; }
.modal-wide { width: min(960px, 100%); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px) scale(0.99); } }
@media (prefers-reduced-motion: reduce) { .modal-back, .modal { animation: none; } }
.dialog { padding: 22px 22px 18px; }
.dialog-wide { width: min(620px, 100vw - 32px); }
.dialog h2 { margin: 0 0 8px; font: 600 1.15rem var(--ui); }
.dialog > p { margin: 0 0 16px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal:has(.dialog-wide) { width: min(620px, 100%); }

.modal-palette { width: min(620px, 100%); }
.palette-input { width: 100%; height: 52px; padding: 0 18px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; font-size: 16px; outline: none; }
.palette-list { max-height: 50vh; overflow: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--ink-2); }
.palette-item.active { background: var(--surface-2); color: var(--ink); }
.pi-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-weight: 500; }
.pi-path { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-cmd .pi-title { font-weight: 400; }
.palette-empty { padding: 18px; color: var(--ink-3); text-align: center; }
.palette-foot { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--line-soft); font-size: 11.5px; color: var(--ink-3); }

.ctx-menu { position: fixed; z-index: 200; min-width: 200px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow); }
.ctx-item { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: var(--r-sm); background: none; font-size: 13.5px; }
.ctx-item:hover, .ctx-item:focus-visible { background: var(--surface-2); outline: none; }
.ctx-item.danger { color: var(--danger); }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--line-soft); }

.toasts { position: fixed; z-index: 300; right: 16px; bottom: 16px; display: grid; gap: 8px; justify-items: end; }
.toast { max-width: 380px; padding: 10px 14px; border-radius: var(--r-md); background: var(--ink); color: var(--bg); font-size: 13px; box-shadow: var(--shadow); transition: opacity 0.25s, transform 0.25s; }
.toast-error { background: var(--danger); color: #fff; }
.toast-agent { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 3px solid var(--focus); }
.toast.out { opacity: 0; transform: translateY(4px); }

/* ----- configurações ----------------------------------------------------------- */

.modal-settings { max-height: 86vh; display: flex; }
.modal-back:has(.modal-settings) { padding-top: 7vh; }
.settings { display: grid; grid-template-columns: 210px 1fr; width: 100%; min-height: 0; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; padding: 14px 10px; background: var(--bg); border-right: 1px solid var(--line-soft); }
.settings-tab { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); text-align: left; font-weight: 500; }
.settings-tab:hover { background: var(--surface-2); color: var(--ink); }
.settings-tab[aria-current="true"] { background: var(--surface-2); color: var(--ink); }
.settings-body { overflow: auto; padding: 24px 28px 28px; max-height: 86vh; }
.settings-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 20px; }
.settings-head h2 { margin: 0 0 6px; font: 600 1.25rem var(--ui); }
.settings-head p { margin: 0; max-width: 60ch; line-height: 1.5; font-size: 13.5px; }
.sub-title { font: 600 13px var(--ui); color: var(--ink-2); margin: 24px 0 10px; }
.empty-card { padding: 18px 20px; border: 1px dashed var(--line); border-radius: var(--r-md); color: var(--ink-2); }
.empty-card h3 { margin: 0 0 6px; font-size: 14px; color: var(--ink); }
.empty-card p { margin: 0; font-size: 13.5px; line-height: 1.5; }

.agent-card { border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 12px; overflow: hidden; background: var(--surface); }
.agent-card.revoked { opacity: 0.6; }
.agent-card-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.agent-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); flex: none; }
.agent-id { flex: 1; min-width: 0; display: grid; gap: 2px; }
.agent-title { border: 0; background: transparent; font-weight: 600; font-size: 14.5px; padding: 2px 4px; margin-left: -4px; border-radius: var(--r-sm); }
.agent-title:hover:not(:disabled) { background: var(--surface-2); }
.agent-title:focus { outline: none; background: var(--surface-2); }
.agent-sub { font-size: 12.5px; color: var(--ink-3); }
.agent-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.perm-matrix { border-top: 1px solid var(--line-soft); }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line-soft); }
.perm-row:last-child { border-bottom: 0; }
.dialog .perm-matrix { border: 1px solid var(--line-soft); border-radius: var(--r-md); }
.perm-part { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 500; }
.seg-perm button { height: 26px; font-size: 12.5px; }
.seg-perm button.perm-read[aria-checked="true"] { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--pc) 60%, transparent), 0 1px 2px rgba(0,0,0,.12); }
.seg-perm button.perm-write[aria-checked="true"] { background: color-mix(in srgb, var(--pc) 26%, var(--surface)); }

.token-box { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-md); background: var(--code-bg); margin-bottom: 8px; }
.token-box code { flex: 1; font-size: 13px; overflow-wrap: anywhere; user-select: all; }
.snippet { border: 1px solid var(--line-soft); border-radius: var(--r-md); margin-bottom: 6px; }
.snippet summary { padding: 9px 12px; cursor: pointer; font-weight: 500; font-size: 13.5px; }
.snippet-body { position: relative; padding: 0 12px 12px; display: grid; gap: 8px; justify-items: start; }
.snippet pre { width: 100%; margin: 0; padding: 10px 12px; border-radius: var(--r-sm); background: var(--code-bg); font-size: 12px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

.part-list { display: grid; gap: 10px; }
.part-card { display: flex; gap: 12px; padding: 12px 14px 12px 16px; border: 1px solid var(--line); border-radius: var(--r-md); position: relative; overflow: hidden; }
.part-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--pc); }
.input-icon { width: 46px; text-align: center; font-size: 18px; padding: 0; flex: none; }
.part-fields { flex: 1; display: grid; gap: 8px; min-width: 0; }
.part-name-input { font-weight: 600; }
.part-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.part-meta code { font-size: 12px; color: var(--ink-3); }
.swatches { display: flex; gap: 6px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch[aria-checked="true"] { border-color: var(--ink); }

.audit-list { display: grid; border: 1px solid var(--line-soft); border-radius: var(--r-md); margin-bottom: 12px; overflow: hidden; }
.audit-row { display: grid; grid-template-columns: 110px 170px 1fr auto; gap: 12px; align-items: center; padding: 8px 12px; font-size: 13px; border-bottom: 1px solid var(--line-soft); }
.audit-row:last-child { border-bottom: 0; }
.audit-row.denied { background: color-mix(in srgb, var(--danger) 7%, transparent); }
.a-time { color: var(--ink-3); }
.a-actor { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.a-actor.agent .icon { color: var(--focus); }
.a-what { color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.a-what code { font-size: 12px; color: var(--ink); }
.denied-badge { font-size: 11.5px; font-weight: 600; color: var(--danger); }
.account-sec { margin-bottom: 26px; max-width: 420px; }

/* ----- login -------------------------------------------------------------------- */

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(380px, 100%); }
.brand { display: flex; align-items: center; gap: 10px; font: 600 16px var(--ui); margin-bottom: 36px; }
.auth h1 { font: 600 2.1rem/1.15 var(--read); margin: 0 0 8px; letter-spacing: -0.015em; }
.auth .muted { margin: 0 0 26px; line-height: 1.5; }
.auth-form .input { height: 42px; }

/* ----- telas menores ------------------------------------------------------------ */

@media (max-width: 1180px) {
  :root { --panel: 0px; }
  .panel { display: none; }
}
@media (max-width: 860px) {
  :root { --side: 0px; }
  .rail { width: 48px; }
  .shell { grid-template-columns: 0 minmax(0, 1fr) 0 !important; }
  .side { position: fixed; z-index: 50; left: 48px; top: 0; bottom: 0; width: min(300px, calc(100vw - 48px)); box-shadow: var(--shadow); visibility: visible !important; }
  .shell.no-side .side { display: none; }
  .pane { padding: 14px 18px 30vh; }
  .doc-body[data-mode="split"] { grid-template-columns: 1fr; }
  .doc-body[data-mode="split"] .pane-read { display: none; }
  .seg-label { display: none; }
  .search-trigger kbd { display: none; }
  .search-trigger { width: auto; flex: 1; margin-left: 4px; }
  .search-trigger span:not(.icon) { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .doc-head { padding: 0 8px 0 16px; }
  .save-status { display: none; }
  .settings { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .settings-nav .spacer { display: none; }
  .settings-tab span { white-space: nowrap; }
  .settings-head { flex-direction: column; }
  .audit-row { grid-template-columns: 1fr auto; }
  .audit-row .a-what { grid-column: 1 / -1; }
  .perm-row { flex-direction: column; align-items: flex-start; }
  .home { padding: 6vh 20px 40px; }
  .inline-title { font-size: 1.7rem; }
}
