:root {
  --bg: #f6f4ef;
  --paper: #fffdf9;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e7e2d8;
  --accent: #1e3a8a;
  --accent-soft: #e6ebf7;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --r: 14px;
  --shadow: 0 1px 2px rgba(29, 36, 51, 0.06), 0 4px 16px rgba(29, 36, 51, 0.06);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-family: var(--serif); font-size: 30px; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 18px; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 18px 4px; }
.grow { flex: 1; min-width: 0; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 500; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #172e70; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #efebe3; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-soft { background: #fbe9e9; color: var(--danger); }
.btn.block { width: 100%; }
.btn.left { justify-content: flex-start; }
.btn .ic { width: 18px; height: 18px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px; }
.iconbtn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; color: var(--muted); }
.iconbtn:hover { background: #efebe3; color: var(--ink); }
.iconbtn:disabled { opacity: .3; cursor: default; }
.iconbtn.sm { width: 30px; height: 30px; }
.help { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid #c9c2b4; background: var(--paper); color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; flex: none; padding: 0; }
.help:hover { border-color: var(--accent); color: var(--accent); }
.help.big { width: 32px; height: 32px; font-size: 15px; }

.input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; color: inherit; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30, 58, 138, .12); }

.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.row.tight { gap: 2px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 8px; }

/* carregando */
.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); background: var(--bg); z-index: 5; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* entrar */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--paper); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.form-err { color: var(--danger); font-size: 14px; min-height: 0; }
.note { background: #fff7e0; color: #7a5b00; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 19px; }
.brand.big { font-size: 26px; justify-content: center; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; font: 600 13px var(--sans); letter-spacing: .04em; }
.brand.big .logo { width: 44px; height: 44px; font-size: 15px; }

/* casca */
.shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: rgba(246, 244, 239, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; }
.crumbs a:hover { color: var(--ink); }
.crumbs .cur { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.crumbs .sep { opacity: .5; }
.top-right { display: flex; align-items: center; gap: 6px; }
.content { width: min(1120px, 100%); margin: 0 auto; padding: 26px 20px 60px; display: flex; flex-direction: column; gap: 18px; }

.sync-chip { border: 0; border-radius: 999px; padding: 5px 11px 5px 22px; font-size: 12.5px; font-weight: 500; position: relative; cursor: pointer; white-space: nowrap; background: #ece8df; }
.sync-chip::before { content: ""; position: absolute; left: 9px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: currentColor; }
.sync-chip.ok { color: var(--ok); background: #e3f3e8; }
.sync-chip.warn { color: var(--warn); background: #fdf0dc; }
.sync-chip.prev { color: #6d5a1c; background: #f6eecf; }

.banner { display: flex; gap: 16px; align-items: center; justify-content: space-between; background: var(--accent-soft); border-radius: var(--r); padding: 16px 18px; }
.banner p { color: #3b4a72; font-size: 14px; }

.sec-head { display: flex; align-items: center; gap: 10px; }
.title-row { display: flex; align-items: center; gap: 12px; }
.title-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }

/* matérias */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { position: relative; background: var(--paper); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 18px 16px; min-height: 120px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; border: 0; text-align: left; cursor: pointer; transition: transform .12s, box-shadow .12s; overflow: hidden; }
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(29,36,51,.06), 0 10px 24px rgba(29,36,51,.08); }
.mat-bar { position: absolute; left: 0; top: 0; right: 0; height: 6px; background: var(--c); }
.mat-name { font-family: var(--serif); font-size: 20px; line-height: 1.2; padding-right: 30px; }
.mat-meta { color: var(--muted); font-size: 13px; }
.card-menu { position: absolute; top: 12px; right: 8px; }
.card.add { align-items: center; justify-content: center; color: var(--accent); background: transparent; box-shadow: none; border: 1.5px dashed #cfc7b8; font-weight: 500; gap: 8px; }
.card.add:hover { background: var(--accent-soft); border-color: var(--accent); }

/* painéis e listas */
.two-col { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.4fr); gap: 18px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
.panel { background: var(--paper); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.panel.drop.over { outline: 2px dashed var(--accent); outline-offset: -6px; background: var(--accent-soft); }
.list { display: flex; flex-direction: column; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; cursor: pointer; }
.row-item + .row-item { border-top: 1px solid #f0ece4; }
.row-item:hover { background: #f8f5ef; }
.ri-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.num { width: 26px; height: 26px; border-radius: 8px; background: #f1ede5; display: grid; place-items: center; font-size: 12.5px; color: var(--muted); flex: none; }
.pdf-ic { width: 34px; height: 34px; border-radius: 9px; background: #fbe9e9; color: var(--danger); display: grid; place-items: center; flex: none; }
.chip { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.add-row .input { flex: 1; }
.uploads:empty { display: none; }
.upload-row { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: #f8f5ef; border-radius: 10px; margin-bottom: 6px; }
.pbar { height: 6px; border-radius: 3px; background: #e9e3d7; overflow: hidden; }
.pbar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tab.on { background: var(--ink); color: #fff; }
.tab.later { opacity: .7; }
.empty { text-align: center; padding: 30px 10px; display: flex; flex-direction: column; gap: 6px; }

/* janelas */
.modal-back { position: fixed; inset: 0; background: rgba(29, 36, 51, .35); display: grid; place-items: center; padding: 20px; z-index: 100; animation: fade .15s; }
.modal { background: var(--paper); border-radius: 18px; padding: 22px; width: min(420px, 100%); max-height: 85vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(640px, 100%); }
.modal p { line-height: 1.55; }
@keyframes fade { from { opacity: 0; } }
.checks { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow: auto; }
.check { display: flex; gap: 10px; align-items: center; padding: 9px 8px; border-radius: 8px; cursor: pointer; }
.check:hover { background: #f5f1ea; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 200; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: opacity .4s, transform .4s; max-width: 90vw; }
.toast.ok { background: #14532d; }
.toast.err { background: #7f1d1d; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* leitor */
.viewer-holder, .viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: #e9e5dc; }
.vbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--paper); border-bottom: 1px solid var(--line); z-index: 5; }
.vleft { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 0 1 260px; }
.vtitle { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.vtools { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: safe center; overflow-x: auto; scrollbar-width: none; min-width: 0; }
@media (max-width: 1180px) {
  .vbar { flex-wrap: wrap; row-gap: 4px; }
  .vleft { flex: 1 1 auto; }
  .vtools { order: 3; flex: 1 1 100%; }
}
.vtools::-webkit-scrollbar { display: none; }
.vright { flex: none; }
.grp { display: flex; gap: 2px; padding: 3px; background: #f1ede5; border-radius: 12px; }
.tbtn { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 9px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; color: #3f4756; }
.tbtn:hover { background: #e7e1d6; }
.tbtn.on { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tbtn:disabled { opacity: .35; cursor: default; }
.tbtn .ic { width: 22px; height: 22px; }
.tbtn .dot { position: absolute; right: 6px; bottom: 6px; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid #fff; }
.tbtn .lbl { font-size: 13px; font-weight: 500; white-space: nowrap; }
@media (max-width: 600px) { .tbtn .lbl { display: none; } .tbtn { min-width: 36px; padding: 0 6px; } .grp { gap: 0; } }
.scroller { flex: 1; overflow: auto; position: relative; -webkit-overflow-scrolling: touch; }
.pages { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.page { position: absolute; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 6px 18px rgba(0,0,0,.06); }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pnum { position: absolute; right: 8px; bottom: -0px; transform: translateY(100%); font-size: 11px; color: #8a8478; padding-top: 1px; }
.viewer[data-tool="eraser"] .pages { cursor: cell; }
.viewer[data-tool="pen"] .pages, .viewer[data-tool="hl"] .pages { cursor: crosshair; }
.pop { position: absolute; z-index: 20; background: var(--paper); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.18); padding: 14px; display: flex; flex-direction: column; gap: 10px; width: 260px; }
.pop-head { display: flex; justify-content: space-between; align-items: center; }
.pop-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #d9d2c4; cursor: pointer; padding: 0; position: relative; }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }
.swatches.big .sw { width: 40px; height: 40px; }
.sw.custom { display: grid; place-items: center; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); color: #fff; font-weight: 700; text-shadow: 0 0 3px #000; overflow: hidden; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.widths { display: flex; gap: 6px; }
.wbtn { flex: 1; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: #fff; display: grid; place-items: center; cursor: pointer; padding: 0 8px; }
.wbtn.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(30,58,138,.15); }
.wline { display: block; width: 100%; border-radius: 6px; }

body.is-preview .topbar { border-bottom-color: #ecdca8; }

/* admin */
.row-item.static { cursor: default; }
.row-item.static:hover { background: transparent; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 600; flex: none; }
.chip.ok { background: #e3f3e8; color: var(--ok); }
.chip.warn { background: #fdf0dc; color: var(--warn); }
.note.ok { background: #e3f3e8; color: #14532d; }
a.banner { color: inherit; }
