/* 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;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 70%, rgba(22, 20, 15, 0));
}
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; font-size: 15px; }
.crumb {
  background: none; border: 0; padding: 4px 8px; border-radius: 4px;
  color: var(--muted); max-width: 240px; 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; }
.topbar .spacer { flex: 1; }
.iconbtn {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; color: var(--muted); font-size: 13px;
}
.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); }

/* ------------------------------------------------------------ grid */
.grid-wrap { padding: 8px 24px 60px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 22px;
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 14px; }
  .grid-wrap, .topbar { padding-left: 14px; padding-right: 14px; }
}
.card {
  position: relative;
  aspect-ratio: 1 / 1;
  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 {
  /* dobra do canto */
  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); margin-top: 10px; aspect-ratio: auto; }
.card.folder::before {
  /* aba da pasta */
  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-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; }
.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); }

/* cartão "+" */
.card.add {
  background: transparent; box-shadow: none;
  border: 2px dashed var(--line-2); color: var(--muted);
  flex-direction: column; gap: 10px; aspect-ratio: 1 / 1;
}
.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; }

/* ------------------------------------------------------------ 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 (editor) */
.note-bar {
  display: flex; align-items: center; gap: 10px; padding: 12px 24px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 70%, rgba(22, 20, 15, 0));
}
.note-bar .back {
  background: none; border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; color: var(--text);
  font-size: 16px;
}
.note-bar .back:hover { border-color: var(--line-2); background: rgba(255, 255, 255, 0.04); }

.paper {
  background: var(--paper); color: var(--ink);
  max-width: 860px; margin: 8px auto 80px;
  min-height: calc(100vh - 140px);
  padding: 56px 64px 80px;
  border-radius: 4px;
  box-shadow: var(--shadow);
}
@media (max-width: 720px) {
  .paper { padding: 32px 22px 60px; margin: 0 10px 60px; }
  .note-bar { padding: 10px 12px; }
}
.note-title {
  width: 100%; border: 0; background: transparent; color: var(--ink);
  font-family: var(--serif); font-size: 2.3rem; font-weight: 700; line-height: 1.15;
  padding: 0 0 10px; margin: 0 0 18px;
  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 {
  font-family: var(--serif); font-size: 1.15rem; line-height: 1.6;
  min-height: 50vh; outline: none;
  caret-color: var(--ink);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.note-body:empty::before, .note-body.is-empty::before {
  content: attr(data-placeholder); color: var(--ink-muted); pointer-events: none; position: absolute;
}
.note-body-wrap { position: relative; }
.note-body img { max-width: 100%; height: auto; border-radius: 4px; display: block; margin: 10px 0; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
.note-body img.selected-img { outline: 3px solid var(--accent); }
.note-body p { margin: 0 0 0.6em; }
.note-body h1, .note-body h2, .note-body h3 { line-height: 1.2; margin: 1.2em 0 0.4em; }
.note-body h1 { font-size: 1.7em; } .note-body h2 { font-size: 1.4em; } .note-body h3 { font-size: 1.15em; }
.note-body blockquote { border-left: 3px solid rgba(42, 36, 25, 0.3); margin: 0.6em 0; padding: 0.2em 0 0.2em 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.4em 0; }
.note-body hr { border: 0; border-top: 1px solid rgba(42,36,25,0.25); margin: 1.2em 0; }
.note-body table { border-collapse: collapse; margin: 0.6em 0; }
.note-body td, .note-body th { border: 1px solid rgba(42,36,25,0.3); padding: 4px 8px; }

.conflict-banner {
  background: var(--danger); color: #fff; padding: 10px 24px; display: flex; align-items: center; gap: 14px;
  font-weight: 600; position: sticky; top: 56px; z-index: 6;
}
.conflict-banner button { background: #fff; color: var(--danger); border: 0; border-radius: 5px; padding: 6px 12px; font-weight: 700; }

/* ------------------------------------------------------------ status de salvamento */
.save-status {
  position: fixed; right: 18px; bottom: 16px; z-index: 40;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow);
  transition: opacity 0.2s;
}
.save-status::before { content: ""; width: 8px; height: 8px; 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.error { color: #fff; background: var(--danger); border-color: var(--danger); font-weight: 600; }
.save-status.error::before { background: #fff; animation: pulse 0.9s infinite; }
.save-status.dirty::before { background: var(--accent); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ------------------------------------------------------------ histórico */
.history {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); z-index: 30;
  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(100%); transition: transform 0.18s ease;
}
.history.open { transform: translateX(0); }
.history-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.history-head h2 { margin: 0; font-size: 16px; flex: 1; }
.history-list { overflow: auto; max-height: 40%; border-bottom: 1px solid var(--line); }
.snap {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; padding: 10px 16px; 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: 130px; }
.snap .reason { font-size: 12px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 8px; }
.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: 16px; }
.history-preview .paper { padding: 28px 30px 40px; min-height: 0; margin: 0; max-width: none; }
.history-preview .paper .note-title { font-size: 1.6rem; }
.history-preview .paper .note-body { font-size: 1rem; min-height: 0; pointer-events: none; }
.history-actions { padding: 12px 16px; 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; }
.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; }
