:root{
  --bg:#f5f6ff;
  --panel:#ffffff;
  --panel2:#eef0ff;
  --text:#1c2250;
  --ink:#12163a;
  --muted:#4f5a9a;
  --accent:#4f5dff;
  --accent2:#7a3cff;
  --cyan:#2ad4d0;
  --ring:rgba(79,93,255,.28);
  --ok:#1fa971;
  --danger:#e5534b;
  --border:rgba(89,103,255,.22);
  --radius:16px;
  --head-height:72px;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth}
html,body{
  margin:0;padding:0;
  background:
    radial-gradient(circle at 10% 0%, rgba(122,60,255,.12), transparent 34%),
    radial-gradient(circle at 90% 20%, rgba(42,212,208,.1), transparent 30%),
    linear-gradient(180deg, #f5f6ff 0%, #ebefff 45%, #f7f8ff 100%);
  color:var(--text);
  font:16px/1.55 "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
img{max-width:100%; display:block}
a{color:var(--accent2); text-decoration:none}
a:hover{color:var(--accent)}
button{font:inherit}

.container{width:min(1120px, 92vw); margin-inline:auto}
main.container{padding:32px 0 72px}
.site-header{
  position:sticky; top:0; z-index:20;
  background:rgba(245,246,255,.94);
  border-bottom:1px solid var(--border);
  box-shadow:0 8px 24px rgba(55,70,180,.08);
  backdrop-filter:blur(10px);
}
.header-inner{display:flex; align-items:center; justify-content:space-between; gap:18px; min-height:var(--head-height)}
.logo{display:flex; align-items:center; gap:12px; color:var(--ink); min-width:0}
.logo:hover{color:var(--ink); text-decoration:none}
.logo-mark{width:48px; height:auto; flex-shrink:0; filter:drop-shadow(0 6px 14px rgba(20,30,90,.22))}
.logo-text{display:flex; flex-direction:column; line-height:1.15}
.logo-name{
  font-weight:800; font-size:22px; letter-spacing:.04em;
  background:linear-gradient(90deg, #12163a 0%, #4f5dff 62%, #2ad4d0 100%);
  -webkit-background-clip:text; background-clip:text; color:transparent;
}
.logo-sub{font-size:13px; font-weight:600; color:var(--muted)}
.nav{display:flex; gap:18px; align-items:center; flex-wrap:wrap}
.nav a{color:var(--ink); font-weight:700; font-size:15px}
.nav a:hover{color:var(--accent2); text-decoration:none}
.nav-back{
  display:inline-flex; align-items:center; gap:6px;
  padding:8px 14px; border-radius:12px;
  border:1px solid var(--border); background:#fff;
  box-shadow:0 6px 16px rgba(70,85,190,.08);
}
.nav a.nav-back:hover{background:rgba(79,93,255,.08); color:var(--accent2)}

.site-footer{
  background:linear-gradient(180deg, #171d52 0%, #12163a 100%);
  color:#b8c4ff;
  padding:28px 0;
  border-top:1px solid rgba(120,140,255,.2);
}
.footer-inner{display:flex; flex-wrap:wrap; gap:18px; justify-content:space-between; align-items:center}
.footer-inner strong{color:#fff; letter-spacing:.04em}
.footer-inner p{margin:6px 0 0}
.site-footer nav{display:flex; flex-wrap:wrap; gap:14px}
.site-footer a{color:#dce3ff; font-weight:600}
.site-footer a:hover{color:var(--cyan)}
.copy{margin:0; font-size:13px; color:#9aa8e8}

.card{
  background:linear-gradient(160deg, #ffffff 0%, #f0f2ff 100%);
  border:1px solid var(--border); border-radius:var(--radius); padding:20px;
  box-shadow:0 10px 24px rgba(70,85,190,.08);
}
.muted{color:var(--muted)}
.eyebrow{
  margin:8px 0 0;
  color:var(--accent2);
  text-transform:uppercase;
  letter-spacing:.12em;
  font-size:12px;
  font-weight:700;
}
.page-title, main h1{
  margin:8px 0 12px;
  font-size:clamp(28px, 4vw, 42px);
  line-height:1.15;
  color:var(--ink);
  font-weight:800;
}
.empty-state{padding:40px; text-align:center}

/* Каталог */
.books-grid{display:grid; grid-template-columns:repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap:14px; margin-top:22px; justify-content:start}
.book-card{display:flex; gap:16px; align-items:flex-start; padding:18px; transition:transform .2s ease, border-color .2s ease, box-shadow .2s ease}
.book-card:hover{transform:translateY(-3px); border-color:rgba(79,93,255,.4); box-shadow:0 14px 30px rgba(70,85,190,.14)}
.book-cover{width:132px; flex:0 0 132px}
.book-cover img{border-radius:12px; aspect-ratio:0.72; width:100%; object-fit:cover; background:var(--panel2);
  transition:transform .18s ease, box-shadow .18s ease; box-shadow:0 10px 22px rgba(55,70,180,.18)}
.book-cover:hover img{transform:translateY(-2px) scale(1.01); box-shadow:0 14px 28px rgba(55,70,180,.28)}
.book-title{margin:0 0 4px; font-size:20px; line-height:1.25}
.book-title a{color:var(--ink)}
.book-title a:hover{color:var(--accent2); text-decoration:none}
.book-author{color:var(--accent2); font-weight:700; margin-bottom:8px}
.book-author.big{font-size:18px}
.book-desc{color:var(--muted); margin:0 0 12px; max-height:6.2em; overflow:hidden}
.book-desc-full{margin:14px 0 18px; color:var(--text); line-height:1.7}
.book-bibliography{margin:18px 0 8px; padding-top:14px; border-top:1px solid var(--border)}
.book-bibliography h2{margin:0 0 12px; font-size:18px; color:var(--ink)}
.bib-list{margin:0; padding-left:1.35em; color:var(--text); line-height:1.55; display:flex; flex-direction:column; gap:10px}
.bib-list li{padding-left:4px}
.bib-row{grid-template-columns:36px 1fr 36px !important}
.bib-text-input{width:100%; min-height:56px; resize:vertical; font:inherit; border:1px solid var(--border); border-radius:10px; padding:8px 10px; color:var(--ink); background:#fff}
.book-actions{display:flex; gap:10px; margin-top:10px; flex-wrap:wrap}

/* Мета-инфо: DOI/ISBN */
.meta-badges{display:flex; gap:8px; flex-wrap:wrap; margin:0 0 8px}
.meta-badge{display:inline-block; background:#fff; border:1px solid var(--border); color:var(--accent2);
  padding:3px 8px; border-radius:999px; font-size:12px; font-weight:700; letter-spacing:.2px}
a.meta-badge:hover{text-decoration:none; border-color:var(--accent); color:var(--accent); background:rgba(79,93,255,.08)}
.meta-list{list-style:none; padding:0; margin:14px 0; display:flex; flex-direction:column; gap:10px}
.meta-list strong{color:var(--ink); margin-right:6px}

/* Сетка форм */
.form-grid{display:grid; gap:14px}
.form-grid-2{grid-template-columns:1fr 1fr}
@media (max-width:760px){ .form-grid-2{grid-template-columns:1fr} }
.form-note{display:flex; align-items:end; padding-bottom:2px}

/* Страница книги */
.book-page{display:grid; grid-template-columns:320px 1fr; gap:22px; margin-top:18px}
.book-page-cover img{border-radius:16px; box-shadow:0 16px 36px rgba(55,70,180,.22)}
.book-page-info{padding:26px}
@media (max-width:900px){ .book-page{grid-template-columns:1fr} .book-page-cover{max-width:280px} }

/* Кнопки */
.btn{appearance:none; border:0; text-decoration:none;
  background:linear-gradient(145deg, var(--accent), var(--accent2));
  color:#fff; padding:12px 16px; border-radius:12px; cursor:pointer; display:inline-flex; align-items:center; gap:8px;
  font-weight:700; letter-spacing:.2px; box-shadow:0 10px 24px rgba(79,93,255,.28);
  transition:transform .12s ease, filter .12s ease;}
.btn:hover{filter:brightness(1.06); color:#fff; text-decoration:none}
.btn:active{transform:translateY(1px)}
.btn-sm{padding:8px 12px; border-radius:10px; font-weight:700; font-size:14px; box-shadow:0 6px 16px rgba(79,93,255,.22)}
.btn-lg{padding:14px 22px; font-size:18px}
.btn-ghost{background:#fff; border:1px solid var(--border); color:var(--ink); box-shadow:none}
.btn-ghost:hover{background:rgba(79,93,255,.08); color:var(--accent2); filter:none}
.btn-danger{background:linear-gradient(145deg, #f0716a, #c83b34); color:#fff; box-shadow:0 8px 18px rgba(229,83,75,.25)}
.btn-danger:hover{color:#fff}
.btn:disabled{opacity:.45; cursor:default; filter:none}
.btn-block{width:100%; justify-content:center}

/* Читалка */
.reader-topbar{position:sticky; top:var(--head-height); z-index:9; display:flex; align-items:center; justify-content:space-between; gap:14px;
  padding:12px 0 14px; margin:0 0 14px; background:rgba(245,246,255,.94); backdrop-filter:blur(10px);
  border-bottom:1px solid var(--border)}
.reader-title{display:flex; flex-direction:column; align-items:center; text-align:center; min-width:220px; color:var(--ink)}
.reader-nav{display:flex; align-items:center; gap:10px}
.page-indicator{display:inline-flex; align-items:center; gap:6px; color:var(--ink); font-weight:700}
.page-indicator input{width:64px; background:#fff; color:var(--ink); border:1px solid var(--border); border-radius:8px; padding:6px 8px; text-align:center; font:inherit}
.zoom-label{display:inline-flex; align-items:center; gap:6px; color:var(--muted); font-size:13px; font-weight:600}
.zoom-label select{background:#fff; color:var(--ink); border:1px solid var(--border); border-radius:8px; padding:6px 8px; font:inherit}

.reader-layout{display:grid; grid-template-columns:300px 1fr; gap:18px; align-items:start}
@media (max-width:1100px){ .reader-layout{grid-template-columns:1fr} .reader-aside{order:2} }

.reader-aside{position:sticky; top:calc(var(--head-height) + 78px); padding:16px}
.reader-aside h3{margin:16px 0 8px; font-size:13px; color:var(--accent2); text-transform:uppercase; letter-spacing:.08em}
.aside-actions{margin-bottom:6px}
.aside-list{list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:8px; max-height:260px; overflow:auto}
.aside-item{display:flex; align-items:center; justify-content:space-between; gap:10px; background:#fff;
  border:1px solid var(--border); border-radius:12px; padding:8px 10px}
.aside-item .link{background:none; border:none; color:var(--accent2); padding:0; cursor:pointer; font-weight:700}
.aside-item .link:hover{text-decoration:underline}
.aside-item .link.danger{color:var(--danger)}
.comment-item{flex-direction:column; align-items:stretch}
.comment-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:4px}
.comment-text{color:var(--text); white-space:pre-wrap}
.comment-new{display:flex; flex-direction:column; gap:8px; margin:8px 0 12px}
.comment-new textarea{background:#fff; color:var(--ink); border:1px solid var(--border); border-radius:12px; padding:10px; font:inherit}
.aside-hint{font-size:13px; margin-top:14px}

/* Оглавление PDF */
.toc-panel{margin:6px 0 4px; padding:10px; background:#fff;
  border:1px solid var(--border); border-radius:12px}
.toc-panel h3{margin:0 0 8px}
.toc-list{list-style:none; padding:0; margin:0; max-height:40vh; overflow:auto; display:flex; flex-direction:column; gap:2px}
.toc-item{display:block; width:100%; text-align:left; background:none; border:none; color:var(--text);
  padding:6px 8px; border-radius:8px; cursor:pointer; font-size:14px; line-height:1.35;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.toc-item:hover{background:rgba(79,93,255,.1); color:var(--ink)}
.toc-item.lv1{font-weight:700}
.toc-item.lv2{padding-left:22px}
.toc-item.lv3{padding-left:38px; font-size:13px; color:var(--muted)}
.toc-item.lv4{padding-left:54px; font-size:13px; color:var(--muted)}

/* Редактор оглавления на admin/edit.php */
.toc-editor{margin-top:4px}
.toc-rows{display:flex; flex-direction:column; gap:6px}
.toc-row{display:grid; grid-template-columns:36px 1fr 90px 36px; gap:6px; align-items:center;
  background:#fff; border:1px solid var(--border); border-radius:10px; padding:6px 8px;
  transition:background .12s, box-shadow .12s, opacity .12s}
.toc-row.is-dragging{opacity:.45; background:rgba(79,93,255,.06)}
.toc-row.is-drop-before{box-shadow:inset 0 2px 0 0 var(--accent, #4f5dff)}
.toc-row.is-drop-after{box-shadow:inset 0 -2px 0 0 var(--accent, #4f5dff)}
.toc-row-num,.toc-row-handle{
  text-align:center; font-size:13px; font-weight:800; color:var(--muted);
  cursor:grab; user-select:none; touch-action:none; padding:8px 4px; border-radius:8px; line-height:1}
.toc-row-handle:hover{background:rgba(79,93,255,.1)}
.toc-row-handle:active,body.toc-dragging .toc-row-handle{cursor:grabbing}
body.toc-dragging{cursor:grabbing; user-select:none}
.toc-title-input{width:100%}
.toc-page-input{width:100%; text-align:right}
.toc-del-btn{padding:4px 8px; opacity:.7}
.toc-del-btn:hover{opacity:1; color:#c83b34}
.toc-editor-actions{display:flex; gap:6px; margin-top:10px; flex-wrap:wrap}

.reader-stage{position:relative; display:flex; justify-content:center; min-height:70vh; padding:18px;
  background:linear-gradient(180deg, rgba(79,93,255,.08), rgba(122,60,255,.04));
  border:1px solid var(--border); border-radius:16px}
#pdfCanvas{box-shadow:0 18px 40px rgba(55,70,180,.22); border-radius:8px; background:#fff}
.reader-loading{position:absolute; inset:0; display:flex; align-items:center; justify-content:center; color:var(--muted); font-size:18px}
.reader-loading::after{content:""; width:18px; height:18px; margin-left:10px; border-radius:50%;
  border:3px solid rgba(79,93,255,.2); border-top-color:var(--accent); animation:spin 1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Всплывающая подсказка (user discovery) */
.tooltip-pop{position:absolute; right:12px; top:calc(100% + 8px); z-index:30; max-width:230px;
  background:#fff; color:var(--text); border:1px solid var(--border); border-radius:12px;
  padding:10px 12px; font-size:13px; line-height:1.4; box-shadow:0 14px 34px rgba(55,70,180,.18);
  animation:tip-in .25s ease}
.tooltip-pop b{color:var(--ink)}
@keyframes tip-in{from{opacity:0; transform:translateY(-4px)} to{opacity:1; transform:none}}
.reader-nav{position:relative}
.aside-actions .btn{margin-bottom:8px}
.aside-actions .btn:last-child{margin-bottom:0}

/* Админка */
.admin-login{max-width:420px; margin:48px auto}
.admin-login input{width:100%; background:#fff; color:var(--ink); border:1px solid var(--border); border-radius:12px; padding:12px; margin:8px 0 14px; font:inherit}
.admin-head{display:flex; align-items:center; justify-content:space-between; gap:12px; margin:8px 0 14px; flex-wrap:wrap}
.admin-table{width:100%; border-collapse:collapse}
.admin-table th,.admin-table td{padding:12px 10px; border-bottom:1px solid rgba(89,103,255,.14); text-align:left; vertical-align:middle}
.admin-table th{color:var(--muted); font-weight:700; font-size:13px; text-transform:uppercase; letter-spacing:.05em}
.admin-actions{display:flex; gap:8px; flex-wrap:wrap}
.form label{display:block; margin:14px 0 6px; color:var(--ink); font-weight:700}
.form input[type=text], .form input[type=number], .form input[type=password], .form textarea, .form select{
  width:100%; background:#fff; color:var(--ink); border:1px solid var(--border); border-radius:12px; padding:12px; font:inherit}
.form input:focus, .form textarea:focus, .form select:focus, .admin-login input:focus, .comment-new textarea:focus, .page-indicator input:focus{
  outline:none; border-color:var(--cyan); box-shadow:0 0 0 3px rgba(42,212,208,.2)}
.form input[type=file]{width:100%; padding:10px; border:1px dashed rgba(89,103,255,.35); border-radius:12px; background:#fff}
.form-actions{display:flex; gap:10px; margin-top:18px}
.alert{padding:12px 14px; border-radius:12px; margin:12px 0}
.alert-ok{background:rgba(31,169,113,.12); border:1px solid rgba(31,169,113,.4); color:#0e7a4e}
.alert-error{background:rgba(229,83,75,.1); border:1px solid rgba(229,83,75,.4); color:#a32d27}

/* Раздел «Авторам» */
.authors-layout{display:grid; grid-template-columns:1fr auto; gap:18px; margin-top:18px; align-items:start}
@media (max-width:980px){
  .authors-layout{grid-template-columns:1fr}
  .authors-company{justify-self:center}
}
.section-title{margin:0 0 14px; font-size:22px; color:var(--ink)}
.authors-info{color:var(--text); font-size:16px; line-height:1.7}
.authors-company{--cover:72px; --shelf-gap:8px; width:max-content; max-width:100%; justify-self:end; display:flex; flex-direction:column; align-items:center; justify-content:flex-start; padding:14px 12px 12px; min-height:0}
.authors-brand-logo{width:calc(var(--cover) * 3 + var(--shelf-gap) * 2); max-width:100%; height:auto; object-fit:contain; filter:drop-shadow(0 8px 16px rgba(20,30,90,.16))}
.authors-shelf{width:max-content; max-width:100%; margin-top:16px; display:grid; grid-template-columns:repeat(3, var(--cover)); grid-template-rows:repeat(4, auto); gap:var(--shelf-gap)}
.authors-shelf-slot{aspect-ratio:.72; border-radius:10px; overflow:hidden; background:#fff; border:1px solid var(--border)}
.authors-shelf-slot img{width:100%; height:100%; object-fit:cover; display:block}
.authors-shelf-empty{background:transparent; border-style:dashed; border-color:rgba(89,103,255,.2)}
.company-table{width:100%; border-collapse:separate; border-spacing:0 10px}
.company-table th{width:110px; text-align:left; vertical-align:top; color:var(--muted); font-weight:700; padding:6px 12px 6px 0; white-space:nowrap}
.company-table td{vertical-align:top; padding:6px 0}
.company-logo{max-width:220px; max-height:110px; width:auto; height:auto; background:#fff; padding:10px 12px; border-radius:12px; display:inline-block; box-shadow:0 8px 18px rgba(55,70,180,.12); border:1px solid var(--border)}
.logo-placeholder{display:inline-block; padding:14px 22px; border-radius:12px; background:linear-gradient(145deg, var(--accent), var(--accent2));
  color:#fff; font-weight:800; letter-spacing:3px}
.logo-row{display:flex; align-items:center; gap:14px; margin-bottom:10px; flex-wrap:wrap}
.logo-row .company-logo{max-width:160px; max-height:80px; padding:8px 10px}
.checkbox{display:inline-flex; align-items:center; gap:8px; color:var(--muted); font-weight:600; cursor:pointer}
.edit-grid{display:grid; grid-template-columns:1fr 280px; gap:22px}
@media (max-width:900px){ .edit-grid{grid-template-columns:1fr} }
.cover-frame{background:#fff; border:1px solid var(--border); border-radius:12px; padding:12px}

@media (max-width:760px){
  .header-inner{flex-wrap:wrap; min-height:0; padding:12px 0}
  .nav{width:100%; gap:12px 16px}
  .reader-topbar{position:static; flex-wrap:wrap}
  .reader-title{min-width:0; align-items:flex-start; text-align:left}
  .books-grid{grid-template-columns:1fr}
  .book-card{flex-direction:column}
  .book-cover{width:160px}
}
