/* ---------- Tokens ---------- */
:root {
  --bg: #efe9df;
  --surface: #fbf8f3;
  --surface-2: #f4efe6;
  --text: #2a2622;
  --muted: #7a7166;
  --border: #ddd4c6;
  --primary: #3b5b92;
  --primary-text: #fff;
  --danger: #b03a2e;
  --paper: #fffdf8;
  --paper-line: #d7e3f1;
  --paper-margin: #f1b8b4;
  --paper-dot: #c9c2b6;
  --shadow: 0 1px 2px rgba(60, 45, 25, .08), 0 8px 24px rgba(60, 45, 25, .10);
  --radius: 10px;
  --line: 32px;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-page: 'Literata', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a18;
    --surface: #262320;
    --surface-2: #2f2b27;
    --text: #ece6dc;
    --muted: #a59b8e;
    --border: #3d3832;
    --primary: #7c9fdc;
    --primary-text: #111;
    --danger: #e0786c;
    --paper: #2b2824;
    --paper-line: #3a4250;
    --paper-margin: #5e3a38;
    --paper-dot: #4c463f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) .drawing-surface,
  :root:not([data-theme="light"]) .markdown img[src^="/drawings/"] { filter: invert(1) hue-rotate(180deg); }
}

* { box-sizing: border-box; }

/* Elementos com o atributo hidden somem mesmo quando uma classe define `display` (ex.: .field, .invite-fields). */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); }

h1, h2 { line-height: 1.2; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font: 500 14px var(--font-ui);
  cursor: pointer;
  text-decoration: none;
  background: var(--surface);
  color: var(--text);
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border); }
.btn:disabled { opacity: .35; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { opacity: .9; border-color: transparent; }
.btn-ghost { background: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(127, 127, 127, .12); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-text { color: var(--danger); }
.btn-block { width: 100%; }
.btn-icon { background: transparent; padding: 6px 10px; font-size: 15px; }
.btn-icon:hover:not(:disabled) { background: rgba(127, 127, 127, .12); }
.btn-google {
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #dadce0;
  padding: 11px 18px;
  font-size: 15px;
}
.btn-google:hover { background: #f7f8f8; border-color: #c6c9cc; }

.badge {
  display: inline-block;
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  background: rgba(46, 139, 87, .16);
  color: #2e8b57;
  padding: 2px 8px;
  border-radius: 99px;
}

.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.user-chip img { width: 28px; height: 28px; border-radius: 50%; }

/* ---------- Landing ---------- */
.hero {
  max-width: 1080px;
  margin: 0 auto;
  padding: 72px 24px;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 48px;
  align-items: center;
}
.hero h1 { font-family: var(--font-page); font-size: clamp(34px, 5vw, 52px); margin: 0 0 16px; }
.hero p { color: var(--muted); font-size: 18px; max-width: 460px; margin: 0 0 28px; }
.hero-shelf { display: flex; gap: 18px; justify-content: center; }
.hero-shelf .cover:nth-child(1) { transform: rotate(-6deg); }
.hero-shelf .cover:nth-child(3) { transform: rotate(5deg); }

/* ---------- Capas ---------- */
.cover {
  --cover: #3b5b92;
  position: relative;
  aspect-ratio: 3 / 4;
  width: 100%;
  min-width: 120px;
  border-radius: 6px 12px 12px 6px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.22) 0, rgba(0,0,0,.22) 10px, rgba(255,255,255,.08) 11px, transparent 14px),
    linear-gradient(160deg, rgba(255,255,255,.18), transparent 45%),
    var(--cover);
  color: #fff;
  box-shadow: var(--shadow);
  padding: 22px 16px 16px 26px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  line-height: 1.25;
  transition: transform .18s ease, box-shadow .18s ease;
  overflow-wrap: anywhere;
  border: none;
  text-align: left;
  font-family: var(--font-ui);
}
.cover > span:first-child {
  background: rgba(255, 255, 255, .92);
  color: #2a2622;
  padding: 8px 10px;
  border-radius: 4px;
  font-family: var(--font-page);
}
.hero-shelf .cover { width: 150px; }
a.cover:hover { transform: translateY(-4px); }
.cover-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-weight: 500; font-size: 12px; opacity: .9; }
.cover-meta .badge { background: rgba(255,255,255,.9); color: #2e8b57; }

/* "Compartilhados comigo": uma capa de dois tons, que lembra uma pilha de cadernos. */
.cover-shared {
  --cover: #5b6b7d;
  background:
    linear-gradient(90deg, rgba(0,0,0,.22) 0, rgba(0,0,0,.22) 10px, rgba(255,255,255,.08) 11px, transparent 14px),
    repeating-linear-gradient(135deg, rgba(255,255,255,.07) 0 12px, transparent 12px 24px),
    var(--cover);
}
.cover-owner { font-weight: 500; font-size: 12px; opacity: .9; }

.cover-new {
  background: transparent;
  border: 2px dashed var(--border);
  color: var(--muted);
  box-shadow: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 16px;
}
.cover-new > span:first-child { background: none; color: inherit; padding: 0; font-family: var(--font-ui); }
.cover-new .plus { font-size: 40px; font-weight: 300; }
.cover-new:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Biblioteca ---------- */
.library { max-width: 1180px; margin: 0 auto; padding: 16px 24px 64px; }
.library-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.library-head h1 { font-family: var(--font-page); font-size: 30px; margin: 0; }
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 28px;
}

/* ---------- Diálogos ---------- */
.dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(20, 15, 10, .45); }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.dialog h2 { margin: 0; font-size: 20px; }
.dialog hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog-danger { padding: 0 24px 24px; margin: 0; }
.dialog-danger .btn { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; border: none; padding: 0; margin: 0; }
.field > span, .field legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
.field input[type="text"], .field select, .copy-link input {
  font: 15px var(--font-ui);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  color: var(--text);
  width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch span {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--cover);
  cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.swatch input:checked + span { outline: 3px solid var(--text); outline-offset: 2px; }
.swatch input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 2px; }

.share-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.share-row form { margin: 0; }
.copy-link { display: flex; gap: 8px; }
.copy-link input { font-size: 13px; }

/* ---------- Caderno ---------- */
.notebook-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.nb-bar {
  --cover: #3b5b92;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--cover);
  color: #fff;
  flex-shrink: 0;
}
.nb-bar .btn-ghost { color: #fff; }
.nb-bar .btn-ghost:hover { background: rgba(255,255,255,.15); }
.nb-bar .badge { background: rgba(255,255,255,.92); }
.nb-title {
  font-family: var(--font-page);
  font-size: 18px;
  margin: 0 8px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nb-actions { display: flex; align-items: center; gap: 4px; }
.nb-toggle-sidebar { display: none; }

.nb-layout { flex: 1; display: grid; grid-template-columns: 220px 1fr; min-height: 0; }
.nb-layout.no-sidebar { grid-template-columns: 1fr; }

.nb-sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.thumbs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.thumbs > li { display: flex; flex-direction: column; align-items: center; gap: 4px; }
/* Miniaturas: a mesma folha reduzida da visão geral (.overview-paper/.overview-sheet), na largura da barra. */
.nb-sidebar { --thumb: 188px; --scale: calc(188 / 820); }
.thumb { position: relative; width: 100%; border-radius: 4px; }
.thumb .overview-paper { box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.thumb-link { position: absolute; inset: 0; border-radius: 4px; }
.thumb-link:focus-visible { outline: none; }
.thumb:hover .overview-paper { outline-color: var(--border); }
.thumbs > li.active .overview-paper, .thumb:has(.thumb-link:focus-visible) .overview-paper { outline-color: var(--primary); }
.thumb-public { position: absolute; top: 6px; right: 8px; color: #2e8b57; font-style: normal; font-size: 10px; }
.thumb-num { font-size: 12px; color: var(--muted); }

.nb-main { overflow-y: auto; padding: 0 24px 64px; }

.page-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 12px 0;
  background: var(--bg);
  max-width: 820px;
  margin: 0 auto;
}
.page-menu { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.page-menu form { margin: 0; }
.save-status { font-size: 13px; color: var(--muted); margin-right: 6px; white-space: nowrap; }
.save-status.ok { color: #2e8b57; }
.save-status.error { color: var(--danger); }

/* Barra de formatação */
.fmt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.fmt-toolbar button {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  font: 14px var(--font-ui);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.fmt-toolbar button:hover:not(:disabled) { background: rgba(127,127,127,.15); }
.fmt-toolbar button.active { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.fmt-toolbar button:disabled { opacity: .35; cursor: default; }
.fmt-toolbar select:disabled { opacity: .6; cursor: default; }
.fmt-toolbar button code { font: 600 12px var(--font-mono); }
.fmt-toolbar svg { width: 18px; height: 18px; fill: currentColor; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.fmt-toolbar svg path { fill: none; }
.fmt-toolbar svg rect { fill: none; }
.fmt-toolbar svg text { stroke: none; font-family: var(--font-ui); font-weight: 600; }
.fmt-toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.fmt-toolbar .table-tools { display: inline-flex; align-items: center; gap: 2px; }
.fmt-toolbar .table-tools[hidden] { display: none; }
.fmt-toolbar .table-tools button { font-size: 12px; }
.fmt-style {
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text);
  font: 500 14px var(--font-ui);
  padding: 0 6px;
  border-radius: 6px;
  cursor: pointer;
}
.fmt-style:hover { background: rgba(127,127,127,.15); }

/* Editor */
.editor { max-width: 820px; margin: 0 auto; }

/* ---------- Folha de papel ---------- */
.sheet {
  position: relative;
  background-color: var(--paper);
  box-shadow: var(--shadow);
  border-radius: 4px;
  min-height: calc(100vh - 170px);
  padding: calc(var(--line) * 2) 56px calc(var(--line) * 2) 72px;
  font-family: var(--font-page);
  font-size: 17px;
  line-height: var(--line);
  color: var(--text);
}
.sheet.paper-LINED {
  background-image:
    linear-gradient(90deg, transparent 52px, var(--paper-margin) 52px, var(--paper-margin) 54px, transparent 54px),
    linear-gradient(transparent calc(var(--line) - 1px), var(--paper-line) calc(var(--line) - 1px));
  background-size: 100% 100%, 100% var(--line);
}
.sheet.paper-GRID {
  background-image:
    linear-gradient(transparent 23px, var(--paper-line) 23px),
    linear-gradient(90deg, transparent 23px, var(--paper-line) 23px);
  background-size: 24px 24px;
}
.sheet.paper-DOTTED {
  background-image: radial-gradient(var(--paper-dot) 1.2px, transparent 1.6px);
  background-size: 24px 24px;
  background-position: 12px 12px;
}

.sheet-title, .sheet-title-input {
  font-family: var(--font-page);
  font-size: 28px;
  font-weight: 600;
  line-height: calc(var(--line) * 1.5);
  margin: 0 0 calc(var(--line) / 2);
  color: var(--text);
}
.sheet-title-input {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  outline: none;
}
.page-body { min-height: calc(100vh - 330px); }
.page-body .ProseMirror { outline: none; min-height: inherit; }
.page-body .ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  color: var(--muted);
  opacity: .7;
  float: left;
  height: 0;
  pointer-events: none;
}
.page-body .ProseMirror-selectednode { outline: 2px solid var(--primary); }
.page-body .selectedCell { background: color-mix(in srgb, var(--primary) 15%, transparent); }
.page-body a { cursor: text; }

.sheet-footer { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font: 12px var(--font-ui); color: var(--muted); }

/* ---------- Markdown renderizado ---------- */
.markdown > :first-child { margin-top: 0; }
/* Cada parágrafo ocupa só a sua linha (Enter cria uma linha nova, não pula duas); linhas em branco são parágrafos vazios. */
.markdown p { margin: 0; }
.markdown ul, .markdown ol, .markdown blockquote, .markdown pre, .markdown table { margin: 0 0 var(--line); }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { line-height: var(--line); margin: var(--line) 0 0; padding-bottom: 0; }
.markdown h1 { font-size: 26px; line-height: calc(var(--line) * 1.5); }
.markdown h2 { font-size: 22px; }
.markdown h3 { font-size: 19px; }
.markdown h1 + *, .markdown h2 + *, .markdown h3 + *, .markdown h4 + * { margin-top: 0; }
.markdown ul, .markdown ol { padding-left: 28px; }
.markdown li p, .markdown td p, .markdown th p { margin: 0; }
.markdown li > ul, .markdown li > ol { margin: 0; }
.markdown blockquote { border-left: 3px solid var(--primary); padding-left: 16px; color: var(--muted); font-style: italic; }
.markdown code { font-family: var(--font-mono); font-size: .86em; background: rgba(127,127,127,.14); padding: 2px 5px; border-radius: 4px; }
.markdown pre { background: rgba(127,127,127,.12); padding: 0 16px; border-radius: 6px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; font-size: 14px; line-height: var(--line); }
.markdown a { color: var(--primary); }
.markdown hr { border: none; height: var(--line); margin: 0; position: relative; }
.markdown hr::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px solid var(--border); }
.markdown img { max-width: 100%; }
.markdown table { border-collapse: collapse; background: var(--paper); display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 0 12px; text-align: left; min-width: 80px; vertical-align: top; }
.markdown th { background: var(--surface-2); }
.markdown li:has(> input[type="checkbox"]) { list-style: none; margin-left: -24px; }
.markdown ul[data-type="taskList"] { list-style: none; padding-left: 4px; }
.markdown ul[data-type="taskList"] li { display: flex; align-items: flex-start; gap: 8px; }
.markdown ul[data-type="taskList"] li > label { flex-shrink: 0; user-select: none; display: flex; align-items: center; height: var(--line); }
.markdown ul[data-type="taskList"] li > div { flex: 1; min-width: 0; }
.markdown ul[data-type="taskList"] li[data-checked="true"] > div { color: var(--muted); text-decoration: line-through; }
.markdown input[type="checkbox"] { margin-right: 8px; accent-color: var(--primary); transform: translateY(1px); }
.markdown del { color: var(--muted); }

/* ---------- Desenho à mão ---------- */
.drawing {
  position: relative;
  margin: 0 0 var(--line);
  border-radius: 6px;
  outline: 1px dashed transparent;
  outline-offset: 4px;
  transition: outline-color .15s;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.drawing:hover, .drawing.selected { outline-color: var(--border); }
.drawing.active { outline: 2px solid var(--primary); }
.drawing-surface {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
  cursor: crosshair;
}
.drawing.active .drawing-surface { touch-action: none; }
.drawing-hint {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font: 13px var(--font-ui);
  color: var(--muted);
  pointer-events: none;
}
.drawing.is-empty:not(.active) .drawing-hint, .drawing.drawing-error .drawing-hint { display: flex; }
.drawing.is-empty:not(.active) { outline-color: var(--border); }

.drawing-tools {
  display: none;
  width: fit-content;
  margin-bottom: 8px;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-family: var(--font-ui);
}
.drawing.active .drawing-tools { display: flex; }
.drawing-group { display: inline-flex; align-items: center; gap: 2px; padding-right: 4px; border-right: 1px solid var(--border); }
.drawing-group[hidden] { display: none; }
.drawing-tools button {
  min-width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: 15px var(--font-ui);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.drawing-tools button:hover:not(:disabled) { background: rgba(127,127,127,.15); }
.drawing-tools button.active { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.drawing-tools button:disabled { opacity: .35; cursor: default; }
.drawing-tools button.danger { color: var(--danger); }
.drawing-tools button.done { background: var(--primary); color: var(--primary-text); padding: 0 12px; font-weight: 600; font-size: 13px; }
.drawing-tools .swatch-btn::after { content: ''; width: 18px; height: 18px; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.drawing-tools .swatch-btn.active { background: transparent; box-shadow: inset 0 0 0 2px var(--primary); }
.drawing-tools .size-btn::after { content: ''; width: var(--dot); height: var(--dot); border-radius: 50%; background: currentColor; }

.drawing-resize {
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 48px;
  height: 14px;
  margin-left: -24px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: ns-resize;
  display: none;
  touch-action: none;
}
.drawing-resize::after { content: ''; position: absolute; inset: 5px 12px; border-top: 1px solid var(--muted); border-bottom: 1px solid var(--muted); }
.drawing.active .drawing-resize { display: block; }

/* Desenho publicado (imagem SVG gerada pelo servidor) */
.markdown img[src^="/drawings/"] { display: block; width: 100%; height: auto; }

/* ---------- Estado vazio ---------- */
.empty-state { max-width: 520px; margin: 96px auto; text-align: center; padding: 0 24px; }
.empty-state h1 { font-family: var(--font-page); }
.empty-state p { color: var(--muted); }

/* ---------- Responsivo ---------- */
@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .user-chip span { display: none; }
  .hero { grid-template-columns: 1fr; padding: 40px 16px; gap: 40px; }
  .hero-shelf .cover { width: 100px; min-width: 0; font-size: 13px; }
  .library { padding: 8px 16px 48px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 18px; }

  .nb-bar { padding: 8px; }
  .nb-back { padding: 8px 10px; }
  .nb-back span { display: none; }
  .nb-toggle-sidebar { display: inline-flex; }
  .nb-actions .badge { display: none; }
  .nb-layout { grid-template-columns: 1fr; }
  .nb-sidebar {
    position: fixed;
    top: 52px;
    bottom: 0;
    left: 0;
    width: 220px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar-open .nb-sidebar { transform: none; }
  .nb-main { padding: 0 16px 48px; }
  .sheet { padding: calc(var(--line) * 1.5) 20px calc(var(--line) * 2) 32px; font-size: 16px; }
  .sheet.paper-LINED {
    background-image:
      linear-gradient(90deg, transparent 20px, var(--paper-margin) 20px, var(--paper-margin) 22px, transparent 22px),
      linear-gradient(transparent calc(var(--line) - 1px), var(--paper-line) calc(var(--line) - 1px));
  }
  .fmt-toolbar { width: 100%; }
}

/* Visualização pública: sem barra de ferramentas acima da folha */
.nb-main > .editor:first-child { margin-top: 24px; }

/* ---------- Histórico de versões ---------- */
.dialog-wide { width: min(1100px, calc(100vw - 32px)); height: min(760px, calc(100vh - 48px)); }
.history { display: flex; flex-direction: column; height: 100%; }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.history-head h2 { margin: 0; font-size: 18px; }
.history-body { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.history-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; border-right: 1px solid var(--border); }
.history-list button {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: 13px var(--font-ui);
  cursor: pointer;
}
.history-list button:hover { background: rgba(127,127,127,.1); }
.history-list button.active { background: color-mix(in srgb, var(--primary) 15%, transparent); }
.history-list strong { font-size: 14px; }
.history-list small { color: var(--muted); }
.history-list span { color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-empty { padding: 16px; color: var(--muted); font-size: 14px; }
.history-preview { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.history-preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; }
.history-sheet { flex: 1; overflow-y: auto; margin: 0 20px 20px; min-height: 0; }

@media (max-width: 760px) {
  .dialog-wide { height: calc(100vh - 32px); }
  .history-body { grid-template-columns: 1fr; grid-template-rows: 35% 1fr; }
  .history-list { border-right: none; border-bottom: 1px solid var(--border); }
  .history-preview-bar { padding: 10px 12px; }
  .history-sheet { margin: 0 12px 12px; padding: 32px 16px 32px 28px; }
}

/* ---------- Importação ---------- */
.library-actions { display: flex; gap: 8px; }
.import-dialog { width: min(520px, calc(100vw - 32px)); }
.import-dialog code { font-family: var(--font-mono); font-size: 12px; }
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px 16px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.drop-zone strong { color: var(--text); }
.drop-zone.dragging { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.drop-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.drop-actions .btn { border: 1px solid var(--border); }
.import-summary { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.import-summary-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600; }
.import-summary ul { margin: 6px 0 0; padding-left: 20px; max-height: 140px; overflow-y: auto; font-size: 13px; color: var(--muted); }
.radio { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }

/* ---------- Exportar página ---------- */
.export-formats { gap: 8px; }
.export-format { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.export-format:has(input:checked) { border-color: var(--primary); background: var(--surface-2); }
.export-format input { margin: 3px 0 0; accent-color: var(--primary); }
.export-format > span { display: flex; flex-direction: column; gap: 2px; }
.export-format strong { font-size: 14px; }
.export-format.disabled { opacity: .55; cursor: default; }
.export-status { margin: 0; font-size: 14px; color: var(--muted); }
.export-status.ok { color: #2e8b57; }
.export-status.error { color: var(--danger); }
.field select:disabled, .field input:disabled { opacity: .5; }
.import-progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.import-progress > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.import-result { font-size: 14px; padding: 10px 12px; border-radius: 8px; }
.import-result ul { margin: 6px 0 10px; padding-left: 20px; max-height: 160px; overflow-y: auto; }
.import-result.warning { background: color-mix(in srgb, #d4a017 14%, transparent); }
.import-result.error { background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* ---------- Convidar para o caderno (no diálogo de exportar) ---------- */
.invite-fields { display: flex; flex-direction: column; gap: 14px; }
.invite-fields input[type="email"] {
  font: inherit; font-size: 15px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
.invite-fields input[type="email"]:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.invite-fields fieldset .radio { margin-bottom: 4px; }
.invite-status { font-size: 14px; padding: 10px 12px; border-radius: 8px; margin: 0; }
.invite-status.ok { background: rgba(46, 139, 87, .14); }
.invite-status.error { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.collaborators { padding: 0 24px 20px; }
.collaborators h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 8px; }
.collaborators ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.collaborators li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.collaborators form { margin: 0; }
.collaborator { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.collaborator .hint { margin: 0; }
.badge-shared { background: rgba(59, 91, 146, .14); color: #3b5b92; }
.readonly-note { margin: 0; align-self: center; }

/* Imagens nas páginas (anexos) */
.markdown img { display: block; max-width: 100%; height: auto; margin: 8px 0; border-radius: 6px; }
.page-body img.ProseMirror-selectednode { outline: 2px solid var(--primary); }

@media (max-width: 760px) {
  .library-head .library-actions .btn-primary { display: none; }
}

/* ---------- Visão geral do caderno ---------- */
.nb-view-toggle { gap: 6px; }
.nb-view-toggle.active { background: rgba(255,255,255,.18); }
.overview {
  /* Miniaturas: a folha real (820px) reduzida para a largura do cartão. */
  --thumb: 200px;
  --scale: calc(200 / 820);
  flex: 1;
  overflow-y: auto;
  padding: 8px 32px 64px;
}
.overview-head { max-width: 1400px; margin: 0 auto 8px; }
.overview-grid {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 1400px;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--thumb));
  justify-content: center;
  gap: 32px 28px;
}
.overview-item { position: relative; }
.overview-paper {
  width: var(--thumb);
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: var(--shadow);
  background: var(--paper);
  outline: 3px solid transparent;
  outline-offset: 3px;
  transition: outline-color .15s, transform .15s;
}
.overview-sheet {
  width: 820px;
  height: calc(820px * 4 / 3);
  min-height: 0;
  overflow: hidden;
  box-shadow: none;
  transform: scale(var(--scale));
  transform-origin: 0 0;
  pointer-events: none;
}
.overview-link { position: absolute; inset: 0; border-radius: 4px; }
.overview-link:focus-visible { outline: none; }
.overview-item:hover .overview-paper, .overview-link:focus-visible ~ * { outline-color: var(--border); }
.overview-item:hover .overview-paper { transform: translateY(-3px); }
.overview-item.current .overview-paper { outline-color: var(--primary); }
.overview-link:focus-visible { box-shadow: 0 0 0 3px var(--primary); }
.overview-caption {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  width: var(--thumb);
}
.overview-number { color: var(--muted); font-variant-numeric: tabular-nums; }
.overview-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.overview-caption .thumb-public { position: static; }
.overview-new-form { margin: 0; }
.overview-new {
  width: var(--thumb);
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px dashed var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: 500 14px var(--font-ui);
  cursor: pointer;
}
.overview-new .plus { font-size: 40px; font-weight: 300; line-height: 1; }
.overview-new:hover { border-color: var(--primary); color: var(--primary); }

@media (max-width: 760px) {
  .overview { --thumb: 148px; --scale: calc(148 / 820); padding: 8px 16px 48px; }
  .overview-grid { gap: 24px 16px; }
  .nb-view-toggle span { display: none; }
}

/* ---------- Páginas de texto (política de privacidade) e rodapé ---------- */
.legal { max-width: 760px; margin: 0 auto; padding: 32px 20px 64px; line-height: 1.6; }
.legal h1 { font-family: var(--font-page); margin-bottom: 4px; }
.legal h2 { font-size: 18px; margin: 28px 0 6px; }
.legal ul { padding-left: 22px; }
.site-footer { text-align: center; padding: 16px; font-size: 13px; }
.site-footer a { color: var(--muted); }
.site-footer span { color: var(--muted); margin: 0 6px; }
.legal h3 { font-size: 16px; margin: 20px 0 4px; }
