:root {
  --paper: #f4efe5;
  --paper-deep: #e8ded0;
  --white: #fffdf9;
  --ink: #1c2925;
  --muted: #67716c;
  --forest: #173f35;
  --forest-2: #285b4c;
  --copper: #bd684b;
  --danger: #a13d35;
  --line: rgba(28, 41, 37, .14);
  --shadow: 0 24px 70px rgba(23, 46, 39, .12);
  --serif: Iowan Old Style, Baskerville, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }
.eyebrow { margin: 0 0 11px; color: var(--copper); font-size: 11px; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.primary-btn, .secondary-btn, .ghost-btn { min-height: 44px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; font-weight: 780; text-decoration: none; cursor: pointer; }
.primary-btn { color: #fff; border: 0; background: var(--copper); }
.primary-btn:hover { filter: brightness(.94); }
.secondary-btn { color: var(--forest); border: 1px solid var(--line); background: var(--white); }
.ghost-btn { color: var(--muted); border: 0; background: transparent; }
.wide { width: 100%; }

.login-view { min-height: 100dvh; padding: 32px; display: grid; place-items: center; background: radial-gradient(circle at 10% 5%, rgba(189,104,75,.28), transparent 30rem), var(--forest); }
.login-brand { position: absolute; top: 28px; left: 32px; display: flex; align-items: center; gap: 11px; color: #fff; }
.login-brand span, .admin-brand > span { width: 40px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50% 50% 50% 8px; color: var(--forest); background: var(--paper); font: 700 22px/1 var(--serif); }
.login-brand p { margin: 0; font: 600 18px/1 var(--serif); }
.login-card { width: min(470px, 100%); padding: clamp(28px, 5vw, 48px); border-radius: 12px 44px 12px 12px; background: var(--white); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 16px; font: 600 clamp(40px, 6vw, 57px)/.98 var(--serif); letter-spacing: -.035em; }
.login-intro { margin-bottom: 28px; color: var(--muted); line-height: 1.55; }
.login-card label { margin-bottom: 15px; display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 800; }
.login-card input { width: 100%; height: 51px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; outline: 0; color: var(--ink); background: var(--paper); font-size: 16px; }
.login-card input:focus { border-color: var(--copper); box-shadow: 0 0 0 3px rgba(189,104,75,.13); }
.back-link { margin-top: 20px; display: block; color: var(--muted); text-align: center; font-size: 13px; text-underline-offset: 4px; }
.form-error { min-height: 20px; margin: 4px 0 10px; color: var(--danger); font-size: 13px; font-weight: 700; }

.app-header { position: sticky; z-index: 20; top: 0; min-height: 76px; padding: 0 max(24px, calc((100vw - 1280px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); background: rgba(244,239,229,.93); backdrop-filter: blur(14px); }
.admin-brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.admin-brand > span { width: 39px; color: #fff; background: var(--forest); }
.admin-brand div { display: grid; gap: 2px; }
.admin-brand strong { font: 600 17px/1 var(--serif); }
.admin-brand small { color: var(--muted); font-size: 10px; letter-spacing: .09em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.app-shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; padding-block: 56px 100px; }
.welcome { display: flex; align-items: end; justify-content: space-between; gap: 30px; }
.welcome h1 { margin: 0 0 12px; font: 600 clamp(43px, 6vw, 70px)/.98 var(--serif); letter-spacing: -.04em; }
.welcome > div > p:last-child { max-width: 650px; margin: 0; color: var(--muted); line-height: 1.6; }
.stat-grid { margin: 40px 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-grid article { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,253,249,.68); }
.stat-grid span { display: block; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; font: 600 35px/1 var(--serif); white-space: nowrap; }
.stat-grid p { margin: 0; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
.tabs { position: sticky; z-index: 15; top: 76px; margin-bottom: 28px; padding: 6px; display: inline-flex; gap: 4px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,253,249,.93); backdrop-filter: blur(12px); }
.tabs button { min-height: 43px; padding: 0 18px; border: 0; border-radius: 999px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 780; cursor: pointer; }
.tabs button span { margin-right: 4px; }
.tabs button.active { color: #fff; background: var(--forest); }

.tab-panel { min-height: 400px; padding: 30px; border: 1px solid var(--line); border-radius: 26px; background: rgba(255,253,249,.68); box-shadow: 0 14px 45px rgba(34,45,40,.05); }
.panel-head { margin-bottom: 24px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.panel-head h2 { margin: 0; font: 600 42px/1 var(--serif); letter-spacing: -.025em; }
.compact-search { width: min(320px, 100%); min-height: 46px; padding: 0 14px; display: flex; align-items: center; gap: 9px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; background: var(--white); }
.compact-search input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font-size: 14px; }
.status-filters { display: flex; gap: 7px; margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.status-filters::-webkit-scrollbar { display: none; }
.status-filters button { min-height: 39px; padding: 0 14px; flex: 0 0 auto; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; background: transparent; font-size: 12px; font-weight: 780; cursor: pointer; }
.status-filters button.active { color: var(--forest); border-color: var(--forest); background: rgba(23,63,53,.07); }

.reading-list, .catalog-list { display: grid; gap: 9px; }
.reading-row, .catalog-row { min-width: 0; padding: 15px; display: grid; grid-template-columns: 54px minmax(0, 1fr) auto auto; align-items: center; gap: 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); }
.mini-cover { width: 54px; height: 72px; overflow: hidden; display: grid; place-items: center; color: rgba(255,255,255,.7); border-radius: 7px 13px 7px 7px; background: var(--book-color, var(--forest)); font: 600 20px/1 var(--serif); }
.mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.row-copy { min-width: 0; }
.row-copy h3 { margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; font: 600 20px/1.1 var(--serif); white-space: nowrap; }
.row-copy p { margin: 0; color: var(--muted); font-size: 12px; }
.row-meta { display: grid; justify-items: end; gap: 5px; }
.status-pill { padding: 6px 9px; border-radius: 999px; color: var(--forest); background: rgba(23,63,53,.09); font-size: 10px; font-weight: 850; text-transform: uppercase; }
.stars { color: var(--copper); font-size: 13px; letter-spacing: .06em; }
.row-actions { display: flex; gap: 5px; }
.icon-action { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 12px; color: var(--forest); background: transparent; font-size: 15px; cursor: pointer; }
.icon-action.danger { color: var(--danger); }
.empty-list { padding: 56px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 16px; line-height: 1.6; }
.empty-list strong { display: block; margin-bottom: 7px; color: var(--ink); font: 600 25px/1.1 var(--serif); }
.catalog-more { padding-top: 22px; text-align: center; }

.lookup-card { margin-bottom: 22px; padding: 23px; border-radius: 18px; color: #fff; background: var(--forest); }
.lookup-card > div:first-child { display: flex; align-items: baseline; gap: 12px; }
.lookup-card > div:first-child strong { font: 600 25px/1 var(--serif); }
.lookup-card p { margin: 0; color: rgba(255,255,255,.67); font-size: 13px; }
.lookup-form { margin-top: 18px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.lookup-form input { min-width: 0; height: 48px; padding: 0 14px; border: 0; border-radius: 12px; outline: 0; background: var(--white); font-size: 16px; }
.lookup-note { margin-top: 10px !important; font-size: 10px !important; }
.lookup-results { margin-top: 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lookup-result { min-width: 0; padding: 12px; display: grid; grid-template-columns: 42px 1fr; gap: 10px; color: var(--ink); border-radius: 12px; background: var(--white); }
.lookup-thumb { width: 42px; height: 58px; object-fit: cover; border-radius: 5px; background: var(--paper-deep); }
.lookup-result div { min-width: 0; }
.lookup-result strong { display: block; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; font: 600 15px/1.1 var(--serif); white-space: nowrap; }
.lookup-result small { display: block; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 10px; white-space: nowrap; }
.lookup-result button { margin-top: 8px; min-height: 32px; padding: 0 10px; color: var(--forest); border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-size: 10px; font-weight: 800; cursor: pointer; }
.lookup-loading { grid-column: 1 / -1; padding: 18px; color: rgba(255,255,255,.8) !important; text-align: center; }

.book-form { display: grid; gap: 14px; }
.form-section { padding: 24px; border: 1px solid var(--line); border-radius: 18px; background: var(--white); }
.form-section-title { margin-bottom: 22px; display: flex; align-items: start; gap: 12px; }
.form-section-title > span { width: 34px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--forest); font-size: 10px; font-weight: 850; }
.form-section-title h3 { margin: 0 0 4px; font: 600 26px/1 var(--serif); }
.form-section-title p { margin: 0; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.form-grid label { min-width: 0; display: grid; align-content: start; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
.form-grid .hint { font-size: 9px; font-weight: 600; text-transform: none; }
.span-2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; min-height: 47px; padding: 11px 13px; color: var(--ink); border: 1px solid var(--line); border-radius: 11px; outline: 0; background: var(--paper); font-size: 14px; font-weight: 500; letter-spacing: 0; text-transform: none; }
.form-grid textarea { resize: vertical; line-height: 1.5; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: var(--copper); box-shadow: 0 0 0 3px rgba(189,104,75,.12); }
.form-grid input[type="color"] { padding: 5px; }
.advanced summary { color: var(--forest); font-weight: 800; cursor: pointer; }
.advanced-intro { margin: 14px 0 20px; color: var(--muted); font-size: 13px; }
.form-actions { display: flex; gap: 8px; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; max-width: min(450px, calc(100% - 30px)); padding: 13px 18px; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); color: #fff; border-radius: 999px; background: #162c25; box-shadow: var(--shadow); font-size: 13px; font-weight: 750; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .lookup-results { grid-template-columns: repeat(2, 1fr); }
  .reading-row, .catalog-row { grid-template-columns: 48px minmax(0, 1fr) auto; }
  .row-meta { display: none; }
}

@media (max-width: 620px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .login-view { padding: 80px 14px 24px; align-items: start; }
  .login-brand { top: 22px; left: 20px; }
  .login-card { padding: 27px 22px; border-radius: 10px 36px 10px 10px; }
  .login-card h1 { font-size: 43px; }
  .app-header { min-height: 68px; padding: 0 14px; }
  .admin-brand > span { width: 37px; }
  .admin-brand strong { font-size: 15px; }
  .admin-brand small, .desktop-only, .header-actions .ghost-btn { display: none; }
  .header-actions .secondary-btn { min-height: 40px; padding: 0 13px; font-size: 12px; }
  .app-shell { width: min(100% - 24px, 1180px); padding-block: 36px 30px; }
  .welcome { align-items: start; flex-direction: column; gap: 21px; }
  .welcome h1 { font-size: 48px; }
  .welcome .primary-btn { width: 100%; }
  .stat-grid { margin: 28px 0; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-grid article { padding: 17px; }
  .stat-grid span { font-size: 30px; }
  .tabs { position: fixed; z-index: 30; top: auto; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); border-radius: 18px; box-shadow: 0 16px 45px rgba(15,39,33,.25); }
  .tabs button { padding: 0 7px; display: grid; place-items: center; align-content: center; gap: 1px; border-radius: 13px; font-size: 9px; }
  .tabs button span { margin: 0; font-size: 18px; line-height: 1; }
  .tab-panel { min-height: 450px; padding: 17px; border-radius: 20px; }
  .panel-head { align-items: stretch; flex-direction: column; gap: 16px; }
  .panel-head h2 { font-size: 37px; }
  .compact-search { width: 100%; }
  .reading-row, .catalog-row { grid-template-columns: 43px minmax(0, 1fr) auto; gap: 10px; padding: 11px; }
  .mini-cover { width: 43px; height: 59px; }
  .row-copy h3 { font-size: 17px; }
  .row-actions { display: grid; grid-template-columns: 1fr; gap: 3px; }
  .icon-action { width: 38px; height: 34px; border-radius: 9px; }
  .lookup-card { padding: 19px; }
  .lookup-card > div:first-child { display: block; }
  .lookup-card > div:first-child p { margin-top: 7px; }
  .lookup-form { grid-template-columns: 1fr; }
  .lookup-results { grid-template-columns: 1fr; }
  .form-section { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-actions { display: grid; grid-template-columns: 1fr; }
  .form-actions > * { width: 100%; }
  .toast { bottom: calc(85px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: .01ms !important; }
}
