/* Notas — tema claro sóbrio inspirado no Mousepad (XFCE/Greybird). */

:root {
  --bg: #f6f5f4;
  --panel: #ffffff;
  --panel-2: #f0eeeb;
  --border: #cdc7c2;
  --border-soft: #dedad6;
  --fg: #2e3436;
  --muted: #787d80;
  --accent: #3584e4;
  --accent-dark: #1c71d8;
  --danger: #c01c28;
  --success: #26a269;
  --warn: #e5a50a;
  --diff-add: #d8f0dd;
  --diff-del: #f8d7da;
  --diff-hunk: #dce8fa;
  --mono: "DejaVu Sans Mono", "Ubuntu Mono", "Cascadia Code", Consolas, monospace;
  --sans: "Cantarell", "Noto Sans", "DejaVu Sans", "Segoe UI", sans-serif;

  /* editor overlay */
  --editor-font: var(--mono);
  --editor-size: 14px;
  --line-h: 22px;
  --pad-x: 16px;
  --pad-y: 14px;

  /* cores de tokens (tema claro Greybird) */
  --tk-heading: #1c5d99;
  --tk-strong: #8f3f00;
  --tk-em: #613583;
  --tk-strike: #7c4a03;
  --tk-code: #0f6b46;
  --tk-code-bg: #eef1ee;
  --tk-fence: #5e5c64;
  --tk-link: #1a5fb4;
  --tk-url: #57636e;
  --tk-tag: #1c71d8;
  --tk-mark: #c35c00;
  --tk-quote: #57636e;
  --tk-html: #a51d2d;
  --tk-attr: #8b5a00;
  --tk-str: #26734d;
  --tk-comment: #888a85;
  --tk-punc: #5e5c64;
  --tk-ent: #9859ae;
  --marker: #e5a50a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
code { font-family: var(--mono); font-size: 0.92em; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ------------------------------------------------------------------ menus */
#menubar {
  display: flex;
  align-items: stretch;
  height: 30px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  flex: none;
}
.menu-brand { display: flex; align-items: center; gap: 6px; padding-right: 8px; }
.brand-title { font-weight: 700; font-size: 13px; letter-spacing: .2px; }

.menu { position: relative; display: flex; }
.menu-btn {
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  padding: 0 11px;
  height: 100%;
  cursor: pointer;
  border-radius: 0;
}
.menu-btn:hover, .menu.open .menu-btn { background: var(--accent); color: #fff; }
#btn-sidebar { width: 34px; border-radius: 3px; margin: 3px 0; }
#btn-sidebar:hover { background: #e0dcd8; }

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 40;
  min-width: 240px;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.menu.open .menu-dropdown { display: block; }
.menu-dropdown li {
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  white-space: nowrap;
}
.menu-dropdown li:hover { background: var(--accent); color: #fff; }
.menu-dropdown li:hover .accel { color: #e5effb; }
.menu-dropdown .accel { color: var(--muted); font-size: 11px; }
.menu-sep { height: 0; padding: 0; margin: 4px 8px; border-top: 1px solid var(--border-soft); cursor: default; }
.menu-sep:hover { background: none; }

/* --------------------------------------------------------------- toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 38px;
  padding: 0 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-caption { font-size: 12px; color: var(--muted); margin-right: 4px; }
.tb-sep { width: 1px; height: 22px; background: var(--border-soft); margin: 0 6px; }
.tb-grow { flex: 1; }
.tb-label { font-size: 12px; margin-left: 4px; }

.btn {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
}
.btn:hover { background: #e6e2dd; }
.btn:active { border-color: var(--accent-dark); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-icon { display: inline-flex; align-items: center; padding: 3px 8px; }
.btn-primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: #9c1720; color: #fff; }
.btn-small { font-size: 12px; padding: 2px 8px; }
.fmt { min-width: 30px; justify-content: center; font-size: 13px; }
#fmt-tools.disabled { opacity: .45; pointer-events: none; }

#toolbar select {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 6px;
}

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.segmented .seg {
  border: 0;
  background: var(--panel-2);
  font: inherit;
  font-size: 12px;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--fg);
}
.segmented .seg + .seg { border-left: 1px solid var(--border); }
.segmented .seg.active { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- layout */
#layout { display: flex; flex: 1 1 auto; min-height: 0; }

/* sidebar ------------------------------------------------------------- */
#sidebar {
  width: 272px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
body.sidebar-off #sidebar { display: none; }
.side-section { padding: 8px 10px; border-bottom: 1px solid var(--border-soft); }
.side-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  margin-bottom: 6px;
}
#sidebar input[type="search"], #sidebar select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--fg);
}
#tag-cloud { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-chip {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--accent-dark);
  border-radius: 10px;
  padding: 1px 8px;
  cursor: pointer;
}
.tag-chip:hover { border-color: var(--accent); }
.tag-chip.active { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.tag-chip .tag-n { color: var(--muted); margin-left: 3px; font-size: 10px; }
.tag-chip.active .tag-n { color: #dbe9fb; }

.side-notes { flex: 1 1 auto; border-bottom: 0; display: flex; flex-direction: column; }
.side-listhead { display: flex; justify-content: space-between; align-items: baseline; }
#notes-count { font-size: 11px; }
#notes-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#notes-list li {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
#notes-list li:hover { background: #e9e6e2; }
#notes-list li.active { background: #cfe2fa; box-shadow: inset 3px 0 0 var(--accent); }
.n-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-sub { font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-ext { color: var(--accent-dark); font-family: var(--mono); font-size: 10px; }

/* editor ------------------------------------------------------------ */
#editor-pane { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
#note-meta {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel);
  flex: none;
}
#note-title {
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 4px 8px;
  background: var(--panel-2);
  color: var(--fg);
}
#note-title:focus, .meta-cat:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.meta-cat {
  flex: 0 0 220px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 8px;
  background: var(--panel);
  color: var(--fg);
}

#editor-host { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* editor com overlay de realce (textarea transparente sobre #hl) */
#editor-wrap { flex: 1 1 auto; display: flex; min-width: 0; min-height: 0; }
#gutter {
  flex: none;
  overflow: hidden;
  background: var(--panel-2);
  border-right: 1px solid var(--border-soft);
  user-select: none;
}
body.no-gutter #gutter { display: none; }
#gutter-inner { padding: var(--pad-y) 0; }
.ln {
  height: var(--line-h);
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  line-height: var(--line-h);
  text-align: right;
  color: var(--muted);
  padding: 0 9px 0 12px;
  min-width: 42px;
}
#code-area { position: relative; flex: 1 1 auto; min-width: 0; }
#hl {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  padding: var(--pad-y) var(--pad-x);
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  line-height: var(--line-h);
  color: var(--fg);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
  tab-size: 4;
}
#hl.nowrap { white-space: pre; overflow-wrap: normal; }
.hl-line { min-height: var(--line-h); }
#col-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--marker);
  opacity: .6;
  z-index: 2;
  pointer-events: none;
}
#editor {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  overflow: auto;
  padding: var(--pad-y) var(--pad-x);
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  line-height: var(--line-h);
  background: transparent;
  color: transparent;
  caret-color: var(--fg);
  tab-size: 4;
}
#editor:focus { outline: none; }
#editor::selection { background: rgba(53, 132, 228, .30); }
#editor::placeholder { color: var(--muted); }

/* tokens de colorização */
.tk-h      { color: var(--tk-heading); font-weight: 700; }
.tk-strong { color: var(--tk-strong); font-weight: 700; }
.tk-em     { color: var(--tk-em); font-style: italic; }
.tk-strike { color: var(--tk-strike); text-decoration: line-through; }
.tk-code   { color: var(--tk-code); background: var(--tk-code-bg); }
.tk-fence  { color: var(--tk-fence); }
.tk-fline  { color: var(--tk-code); }
.tk-link   { color: var(--tk-link); text-decoration: underline; }
.tk-url    { color: var(--tk-url); text-decoration: underline; }
.tk-tag    { color: var(--tk-tag); font-weight: 600; }
.tk-mark   { color: var(--tk-mark); font-weight: 700; }
.tk-quote  { color: var(--tk-quote); font-style: italic; }
.tk-html   { color: var(--tk-html); }
.tk-attr   { color: var(--tk-attr); }
.tk-str    { color: var(--tk-str); }
.tk-comment{ color: var(--tk-comment); font-style: italic; }
.tk-punc   { color: var(--tk-punc); }
.tk-ent    { color: var(--tk-ent); }
#preview {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 22px;
  background: var(--panel);
  white-space: pre-wrap; /* usado no modo txt; sobrescrito pelas regras md */
}
#preview-frame { flex: 1 1 auto; width: 100%; border: 0; background: #fff; }

/* preview markdown --------------------------------------------------- */
#preview.md { white-space: normal; line-height: 1.55; }
#preview.md h1, #preview.md h2, #preview.md h3 { margin: 18px 0 8px; line-height: 1.25; }
#preview.md h1 { font-size: 1.7em; border-bottom: 1px solid var(--border-soft); padding-bottom: 4px; }
#preview.md h2 { font-size: 1.35em; }
#preview.md p { margin: 8px 0; }
#preview.md ul, #preview.md ol { margin: 8px 0; padding-left: 26px; }
#preview.md blockquote {
  margin: 10px 0; padding: 4px 14px; color: var(--muted);
  border-left: 3px solid var(--accent); background: var(--panel-2);
}
#preview.md pre {
  background: var(--panel-2); border: 1px solid var(--border-soft);
  border-radius: 4px; padding: 10px 12px; overflow-x: auto;
}
#preview.md code { background: var(--panel-2); padding: 1px 4px; border-radius: 3px; }
#preview.md pre code { background: none; padding: 0; }
#preview.md table { border-collapse: collapse; margin: 10px 0; }
#preview.md th, #preview.md td { border: 1px solid var(--border); padding: 4px 10px; }
#preview.md a { color: var(--accent-dark); }
#preview.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* painel de versões --------------------------------------------------- */
#versions-panel {
  width: 350px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}
.panel-head .side-label { margin: 0; }
#revisions-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 0 1 40%; }
#revisions-list li { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); cursor: pointer; }
#revisions-list li:hover { background: #e9e6e2; }
#revisions-list li.active { background: #cfe2fa; box-shadow: inset 3px 0 0 var(--accent); }
.rev-top { display: flex; justify-content: space-between; font-size: 12px; gap: 8px; }
.rev-hash { font-family: var(--mono); color: var(--accent-dark); font-size: 11px; }
.rev-msg { font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rev-when { font-size: 11px; color: var(--muted); }

#version-detail {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 2px solid var(--border);
  background: var(--panel);
}
.diff-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}
#version-info { font-size: 12px; }
#version-diff {
  flex: 1 1 auto;
  margin: 0;
  overflow: auto;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  background: var(--panel);
  white-space: pre;
}
.d-add { display: block; background: var(--diff-add); }
.d-del { display: block; background: var(--diff-del); }
.d-hunk { display: block; color: var(--accent-dark); background: var(--diff-hunk); }
.d-head { display: block; color: var(--muted); }
.panel-foot { padding: 8px 10px; border-top: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 6px; }
.panel-foot input {
  font: inherit;
  font-size: 12.5px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--fg);
}

/* barra de status ------------------------------------------------------ */
#statusbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  flex: none;
}
.st-item {
  padding: 0 10px;
  border-right: 1px solid var(--border-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.st-grow { flex: 1; }
#st-saved.dirty { color: var(--warn); font-weight: 600; }
#st-saved.ok { color: var(--success); }

/* overlays / diálogos --------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 20, .45);
}
.dialog {
  width: min(440px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  padding: 18px 20px;
}
.dialog h1 { margin: 0 0 6px; font-size: 18px; }
.dialog-hint { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.dialog input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.dialog-error { color: var(--danger); font-size: 12.5px; margin: 8px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#modal-body { font-size: 13px; line-height: 1.6; }
#modal-body code { background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  z-index: 120;
  background: #2e3436;
  color: #fff;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}

/* responsivo simples -----------------------------------------------------*/
@media (max-width: 940px) {
  #sidebar { position: absolute; left: 0; top: 68px; bottom: 26px; z-index: 30; box-shadow: 4px 0 14px rgba(0,0,0,.12); }
  #versions-panel { position: absolute; right: 0; top: 68px; bottom: 26px; z-index: 30; box-shadow: -4px 0 14px rgba(0,0,0,.12); }
}

/* ---------------------------------------------------- temas / esquemas */
html[data-theme="escuro"] {
  --bg: #232323;
  --panel: #1e1e1e;
  --panel-2: #262626;
  --border: #454545;
  --border-soft: #383838;
  --fg: #dbdbdb;
  --muted: #9a9a9a;
  --accent: #3584e4;
  --accent-dark: #62a0ea;
  --danger: #f66151;
  --success: #33d17a;
  --warn: #f5c211;
  --diff-add: #22352a;
  --diff-del: #3d2629;
  --diff-hunk: #24334d;
  --tk-heading: #73c2ff;
  --tk-strong: #ffa348;
  --tk-em: #c58fe0;
  --tk-strike: #e8b07d;
  --tk-code: #57e389;
  --tk-code-bg: #2a3330;
  --tk-fence: #b0b0b0;
  --tk-link: #78aeff;
  --tk-url: #a5a5a5;
  --tk-tag: #78aeff;
  --tk-mark: #ffb84d;
  --tk-quote: #9a9a9a;
  --tk-html: #ff7b6b;
  --tk-attr: #ffc27d;
  --tk-str: #6bd490;
  --tk-comment: #6f6f6f;
  --tk-punc: #b0b0b0;
  --tk-ent: #d99ce8;
  --marker: #a86f00;
}
html[data-theme="escuro"] #editor::selection { background: rgba(120, 174, 255, .28); }
html[data-theme="escuro"] #notes-list li.active,
html[data-theme="escuro"] #revisions-list li.active { background: #2b3f5c; }
html[data-theme="escuro"] #notes-list li:hover,
html[data-theme="escuro"] #revisions-list li:hover { background: #303030; }

html[data-theme="solar-claro"] {
  --bg: #eee8d5;
  --panel: #fdf6e3;
  --panel-2: #f4efdc;
  --border: #d9cfb0;
  --border-soft: #e4dcc2;
  --fg: #586e75;
  --muted: #93a1a1;
  --accent: #268bd2;
  --accent-dark: #1a6bab;
  --danger: #dc322f;
  --success: #859900;
  --warn: #b58900;
  --diff-add: #e6edc9;
  --diff-del: #f6ddd8;
  --diff-hunk: #d8e6f3;
  --tk-heading: #268bd2;
  --tk-strong: #cb4b16;
  --tk-em: #6c71c4;
  --tk-strike: #b58900;
  --tk-code: #2aa198;
  --tk-code-bg: #efe9d4;
  --tk-fence: #93a1a1;
  --tk-link: #268bd2;
  --tk-url: #93a1a1;
  --tk-tag: #268bd2;
  --tk-mark: #cb4b16;
  --tk-quote: #93a1a1;
  --tk-html: #dc322f;
  --tk-attr: #b58900;
  --tk-str: #859900;
  --tk-comment: #aaa79b;
  --tk-punc: #93a1a1;
  --tk-ent: #d33682;
  --marker: #b58900;
}

html[data-theme="solar-escuro"] {
  --bg: #073642;
  --panel: #002b36;
  --panel-2: #0a3d4a;
  --border: #2b5662;
  --border-soft: #1b4552;
  --fg: #93a1a1;
  --muted: #657b83;
  --accent: #268bd2;
  --accent-dark: #2aa198;
  --danger: #dc322f;
  --success: #859900;
  --warn: #b58900;
  --diff-add: #0d4440;
  --diff-del: #3c2a2e;
  --diff-hunk: #0a3d5c;
  --tk-heading: #268bd2;
  --tk-strong: #cb4b16;
  --tk-em: #6c71c4;
  --tk-strike: #b58900;
  --tk-code: #2aa198;
  --tk-code-bg: #0a3d4a;
  --tk-fence: #586e75;
  --tk-link: #268bd2;
  --tk-url: #657b83;
  --tk-tag: #2aa198;
  --tk-mark: #cb4b16;
  --tk-quote: #657b83;
  --tk-html: #dc322f;
  --tk-attr: #b58900;
  --tk-str: #859900;
  --tk-comment: #586e75;
  --tk-punc: #657b83;
  --tk-ent: #d33682;
  --marker: #b58900;
}
html[data-theme="solar-escuro"] #editor::selection { background: rgba(38, 139, 210, .30); }
html[data-theme="solar-escuro"] #notes-list li.active,
html[data-theme="solar-escuro"] #revisions-list li.active { background: #0a4a63; }
html[data-theme="solar-escuro"] #notes-list li:hover,
html[data-theme="solar-escuro"] #revisions-list li:hover { background: #0c4450; }

/* ------------------------------------------------- diálogo preferências */
.dialog-wide { width: min(560px, 92vw); }
.dialog fieldset {
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  margin: 12px 0 0;
  padding: 8px 14px 12px;
}
.dialog legend { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 0 6px; }
.dialog .row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--fg);
}
.dialog .row input[type="checkbox"] { width: auto; margin: 0; }
.dialog .row select {
  flex: 1 1 auto;
  font: inherit;
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--fg);
}
.dialog .num { width: 74px; flex: none; }
