*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --paper:   #f2f0ed;
  --paper2:  #ebe9e5;
  --paper3:  #e0ddd8;
  --sheet:   #faf9f7;
  --rule:    #ccc9c2;
  --rule2:   #b8b4ac;
  --ink:     #2a2825;
  --ink2:    #5a5752;
  --ink3:    #8a8782;
  --ink4:    #aeaba4;
  --ok:      #7a9e7e;
  --warn:    #a09060;
  --err:     #8a6050;
  --serif:   'EB Garamond', Georgia, serif;
  --mono:    'DM Mono', 'Courier New', monospace;
  --r:       8px;
  --side-w:  264px;
  --panel-w: 340px;
  --top-h:   50px;
  --safe-t:  env(safe-area-inset-top, 0px);
  --safe-b:  env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { overflow: hidden; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
* { -webkit-tap-highlight-color: transparent; }

/* grão de papel */
/* tons de cinza: a app abre sempre sem cor; o botão ao lado dos sinais liga e desliga as cores.
   É só um filtro por cima de tudo (não mexe em nada por baixo nem bloqueia toques). */
html.mono body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 10000;
  -webkit-backdrop-filter: grayscale(1); backdrop-filter: grayscale(1);
}

body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

.icon { width: 16px; height: 16px; display: block; flex-shrink: 0; }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; }

.screen { display: none; height: 100dvh; width: 100%; }
.screen.active { display: flex; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

/* ════════ ENTRAR ════════ */
#screen-login { flex-direction: column; align-items: center; justify-content: center; }
.login-wrap { width: min(320px, 88vw); animation: rise .5s cubic-bezier(.16,1,.3,1) both; }
.wordmark {
  font-family: var(--mono); font-size: 11px; letter-spacing: .3em; text-transform: uppercase;
  color: var(--ink3); text-align: center; margin-bottom: 40px;
}
.wordmark.small { font-size: 10px; margin: 0; text-align: left; }
.lock-icon { display: flex; justify-content: center; margin: -12px 0 28px; opacity: .25; }
.field-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink4); margin-bottom: 10px; display: block;
}
.field-row { position: relative; }
.pw-input {
  width: 100%; background: transparent; border: none; border-bottom: 1px solid var(--rule);
  color: var(--ink); font-family: var(--mono); font-size: 16px; font-weight: 300; letter-spacing: .1em;
  padding: 10px 36px 10px 0; outline: none; transition: border-color .2s; caret-color: var(--ink2); border-radius: 0;
}
.pw-input:focus { border-bottom-color: var(--ink2); }
.pw-input::placeholder { color: var(--ink4); }
.eye-btn {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--ink4); cursor: pointer; padding: 4px; display: flex;
}
.eye-btn:hover { color: var(--ink2); }
.login-btn {
  margin-top: 28px; width: 100%; background: var(--ink); color: var(--paper); border: none; border-radius: var(--r);
  font-family: var(--mono); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; padding: 14px;
  cursor: pointer; transition: background .2s, transform .1s;
}
.login-btn:hover { background: var(--ink2); }
.login-btn:active { transform: scale(.98); }
.login-btn:disabled { background: var(--ink4); cursor: default; transform: none; }
.login-error {
  font-family: var(--mono); font-size: 11px; color: var(--err); text-align: center;
  min-height: 18px; margin-top: 16px; letter-spacing: .04em;
}

/* ════════ ESTRUTURA ════════ */
#screen-app { position: relative; }
.sidebar {
  width: var(--side-w); flex-shrink: 0; background: var(--paper2); border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; padding-top: var(--safe-t); min-height: 0;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; padding-top: var(--safe-t); }
.scrim { display: none; }

.side-head { height: var(--top-h); display: flex; align-items: center; justify-content: space-between; padding: 0 18px; flex-shrink: 0; }
.search-row {
  margin: 4px 14px 10px; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  border: 1px solid var(--rule); border-radius: 7px; background: var(--paper); color: var(--ink4);
}
.search-row input {
  flex: 1; min-width: 0; border: none; background: none; outline: none; padding: 8px 0;
  font-family: var(--mono); font-size: 12px; color: var(--ink); letter-spacing: .03em;
}
.search-row input::placeholder { color: var(--ink4); }
.search-results { margin: 0 14px 10px; border: 1px solid var(--rule); border-radius: 7px; background: var(--paper); max-height: 45vh; overflow: auto; }
.search-results .sr-item { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--paper3); padding: 9px 12px; cursor: pointer; }
.search-results .sr-item:last-child { border-bottom: none; }
.search-results .sr-item:hover { background: var(--paper2); }
.sr-title { font-size: 15px; }
.sr-snip { font-family: var(--mono); font-size: 10.5px; color: var(--ink3); margin-top: 3px; line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sr-snip mark { background: rgba(160,144,96,.25); color: inherit; }
.sr-empty { padding: 12px; font-family: var(--mono); font-size: 11px; color: var(--ink4); }

.side-section { flex: 1; overflow: auto; padding: 4px 8px 12px; min-height: 0; }
.side-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink4); padding: 8px 10px 8px;
}
.tab-list { list-style: none; }
.tab-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 6px 7px 10px; border-radius: 6px;
  cursor: pointer; font-size: 16px; color: var(--ink2); position: relative; user-select: none; -webkit-user-select: none;
}
.tab-item:hover { background: var(--paper3); }
.tab-item.active { background: var(--paper); color: var(--ink); box-shadow: 0 0 0 1px var(--rule) inset; }
.tab-item .t-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-item .t-who { display: flex; gap: 6px; align-items: center; padding-right: 2px; }
.tdot { width: 9px; height: 9px; border-radius: 50%; display: block; background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent), 0 0 8px var(--c); animation: glow 2.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .tdot { animation: none; } }
.pdot.go { cursor: pointer; }
.pdot.go:hover { text-decoration: underline; text-underline-offset: 3px; }
.tab-item .t-more { opacity: 0; background: none; border: none; color: var(--ink3); cursor: pointer; padding: 2px; border-radius: 4px; display: flex; }
.tab-item:hover .t-more, .tab-item.active .t-more { opacity: 1; }
.tab-item .t-more:hover { background: var(--paper2); color: var(--ink); }
.tab-item.dragging { opacity: .4; }
.tab-item.drop-before::before, .tab-item.drop-after::after {
  content: ''; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--ink3); border-radius: 2px;
}
.tab-item.drop-before::before { top: -1px; }
.tab-item.drop-after::after { bottom: -1px; }
.tab-rename { flex: 1; min-width: 0; font: inherit; font-size: 16px; border: none; border-bottom: 1px solid var(--ink3); background: transparent; outline: none; color: var(--ink); padding: 0; }
.add-tab {
  margin: 6px 0 0; width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: none; border: 1px dashed var(--rule); border-radius: 6px; cursor: pointer; color: var(--ink3);
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em;
}
.add-tab:hover { border-color: var(--ink3); color: var(--ink); }
.side-foot { border-top: 1px solid var(--rule); padding: 8px 8px calc(10px + var(--safe-b)); flex-shrink: 0; }
.side-link {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px; background: none;
  border: none; cursor: pointer; color: var(--ink3); font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
}
.side-link:hover, .side-link.active { background: var(--paper3); color: var(--ink); }

.storage-warning { background: #8a6050; color: #fff; font-family: var(--mono); font-size: 11px; letter-spacing: .03em; line-height: 1.5; padding: 8px 16px; text-align: center; flex-shrink: 0; }

/* ════════ BARRA DE TOPO ════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px 0 20px; height: var(--top-h);
  border-bottom: 1px solid var(--rule); background: var(--paper2); flex-shrink: 0; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rule2); flex-shrink: 0; transition: background .4s; }
.dot.online { background: var(--ok); }
.dot.syncing { background: var(--warn); animation: blink 1s infinite; }
.status-txt { font-family: var(--mono); font-size: 11px; color: var(--ink4); letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-txt b { font-weight: 400; color: var(--ink3); }

.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 6px; color: var(--ink3); cursor: pointer;
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; position: relative; flex-shrink: 0;
}
.icon-btn:hover { background: var(--paper3); color: var(--ink); }
.icon-btn.active { background: var(--paper); border-color: var(--rule); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.badge {
  position: absolute; top: 1px; right: 0; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px;
  background: var(--ink3); color: var(--paper); font-family: var(--mono); font-size: 9px; line-height: 14px; text-align: center;
}
.badge:empty { display: none; }

.notify-row { display: flex; align-items: center; gap: 7px; cursor: pointer; margin: 0 6px 0 8px; }
.notify-row input { display: none; }
.tog { width: 28px; height: 16px; border-radius: 8px; background: var(--rule); position: relative; transition: background .25s; flex-shrink: 0; }
.tog::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper2); transition: transform .25s; box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.notify-row input:checked + .tog { background: var(--ink3); }
.notify-row input:checked + .tog::after { transform: translateX(12px); }
.notify-lbl { font-family: var(--mono); font-size: 10px; color: var(--ink4); letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.close-btn {
  background: none; border: 1px solid var(--rule); border-radius: 6px; color: var(--ink3); font-family: var(--mono);
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase; padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.close-btn:hover { border-color: var(--ink3); color: var(--ink); background: var(--paper3); }
.panic-btn { color: var(--err); }
.panic-btn:hover { color: var(--paper); background: var(--err); }
.panic-btn .icon { width: 20px; height: 20px; }

/* sinais de presença (cor de cada conta; aceso = online) */
.presence { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.pdot { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--ink4); transition: color .3s; }
.pdot i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--c); background: transparent; opacity: .45; transition: all .3s; }
.pdot.on { color: var(--c); }
.pdot.on i { background: var(--c); opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent), 0 0 8px var(--c); animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent), 0 0 6px var(--c); } 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 12%, transparent), 0 0 12px var(--c); } }
@media (prefers-reduced-motion: reduce) { .pdot.on i { animation: none; } }
/* meio aceso: em segundo plano (a app continua aberta) */
.pdot.away { color: var(--c); }
.pdot.away i { opacity: 1; background: linear-gradient(90deg, var(--c) 50%, transparent 50%); }

/* manter aberta */
.grace-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.grace-lbl { font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink4); white-space: nowrap; }
.grace { display: flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.grace button { background: none; border: none; border-left: 1px solid var(--rule); padding: 5px 9px; cursor: pointer; font-family: var(--mono); font-size: 11px; color: var(--ink3); font-variant-numeric: tabular-nums; min-width: 34px; }
.grace button:first-child { border-left: none; }
.grace button:hover { background: var(--paper3); color: var(--ink); }
.grace button.on { background: var(--ink); color: var(--paper); }

/* popovers da barra */
.tb-wide { min-width: 108px; justify-content: flex-start; font-family: 'Gill Sans', 'Gill Sans MT', 'Cabin', sans-serif; font-size: 13.5px; letter-spacing: 0; white-space: nowrap; }
.pen-swatch { width: 16px; height: 16px; border-radius: 50%; display: block; box-shadow: 0 0 0 1.5px var(--paper), 0 0 0 2.5px var(--rule2); }
.emoji-ico { font-size: 17px; line-height: 1; }
.menu.pop-fonts button { font-size: 16px; letter-spacing: 0; padding: 9px 12px; }
.menu.pop-fonts button.on { background: var(--paper2); color: var(--ink); }
.menu.pop-colors { width: 236px; padding: 8px; }
.pc-default { font-size: 11px !important; }
.pc-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; padding: 8px 4px; }
.sw { width: 20px; height: 20px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.pc-grid .sw { border: none; padding: 0; cursor: pointer; width: 22px; height: 22px; }
.pc-grid .sw.on, .pc-grid .sw:hover { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--ink3); }
.menu .pc-grid button { width: 22px; padding: 0; border-radius: 50%; }
.pc-custom { display: flex; gap: 6px; padding: 4px; }
.pc-custom input { flex: 1; min-width: 0; border: 1px solid var(--rule); border-radius: 5px; background: var(--paper); padding: 6px 8px; font-family: var(--mono); font-size: 12px; color: var(--ink); outline: none; }
.menu .pc-custom button { width: auto; border: 1px solid var(--rule); padding: 6px 10px; }
.pc-hint { font-family: var(--mono); font-size: 9.5px; color: var(--ink4); line-height: 1.5; padding: 6px 4px 2px; }
.menu.pop-emoji { width: min(340px, calc(100vw - 16px)); max-height: min(380px, 60vh); overflow-y: auto; padding: 6px 8px 10px; }
.pe-cat { font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink4); padding: 8px 4px 4px; }
.pe-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.menu .pe-grid button { font-size: 22px; line-height: 1; padding: 6px 0; justify-content: center; font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; }

/* ════════ VISTAS ════════ */
.view { display: none; flex: 1; min-height: 0; flex-direction: column; position: relative; }
.view.active { display: flex; }

/* barra de formatação */
.toolbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 14px; border-bottom: 1px solid var(--rule);
  background: var(--paper); overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tb-btn {
  height: 30px; min-width: 30px; padding: 0 6px; background: none; border: none; border-radius: 5px; color: var(--ink3);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-family: var(--mono); font-size: 11px; letter-spacing: .04em;
}
.tb-btn:hover { background: var(--paper3); color: var(--ink); }
.tb-btn.on { background: var(--paper3); color: var(--ink); }
.tb-btn:disabled { opacity: .3; cursor: default; background: none; }
.tb-sep { width: 1px; height: 18px; background: var(--rule); margin: 0 6px; flex-shrink: 0; }
.tb-group-table { display: none; align-items: center; gap: 2px; }
.tb-group-table.show { display: inline-flex; }

.page-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page { max-width: 780px; margin: 0 auto; padding: clamp(28px, 5vw, 64px) clamp(20px, 6vw, 72px) 30vh; }
.doc-title {
  width: 100%; border: none; background: none; outline: none; font-family: var(--serif); font-size: clamp(26px, 3.4vw, 34px);
  font-weight: 500; color: var(--ink); letter-spacing: .005em; padding: 0; border-radius: 0;
}
.doc-title::placeholder { color: var(--ink4); }
.doc-meta { font-family: var(--mono); font-size: 10.5px; color: var(--ink4); letter-spacing: .06em; margin: 8px 0 26px; min-height: 14px; }

/* conteúdo do documento */
.ProseMirror { outline: none; font-family: 'Gill Sans', 'Gill Sans MT', 'Cabin', Calibri, sans-serif; font-size: 17px; line-height: 1.75; letter-spacing: .01em; color: var(--ink); caret-color: var(--ink2); word-wrap: break-word; min-height: 40vh; }
.ProseMirror > * + * { margin-top: .7em; }
.ProseMirror h1 { font-size: 1.6em; font-weight: 500; line-height: 1.3; margin-top: 1.3em; }
.ProseMirror h2 { font-size: 1.3em; font-weight: 500; line-height: 1.35; margin-top: 1.2em; }
.ProseMirror h3 { font-family: var(--mono); font-size: .72em; font-weight: 400; letter-spacing: .16em; text-transform: uppercase; color: var(--ink2); margin-top: 1.6em; }
.ProseMirror ul, .ProseMirror ol { padding-left: 1.4em; }
.ProseMirror li > p { margin: 0; }
.ProseMirror li + li { margin-top: .2em; }
.ProseMirror blockquote { border-left: 2px solid var(--rule2); padding-left: 1em; color: var(--ink2); font-style: italic; }
.ProseMirror hr { border: none; border-top: 1px solid var(--rule); margin: 2em 0; }
.ProseMirror a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--rule2); text-underline-offset: 3px; }
.ProseMirror code { font-family: var(--mono); font-size: .8em; background: var(--paper3); padding: 1px 5px; border-radius: 4px; }
.ProseMirror pre { font-family: var(--mono); font-size: .78em; background: var(--paper2); border: 1px solid var(--rule); padding: 12px 14px; border-radius: 6px; overflow-x: auto; }
.ProseMirror pre code { background: none; padding: 0; }
.ProseMirror img { max-width: 100%; height: auto; border-radius: 4px; display: block; cursor: zoom-in; }
.ProseMirror img.ProseMirror-selectednode { outline: 2px solid var(--ink3); outline-offset: 2px; }
.ProseMirror ::selection { background: rgba(42,40,37,.12); }
.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder); color: var(--ink4); font-style: italic; float: left; height: 0; pointer-events: none;
}
.ProseMirror ul[data-type="taskList"] { list-style: none; padding-left: .2em; }
.ProseMirror ul[data-type="taskList"] li { display: flex; gap: .6em; align-items: flex-start; }
.ProseMirror ul[data-type="taskList"] li > label { margin-top: .38em; flex-shrink: 0; }
.ProseMirror ul[data-type="taskList"] li > label input { accent-color: var(--ink2); width: 15px; height: 15px; }
.ProseMirror ul[data-type="taskList"] li > div { flex: 1; }
.ProseMirror ul[data-type="taskList"] li[data-checked="true"] > div { color: var(--ink4); text-decoration: line-through; }
.ProseMirror table { border-collapse: collapse; width: 100%; font-size: .9em; table-layout: fixed; overflow: hidden; margin: 1em 0; }
.ProseMirror td, .ProseMirror th { border: 1px solid var(--rule); padding: 6px 9px; vertical-align: top; position: relative; }
.ProseMirror th { background: var(--paper2); font-weight: 500; text-align: left; }
.ProseMirror td > p, .ProseMirror th > p { margin: 0; }
.ProseMirror .selectedCell::after { content: ''; position: absolute; inset: 0; background: rgba(42,40,37,.06); pointer-events: none; }
.tableWrapper { overflow-x: auto; }

/* cursor do outro utilizador */
.collaboration-cursor__caret { border-left: 1.5px solid; border-right: none; margin-left: -1px; margin-right: -1px; position: relative; word-break: normal; pointer-events: none; }
.collaboration-cursor__label {
  position: absolute; top: -1.35em; left: -1px; font-family: var(--mono); font-size: 10px; font-style: normal; font-weight: 400;
  line-height: 1; letter-spacing: .06em; color: #fff; padding: 3px 5px; border-radius: 3px 3px 3px 0; white-space: nowrap; user-select: none;
}

.remote-toast {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%) translateY(-4px); background: var(--paper2);
  border: 1px solid var(--rule); color: var(--ink3); font-family: var(--mono); font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; padding: 5px 16px; border-radius: 20px; pointer-events: none; opacity: 0;
  transition: opacity .25s, transform .25s; box-shadow: 0 2px 12px rgba(0,0,0,.08); z-index: 50; white-space: nowrap;
}
.remote-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* arquivo / reciclagem */
.view-scroll { flex: 1; overflow-y: auto; }
.view-inner { max-width: 980px; margin: 0 auto; padding: clamp(24px, 4vw, 48px) clamp(18px, 4vw, 40px) 80px; }
.view-title { font-size: 30px; font-weight: 500; margin-bottom: 20px; }
.sub-title { font-family: var(--mono); font-size: 10px; font-weight: 400; letter-spacing: .18em; text-transform: uppercase; color: var(--ink4); margin: 36px 0 12px; }
.hint { font-family: var(--mono); font-size: 11px; color: var(--ink3); line-height: 1.7; letter-spacing: .02em; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  background: none; border: 1px solid var(--rule); border-radius: 20px; padding: 6px 13px; cursor: pointer;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; color: var(--ink3);
}
.chip:hover { border-color: var(--ink3); color: var(--ink); }
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.filter-input {
  width: 100%; max-width: 360px; border: none; border-bottom: 1px solid var(--rule); background: none; outline: none;
  font-family: var(--mono); font-size: 13px; padding: 8px 0; margin-bottom: 22px; color: var(--ink); border-radius: 0;
}
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.file-card {
  border: 1px solid var(--rule); border-radius: 8px; background: var(--sheet); overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; text-align: left; padding: 0; transition: border-color .2s, transform .15s;
}
.file-card:hover { border-color: var(--ink4); transform: translateY(-1px); }
.fc-thumb { aspect-ratio: 4 / 3; background: var(--paper2); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--ink4); }
.fc-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fc-ext { font-family: var(--mono); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink3); border: 1px solid var(--rule2); padding: 6px 9px; border-radius: 4px; background: var(--paper); }
.fc-info { padding: 9px 11px 10px; min-width: 0; }
.fc-name { font-size: 14.5px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-meta { font-family: var(--mono); font-size: 9.5px; color: var(--ink4); letter-spacing: .04em; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { font-family: var(--mono); font-size: 11px; color: var(--ink4); padding: 18px 0; grid-column: 1 / -1; }

.plain-list { list-style: none; border-top: 1px solid var(--paper3); }
.plain-list li { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--paper3); }
.plain-list .pl-name { flex: 1; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plain-list .pl-meta { font-family: var(--mono); font-size: 10px; color: var(--ink4); white-space: nowrap; }
.plain-list .empty { border: none; }
.txt-btn {
  background: none; border: 1px solid var(--rule); border-radius: 5px; padding: 5px 10px; cursor: pointer; white-space: nowrap;
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink3);
}
.txt-btn:hover { border-color: var(--ink3); color: var(--ink); }
.txt-btn.danger:hover { border-color: var(--err); color: var(--err); }

/* ════════ PAINEL LATERAL ════════ */
.panel {
  width: var(--panel-w); flex-shrink: 0; border-left: 1px solid var(--rule); background: var(--paper2);
  display: none; flex-direction: column; padding-top: var(--safe-t); min-height: 0;
}
.panel.open { display: flex; }
.panel-head { height: var(--top-h); display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 18px; border-bottom: 1px solid var(--rule); flex-shrink: 0; }
.panel-title { font-family: var(--mono); font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink3); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; display: none; padding-bottom: calc(16px + var(--safe-b)); }
.panel-body.active { display: block; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px 12px; border: 1px dashed var(--rule2);
  border-radius: 8px; cursor: pointer; color: var(--ink3); text-align: center; font-family: var(--mono); font-size: 11px; letter-spacing: .06em;
  transition: border-color .2s, background .2s;
}
.dropzone small { font-size: 9.5px; color: var(--ink4); letter-spacing: .02em; }
.dropzone:hover, .dropzone.over { border-color: var(--ink3); background: var(--paper); color: var(--ink); }
.upload-progress { font-family: var(--mono); font-size: 10.5px; color: var(--ink3); margin-top: 10px; }
.file-list { list-style: none; margin-top: 14px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 6px; cursor: pointer; }
.file-row:hover { background: var(--paper3); }
.fr-thumb { width: 40px; height: 40px; border-radius: 5px; background: var(--paper); border: 1px solid var(--rule); overflow: hidden; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-family: var(--mono); font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink3); }
.fr-thumb img { width: 100%; height: 100%; object-fit: cover; }
.fr-info { flex: 1; min-width: 0; }
.fr-name { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr-meta { font-family: var(--mono); font-size: 9.5px; color: var(--ink4); margin-top: 2px; }
.version-list { list-style: none; margin-top: 14px; }
.v-day { font-family: var(--mono); font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink4); margin: 16px 6px 6px; }
.v-row { display: block; width: 100%; text-align: left; background: none; border: none; padding: 8px 8px; border-radius: 6px; cursor: pointer; }
.v-row:hover { background: var(--paper3); }
.v-time { font-size: 15.5px; }
.v-who { font-family: var(--mono); font-size: 10px; color: var(--ink3); margin-top: 2px; }
.v-label { font-family: var(--mono); font-size: 9.5px; color: var(--warn); margin-top: 2px; }

/* ════════ VISUALIZADOR ════════ */
.viewer { position: fixed; inset: 0; z-index: 300; background: rgba(242,240,237,.97); display: none; flex-direction: column; padding-top: var(--safe-t); }
.viewer.active { display: flex; animation: rise .25s cubic-bezier(.16,1,.3,1) both; }
.viewer-bar { height: var(--top-h); display: flex; align-items: center; gap: 6px; padding: 0 12px; border-bottom: 1px solid var(--rule); background: var(--paper2); flex-shrink: 0; }
.viewer-name { flex: 1; min-width: 0; text-align: center; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; gap: 6px; }
.viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 16px; padding-bottom: calc(16px + var(--safe-b)); }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 4px 30px rgba(0,0,0,.08); background: #fff; }
.viewer-body iframe { width: 100%; height: 100%; max-width: 1000px; border: 1px solid var(--rule); background: #fff; border-radius: 4px; }
.viewer-body video, .viewer-body audio { max-width: 100%; max-height: 100%; }
.viewer-body .v-doc { width: 100%; max-width: 780px; height: 100%; overflow: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 36px clamp(18px, 5vw, 56px); align-self: stretch; }
.viewer-body .v-pdf { width: 100%; height: 100%; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 4px 0 20px; align-self: stretch; }
.v-pdf canvas { background: #fff; box-shadow: 0 2px 16px rgba(0,0,0,.08); max-width: 100%; height: auto !important; }
.viewer-msg { font-family: var(--mono); font-size: 12px; color: var(--ink3); text-align: center; line-height: 1.8; }

/* ════════ MODAL / MENU ════════ */
.overlay {
  display: none; position: fixed; inset: 0; background: rgba(242,240,237,.75); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); align-items: center; justify-content: center; z-index: 400;
}
.overlay.active { display: flex; }
.modal {
  background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: 30px 26px 22px; width: min(340px, 90vw);
  box-shadow: 0 8px 40px rgba(0,0,0,.1); animation: rise .3s cubic-bezier(.16,1,.3,1) both; display: flex; flex-direction: column; gap: 12px;
}
.modal-title { font-size: 19px; font-weight: 500; }
.modal-body { font-family: var(--mono); font-size: 11px; color: var(--ink3); line-height: 1.75; letter-spacing: .03em; }
.modal-body input {
  width: 100%; display: block; margin-top: 10px; border: none; border-bottom: 1px solid var(--rule); background: none; outline: none; padding: 8px 0;
  font-family: var(--mono); font-size: 14px; color: var(--ink); border-radius: 0;
}
.modal-body input:focus { border-bottom-color: var(--ink2); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.btn-ghost, .btn-solid {
  flex: 1; border-radius: 7px; font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; padding: 12px; cursor: pointer;
}
.btn-ghost { background: none; border: 1px solid var(--rule); color: var(--ink3); }
.btn-ghost:hover { border-color: var(--ink3); color: var(--ink); }
.btn-solid { background: var(--ink); border: none; color: var(--paper); }
.btn-solid:hover { background: var(--ink2); }
.btn-solid.danger { background: var(--err); }

.menu {
  position: fixed; z-index: 450; display: none; min-width: 180px; background: var(--paper); border: 1px solid var(--rule);
  border-radius: 8px; box-shadow: 0 6px 28px rgba(0,0,0,.1); padding: 5px;
}
.menu.open { display: block; animation: rise .15s ease-out both; }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: none; padding: 8px 10px;
  border-radius: 5px; cursor: pointer; font-family: var(--mono); font-size: 11px; letter-spacing: .04em; color: var(--ink2);
}
.menu button:hover { background: var(--paper2); color: var(--ink); }
.menu button.danger:hover { color: var(--err); }
.menu hr { border: none; border-top: 1px solid var(--paper3); margin: 4px 2px; }

/* ════════ TELEMÓVEL ════════ */
.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 200; width: min(86vw, 320px);
    transform: translateX(-102%); transition: transform .28s cubic-bezier(.16,1,.3,1); box-shadow: 0 0 40px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 190; background: rgba(42,40,37,.18); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .panel { position: fixed; inset: 0; z-index: 210; width: auto; border-left: none; }
  .topbar { padding: 0 8px; flex-wrap: wrap; height: auto; min-height: var(--top-h); row-gap: 0; }
  .topbar-left, .topbar-right { height: var(--top-h); }
  .grace-wrap { order: 3; width: 100%; justify-content: space-between; border-top: 1px solid var(--rule); height: 40px; padding: 0 4px; }
  .grace button { padding: 6px 12px; min-width: 44px; }
  .status-txt { display: none; }
  .notify-lbl { display: none; }
  .notify-row { margin: 0 4px; }
  .close-btn { padding: 7px 10px; }
  .tab-item .t-more { opacity: 1; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .viewer-body { padding: 8px; }
}
@media (max-width: 860px) {
  .ProseMirror { font-size: 16px; } /* telemóvel: um pouco mais pequena */
}
@media (max-width: 420px) {
  .status-txt { font-size: 10px; }
}

/* a letra manuscrita é mais pequena de origem: compensar */
.ProseMirror span[style*="Caveat"], .v-doc span[style*="Caveat"] { font-size: 1.32em; line-height: 1.2; }
.menu.pop-fonts button[style*="Caveat"], .tb-wide[style*="Caveat"] { font-size: 21px; }
