/* ==========================================================================
   Notas (docs/NOTAS-SPEC.md) — lista + editor; no celular, um painel por vez.

   Desktop: a tela ocupa a altura da janela; a lista e o editor rolam por dentro, então a
   barra de formatação fica sempre à vista sem precisar de `sticky`.
   Celular: a página rola normalmente e a barra da nota gruda logo abaixo da barra do topo
   (--header-h, medida em app.js). Por isso o cartão NÃO pode ter overflow:hidden — isso
   o tornaria o contêiner do sticky e empurraria a barra para baixo.
   ========================================================================== */

/* ---------- Tela cheia (desktop) ---------- */
body[data-route="notes"] .main { max-width: none; padding: 1rem clamp(.75rem, 2vw, 1.5rem); }
.notes {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 1.25rem;
  height: calc(100vh - 2rem);
  height: calc(100dvh - 2rem);
}

/* ---------- Menu lateral recolhido (desktop, qualquer tela; ver app.js) ----------
   A alça é um botão redondo no MEIO da borda direita do menu, meio para fora: fica sempre no
   mesmo lugar (aberto ou recolhido), longe dos itens do menu e perto de onde o olho procura a
   borda. Discreta até passar o mouse no menu. */
.sidebar-toggle {
  position: absolute; top: 50%; right: 0; z-index: 25;
  width: 26px; height: 26px; transform: translate(50%, -50%);
  display: grid; place-items: center; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--muted); box-shadow: var(--shadow);
  opacity: .55; transition: opacity .15s, color .15s, transform .15s;
}
.sidebar-toggle .icon { width: 14px; height: 14px; }
.sidebar:hover .sidebar-toggle, .sidebar-toggle:focus-visible { opacity: 1; }
.sidebar-toggle:hover { color: var(--text); transform: translate(50%, -50%) scale(1.1); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar-toggle[hidden] { display: none; }
@media (min-width: 861px) {
  .sidebar { z-index: 20; } /* a alça passa por cima do conteúdo */
  .shell { transition: grid-template-columns .2s ease; }
  body.sidebar-compact { --sidebar: 68px; }
  body.sidebar-compact .sidebar { padding: 1rem .5rem; align-items: center; }
  body.sidebar-compact .brand { padding: 0; }
  body.sidebar-compact .brand-name,
  body.sidebar-compact .top-hud { display: none; }
  body.sidebar-compact .nav { width: 100%; }
  body.sidebar-compact .nav a { justify-content: center; padding: .65rem 0; }
  body.sidebar-compact .nav a > span:not(.nav-badge) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  body.sidebar-compact .nav a { position: relative; }
  body.sidebar-compact .nav .nav-badge { position: absolute; top: 2px; right: 6px; }
  body.sidebar-compact .sidebar-foot { flex-direction: column; margin-top: auto; }
}
@media (max-width: 860px) {
  .sidebar-toggle { display: none !important; }
}

/* ---------- Lista ---------- */
.notes-side { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.notes-side-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.notes-side-head h1 { font-size: var(--fs-xxl); line-height: 1.1; }
.notes-count { font-size: var(--fs-xs); margin: .35rem 0 .75rem; min-height: 1.2em; }
.notes-list {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto; min-height: 0;
}
.notes-none { padding: .75rem; }

.note-item {
  position: relative; width: 100%; text-align: left;
  display: flex; flex-direction: column; gap: .15rem;
  padding: .6rem .75rem; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text); cursor: pointer; font: inherit;
}
.note-item:hover { background: var(--surface-2); }
.note-item[aria-current="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--brand); }
.note-item-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 1rem; }
.note-item-meta { display: flex; gap: .5rem; font-size: var(--fs-xs); color: var(--muted); min-width: 0; }
.note-item-meta time { flex: none; font-weight: 700; }
.note-item-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item-pending { position: absolute; top: .6rem; right: .6rem; color: var(--medium); font-size: .7rem; }

/* ---------- Painel da nota ---------- */
.notes-main {
  position: relative; /* referência da barrinha de link */
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
}
/* Barra da nota: [voltar] · ferramentas CENTRALIZADAS · [status, desfazer/refazer, lixeira]
   à direita. Grid 1fr/auto/1fr para o centro ser o centro da barra, não do espaço que sobra. */
.notes-bar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: .5rem;
  padding: .5rem .75rem; border-bottom: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.notes-back { display: none; grid-column: 1; justify-self: start; }
.notes-bar > .notes-toolbar { grid-column: 2; }
.notes-bar-end { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: .25rem; min-width: 0; max-width: 100%; }
.notes-history { display: inline-flex; gap: 2px; flex: none; }
.notes-history[hidden] { display: none; }
.icon.flip { transform: rotate(180deg); }
/* O status encolhe ANTES da barra de formatação (texto completo no title). */
.notes-status {
  margin-left: auto; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap;
  flex: 0 20 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
.notes-status[data-kind="warn"] { color: var(--medium); }
.notes-status[data-kind="danger"] { color: var(--hard); }

.notes-toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
/* Nada na barra encolhe: sem isto o seletor de estilo vira um "⌄" e o "1. ≡" quebra linha. */
.notes-toolbar > * { flex: none; }
.tb-btn {
  display: inline-grid; place-items: center; min-width: 30px; height: 32px; padding: 0 .3rem;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text);
  font: inherit; font-size: var(--fs-sm); cursor: pointer; line-height: 1; white-space: nowrap;
}
.tb-btn:hover { background: var(--surface-2); }
.tb-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--brand-ink); box-shadow: inset 0 0 0 1px var(--line); }
.tb-btn:disabled { opacity: .35; cursor: not-allowed; background: transparent; }
.tb-btn:focus-visible, .tb-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 .15rem; }
/* ---------- Barra no estilo do Notas da Apple ----------
   Aa (formatação) · Tarefa · Link · ⋯ (mais) · desfazer/refazer. Cabe numa linha até no
   celular; o resto mora nos menus. */
.tb-btn .icon { width: 1.15em; height: 1.15em; }
.tb-btn.tb-aa { font-weight: 700; font-size: var(--fs-md); letter-spacing: -.02em; padding: 0 .5rem; }
.tb-btn.tb-aa[aria-expanded="true"], .tb-btn[data-pop-open][aria-expanded="true"] { background: var(--surface-2); color: var(--accent); }
/* Tarefa: botão comum (sem borda, sem estado ativo), só na cor de destaque do site — o
   laranja dos botões principais (--gold). No tema claro, um tom mais escuro para contraste. */
.tb-btn.tb-task { color: var(--brand); }
.tb-btn.tb-task .icon { width: 1.3em; height: 1.3em; stroke-width: 2.2; }
.tb-btn.tb-task:hover { background: color-mix(in srgb, var(--brand) 16%, transparent); }
:root[data-theme="light"] .tb-btn.tb-task { color: var(--brand-ink); }

/* Menus Aa e ⋯ (position: fixed, posicionados por views/notes.js). */
.tb-pop {
  position: fixed; z-index: 60; width: 340px; max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); overflow-y: auto;
  padding: .4rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
}
.tb-pop[hidden] { display: none; }
.fmt-marks { display: flex; align-items: center; justify-content: space-between; gap: 2px; padding: .1rem .15rem .35rem; }
.fmt-marks .tb-btn { flex: 1; font-size: var(--fs-md); }
.fmt-color { display: inline-flex !important; gap: .3rem; }
.fmt-color-dot { width: .6em; height: .6em; border-radius: 50%; background: currentColor; }
.fmt-colors { display: flex; flex-wrap: wrap; gap: 5px; padding: .25rem .35rem .5rem; }
.tb-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.pop-list { display: flex; flex-direction: column; }
.pop-item {
  display: flex; align-items: center; gap: .4rem; width: 100%; min-height: 36px; padding: .25rem .5rem .25rem .3rem;
  border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font: inherit; font-size: var(--fs-sm);
  text-align: left; cursor: pointer;
}
.pop-item:hover, .pop-item:focus-visible { background: var(--surface-2); outline: none; }
.pop-check { width: 1.1em; flex: none; text-align: center; color: var(--accent); font-weight: 700; }
.pop-item[aria-pressed="true"] .pop-check::before { content: '✓'; }
.pop-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-kbd { white-space: nowrap; flex: none; font: inherit; font-size: var(--fs-xs); color: var(--muted); background: none; border: 0; padding: 0; }
@media (hover: none) { .pop-kbd { display: none; } }
/* Cada estilo aparece escrito no próprio estilo (como no Notas da Apple). */
.pop-title .pop-label { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 700; line-height: 1.15; }
.pop-heading .pop-label { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; }
.pop-subheading .pop-label { font-family: var(--font-display); font-size: var(--fs-md); font-weight: 700; }
.pop-mono .pop-label { font-family: ui-monospace, Menlo, Consolas, monospace; }
.pop-quote-bar { display: inline-block; width: 3px; height: 1em; margin-right: .5rem; vertical-align: -.15em; background: var(--brand); border-radius: 2px; }
.tb-swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); background: var(--sw);
}
.tb-swatch:hover { transform: scale(1.1); }
.tb-swatch-none { background: linear-gradient(135deg, var(--surface) 45%, var(--hard) 45% 55%, var(--surface) 55%); }
.pop-sep { height: 1px; background: var(--line); margin: .3rem .35rem; }
.pop-head { margin: .2rem .5rem .1rem; font-size: var(--fs-xs); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.notes-editor { flex: 1; min-height: 0; overflow-y: auto; padding: 1.5rem clamp(1rem, 4vw, 3rem) 4rem; cursor: text; }
.notes-empty { margin: 2rem; flex: 1; justify-content: center; }
.notes-empty code { font-size: var(--fs-xs); }

/* ---------- Conteúdo (ProseMirror) ----------
   Como no Notas da Apple: cada Enter é uma linha, sem espaço extra entre parágrafos.
   Títulos, listas e blocos ganham um respiro. */
.note-prose { outline: none; max-width: 72ch; margin: 0 auto; line-height: 1.55; font-size: var(--fs-md); min-height: 50vh; }
.note-prose p { margin: 0; }
.note-prose > :is(h1, h2, h3, ul, ol, blockquote, pre, hr, .tableWrapper, .note-img) { margin-top: .5em; margin-bottom: .25em; }
.note-prose > :first-child { margin-top: 0; }
.note-prose h1 { font-family: var(--font-display); font-size: var(--fs-xxl); line-height: 1.15; }
.note-prose h2 { font-family: var(--font-display); font-size: var(--fs-xl); line-height: 1.2; }
.note-prose h3 { font-family: var(--font-display); font-size: var(--fs-lg); line-height: 1.25; }
/* Seções recolhíveis (notes/collapse.js): setinha na margem esquerda do título; a seção
   escondida some sem sair do documento. No toque a setinha fica sempre visível. */
.note-prose .nc-hidden { display: none !important; } /* vence o display das tarefas (.qt), tabelas e imagens */
.note-prose .nc-heading { position: relative; }
.note-prose .nc-toggle {
  position: absolute; left: -1.6rem; top: 50%; transform: translateY(-50%);
  width: 1.4rem; height: 1.4rem; padding: 0; border: 0; border-radius: 6px; background: none;
  color: var(--muted); cursor: pointer; display: grid; place-items: center; opacity: 0;
  transition: opacity .12s, color .12s;
}
.note-prose .nc-toggle svg { width: 16px; height: 16px; transition: transform .15s; }
.note-prose .nc-toggle.is-collapsed svg { transform: rotate(-90deg); }
.note-prose .nc-heading:hover .nc-toggle, .note-prose .nc-toggle.is-collapsed, .note-prose .nc-toggle:focus-visible { opacity: 1; }
.note-prose .nc-toggle:hover { color: var(--text); background: var(--surface-2, rgba(127,127,127,.12)); }
.note-prose .nc-heading.is-collapsed::after { content: '…'; margin-left: .35em; color: var(--muted); font-weight: 400; }
@media (hover: none) { .note-prose .nc-toggle { opacity: .75; } }
@media (max-width: 860px) { .note-prose .nc-toggle { left: -1.1rem; width: 1.05rem; } }
.note-prose ul, .note-prose ol { padding-left: 1.5em; }
.note-prose ul { list-style: disc; }
.note-prose ol { list-style: decimal; }
.note-prose ul.dash-list { list-style: none; }
.note-prose ul.dash-list > li { position: relative; }
.note-prose ul.dash-list > li::before { content: '–'; position: absolute; left: -1.1em; color: var(--muted); }
.note-prose li > p { margin: 0; }
.note-prose blockquote { border-left: 3px solid var(--brand); padding-left: 1em; color: var(--muted); }
.note-prose hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.note-prose a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.note-prose code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em;
  background: var(--surface-2); padding: .1em .3em; border-radius: 4px;
}
.note-prose pre.note-code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: var(--fs-sm);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: .75em 1em; overflow-x: auto; white-space: pre-wrap;
}
.note-prose pre.note-code code { background: none; padding: 0; }
/* Placeholder do Tiptap (extensão Placeholder) */
.note-prose :is(p, h1, h2, h3).is-empty::before {
  content: attr(data-placeholder); float: left; height: 0; pointer-events: none; color: var(--muted); opacity: .7;
}

/* ---------- Tabelas (fase 3) ----------
   A tabela larga rola na horizontal dentro do próprio invólucro (a página nunca rola de lado).
   Colunas redimensionáveis arrastando a borda (a alça aparece ao passar o mouse). */
.note-prose .tableWrapper { max-width: 100%; overflow-x: auto; padding-bottom: 2px; }
.note-prose table {
  border-collapse: collapse; table-layout: fixed; width: 100%; margin: 0;
  font-size: .95em; line-height: 1.45;
}
.note-prose :is(td, th) {
  position: relative; box-sizing: border-box; min-width: 3em; vertical-align: top;
  padding: .35em .55em; border: 1px solid var(--line); overflow-wrap: break-word;
}
.note-prose th { background: var(--surface-2); font-weight: 700; text-align: left; }
.note-prose :is(td, th) > :is(p, h1, h2, h3) { margin: 0; }
.note-prose :is(td, th) > * + * { margin-top: .25em; }
.note-prose :is(td, th) .qt { margin: 0; }
/* Células selecionadas (arrastar por várias células, Shift+setas). */
.note-prose .selectedCell::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.note-prose .column-resize-handle {
  position: absolute; top: 0; bottom: -1px; right: -2px; width: 4px; z-index: 3;
  background: var(--accent); pointer-events: none;
}
.note-prose.resize-cursor { cursor: col-resize; }

/* ---------- Imagens por link (fase 3) ---------- */
.note-prose .note-img { display: block; margin: .5em 0; max-width: 100%; line-height: 0; }
.note-prose .note-img img {
  display: block; max-width: 100%; height: auto; border-radius: var(--r-md);
  background: var(--surface-2); min-height: 2rem; min-width: 2rem;
}
.note-prose .note-img.ProseMirror-selectednode img,
.note-prose .note-img.ProseMirror-selectednode .note-img-broken { outline: 3px solid var(--accent); outline-offset: 2px; }
.note-prose .note-img.ProseMirror-selectednode { outline: none; }
.note-img-broken {
  display: none; align-items: center; gap: .75rem; line-height: 1.4;
  padding: .75rem .9rem; border: 1px dashed var(--line); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--muted); font-size: var(--fs-sm);
}
.note-img.is-broken img { display: none; }
.note-img.is-broken .note-img-broken { display: flex; }
.note-img-broken-icon .icon { width: 1.6rem; height: 1.6rem; }
.note-img-broken-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.note-img-broken-text b { color: var(--text); }
.note-img-broken-url { color: var(--accent); text-decoration: underline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-img-broken-text small { font-size: var(--fs-xs); }
.note-img-broken .tb-btn { flex: none; border: 1px solid var(--line); background: var(--surface); }

/* Pré-visualização no diálogo "Imagem por link". */
.note-img-preview {
  display: grid; place-items: center; min-height: 5rem; max-height: 14rem; overflow: hidden;
  margin: .25rem 0 .5rem; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2);
}
.note-img-preview[hidden] { display: none; }
.note-img-preview img { max-width: 100%; max-height: 14rem; object-fit: contain; display: block; }
.note-img-preview.is-loading img, .note-img-preview.is-broken img { display: none; }
.note-img-preview.is-loading::after { content: 'Carregando…'; color: var(--muted); font-size: var(--fs-xs); }
.note-img-preview.is-broken::after { content: 'Não foi possível carregar a imagem deste endereço.'; color: var(--hard); font-size: var(--fs-xs); padding: .5rem; text-align: center; }
.note-img-tip { font-size: var(--fs-xs); margin: 0; }

/* ---------- Linhas de tarefa = quests (fase 2) ----------
   Caixinha (cor das quests do Hoje quando ligada a uma quest), texto editável e, à direita,
   tag do objetivo e ícone de descrição (clicáveis). */
.note-prose .qt {
  --diff: var(--muted);
  display: flex; align-items: flex-start; gap: .55em; margin: .1em 0; border-radius: var(--r-sm);
}
.note-prose .qt.is-linked { --diff: var(--easy); }
.note-prose .qt > .qt-check {
  flex: none; width: 1.15em; height: 1.15em; margin-top: .2em; padding: 0;
  border: 2px solid var(--diff); border-radius: 50%; background: transparent; cursor: pointer;
  display: grid; place-items: center; color: #fff; transition: background .15s, transform .1s;
}
.note-prose .qt > .qt-check:hover { background: color-mix(in srgb, var(--diff) 20%, transparent); }
.note-prose .qt > .qt-check:active { transform: scale(.9); }
.note-prose .qt.is-done > .qt-check { background: var(--diff); }
.note-prose .qt.is-done > .qt-check::after { content: ''; width: .32em; height: .6em; border: solid #fff; border-width: 0 .15em .15em 0; transform: translateY(-.06em) rotate(45deg); }
.note-prose .qt > .qt-check.is-locked { cursor: not-allowed; opacity: .75; }
.note-prose .qt > .qt-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.note-prose .qt.is-done > .qt-text { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.note-prose .qt > .qt-meta { flex: none; display: inline-flex; align-items: center; gap: .3em; margin-top: .15em; user-select: none; }
/* Texto longo (quest com "…" e o texto inteiro na descrição): expande abaixo da linha. */
.note-prose .qt { flex-wrap: wrap; }
.note-prose .qt > .qt-full {
  flex: 0 0 calc(100% - 1.9em); order: 10; margin: .15em 0 .35em 1.9em; padding: .45em .65em; box-sizing: border-box;
  border-left: 2px solid var(--brand); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: color-mix(in srgb, var(--brand) 7%, transparent);
  font-size: .95em; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; user-select: text;
}
.note-prose .qt > .qt-full[hidden] { display: none; }
.note-prose .qt-meta .qt-more .icon { width: 1em; height: 1em; vertical-align: -.15em; transform: rotate(90deg); transition: transform .15s; }
.note-prose .qt.is-expanded .qt-meta .qt-more .icon { transform: rotate(-90deg); }
.note-prose .qt-meta .qt-more { color: var(--accent); }
/* Olho do modo foco (js/focus.js): discreto até o hover, como os ícones vazios. */
.note-prose .qt-meta .qt-eye { opacity: 0; }
.note-prose .qt-meta .qt-eye .icon { width: 1em; height: 1em; vertical-align: -.15em; }
.note-prose .qt:hover .qt-meta .qt-eye, .note-prose .qt-meta .qt-eye:focus-visible { opacity: .7; }
.note-prose .qt-meta .qt-eye.is-on { opacity: 1; color: var(--brand-ink); }
@media (hover: none) { .note-prose .qt-meta .qt-eye { opacity: .45; } }
.note-prose .qt.fm-target { padding: .2em .4em; margin-left: -.4em; margin-right: -.4em; }
.note-prose .qt-meta button {
  border: 0; background: none; padding: 0 .25em; height: 1.5em; border-radius: var(--r-sm);
  font: inherit; font-size: var(--fs-xs); color: var(--muted); cursor: pointer; line-height: 1.5em;
}
.note-prose .qt-meta button:hover, .note-prose .qt-meta button:focus-visible { background: var(--surface-2); color: var(--text); }
.note-prose .qt-meta .qt-goal { color: var(--accent); font-weight: 700; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.note-prose .qt-meta .qt-desc .icon { width: 1em; height: 1em; vertical-align: -.15em; }
.note-prose .qt-meta .qt-desc.has-desc { color: var(--accent); }
/* Vazios (sem objetivo/descrição) só aparecem ao passar o mouse; no toque, bem discretos. */
.note-prose .qt-meta .is-empty { opacity: 0; background: none; }
.note-prose .qt:hover .qt-meta .is-empty, .note-prose .qt-meta .is-empty:focus-visible { opacity: .6; }
@media (hover: none) { .note-prose .qt-meta .is-empty { opacity: .35; } }
/* Alça de arrastar: na margem À ESQUERDA da caixinha, só no hover (fora do fluxo: o texto não
   anda quando ela aparece). No toque não aparece: segurar a linha levanta a tarefa. */
.note-prose .qt { position: relative; }
.note-prose .qt > .qt-drag {
  position: absolute; left: -1.45em; top: .1em; display: grid; place-items: center;
  width: 1.2em; height: 1.5em; color: var(--muted); cursor: grab; border-radius: var(--r-sm);
  opacity: 0; transition: opacity .12s; user-select: none; -webkit-user-drag: element;
}
.note-prose .qt > .qt-drag .icon { width: 1em; height: 1em; }
.note-prose .qt:hover > .qt-drag { opacity: .7; }
.note-prose .qt > .qt-drag:hover { opacity: 1; background: var(--surface-2); color: var(--text); }
.note-prose .qt > .qt-drag:active { cursor: grabbing; }
/* Numa célula não há margem (e a alça de linha da tabela fica ali): a alça entra no fluxo,
   antes da caixinha, com o espaço reservado (continua só aparecendo no hover). */
.note-prose :is(td, th) .qt > .qt-drag { position: static; flex: none; margin: .05em -.25em 0 -.2em; }
.note-prose .qt.is-dragging { opacity: .45; }
.note-prose .qt.ProseMirror-selectednode { background: color-mix(in srgb, var(--accent) 10%, transparent); outline: none; }
@media (hover: none) { .note-prose .qt > .qt-drag { display: none; } }
/* Toque: linha levantada (apertar e segurar) e a linha que mostra onde ela vai cair. */
.note-prose .qt.is-lifted {
  background: var(--surface); box-shadow: 0 6px 18px rgb(0 0 0 / .18); transform: scale(1.02);
  transition: transform .12s, box-shadow .12s; z-index: 5; -webkit-user-select: none; user-select: none;
}
body.qt-touch-dragging, body.qt-touch-dragging .note-prose { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.qt-drop-line {
  position: fixed; z-index: 1000; height: 3px; margin-top: -1px; border-radius: 3px;
  background: var(--accent); pointer-events: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.qt-drop-line[hidden] { display: none; }
/* Mouse na margem/coluna das alças: vale a linha acima; a do editor (parada) some. */
body.qt-gutter-drop :is(.prosemirror-dropcursor-block, .prosemirror-dropcursor-inline) { display: none !important; }
/* Segurar a linha no toque não abre o balão de copiar/colar do iOS. */
@media (hover: none) { .note-prose .qt { -webkit-touch-callout: none; } }
/* Placeholder: o Tiptap marca o nó; o texto aparece dentro da área editável. */
.note-prose .qt.is-empty::before { content: none; }
.note-prose .qt.is-empty > .qt-text::before { content: 'Tarefa'; float: left; height: 0; pointer-events: none; color: var(--muted); opacity: .7; }
/* Aberta pelo ícone do Hoje: pisca de leve. */
@keyframes qt-flash { 0%, 100% { background: transparent; } 30% { background: color-mix(in srgb, var(--brand) 28%, transparent); } }
.note-prose .qt.qt-flash { animation: qt-flash 1.6s ease-out 1; }
@media (prefers-reduced-motion: reduce) { .note-prose .qt.qt-flash { animation: none; outline: 2px solid var(--brand); } }

/* Autocompletar do #objetivo e menus de objetivo/dificuldade (position: fixed, no <body>). */
.qt-ac, .qt-menu {
  position: fixed; z-index: 1000; min-width: 180px; max-width: min(320px, calc(100vw - 16px));
  display: flex; flex-direction: column; padding: .25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow);
}
.qt-ac[hidden] { display: none; }
.qt-ac-item, .qt-menu-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; text-align: left;
  border: 0; background: none; padding: .4rem .55rem; border-radius: var(--r-sm); color: var(--text); font: inherit; font-size: var(--fs-sm); cursor: pointer;
}
.qt-ac-item span, .qt-menu-item small { color: var(--muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qt-ac-item b { color: var(--accent); }
.qt-ac-item[aria-selected="true"], .qt-ac-item:hover, .qt-menu-item:hover { background: var(--surface-2); }
.qt-menu-item[aria-checked="true"] { font-weight: 700; }

/* Objetivo padrão da nota (faixa no topo do editor). */
.note-goal {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .45rem clamp(1rem, 4vw, 3rem) 0; color: var(--muted); font-size: var(--fs-xs);
}
.note-goal .icon { width: 1em; height: 1em; flex: none; }
.note-goal .tb-select {
  width: auto; max-width: 16rem; min-width: 0; height: 28px; padding: 0 .3rem;
  font-size: var(--fs-xs); border-radius: var(--r-sm); text-overflow: ellipsis;
}
.note-goal[hidden] { display: none; }

/* Hoje: chip com o nome da nota (abre a nota na linha). */
.chip-note {
  border: 0; cursor: pointer; font-family: inherit; color: var(--muted);
  background: color-mix(in srgb, var(--muted) 14%, transparent); max-width: 14rem;
}
.chip-note span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-note:hover { color: var(--text); }
.chip-note .icon { width: .9em; height: .9em; flex: none; }

/* ---------- Barrinhas da tabela e da imagem (fase 3) ---------- */
/* Alças da tabela: pílulas com três pontinhos que acompanham a célula atual — vertical à
   esquerda da LINHA, horizontal em cima da COLUNA (como no Notas da Apple). Clicar seleciona a
   linha/coluna e abre o menu dela. */
.note-table-handle {
  position: absolute; z-index: 16; display: flex; align-items: center; justify-content: center; gap: 2px;
  padding: 0; cursor: pointer; border: 1px solid var(--line); background: var(--surface);
  color: var(--accent); box-shadow: 0 1px 4px rgb(0 0 0 / .12); border-radius: 999px;
  transition: background .15s, transform .1s;
}
.note-table-handle[hidden] { display: none; }
.note-table-handle.is-row { width: 16px; height: 30px; flex-direction: column; }
.note-table-handle.is-col { width: 30px; height: 16px; }
.note-table-handle span { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.note-table-handle:hover, .note-table-handle[aria-expanded="true"] { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.note-table-handle:active { transform: scale(.94); }
.note-table-handle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Toque: alvo maior. */
@media (hover: none) {
  .note-table-handle.is-row { width: 20px; height: 36px; }
  .note-table-handle.is-col { width: 36px; height: 20px; }
}

.note-imagebar {
  position: absolute; z-index: 16; max-width: calc(100% - 16px);
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: .15rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow);
  font-size: var(--fs-xs);
}
.note-imagebar[hidden] { display: none; }
.note-imagebar .tb-btn { height: 28px; font-size: var(--fs-xs); padding: 0 .45rem; }
.note-imagebar [data-image-edit] { display: inline-flex; gap: .3rem; }
@media (max-width: 480px) { .note-imagebar { flex-wrap: nowrap; } .note-imagebar .tb-btn { min-width: 30px; padding: 0 .35rem; } }
.note-imagebar-sizes { display: inline-flex; gap: 2px; }
.note-imagebar-sizes .tb-btn { min-width: 28px; font-weight: 700; }
.pop-item:disabled { opacity: .4; cursor: not-allowed; background: none; }
.pop-item.pop-danger .pop-label { color: var(--hard); }

/* ---------- Ocorrências: multisseleção (⌘D) e Buscar e substituir ---------- */
/* Outras ocorrências selecionadas (a principal usa a seleção normal do navegador). */
.note-prose .mc-sel { background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 2px; }
.note-prose .mc-caret {
  display: inline-block; width: 0; height: 1.15em; margin: 0 -1px; vertical-align: text-bottom;
  border-left: 2px solid var(--accent); pointer-events: none; animation: mc-blink 1.06s steps(1) infinite;
}
@keyframes mc-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .note-prose .mc-caret { animation: none; } }
.note-multi {
  position: absolute; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 17;
  padding: .35rem .8rem; border-radius: 999px; background: var(--text); color: var(--surface);
  font-size: var(--fs-xs); box-shadow: var(--shadow); white-space: nowrap; pointer-events: none;
}
.note-multi[hidden] { display: none; }
.note-multi kbd {
  font: inherit; font-weight: 700; padding: 0 .35em; border: 0; border-radius: 4px; box-shadow: none;
  color: var(--text); background: var(--surface);
}
/* Resultados da busca: todos em amarelo claro, o atual mais forte. */
.note-prose .fr-match { background: color-mix(in srgb, var(--brand) 32%, transparent); border-radius: 2px; }
.note-prose .fr-current { background: color-mix(in srgb, var(--brand) 75%, transparent); box-shadow: 0 0 0 1px var(--brand); color: #1b1b1b; }

/* Painel dentro da barra da nota: linha inteira da grade, embaixo das ferramentas. */
.note-find {
  grid-column: 1 / -1; display: flex; align-items: flex-start; gap: .25rem;
  padding: .35rem 0 .1rem; border-top: 1px solid var(--line); margin-top: .1rem;
}
.note-find[hidden] { display: none; }
.note-find [data-find-toggle] .icon { transition: transform .15s; }
.note-find.with-replace [data-find-toggle] .icon { transform: rotate(90deg); }
.nf-rows { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.nf-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.nf-row[hidden] { display: none; }
.nf-input {
  flex: 1; min-width: 6rem; max-width: 22rem; height: 30px; padding: 0 .5rem; font: inherit; font-size: var(--fs-sm);
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.nf-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.note-find.is-none [data-find-q] { border-color: var(--hard); outline-color: var(--hard); }
.nf-count { min-width: 4.5rem; padding: 0 .35rem; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; text-align: center; }
.note-find.is-none .nf-count { color: var(--hard); }
.note-find .tb-btn { height: 30px; font-size: var(--fs-xs); flex: none; }
.note-find [data-find-case], .note-find [data-find-word] { font-weight: 700; }

/* ---------- Barrinha de link (cursor dentro de um link) ---------- */
.note-linkbar {
  position: absolute; z-index: 15; max-width: min(420px, calc(100% - 16px));
  display: flex; align-items: center; gap: .35rem; padding: .25rem .35rem .25rem .6rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow);
  font-size: var(--fs-xs);
}
.note-linkbar > .icon { color: var(--muted); flex: none; }
.note-linkbar-url {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--accent); font-weight: 700; text-decoration: underline;
}
.note-linkbar .tb-btn { height: 28px; font-size: var(--fs-xs); flex: none; }

/* ---------- Celular: um painel por vez, a página rola ---------- */
@media (max-width: 860px) {
  body[data-route="notes"] .main { padding: .75rem .75rem 6rem; }
  .notes { grid-template-columns: 1fr; height: auto; gap: 0; }
  .notes[data-pane="list"] .notes-main { display: none; }
  .notes[data-pane="editor"] .notes-side { display: none; }
  .notes-side-head h1 { font-size: var(--fs-xl); }

  .notes-main { min-height: calc(100dvh - var(--header-h, 53px) - 7.5rem); border-radius: var(--r-md); }
  .notes-bar {
    position: sticky; top: var(--header-h, 53px); z-index: 30;
    flex-wrap: wrap; row-gap: .35rem; padding: .35rem .5rem;
    border-radius: var(--r-md) var(--r-md) 0 0;
  }
  .notes-back { display: inline-grid; }
  /* A barra agora é curta (o resto mora no Aa e no ⋯): cabe na MESMA linha do voltar e da
     lixeira. Em tela muito estreita a Tarefa mostra só o ícone, como no Notas da Apple. */
  /* Celular: sem espaço para o centro exato da barra; as ferramentas centralizam no espaço
     entre o voltar e o grupo da direita. */
  .notes-bar { grid-template-columns: auto minmax(0, 1fr) auto; gap: .15rem; }
  .notes-bar > .notes-toolbar { justify-self: center; }
  .notes-bar .tb-btn, .notes-bar .icon-btn { min-width: 34px; }
  .notes-toolbar { flex-wrap: nowrap; min-width: 0; }
  .tb-btn { min-width: 36px; height: 36px; } /* alvo de toque maior */
  /* Status de rotina (Editando…/Salvo) some no celular; avisos (sem conexão, erro) ficam. */
  .notes-status:not([data-kind="warn"]):not([data-kind="danger"]) { display: none; }
  .tb-pop { width: min(300px, calc(100vw - 16px)); }
  .pop-item { min-height: 42px; }

  .note-goal { padding: .5rem 1rem 0; }
  .note-goal .tb-select { height: 32px; max-width: 100%; }
  .notes-editor { overflow: visible; padding: 1rem 1rem 3rem; }
  .note-prose { min-height: 40vh; }
  .note-prose h1 { font-size: var(--fs-xl); }
  /* Tabela no celular: colunas com largura mínima confortável; rola de lado por dentro. */
  .note-prose table { min-width: 100%; }
  .note-imagebar .tb-btn { height: 34px; }
  .note-multi { position: fixed; bottom: 5.5rem; }
  .nf-input { max-width: none; height: 34px; font-size: 16px; } /* 16px: o iOS não dá zoom no campo */
  .nf-count { min-width: 3.5rem; }
  .note-find .tb-btn { height: 34px; min-width: 30px; }
}
/* Barra da nota com Tabela e Imagem: em tela muito estreita os botões ficam mais justos. */
@media (max-width: 400px) {
  .notes-bar .tb-btn, .notes-bar .icon-btn { min-width: 30px; padding: 0 .1rem; }
  .notes-toolbar, .notes-history, .notes-bar-end { gap: 0; }
  .notes-bar > .notes-toolbar { margin-right: .35rem; }
}

/* ==========================================================================
   Fase 5 (spec seção 14): busca em todas as notas, pastas e notas fixadas.
   ========================================================================== */
.icon.down { transform: rotate(90deg); }

/* Busca acima da lista */
.notes-search {
  position: relative; display: flex; align-items: center; margin-top: .75rem;
}
.notes-search > .icon {
  position: absolute; left: .65rem; width: 1rem; height: 1rem; color: var(--muted); pointer-events: none;
}
.notes-side .notes-search input.notes-search-input {
  width: 100%; height: 36px; padding: 0 2.1rem 0 2.1rem;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-sm);
}
.notes-side .notes-search input.notes-search-input::-webkit-search-cancel-button { display: none; } /* usamos o nosso ✕ */
.notes-search-clear { position: absolute; right: 2px; width: 32px; height: 32px; }
.notes-search-clear .icon { width: .9rem; height: .9rem; }
.notes-search-clear[hidden] { display: none; }

/* Pasta mostrada + contagem */
.notes-folderbar {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin: .5rem 0 .5rem; min-width: 0;
}
.notes-folderbar .notes-count { margin: 0; flex: none; }
.notes-folder-btn {
  display: inline-flex; align-items: center; gap: .35rem; min-width: 0; max-width: 70%;
  height: 32px; padding: 0 .5rem; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text); font: inherit; font-size: var(--fs-sm); font-weight: 700; cursor: pointer;
}
.notes-folder-btn:hover, .notes-folder-btn[aria-expanded="true"] { background: var(--surface-2); }
.notes-folder-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.notes-folder-btn .icon { width: 1rem; height: 1rem; flex: none; color: var(--brand-ink); }
.notes-folder-btn .icon.down { color: var(--muted); width: .8rem; height: .8rem; }
.notes-folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes.is-searching .notes-folderbar { display: none; } /* a busca vale para todas as pastas */

/* Grupos da lista ("Fixadas", "Notas", contagem dos resultados) */
.notes-group {
  padding: .6rem .75rem .25rem; font-size: var(--fs-xs); font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.notes-group:first-child { padding-top: .15rem; }
.notes-group.is-busy { opacity: .6; }
.notes-group-note { display: block; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--medium); margin-top: .15rem; }
.notes-error { color: var(--hard); }

/* Item: alfinete (fixada), pasta, botão de fixar no hover */
.note-row { position: relative; }
.note-item-pinned { width: .85em; height: .85em; margin-right: .3rem; vertical-align: -.08em; color: var(--brand); }
.note-item-folder {
  display: inline-flex; align-items: center; gap: .25rem; min-width: 0; max-width: 100%;
  font-size: var(--fs-xs); color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.note-item-folder .icon { width: .85em; height: .85em; flex: none; }
.note-pin {
  position: absolute; top: 50%; right: .35rem; transform: translateY(-50%);
  width: 28px; height: 28px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer;
  background: var(--surface); color: var(--muted); box-shadow: 0 0 0 1px var(--line);
  opacity: 0; transition: opacity .12s;
}
.note-pin .icon { width: .9rem; height: .9rem; }
.note-row:hover .note-pin, .note-pin:focus-visible { opacity: 1; }
.note-pin:hover { color: var(--text); }
.note-pin[aria-pressed="true"] { color: var(--brand); }
.note-pin:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (hover: none) { .note-pin { display: none; } } /* no toque: ⋯ → Fixar nota */

/* Resultados da busca */
.note-item.is-result { gap: .2rem; }
.note-result-excerpt {
  font-size: var(--fs-sm); color: var(--text); opacity: .85; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.note-item mark {
  background: color-mix(in srgb, var(--brand) 35%, transparent); color: inherit;
  border-radius: 3px; padding: 0 1px;
}

/* Menus de pasta e de mover */
.tb-pop-folders, .tb-pop-move { width: 290px; }
.pop-icon { width: 1rem; height: 1rem; flex: none; color: var(--muted); }
.pop-count { flex: none; font-size: var(--fs-xs); color: var(--muted); padding-left: .5rem; }
.pop-folder { display: flex; align-items: center; gap: 2px; }
.pop-folder > .pop-item { flex: 1; min-width: 0; }
.pop-folder-act { min-width: 30px; height: 30px; opacity: 0; color: var(--muted); }
.pop-folder:hover .pop-folder-act, .pop-folder-act:focus-visible { opacity: 1; }
.pop-folder-act:hover { color: var(--text); }
@media (hover: none) { .pop-folder-act { opacity: .7; } }

@media (max-width: 860px) {
  .notes-side .notes-search input.notes-search-input { height: 40px; font-size: 16px; } /* 16px: o iOS não dá zoom no campo */
  .notes-folder-btn { height: 36px; }
}

/* Envio de imagem em andamento (fase 5, notes/editor.js: bloco imageUpload). */
.note-upload {
  display: flex; flex-direction: column; gap: .4rem;
  margin: .5rem 0; padding: .8rem 1rem;
  border: 1px dashed var(--line); border-radius: var(--r-md, 10px);
  background: var(--surface-2); color: var(--muted);
  font-size: var(--fs-sm, .95rem); user-select: none;
}
.note-upload-bar { display: block; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.note-upload-bar > span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s ease; }
.note-img-file { cursor: pointer; margin-right: auto; }
