/* Библиотека Шамины — бордово-бумажная тема */
:root {
  --paper: #f6f1e7;
  --panel: #fffdf8;
  --ink: #2b2320;
  --muted: #8a7f74;
  --line: #e3d9c8;
  --accent: #7b2333;
  --accent-dark: #5c1a26;
  --accent-light: #a8394d;
  --gold: #b98a2f;
  --ok: #3d7a4a;
  --err: #a33030;
  --shadow: 0 2px 10px rgba(60, 40, 20, .12);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
h1, h2, h3, .brand-text, .book-title { font-family: Georgia, "Times New Roman", serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
mark { background: #ffe9a8; color: inherit; padding: 0 1px; border-radius: 2px; }

/* ---------- кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font-size: 14px;
  cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--accent-light); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--err); }
.btn-danger:hover { border-color: var(--err); }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.btn-ghost:hover { border-color: #fff; color: #fff; }
.btn-wide { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-light); }

/* ---------- вход ---------- */
#login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--accent-dark), var(--accent) 55%, #8f3040);
}
.login-card {
  background: var(--panel); border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,.35);
  padding: 38px 42px; width: 360px; text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 2px; font-size: 26px; color: var(--accent-dark); }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card input { width: 100%; margin-bottom: 10px; }
.login-error { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- шапка ---------- */
#topbar {
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  color: #fff; padding: 10px 22px; box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 26px; }
.brand-text { font-size: 19px; line-height: 1.1; display: flex; flex-direction: column; }
.brand-text small { font-size: 11px; opacity: .75; font-family: inherit; }
#search-form { display: flex; gap: 8px; flex: 1; min-width: 260px; max-width: 620px; }
#search-form input { flex: 1; border: none; }
#search-form select { border: none; background: #fff; }
#mainnav { display: flex; gap: 4px; }
#mainnav a {
  color: #fff; padding: 7px 12px; border-radius: 8px; font-size: 14px; opacity: .85;
}
#mainnav a:hover { background: rgba(255,255,255,.12); text-decoration: none; opacity: 1; }
#mainnav a.active { background: rgba(255,255,255,.2); opacity: 1; }
#usermenu { position: relative; margin-left: auto; }
#user-dropdown {
  position: absolute; right: 0; top: 110%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  min-width: 180px; overflow: hidden; z-index: 60;
}
#user-dropdown button {
  display: block; width: 100%; text-align: left; padding: 10px 14px;
  border: none; background: none; font: inherit; cursor: pointer; color: var(--ink);
}
#user-dropdown button:hover { background: var(--paper); color: var(--accent); }

/* ---------- каркас страниц ---------- */
#view { max-width: 1280px; margin: 0 auto; padding: 22px; }
.layout { display: flex; gap: 22px; align-items: flex-start; }
.sidebar {
  width: 288px; flex-shrink: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.sidebar h3 { margin: 4px 0 10px; font-size: 15px; color: var(--accent-dark); }
#cat-tree, #cat-tree-admin { max-height: 72vh; overflow-y: auto; }
.cat-item {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  border-radius: 7px; cursor: pointer; font-size: 14px;
}
.cat-item:hover { background: var(--paper); }
.cat-item.active { background: var(--accent); color: #fff; }
.cat-item .cat-name { flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.cat-item .n { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.cat-item.active .n { color: rgba(255,255,255,.85); }
.cat-tw { width: 14px; flex-shrink: 0; text-align: center; color: var(--muted);
  font-size: 11px; user-select: none; }
.cat-tw.leaf { color: var(--line); }
.cat-item.active .cat-tw { color: rgba(255,255,255,.85); }
.cat-tw:not(.leaf):hover { color: var(--accent-dark); }
.scan-status { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.scan-status .scan-line { margin-bottom: 6px; }
.scan-status code { font-size: 12px; word-break: break-all; }
.content { flex: 1; min-width: 0; }

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px;
}
.toolbar .spacer { flex: 1; }
.count-note { color: var(--muted); font-size: 13px; }

/* ---------- статистика ---------- */
.stats-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 20px; min-width: 130px;
}
.stat-card .v { font-size: 22px; font-weight: 700; color: var(--accent-dark); font-family: Georgia, serif; }
.stat-card .l { font-size: 12px; color: var(--muted); }

/* ---------- сетка книг ---------- */
.book-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px;
}
.book-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: .15s; position: relative;
  display: flex; flex-direction: column;
}
.book-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--accent-light); }
.book-cover {
  aspect-ratio: 3/4; background: linear-gradient(150deg, #e8ddc9, #d6c6a8);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .ph { font-size: 44px; opacity: .5; }
.book-card .info { padding: 10px 12px 12px; }
.book-title { font-size: 14px; font-weight: 700; line-height: 1.3; margin: 0 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta { font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block; font-size: 10.5px; padding: 2px 7px; border-radius: 20px;
  background: var(--paper); border: 1px solid var(--line); color: var(--muted);
  margin-right: 4px; text-transform: uppercase; letter-spacing: .4px;
}
.badge.fmt-pdf { color: #8c2b2b; border-color: #dcc0c0; }
.badge.fmt-djvu { color: #2b5e8c; border-color: #c0cfdc; }
.badge.st-error { color: var(--err); border-color: var(--err); }
.badge.st-indexing, .badge.st-pending { color: var(--gold); border-color: var(--gold); }
.fav-star {
  position: absolute; top: 8px; right: 8px; font-size: 18px; cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.4));
}

/* ---------- пагинация ---------- */
.pager { display: flex; gap: 6px; justify-content: center; margin: 22px 0 6px; flex-wrap: wrap; }
.pager button {
  min-width: 34px; padding: 6px 9px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 7px; cursor: pointer; font: inherit; font-size: 13px;
}
.pager button.cur { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager button:disabled { opacity: .4; cursor: default; }

/* ---------- результаты полнотекстового поиска ---------- */
.hit {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 12px;
}
.hit h3 { margin: 0 0 4px; font-size: 16px; }
.hit .snippet { font-size: 14px; margin: 8px 0; color: #4a4038; }
.hit .src { font-size: 12.5px; color: var(--muted); }

/* ---------- карточка книги ---------- */
.book-page { display: flex; gap: 26px; align-items: flex-start; flex-wrap: wrap; }
.book-page .cover-col { width: 260px; flex-shrink: 0; }
.book-page .cover-col img {
  width: 100%; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.book-page .detail-col { flex: 1; min-width: 300px; }
.book-page h1 { margin: 0 0 6px; font-size: 26px; color: var(--accent-dark); }
.meta-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.meta-table td { padding: 5px 0; vertical-align: top; }
.meta-table td:first-child { color: var(--muted); width: 130px; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-top: 18px;
}
.panel h3 { margin: 0 0 10px; font-size: 16px; color: var(--accent-dark); }
.inbook-hit {
  padding: 9px 4px; border-bottom: 1px dashed var(--line); cursor: pointer; font-size: 14px;
}
.inbook-hit:hover { background: var(--paper); }
.inbook-hit .pg { color: var(--accent); font-weight: 600; margin-right: 8px; white-space: nowrap; }
.bm-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.bm-row .pg { color: var(--accent); font-weight: 600; cursor: pointer; }
.bm-row .note { flex: 1; color: #4a4038; }
.bm-row .del { cursor: pointer; color: var(--muted); }
.bm-row .del:hover { color: var(--err); }

/* ---------- читалка ---------- */
#reader {
  position: fixed; inset: 0; z-index: 100; background: #241f1c;
  display: flex; flex-direction: column;
}
.reader-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: #1a1614; color: #e8ddc9; flex-wrap: wrap;
}
.reader-bar .title {
  font-family: Georgia, serif; font-size: 15px; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; max-width: 34vw;
}
.reader-bar .btn {
  background: #332c28; border-color: #4a413c; color: #e8ddc9; padding: 5px 11px;
}
.reader-bar .btn:hover { border-color: var(--gold); color: #fff; }
.reader-bar input.page-input {
  width: 60px; text-align: center; background: #332c28; border-color: #4a413c; color: #fff;
}
.reader-bar .total { color: #9c9088; font-size: 13px; }
.reader-body { flex: 1; display: flex; overflow: hidden; }
.reader-main { flex: 1; overflow: auto; text-align: center; padding: 16px; }
.reader-main img {
  max-width: 100%; box-shadow: 0 4px 24px rgba(0,0,0,.5); background: #fff;
}
.reader-main .loading { color: #9c9088; margin-top: 40vh; }
.reader-side {
  width: 320px; background: #2e2825; color: #e8ddc9; padding: 14px; overflow: auto;
  border-left: 1px solid #4a413c;
}
.reader-side h4 { margin: 2px 0 10px; }
.reader-side input { width: 100%; background: #241f1c; border-color: #4a413c; color: #fff; }
.reader-side .inbook-hit { border-color: #4a413c; }
.reader-side .inbook-hit:hover { background: #38312d; }
.reader-side .textview { white-space: pre-wrap; font-size: 13px; line-height: 1.55; color: #d8cdbd; }
.reader-side .rds-near { display: flex; gap: 6px; align-items: center; margin-top: 8px; font-size: 12.5px; color: #b8ad9d; }
.reader-side .rds-near input { width: 64px; }
.reader-side .rds-hint { font-size: 11.5px; color: #8c8175; margin-top: 6px; }

/* ---------- админка ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 2px solid var(--line); }
.tabs a {
  padding: 9px 16px; border-radius: 8px 8px 0 0; color: var(--muted); font-size: 14px;
}
.tabs a.active { background: var(--accent); color: #fff; }
.tabs a:hover { text-decoration: none; color: var(--accent); }
.tabs a.active:hover { color: #fff; }
table.list {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 14px;
}
table.list th, table.list td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
table.list th { background: var(--paper); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
table.list tr:hover td { background: #fbf7ee; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.drop-zone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px;
  text-align: center; color: var(--muted); cursor: pointer; transition: .15s; margin-bottom: 12px;
}
.drop-zone:hover, .drop-zone.over { border-color: var(--accent-light); color: var(--accent); background: #fbf5ec; }
.progress-bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress-bar > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- модальные окна ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(30, 20, 15, .55); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: 0 12px 50px rgba(0,0,0,.4);
  padding: 22px 26px; width: 560px; max-width: 100%; max-height: 90vh; overflow: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 20px; color: var(--accent-dark); }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- тосты ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #332c28; color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; animation: toast-in .2s;
}
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.empty { text-align: center; color: var(--muted); padding: 60px 0; }
.empty .big { font-size: 46px; }

/* ---------- полное название / подсказки метаданных ---------- */
.full-title { font-size: 15px; color: #4a4038; font-style: italic; margin: -2px 0 8px; }
.field-actions { display: flex; gap: 8px; align-items: flex-start; }
.field-actions textarea { flex: 1; }
.field-actions .btn { white-space: nowrap; margin-top: 2px; }
#bf-suggest-box { display: flex; flex-direction: column; gap: 6px; }
.suggest-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; background: #fff;
}
.suggest-item:hover { border-color: var(--accent-light); background: #fbf5ec; }
.suggest-title { font-size: 13.5px; color: var(--ink); }
.suggest-src { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ---------- опции поиска (расстояние, кавычки) ---------- */
.search-opts {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
}
.search-opts label { display: flex; gap: 6px; align-items: center; }
.search-opts .hint { color: var(--muted); font-size: 13px; margin-left: auto; }
.search-opts code {
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12.5px;
}

/* ---------- панель массового перемещения ---------- */
.move-bar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 14px; font-size: 14px; }
.move-bar #ab-selcount { color: var(--accent-dark); }
table.list td:first-child, table.list th:first-child { text-align: center; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .reader-side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; }
  .book-page .cover-col { width: 170px; }
}

/* ---------- индикатор загрузки ---------- */
#loadbar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 9999;
  background: transparent; overflow: hidden; pointer-events: none;
}
#loadbar.hidden { display: none; }
#loadbar .loadbar-fill {
  height: 100%; width: 40%; border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, var(--accent-light), var(--gold));
  animation: loadslide 1.1s ease-in-out infinite;
}
@keyframes loadslide {
  0% { margin-left: -42%; } 100% { margin-left: 102%; }
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.view-loading {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 60px 0; color: var(--muted);
}
.reader-main .loading {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted);
}

/* ---------- уточнение поиска ---------- */
.refine-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin: 8px 0 14px;
}
.refine-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0; }
.refine-label { color: var(--muted); font-size: 14px; }
.term-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.term-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; font-size: 14px;
}
.term-chip .x { cursor: pointer; color: var(--muted); font-size: 12px; }
.term-chip .x:hover { color: var(--err); }
#refine-input { flex: 1; min-width: 220px; }

/* ---------- страница-справка ---------- */
.help-page { max-width: 940px; margin: 0 auto; }
.help-hero { text-align: center; margin-bottom: 18px; }
.help-hero h1 { margin: 0 0 8px; }
.help-lead { color: var(--muted); font-size: 16px; line-height: 1.6; max-width: 760px; margin: 0 auto; }
.help-scheme {
  width: 100%; height: auto; display: block; margin: 8px auto 20px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px;
}
.help-h2 {
  margin: 26px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--line);
  color: var(--accent-dark);
}
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.help-card {
  display: flex; gap: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.help-card h3 { margin: 0 0 6px; font-size: 16px; }
.help-card p { margin: 0; color: var(--ink); line-height: 1.55; font-size: 14.5px; }
.help-ic { font-size: 30px; line-height: 1; flex-shrink: 0; }
.help-steps { line-height: 1.7; font-size: 15px; padding-left: 22px; }
.help-steps li { margin-bottom: 8px; }
.help-note {
  display: flex; gap: 14px; align-items: flex-start;
  background: linear-gradient(0deg, var(--paper), var(--panel));
  border: 1px solid var(--gold); border-left: 4px solid var(--gold);
  border-radius: var(--radius); padding: 16px 18px; margin: 18px 0;
}
.help-note h3 { margin: 0 0 6px; color: var(--accent-dark); }
.help-note p { margin: 0; line-height: 1.6; }
.help-foot { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: 22px; }
@media (max-width: 720px) { .help-grid { grid-template-columns: 1fr; } }

/* ---------- сверка названий ---------- */
.badge.src-badge { color: var(--ok); border-color: var(--ok); font-weight: 700; }
.verified-line {
  margin: 2px 0 8px; font-size: 13px; color: var(--ok);
}
.verified-line a { color: var(--accent); }
.verify-review {
  background: linear-gradient(0deg, var(--paper), var(--panel));
  border: 1px solid var(--gold); border-left: 4px solid var(--gold);
  border-radius: var(--radius); padding: 12px 14px; margin: 10px 0;
}
.vr-head { font-weight: 700; margin-bottom: 8px; color: var(--accent-dark); }
.vr-cand {
  padding: 8px 0; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 3px;
}
.vr-cand .vr-sub { font-size: 13px; color: var(--muted); }
.vr-cand button { align-self: flex-start; margin-top: 4px; }
.verify-admin { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.verify-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
