/* ============================================================
   Shelf — дизайн-система библиотеки
   Тёплая «бумажная» палитра, серифные заголовки, мягкие тени.
   ============================================================ */

:root {
  --paper:      #f6f2ea;
  --paper-2:    #efe8db;
  --surface:    #ffffff;
  --ink:        #221d18;
  --ink-soft:   #6b6151;
  --ink-faint:  #a89f8e;
  --line:       #e7ded0;
  --line-soft:  #f0e9dd;

  --brand:      #2f5d3a;
  --brand-dark: #244a2e;
  --brand-soft: #e9f0ea;
  --gold:       #b7892f;
  --gold-soft:  #f6edd8;

  --ok:     #2f7a43;
  --ok-bg:  #e6f2e9;
  --warn:   #9a6500;
  --warn-bg:#f8eed6;
  --danger: #b3261e;
  --danger-bg:#fae9e7;
  --info-bg:#e8eef6;

  --r-sm: 9px;
  --r:    14px;
  --r-lg: 20px;
  --pill: 999px;

  --shadow-sm: 0 1px 2px rgba(34,29,24,.06), 0 1px 3px rgba(34,29,24,.05);
  --shadow:    0 4px 14px rgba(34,29,24,.08), 0 2px 6px rgba(34,29,24,.05);
  --shadow-lg: 0 18px 40px rgba(34,29,24,.16), 0 6px 14px rgba(34,29,24,.08);

  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --maxw: 1120px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--gold-soft), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, var(--brand-soft), transparent 55%),
    var(--paper);
  background-attachment: fixed;
  line-height: 1.6;
  font-size: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; color: var(--ink); margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.7rem); }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.25rem; }

a { color: var(--brand); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--brand-dark); }

p { margin: 0 0 1rem; }
.muted { color: var(--ink-soft); }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2rem); }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.78);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.nav {
  display: flex; align-items: center; gap: 1rem;
  height: 68px;
}
.brand {
  display: inline-flex; align-items: center; gap: .6rem;
  font-family: var(--serif); font-weight: 600; font-size: 1.25rem;
  color: var(--ink); margin-right: auto;
}
.brand:hover { color: var(--ink); }
.brand .mark {
  width: 38px; height: 38px; border-radius: 11px;
  box-shadow: var(--shadow-sm); display: block;
}

.nav-links { display: flex; align-items: center; gap: .35rem; }
.nav-links a.navlink {
  padding: .5rem .8rem; border-radius: var(--r-sm);
  color: var(--ink-soft); font-weight: 500; font-size: .96rem;
  transition: background .15s ease, color .15s ease;
}
.nav-links a.navlink:hover { background: var(--paper-2); color: var(--ink); }
.nav-links a.navlink.active { color: var(--brand); background: var(--brand-soft); }

.nav-user { display: flex; align-items: center; gap: .6rem; }
.nav-user .who { font-size: .9rem; color: var(--ink-soft); }
.nav-user .who b { color: var(--ink); font-weight: 600; }

.nav-toggle { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 600; font-size: .95rem; line-height: 1;
  padding: .72rem 1.15rem; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(150deg, var(--brand), var(--brand-dark)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { color: #fff; box-shadow: var(--shadow); filter: brightness(1.04); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper-2); color: var(--ink); border-color: var(--line); }
.btn-soft { background: var(--brand-soft); color: var(--brand-dark); }
.btn-soft:hover { background: #dfeae0; color: var(--brand-dark); }
.btn-danger-ghost { background: var(--surface); color: var(--danger); border-color: #eccfcc; }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-block { width: 100%; }
.btn-lg { padding: .9rem 1.4rem; font-size: 1.02rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Cards / surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
}

/* ---------- Page header ---------- */
main { flex: 1; padding: clamp(1.5rem, 4vw, 2.75rem) 0 3rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head .sub { color: var(--ink-soft); font-size: 1.02rem; margin: -.2rem 0 0; }
.breadcrumb { font-size: .9rem; color: var(--ink-soft); margin-bottom: 1rem; display: inline-flex; gap: .4rem; align-items: center; }

/* ---------- Search & filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .7rem; margin-bottom: 1.75rem; }
.search {
  position: relative; flex: 1 1 320px; min-width: 220px;
}
.search .ico { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--ink-soft); pointer-events: none; }
.search input {
  width: 100%; padding: .8rem 2.4rem .8rem 2.6rem;
  border: 1px solid var(--line); border-radius: var(--pill);
  background: var(--surface); font: inherit; color: var(--ink);
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.search .clear { position: absolute; right: .55rem; top: 50%; transform: translateY(-50%); border: none; background: var(--paper-2); color: var(--ink-soft); width: 26px; height: 26px; border-radius: var(--pill); cursor: pointer; display: none; align-items: center; justify-content: center; font-size: 1rem; }
.search input:not(:placeholder-shown) + .clear { display: inline-flex; }
.select-wrap { position: relative; }
select.field {
  appearance: none; padding: .8rem 2.4rem .8rem 1rem;
  border: 1px solid var(--line); border-radius: var(--pill);
  background: var(--surface); font: inherit; color: var(--ink); cursor: pointer;
  box-shadow: var(--shadow-sm);
}
select.field:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.select-wrap::after { content: ""; position: absolute; right: 1rem; top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--ink-soft); border-bottom: 2px solid var(--ink-soft); transform: translateY(-65%) rotate(45deg); pointer-events: none; }

/* ---------- Book grid & cards ---------- */
.grid-books {
  display: grid; gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.book {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.book:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: #dcd0bd; }
.book-cover { aspect-ratio: 3 / 4; width: 100%; object-fit: cover; display: block; background: var(--paper-2); }
.book-cover.ph {
  display: grid; place-items: center; text-align: center; padding: 1rem;
  background: linear-gradient(155deg, #355f40, #223f2b);
  color: #f3ecdb;
}
.book-cover.ph .ph-title { font-family: var(--serif); font-size: 1.05rem; line-height: 1.25; }
.book-cover.ph svg { width: 30px; height: 30px; opacity: .7; margin-bottom: .5rem; }
.book-body { padding: .85rem .95rem 1rem; display: flex; flex-direction: column; flex: 1; }
.book-title { font-family: var(--serif); font-size: 1.06rem; font-weight: 600; margin: 0 0 .15rem; }
.book-title a { color: var(--ink); }
.book-title a:hover { color: var(--brand); }
.book-author { color: var(--ink-soft); font-size: .9rem; margin: 0 0 .7rem; }
.book-foot { margin-top: auto; }

/* ---------- Pills / badges ---------- */
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .6rem; border-radius: var(--pill); font-size: .8rem; font-weight: 600; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-out { background: var(--danger-bg); color: var(--danger); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-info { background: var(--info-bg); color: #355f9e; }

/* ---------- Book detail ---------- */
.detail { display: grid; grid-template-columns: 300px 1fr; gap: 2.25rem; align-items: start; }
.detail-cover { width: 100%; border-radius: var(--r); box-shadow: var(--shadow); aspect-ratio: 3/4; object-fit: cover; background: var(--paper-2); }
.detail-cover.ph { display: grid; place-items: center; color: #f3ecdb; background: linear-gradient(155deg, #355f40, #223f2b); text-align: center; padding: 1.5rem; }
.detail h1 { margin-bottom: .15rem; }
.detail .author { font-size: 1.15rem; color: var(--ink-soft); margin-bottom: 1.1rem; }
.meta { list-style: none; padding: 0; margin: 1.25rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: .45rem 1.1rem; font-size: .95rem; }
.meta dt { color: var(--ink-soft); }
.meta dd { margin: 0; }
.borrow-box { margin: 1.4rem 0; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.description { margin-top: 2rem; max-width: 70ch; }
.description h3 { margin-bottom: .5rem; }

/* ---------- Tables ---------- */
.table-card { overflow: hidden; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: var(--paper); }
table.tbl td { padding: .85rem 1rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: #fcfaf5; }
.row-overdue td { background: var(--danger-bg) !important; }

/* ---------- Forms ---------- */
.auth-wrap { max-width: 440px; margin: 1rem auto; }
.form-card { padding: clamp(1.5rem, 4vw, 2.25rem); }
.form-card h1 { text-align: center; }
.form-intro { text-align: center; color: var(--ink-soft); margin-top: -.4rem; margin-bottom: 1.5rem; }
.field-group { margin-bottom: 1.1rem; }
.field-group > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.field-group .hint { color: var(--ink-soft); font-size: .83rem; margin-top: .3rem; }
.field-group .err { color: var(--danger); font-size: .83rem; margin-top: .3rem; }
input.field, .input {
  width: 100%; padding: .75rem .9rem; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
input.field:focus, .input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
input.field::placeholder { color: var(--ink-faint); }
.field-error input.field { border-color: var(--danger); }

/* password reveal */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 2.8rem; }
.pw-toggle {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; color: var(--ink-soft); cursor: pointer;
  width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center;
}
.pw-toggle:hover { background: var(--paper-2); color: var(--ink); }

.divider-or { display: flex; align-items: center; gap: .8rem; color: var(--ink-faint); font-size: .85rem; margin: .4rem 0; }
.divider-or::before, .divider-or::after { content: ""; height: 1px; background: var(--line); flex: 1; }

/* ---------- Alerts / messages ---------- */
.alerts { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1.5rem; }
.alert { display: flex; gap: .7rem; align-items: flex-start; padding: .85rem 1rem; border-radius: var(--r-sm); border: 1px solid; font-size: .95rem; }
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert.success { background: var(--ok-bg); border-color: #bfe0c9; color: #1f5a30; }
.alert.warning { background: var(--warn-bg); border-color: #ecd8a8; color: #7a5200; }
.alert.error   { background: var(--danger-bg); border-color: #eccac6; color: #8c1c16; }
.alert.info, .alert.debug { background: var(--info-bg); border-color: #cdd9ec; color: #2f4f80; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 3.5rem 1rem; color: var(--ink-soft); }
.empty svg { width: 56px; height: 56px; opacity: .35; margin-bottom: 1rem; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 2.25rem; }
.pager .pos { color: var(--ink-soft); font-size: .9rem; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 1.6rem 0; color: var(--ink-soft); font-size: .9rem; }
.site-footer .container { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---------- Skip link (a11y) ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: .6rem 1rem;
  border-radius: var(--r-sm); box-shadow: var(--shadow);
}
.skip-link:focus { left: 1rem; top: .7rem; color: #fff; }
main:focus { outline: none; }

/* ---------- Required marker ---------- */
.req { color: var(--danger); }

/* ---------- Contact block (register) ---------- */
.contact-block {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); padding: 1rem 1rem .35rem; margin-bottom: 1.1rem;
}
.contact-block.field-error { border-color: var(--danger); }
.contact-block .legend { font-weight: 600; font-size: .9rem; margin-bottom: .7rem; }
.contact-block .legend small { font-weight: 500; color: var(--ink-soft); font-size: .82rem; }
.contact-block .field-group { margin-bottom: .8rem; }
.contact-block .field-group > label { font-weight: 500; color: var(--ink-soft); font-size: .85rem; }

/* ---------- Live password requirements ---------- */
.pw-rules { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .35rem; }
.pw-rules li {
  display: flex; align-items: center; gap: .55rem;
  font-size: .85rem; color: var(--ink-soft); transition: color .15s ease;
}
.pw-rules .tick {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid var(--line); display: grid; place-items: center;
  color: transparent; transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.pw-rules li.ok { color: var(--ok); }
.pw-rules li.ok .tick { background: var(--ok-bg); border-color: #bfe0c9; color: var(--ok); }

/* ---------- Category chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1.5rem; }
.chip {
  padding: .42rem .9rem; border-radius: var(--pill);
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); font-size: .9rem; font-weight: 500;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.chip:hover { border-color: #d8ccb8; color: var(--ink); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.active:hover { color: #fff; }

/* ---------- Result count ---------- */
.result-count { color: var(--ink-soft); font-size: .92rem; margin: -.4rem 0 1.1rem; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 240px; }
  .nav-toggle {
    display: grid; place-items: center; width: 42px; height: 42px; margin-left: auto;
    border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); cursor: pointer;
  }
  .nav-links, .nav-user { display: none; }
  .nav.open { height: auto; flex-wrap: wrap; padding-bottom: 1rem; }
  .nav.open .nav-links, .nav.open .nav-user { display: flex; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: .25rem; }
  .nav.open .nav-user { border-top: 1px solid var(--line); margin-top: .5rem; padding-top: .75rem; }
  .nav.open .nav-links a.navlink { padding: .7rem .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
