/* ------------------------------------------------------------ tema */
:root {
  --bg: #f5f4f0; --surface: #ffffff; --ink: #1d2024; --muted: #6a7078; --line: #e3e1da;
  --accent: #2f6f5e; --accent-ink: #ffffff; --accent-soft: #e2efea;
  --danger: #b42318; --ok: #1a7f4b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 6px 18px rgba(0, 0, 0, .05);
  --radius: 12px;
}
html[data-theme="dark"] {
  --bg: #15171a; --surface: #1e2125; --ink: #e8e6e1; --muted: #9aa0a6; --line: #32363b;
  --accent: #6fb5a0; --accent-ink: #0f1a17; --accent-soft: #23322d;
  --danger: #f97066; --ok: #47cd89; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #15171a; --surface: #1e2125; --ink: #e8e6e1; --muted: #9aa0a6; --line: #32363b;
    --accent: #6fb5a0; --accent-ink: #0f1a17; --accent-soft: #23322d;
    --danger: #f97066; --ok: #47cd89; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 14px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
code { background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); font-size: .9rem; }
.ok-text { color: var(--ok); }
.center { text-align: center; }
.inline { display: inline; }
.js .nojs-only { display: none; }

/* ------------------------------------------------------------ topo */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 24px; position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { color: var(--ink); font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.nav a.on, .nav a:hover { color: var(--ink); background: var(--accent-soft); text-decoration: none; }
.usermenu { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 72px; }
.crumbs { margin: 0 0 12px; }
.block { margin-bottom: 28px; }

/* ------------------------------------------------------------ formulários e botões */
input[type=text], input[type=password], input[type=search], input[type=number], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: 14px 0 4px; font-size: .9rem; color: var(--muted); }
button, .btn {
  display: inline-block; padding: 9px 16px; border: 0; border-radius: 9px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.alt, button.alt { background: var(--accent-soft); color: var(--accent); }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.link-danger { background: none; color: var(--danger); padding: 0; font-weight: 500; }
button.icon { background: transparent; color: var(--ink); border: 1px solid var(--line); padding: 4px 10px; }
.small { padding: 5px 11px; font-size: .88rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.narrow { max-width: 400px; margin: 40px auto; }
.form-card { max-width: 720px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.actions.subtle { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; border: 1px solid var(--line); background: var(--surface); word-break: break-word; }
.flash.erro { color: var(--danger); border-color: var(--danger); }
.flash.ok { color: var(--ok); }

/* ------------------------------------------------------------ envio */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 16px 20px; background: var(--surface); transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-body { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: space-between; }
.dz-body input[type=file] { width: auto; max-width: 320px; }
.upload-list { list-style: none; margin: 0; padding: 0; }
.upload-list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 0; border-top: 1px solid var(--line); margin-top: 8px; font-size: .92rem; }
.upload-list progress { grid-column: 1 / -1; width: 100%; height: 6px; accent-color: var(--accent); }
.upload-list .err { color: var(--danger); } .upload-list .good { color: var(--ok); }

/* ------------------------------------------------------------ biblioteca */
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 28px; align-items: start; }
.filters ul { list-style: none; margin: 0; padding: 0; }
.filters li a { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; border-radius: 7px; color: var(--ink); font-size: .93rem; }
.filters li a:hover { background: var(--accent-soft); text-decoration: none; }
.filters li a.on, .toolbar-right a.on, .tabs a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count { color: var(--muted); font-size: .8rem; font-weight: 400; }
.tagcloud { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: .85rem; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on .count { color: inherit; opacity: .8; }
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar-right { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.toolbar-right a { padding: 3px 9px; border-radius: 7px; color: var(--ink); font-size: .9rem; }
.toolbar-right .sep { width: 1px; height: 18px; background: var(--line); margin: 0 6px; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.empty { text-align: center; padding: 56px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 28px; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tabs a { padding: 6px 14px; border-radius: 8px; color: var(--ink); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 24px 18px; }
.grid-small { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.card-book .cover-link { position: relative; display: block; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); aspect-ratio: 2 / 3; background: var(--line); }
.card-book .cover-link:hover { transform: translateY(-2px); transition: transform .12s; text-decoration: none; }
.cover-img, .cover-ph { width: 100%; height: 100%; display: block; object-fit: cover; }
.cover-ph {
  display: flex; align-items: flex-end; padding: 12px; font-weight: 600; font-size: .9rem; line-height: 1.25; color: #fff; overflow: hidden;
  background: linear-gradient(160deg, hsl(var(--h) 42% 40%), hsl(calc(var(--h) + 35) 48% 26%));
}
.cover-ph span { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.badge { position: absolute; top: 6px; left: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; letter-spacing: .04em; }
.fav-mark { position: absolute; top: 4px; right: 7px; color: #ffc83d; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.done { position: absolute; bottom: 6px; right: 6px; background: var(--ok); color: #fff; width: 22px; height: 22px; border-radius: 50%; text-align: center; line-height: 22px; font-size: .8rem; }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(0, 0, 0, .35); }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar.big { position: static; height: 8px; border-radius: 6px; background: var(--line); overflow: hidden; flex: 1; max-width: 320px; }
.meta { padding-top: 8px; }
.meta .title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 600; color: var(--ink); line-height: 1.3; }
.meta .author { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

table.list { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.list th, table.list td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
table.list .title { font-weight: 600; color: var(--ink); }
td.thumb { width: 46px; }
.cover-img.mini, .cover-ph.mini { width: 36px; height: 54px; border-radius: 4px; font-size: .5rem; padding: 3px; }
.row-actions { white-space: nowrap; }
.row-actions form { margin-right: 4px; }
.badge-inline { background: var(--danger); color: #fff; padding: 1px 7px; border-radius: 999px; font-size: .72rem; }
.invite-link { margin-right: 6px; }

/* ------------------------------------------------------------ página do livro */
.detail { display: grid; grid-template-columns: 240px 1fr; gap: 32px; align-items: start; margin-bottom: 36px; }
.detail-cover { aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); background: var(--line); }
.lead { font-size: 1.1rem; margin: -6px 0 6px; }
.progress-line { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; }
.description { max-width: 70ch; white-space: pre-line; }
.facts { display: grid; grid-template-columns: 110px 1fr; gap: 6px 16px; margin: 20px 0 0; max-width: 620px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; word-break: break-word; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat strong { display: block; font-size: 1.4rem; } .stat span { color: var(--muted); font-size: .85rem; }

/* ------------------------------------------------------------ leitor */
html[data-rtheme="light"] body.reader { --r-bg: #ffffff; --r-fg: #1d2024; --r-line: #e3e1da; --r-bar: #f7f6f2; }
html[data-rtheme="sepia"] body.reader { --r-bg: #f4ecd8; --r-fg: #433422; --r-line: #dccfb0; --r-bar: #ece2c8; }
html[data-rtheme="dark"] body.reader { --r-bg: #121416; --r-fg: #d6d3cc; --r-line: #2d3136; --r-bar: #1a1d20; }
body.reader {
  --r-bg: #ffffff; --r-fg: #1d2024; --r-line: #e3e1da; --r-bar: #f7f6f2;
  margin: 0; height: 100vh; display: flex; flex-direction: column; background: var(--r-bg); color: var(--r-fg); overflow: hidden;
}
.rbar, .rfoot { display: flex; align-items: center; gap: 10px; padding: 7px 12px; background: var(--r-bar); border-color: var(--r-line); }
.rbar { border-bottom: 1px solid var(--r-line); }
.rfoot { border-top: 1px solid var(--r-line); justify-content: space-between; }
.rtitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rtools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.rbtn, .rselect { background: transparent; color: var(--r-fg); border: 1px solid var(--r-line); border-radius: 8px; padding: 4px 10px; font: inherit; font-size: .88rem; font-weight: 500; text-decoration: none; cursor: pointer; width: auto; }
.rbtn:hover { background: var(--r-line); text-decoration: none; filter: none; }
.rselect option { color: #1d2024; }
.rpct { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; opacity: .8; }
.rpos { opacity: .85; font-size: .92rem; }
.rpos input { width: 4.5em; padding: 2px 6px; background: transparent; color: var(--r-fg); border: 1px solid var(--r-line); border-radius: 6px; text-align: center; }
#stage { flex: 1; position: relative; overflow: auto; background: var(--r-bg); }
body.reader[data-kind="epub"] #stage { overflow: hidden; }
#viewer { height: 100%; }
body.reader[data-kind="pdf"] #viewer { display: flex; justify-content: center; align-items: flex-start; padding: 12px; min-height: 100%; height: auto; }
.pdf-canvas { background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, .3); max-width: none; }
html[data-rtheme="dark"] .pdf-canvas { filter: invert(.9) hue-rotate(180deg); }
html[data-rtheme="sepia"] .pdf-canvas { filter: sepia(.35); }
.txt { max-width: 70ch; margin: 0 auto; padding: 28px 18px 90px; white-space: pre-wrap; word-wrap: break-word; font: var(--txt-size, 18px) / 1.7 Georgia, "Times New Roman", serif; }
.rmsg { position: absolute; left: 0; right: 0; top: 40%; text-align: center; margin: 0; opacity: .8; padding: 0 20px; z-index: 3; }
.rmsg.error { color: var(--danger); opacity: 1; }
#toc { position: absolute; left: 0; top: 49px; bottom: 49px; width: min(330px, 88vw); overflow: auto; z-index: 6; background: var(--r-bar); border-right: 1px solid var(--r-line); box-shadow: 4px 0 18px rgba(0, 0, 0, .18); }
.toc-head { padding: 12px 14px; font-weight: 700; border-bottom: 1px solid var(--r-line); }
#toc ul { list-style: none; margin: 0; padding: 6px 0; }
#toc a { display: block; padding: 6px 14px; color: var(--r-fg); font-size: .92rem; }
#toc a:hover { background: var(--r-line); text-decoration: none; }

/* ------------------------------------------------------------ telas pequenas */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .filters { order: 2; }
  .detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 200px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .search { order: 5; max-width: none; flex-basis: 100%; }
  .usermenu { margin-left: auto; }
}
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .two, .three { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .rtools .rselect, #btn-flow { display: none; }
}
