/* Notas - tema "papel sobre mesa escura" */
:root {
  --bg: #16140f;
  --bg-2: #1f1c15;
  --line: rgba(255, 255, 255, 0.10);
  --line-2: rgba(255, 255, 255, 0.18);
  --text: #e9e2d2;
  --muted: rgba(233, 226, 210, 0.55);
  --paper: #f3ead6;
  --paper-2: #e9dfc7;
  --ink: #2a2419;
  --ink-muted: rgba(42, 36, 25, 0.55);
  --kraft: #c89f62;
  --kraft-2: #b48a4e;
  --accent: #e3b45b;
  --danger: #e05d4b;
  --ok: #7cc47f;
  --radius: 6px;
  --shadow: 0 2px 2px rgba(0, 0, 0, 0.25), 0 10px 24px rgba(0, 0, 0, 0.35);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body.resizing-x { cursor: col-resize; user-select: none; }
body.resizing-y { cursor: row-resize; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ paineis */
#app { height: 100%; display: flex; }
#app > * { flex: 1 1 0; min-width: 0; min-height: 0; }
.split { display: flex; min-width: 0; min-height: 0; }
.split.row { flex-direction: row; }
.split.col { flex-direction: column; }
.split > * { min-width: 0; min-height: 0; }
.split > .pane, .split > .split { flex: 1 1 0; } /* base; applyRatio() poe o flex exato nos dois filhos */
.divider { flex: 0 0 6px; background: #000; position: relative; z-index: 2; transition: background 0.12s; }
.split.row > .divider { cursor: col-resize; }
.split.col > .divider { cursor: row-resize; }
.divider:hover, .resizing-x .divider, .resizing-y .divider { background: var(--accent); }
.pane {
  position: relative; display: flex; flex-direction: column;
  min-width: 0; min-height: 0; overflow: hidden; outline: none;
  background: var(--bg);
  container-type: inline-size;
}
/* painel estreito: a barra prioriza as ferramentas e os controles do painel (atalhos continuam valendo) */
@container (max-width: 760px) { .pane .bar .crumbs { display: none; } }
@container (max-width: 560px) { .pane .bar .toolbar, .pane .bar .zoom { display: none; } }
@container (max-width: 400px) { .pane .bar .save-status { display: none; } }
@container (max-width: 330px) { .pane .bar .iconbtn { display: none; } }
.pane.active { box-shadow: inset 0 2px 0 var(--accent); }
.pane-controls { display: flex; gap: 2px; margin-left: 6px; }
.pbtn {
  width: 26px; height: 26px; border: 0; border-radius: 5px; background: none; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.pbtn svg { width: 15px; height: 15px; }
.pbtn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.pbtn:disabled { opacity: 0.25; cursor: default; background: none; }

/* espaco livre: painel vazio que sobra de um encaixe (some sozinho ao fechar o vizinho) */
.empty-pane {
  flex: 1 1 0; margin: 12px; border-radius: 10px; border: 2px dashed var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  color: var(--muted); text-align: center; padding: 20px;
}
.empty-pane-hint { font-family: var(--serif); font-size: 1.15rem; }
.empty-pane.drop-target { border-color: var(--accent); color: var(--accent); background: rgba(227, 180, 91, 0.07); }
.dragging-card .empty-pane { border-color: var(--line-2); }

/* dock de encaixe: aparece em cada painel enquanto um cartao e arrastado */
.dock {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; max-width: calc(100% - 24px);
  padding: 12px 14px; border-radius: 12px;
  background: rgba(22, 20, 15, 0.94); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  animation: dock-in 0.14s ease-out;
}
@keyframes dock-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.dock-item { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.dock-thumb { display: grid; gap: 2px; width: 60px; height: 40px; }
.dock-cell { background: rgba(255, 255, 255, 0.14); border-radius: 2px; }
.dock-cell.hot { background: var(--accent); }
.dock-label { font-size: 11px; color: var(--muted); letter-spacing: 0.02em; }
.slot-ghost {
  position: absolute; z-index: 15; pointer-events: none;
  background: rgba(227, 180, 91, 0.16); outline: 2px dashed var(--accent); outline-offset: -3px;
}

/* ------------------------------------------------------------ barra do painel */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; flex: 0 0 auto;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.bar::-webkit-scrollbar { display: none; }
.crumbs { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 14px; }
.crumb {
  background: none; border: 0; padding: 4px 7px; border-radius: 4px;
  color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumb:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.crumb.current { color: var(--text); font-weight: 600; cursor: default; }
.crumb.current:hover { background: none; }
.crumb.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; color: var(--accent); }
.crumb-sep { color: var(--muted); opacity: 0.6; }
.spacer { flex: 1; min-width: 8px; }
.iconbtn {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; color: var(--muted); font-size: 13px; white-space: nowrap;
}
.iconbtn:hover { color: var(--text); border-color: var(--line-2); background: rgba(255, 255, 255, 0.04); }
.iconbtn.active { color: var(--accent); border-color: var(--accent); }
.bar .back {
  background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; color: var(--text); font-size: 15px;
}
.bar .back:hover { border-color: var(--line-2); background: rgba(255, 255, 255, 0.04); }

/* ferramentas da nota */
.toolbar { display: flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.tbtn {
  background: none; border: 0; border-radius: 4px; color: var(--muted); font-family: var(--serif); font-weight: 700;
  min-width: 28px; height: 24px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.tbtn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.tbtn.h1 { font-size: 19px; }
.tbtn.h2 { font-size: 16px; }
.tbtn.h3 { font-size: 13px; }
.tbtn.p { font-size: 13px; font-family: var(--sans); font-weight: 500; }
.zoom { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.zbtn {
  background: none; border: 0; border-radius: 4px; color: var(--muted); height: 24px; min-width: 26px; padding: 0 6px;
  font-size: 15px; line-height: 1;
}
.zbtn.zoom-value { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 44px; }
.zbtn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

/* status de salvamento (na barra da nota) */
.save-status {
  font-size: 12px; color: var(--muted); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px;
}
.save-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.save-status.saving::before { background: var(--accent); animation: pulse 0.9s infinite; }
.save-status.saved::before { background: var(--ok); }
.save-status.dirty::before { background: var(--accent); }
.save-status.error { color: #fff; background: var(--danger); font-weight: 600; }
.save-status.error::before { background: #fff; animation: pulse 0.9s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ------------------------------------------------------------ grade */
.grid-wrap { padding: 20px 24px 60px; overflow: auto; flex: 1 1 0; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 12px 22px; /* row-gap menor: todo cartao tem margin-top de 10px (aba da pasta) */
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 4px 14px; }
  .grid-wrap { padding-left: 14px; padding-right: 14px; }
  .bar { padding-left: 10px; padding-right: 10px; }
}
.card {
  position: relative;
  aspect-ratio: 1 / 1;
  margin-top: 10px; /* espaco da aba da pasta; igual em todos para a linha ficar alinhada e quadrada */
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  padding: 18px 14px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: var(--shadow);
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 4px rgba(0,0,0,0.25), 0 16px 30px rgba(0,0,0,0.4); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.card.dragging { opacity: 0.35; }
.card.drop-target { outline: 3px dashed var(--accent); outline-offset: 2px; transform: scale(1.03); }

.card.note { background: var(--paper); color: var(--ink); }
.card.note::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 22px; height: 22px;
  background: linear-gradient(135deg, transparent 50%, rgba(0, 0, 0, 0.10) 50%, rgba(0, 0, 0, 0.05));
  border-top-left-radius: 3px;
}
.card.note.empty { background: var(--paper-2); }

.card.folder { background: var(--kraft); color: var(--ink); }
.card.folder::before {
  content: ""; position: absolute; left: 0; top: -10px; width: 42%; height: 14px;
  background: var(--kraft-2); border-radius: 5px 8px 0 0;
}
.card.folder .count { position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: var(--ink-muted); font-weight: 600; }
.card.folder .folder-icon { position: absolute; left: 12px; top: 10px; width: 18px; height: 18px; opacity: 0.55; }
.card.folder .folder-icon svg { width: 18px; height: 18px; }

.card-title {
  font-family: var(--serif);
  text-align: center;
  font-weight: 600;
  line-height: 1.15;
  word-break: break-word;
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden;
  width: 100%;
  letter-spacing: -0.01em;
}
.card-title.len-xs { font-size: 1.9rem; }
.card-title.len-s { font-size: 1.5rem; }
.card-title.len-m { font-size: 1.25rem; -webkit-line-clamp: 4; }
.card-title.len-l { font-size: 1.05rem; font-weight: 600; -webkit-line-clamp: 6; }
/* nota sem titulo: o cartao mostra o texto corrido, como um papel escrito */
.card.has-preview { align-items: flex-start; padding: 36px 16px 16px; }
.card-title.preview {
  font-size: 0.92rem; font-weight: 400; text-align: left; line-height: 1.3;
  color: rgba(42, 36, 25, 0.85); -webkit-line-clamp: 7; letter-spacing: 0;
}
.card-title.untitled { color: var(--ink-muted); font-weight: 500; font-style: italic; font-size: 1.1rem; }
.card-title[contenteditable="true"] {
  outline: 2px solid rgba(0, 0, 0, 0.25); outline-offset: 4px; border-radius: 3px;
  display: block; -webkit-line-clamp: unset; overflow: visible; cursor: text; user-select: text;
  background: rgba(255, 255, 255, 0.35);
}

.card-menu {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, 0.08); color: var(--ink);
  font-size: 18px; line-height: 1; letter-spacing: 1px;
  display: flex; align-items: center; justify-content: center;
}
.card-menu:hover { background: rgba(0, 0, 0, 0.2); }

.card.add {
  background: transparent; box-shadow: none;
  border: 2px dashed var(--line-2); color: var(--muted);
  flex-direction: column; gap: 10px;
}
.card.add:hover { border-color: var(--accent); color: var(--accent); transform: none; box-shadow: none; }
.card.add .plus { font-size: 56px; line-height: 1; font-weight: 200; }
.card.add .add-choices { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.card.add .add-choices button {
  width: 100%; padding: 14px 10px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--text); font-weight: 600; font-size: 15px;
}
.card.add .add-choices button:hover { border-color: var(--accent); color: var(--accent); }
.card.add .add-choices button.note-choice { background: var(--paper); color: var(--ink); border-color: transparent; font-family: var(--serif); }
.card.add .add-choices button.folder-choice { background: var(--kraft); color: var(--ink); border-color: transparent; font-family: var(--serif); }

.empty-hint { color: var(--muted); padding: 40px 0; text-align: center; grid-column: 1 / -1; font-size: 15px; }
.pane-error { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }
.pane-error-title { font-family: var(--serif); font-size: 1.3rem; color: var(--text); }
.pane-error-msg { color: var(--danger); font-size: 13px; max-width: 520px; word-break: break-word; }
.pane-error-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ------------------------------------------------------------ menu de contexto */
.ctx {
  position: fixed; z-index: 50; min-width: 170px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 6px; box-shadow: var(--shadow);
}
.ctx button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 9px 12px; border-radius: 5px; font-size: 14px; color: var(--text);
}
.ctx button:hover { background: rgba(255, 255, 255, 0.07); }
.ctx button.danger { color: var(--danger); }
.ctx .ctx-sep { height: 1px; background: var(--line); margin: 4px 0; }

/* ------------------------------------------------------------ nota (tela inteira do painel) */
.paper {
  --zoom: 1;
  background: var(--paper); color: var(--ink);
  flex: 1 1 0; overflow: auto;
  padding: 26px 40px 50vh;
}
@media (max-width: 720px) { .paper { padding: 18px 18px 40vh; } }
.note-title {
  width: 100%; border: 0; background: transparent; color: var(--ink);
  font-family: var(--serif); font-size: calc(1.7rem * var(--zoom)); font-weight: 700; line-height: 1.15;
  padding: 0 0 8px; margin: 0 0 12px;
  border-bottom: 1px solid rgba(42, 36, 25, 0.15);
  outline: none;
  resize: none; overflow: hidden; display: block;
}
.note-title::placeholder { color: var(--ink-muted); font-weight: 600; }
.note-body-wrap { position: relative; }
.note-body {
  font-family: var(--serif); font-size: calc(1.05rem * var(--zoom)); line-height: 1.35;
  min-height: 40vh; outline: none;
  caret-color: var(--ink);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.note-body.is-empty::before {
  content: attr(data-placeholder); color: var(--ink-muted); pointer-events: none; position: absolute;
}
.note-body img { max-width: 100%; height: auto; border-radius: 4px; display: block; margin: 6px 0; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
/* entrelinha 1.0, como num editor de texto: paragrafo = linha; linha vazia = <p><br></p> */
.note-body p, .note-body div { margin: 0; }
.note-body h1, .note-body h2, .note-body h3, .note-body h4 { line-height: 1.15; margin: 0.5em 0 0.15em; font-weight: 700; }
.note-body h1 { font-size: 2.3em; }
.note-body h2 { font-size: 1.7em; }
.note-body h3 { font-size: 1.3em; }
.note-body h4 { font-size: 1.1em; }
.note-body blockquote { border-left: 3px solid rgba(42, 36, 25, 0.3); margin: 0.3em 0; padding: 0.1em 0 0.1em 1em; color: rgba(42,36,25,0.8); }
.note-body pre, .note-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: rgba(0,0,0,0.06); border-radius: 4px; }
.note-body pre { padding: 10px 12px; overflow: auto; white-space: pre-wrap; }
.note-body code { padding: 1px 5px; }
.note-body a { color: #6b4a1a; }
.note-body ul, .note-body ol { padding-left: 1.5em; margin: 0.2em 0; }
.note-body hr { border: 0; border-top: 1px solid rgba(42,36,25,0.25); margin: 0.8em 0; }
.note-body table { border-collapse: collapse; margin: 0.4em 0; }
.note-body td, .note-body th { border: 1px solid rgba(42,36,25,0.3); padding: 3px 8px; }

.conflict-banner {
  background: var(--danger); color: #fff; padding: 8px 16px; display: flex; align-items: center; gap: 14px;
  font-weight: 600; flex: 0 0 auto; font-size: 14px;
}
.conflict-banner button { background: #fff; color: var(--danger); border: 0; border-radius: 5px; padding: 6px 12px; font-weight: 700; }

/* ------------------------------------------------------------ histórico (gaveta dentro do painel) */
.history {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(480px, 100%); z-index: 10;
  background: var(--bg-2); border-left: 1px solid var(--line-2);
  display: flex; flex-direction: column;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
  transform: translateX(105%); visibility: hidden;
  transition: transform 0.18s ease, visibility 0s linear 0.18s;
}
.history.open { transform: translateX(0); visibility: visible; transition-delay: 0s; }
.history-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.history-head h2 { margin: 0; font-size: 16px; flex: 1; }
.history-list { overflow: auto; max-height: 40%; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.snap {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; padding: 10px 14px; color: var(--text); font-size: 14px;
  box-shadow: 0 -1px 0 0 var(--line);
}
.snap:hover, .snap.active { background: rgba(255, 255, 255, 0.06); }
.snap .when { font-weight: 600; min-width: 120px; }
.snap .reason { font-size: 12px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.snap .reason.manual { color: var(--accent); border-color: var(--accent); }
.snap .snap-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.history-empty { padding: 24px 16px; color: var(--muted); text-align: center; }
.history-preview { flex: 1; overflow: auto; padding: 14px; }
.history-preview .paper.preview { padding: 22px 24px 30px; min-height: 0; flex: none; overflow: visible; border-radius: 4px; }
.history-preview .paper .note-title { font-size: 1.4rem; }
.history-preview .paper .note-body { font-size: 0.95rem; min-height: 0; pointer-events: none; }
.history-actions { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.btn-primary { background: var(--accent); color: #1a150c; border: 0; border-radius: 6px; padding: 9px 16px; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.history-hint { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; overflow: auto; }
.login-card {
  background: var(--paper); color: var(--ink);
  width: min(360px, calc(100vw - 32px)); padding: 36px 32px 30px; border-radius: 6px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.login-logo { font-family: var(--serif); font-size: 2.2rem; font-weight: 700; text-align: center; margin-bottom: 8px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-muted); }
.login-card input {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 5px;
  border: 1px solid rgba(42, 36, 25, 0.3); background: rgba(255, 255, 255, 0.5); color: var(--ink);
  cursor: text;
}
.login-card input[readonly] { color: var(--ink-muted); background: rgba(0, 0, 0, 0.04); }
.login-card input:focus { outline: 2px solid var(--kraft); border-color: transparent; }
.login-card button {
  margin-top: 6px; background: var(--ink); color: var(--paper); border: 0; border-radius: 5px;
  padding: 12px; font-weight: 700; font-size: 15px;
}
.login-card button:disabled { opacity: 0.6; }
.login-error { background: var(--danger); color: #fff; padding: 8px 12px; border-radius: 5px; font-weight: 600; font-size: 14px; }
