/* ============================================================
   E-Book Flipbook Catalog — Stylesheet
   ============================================================ */
:root {
  --ink: #1a1d21;
  --ink-soft: #55606b;
  --paper: #f4f2ee;
  --card: #ffffff;
  --accent: #0e8f8b;          /* teal เหมือนแถบข้าง catalog */
  --accent-dark: #0a6b68;
  --gold: #c9a227;
  --line: #e2ded7;
  --shadow: 0 10px 30px rgba(20, 24, 28, .12);
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "Leelawadee UI", Tahoma, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   หน้า Library (index.html)
   ============================================================ */
.lib-header {
  background: linear-gradient(135deg, #14181c 0%, #1f2a30 60%, #0e8f8b 160%);
  color: #fff;
  padding: 56px 24px 120px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.lib-header::before {
  /* ลาย perforated จางๆ พื้นหลัง header */
  content: "";
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.10) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  pointer-events: none;
}
.lib-header .brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-size: 13px; letter-spacing: 4px;
  color: #9fd8d5; margin-bottom: 14px;
}
.lib-header .brand::before,
.lib-header .brand::after {
  content: ""; width: 40px; height: 1px; background: #3f6d6b;
}
.header-logo {
  width: 120px;
  height: auto;
  filter: brightness(2.2);
  margin-bottom: 12px;
}
.lib-header h1 {
  font-size: clamp(28px, 4.5vw, 46px);
  font-weight: 700; letter-spacing: .5px;
}
.lib-header p.tagline {
  margin-top: 12px; color: #c9d4d6; font-size: 15px;
}

/* แถบค้นหา + filter ลอยทับ header */
.lib-toolbar {
  max-width: 1080px;
  margin: -66px auto 0;
  padding: 0 24px;
  position: relative; z-index: 5;
}
.toolbar-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
}
.search-box {
  flex: 1 1 260px;
  display: flex; align-items: center; gap: 10px;
  background: #f2f0ec;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
.search-box svg { flex: none; opacity: .5; }
.search-box input {
  border: 0; outline: 0; background: transparent;
  font: inherit; width: 100%; color: var(--ink);
}
.cat-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit; font-size: 13.5px;
  cursor: pointer;
  transition: all .18s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent-dark); }
.chip.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* แถบประเภท (แยกจาก toolbar) */
.lib-cat-bar {
  max-width: 1080px;
  margin: 16px auto 0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.cat-label {
  font-size: 13.5px;
  color: var(--ink-soft);
  font-weight: 500;
  white-space: nowrap;
}
.admin-link {
  text-decoration: none;
  flex-shrink: 0;
}

/* กริดการ์ด catalog */
.lib-grid {
  max-width: 1080px;
  margin: 34px auto 80px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 26px;
}
.book-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(20,24,28,.08);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex; flex-direction: column;
  transition: transform .22s ease, box-shadow .22s ease;
}
.book-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 18px 38px rgba(20,24,28,.18);
}
.book-cover {
  position: relative;
  aspect-ratio: 707 / 1000;
  background: #dfe3e6;
  overflow: hidden;
}
.book-cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.book-cover .badge {
  position: absolute; top: 12px; left: 12px;
  background: rgba(14,143,139,.92); color: #fff;
  font-size: 11.5px; letter-spacing: .5px;
  padding: 5px 11px; border-radius: 999px;
}
.book-cover .open-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(16,20,24,.45);
  opacity: 0; transition: opacity .2s ease;
}
.book-card:hover .open-hint { opacity: 1; }
.open-hint span {
  background: #fff; color: var(--ink);
  font-size: 13.5px; font-weight: 600;
  padding: 10px 20px; border-radius: 999px;
  display: inline-flex; gap: 8px; align-items: center;
}
.book-meta { padding: 15px 16px 17px; }
.book-meta h3 { font-size: 15.5px; line-height: 1.35; }
.book-meta .sub {
  margin-top: 5px; font-size: 12.5px; color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-meta .foot {
  margin-top: 10px; display: flex; justify-content: space-between;
  font-size: 12px; color: #98938a;
}
.lib-empty {
  grid-column: 1/-1; text-align: center;
  color: var(--ink-soft); padding: 60px 0; font-size: 15px;
}
.lib-footer {
  text-align: center; color: #a09a90;
  font-size: 12.5px; padding: 26px 0 40px;
  border-top: 1px solid var(--line);
}

/* Toast notification (sync) */
.sync-toast {
  position: fixed; bottom: 28px; left: 50%; z-index: 100;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff;
  font-size: 13.5px; font-weight: 500;
  padding: 12px 24px; border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
  opacity: 0; transition: opacity .3s ease, transform .3s ease;
  pointer-events: none; white-space: nowrap;
}
.sync-toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ============================================================
   หน้า Viewer (viewer.html)
   ============================================================ */
body.viewer-body {
  background: radial-gradient(1200px 700px at 50% 30%, #2c353c 0%, #171c20 70%);
  color: #e8e6e1;
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

.v-topbar {
  flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  background: rgba(12,15,18,.55);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,.07);
  z-index: 20;
}
.v-topbar .back-btn {
  display: inline-flex; align-items: center; gap: 8px;
  color: #cfd6d5; text-decoration: none; font-size: 13.5px;
  border: 1px solid rgba(255,255,255,.18);
  padding: 7px 14px; border-radius: 999px;
  transition: all .18s ease; white-space: nowrap;
}
.v-topbar .back-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.v-title { min-width: 0; }
.v-title h1 {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.v-title .pub { font-size: 11.5px; color: #8fa5a3; margin-top: 1px; }
.v-topbar .spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px; color: #dfe5e4; cursor: pointer;
  transition: all .18s ease;
}
.icon-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.active { background: var(--accent); border-color: var(--accent); color:#fff; }

/* พื้นที่หนังสือ */
.v-stage {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  padding: 26px 74px;
}

.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 15;
  width: 48px; height: 48px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: rgba(255,255,255,.9); color: #22282d;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  transition: all .18s ease;
}
.nav-arrow:hover { background: var(--accent); color: #fff; transform: translateY(-50%) scale(1.07); }
.nav-arrow:disabled { opacity: .25; pointer-events: none; }
.nav-arrow.prev { left: 16px; }
.nav-arrow.next { right: 16px; }

/* ---------- StPageFlip (เอฟเฟคกระดาษโค้งจริง) ---------- */
.book-wrap {
}
.book-wrap.cover-mode {
  transform: translateX(-25%);
}
.book-wrap.cover-mode #flipbook {
  box-shadow: none;
}
#flipbook {
  width: 100%; height: 100%;
  box-shadow: 0 30px 60px rgba(0,0,0,.45);
}
.stf__parent { margin: 0 auto; }
.stf__item { background: #fff; overflow: hidden; }
.stf__item img {
  width: 100%; height: 100%;
  object-fit: fill;
  display: block;
}
.pan-overlay {
  position: absolute; inset: 0; z-index: 14;
  cursor: grab;
}

/* ---------- Branding badge (มุมล่างซ้าย) ---------- */
.viewer-brand {
  position: fixed;
  left: 18px;
  bottom: 58px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #ffffff;
  padding: 10px 20px 10px 12px;
  border-radius: 50px;
  box-shadow: 0 2px 16px rgba(0,0,0,.18);
  cursor: default;
  user-select: none;
  transition: opacity .25s, transform .2s;
}
.viewer-brand:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(0,0,0,.22);
}
.viewer-brand .brand-logo {
  width: 50px;
  height: auto;
  object-fit: contain;
}
.viewer-brand .brand-text {
  font-size: 15px;
  color: #666;
  letter-spacing: .2px;
  line-height: 1;
  font-weight: 400;
}
.viewer-brand .brand-text strong {
  color: #1a1d21;
  font-weight: 700;
  text-transform: lowercase;
}

/* ---------- ตัวหนังสือ (flipbook) ---------- */
.book {
  position: relative;
  transform-style: preserve-3d;
  perspective: 2600px;
  filter: drop-shadow(0 30px 45px rgba(0,0,0,.5));
  transition: transform .25s ease;
}
.book .sheet-static {
  position: absolute; top: 0; overflow: hidden;
  background: #fff;
}
.book .sheet-static.left  { left: 0; border-radius: 6px 0 0 6px; }
.book .sheet-static.right { right: 0; border-radius: 0 6px 6px 0; }
.book .sheet-static img, .flip-face img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  user-select: none; -webkit-user-drag: none;
}

/* เงาสันกลางเล่ม */
.book .spine-shade {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 90px; height: 100%; z-index: 5; pointer-events: none;
  background: linear-gradient(90deg,
    transparent 0%, rgba(0,0,0,.10) 42%, rgba(0,0,0,.22) 50%,
    rgba(0,0,0,.10) 58%, transparent 100%);
}

/* แผ่นที่กำลังพลิก */
.flip-sheet {
  position: absolute; top: 0; left: 50%;
  height: 100%; width: 50%;
  transform-style: preserve-3d;
  transform-origin: left center;
  z-index: 10;
}
.flip-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  overflow: hidden; background: #fff;
}
.flip-face.front { border-radius: 0 6px 6px 0; }
.flip-face.back  { transform: rotateY(180deg); border-radius: 6px 0 0 6px; }
.flip-face::after {
  /* เงาโค้งบนหน้าที่พลิก */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.16), transparent 26%);
}
.flip-face.front::after {
  background: linear-gradient(270deg, rgba(0,0,0,.0), transparent 60%),
              linear-gradient(90deg, rgba(0,0,0,.14), transparent 24%);
}

@keyframes flipNext {
  0%   { transform: rotateY(0deg); }
  100% { transform: rotateY(-180deg); }
}
@keyframes flipPrev {
  0%   { transform: rotateY(-180deg); }
  100% { transform: rotateY(0deg); }
}
.flip-sheet.anim-next { animation: flipNext .8s cubic-bezier(.45,.05,.3,1) forwards; }
.flip-sheet.anim-prev { animation: flipPrev .8s cubic-bezier(.45,.05,.3,1) forwards; }

/* คลิกขอบหน้าเพื่อพลิก */
.tap-zone {
  position: absolute; top: 0; height: 100%; width: 18%;
  z-index: 12; cursor: pointer;
}
.tap-zone.left { left: 0; }
.tap-zone.right { right: 0; }

/* ---------- แถบล่าง ---------- */
.v-bottombar {
  flex: none; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 22px 14px;
  background: rgba(12,15,18,.55);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255,255,255,.07);
}
.page-indicator {
  font-size: 12.5px; color: #aebbba; white-space: nowrap;
  min-width: 92px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.page-slider {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 4px;
  background: rgba(255,255,255,.18); outline: none; cursor: pointer;
}
.page-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4); cursor: pointer;
}

/* ---------- แถบ thumbnail ---------- */
.thumb-drawer {
  position: absolute; left: 0; right: 0; bottom: 0;
  transform: translateY(105%);
  transition: transform .3s ease;
  background: rgba(10,13,16,.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,.1);
  padding: 14px 18px 16px;
  z-index: 30;
}
.thumb-drawer.open { transform: translateY(0); }
.thumb-strip {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px;
}
.thumb-strip::-webkit-scrollbar { height: 8px; }
.thumb-strip::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 8px; }
.thumb-item {
  flex: none; cursor: pointer; text-align: center;
  opacity: .75; transition: all .15s ease;
}
.thumb-item:hover { opacity: 1; transform: translateY(-3px); }
.thumb-item.current { opacity: 1; }
.thumb-item img {
  height: 108px; aspect-ratio: 707/1000; object-fit: cover;
  border-radius: 4px; border: 2px solid transparent; display: block;
  background: #fff;
}
.thumb-item.current img { border-color: var(--accent); }
.thumb-item .n { font-size: 11px; color: #9db3b1; margin-top: 5px; }

/* โหลด / error */
.v-loading {
  position: absolute; inset: 0; z-index: 40;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  color: #9db3b1; font-size: 14px;
  background: inherit;
}
.v-loading .ring {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   หน้า Admin (admin.html)
   ============================================================ */
.adm-header { padding-bottom: 100px; }
.adm-nav { justify-content: space-between; }
.adm-nav .chip { text-decoration: none; }
.adm-status { font-size: 12.5px; }
.adm-status.ok { color: var(--accent-dark); }
.adm-status.err { color: #c0392b; }

.adm-wrap {
  max-width: 1080px; margin: 30px auto 60px; padding: 0 24px;
  display: flex; flex-direction: column; gap: 26px;
}
.adm-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 26px 28px;
}
.adm-card h2 { font-size: 18px; margin-bottom: 18px; }
.adm-card h2 .count {
  font-size: 12.5px; font-weight: 500; color: var(--ink-soft);
  background: #f0ede8; border-radius: 999px; padding: 4px 12px;
  vertical-align: 2px; margin-left: 8px;
}

.drop-zone {
  border: 2px dashed #cfc9bf; border-radius: 12px;
  padding: 34px 20px; text-align: center; cursor: pointer;
  color: var(--ink-soft); transition: all .18s ease;
}
.drop-zone:hover, .drop-zone.over {
  border-color: var(--accent); background: #f2faf9; color: var(--accent-dark);
}
.drop-zone.has-file { border-style: solid; border-color: var(--accent); background: #f2faf9; }
.drop-zone svg { opacity: .55; margin-bottom: 10px; }
.dz-text { font-size: 14px; }
.dz-file { margin-top: 10px; font-size: 13.5px; font-weight: 600; color: var(--accent-dark); }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px;
  margin-top: 18px;
}
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.fld.span2 { grid-column: span 3; }
.fld input {
  font: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; background: #faf9f7; outline: none;
}
.fld input:focus { border-color: var(--accent); background: #fff; }

.adm-actions { margin-top: 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.btn-primary {
  font: inherit; font-size: 14.5px; font-weight: 600;
  background: var(--accent); color: #fff; border: 0;
  border-radius: 10px; padding: 12px 24px; cursor: pointer;
  transition: background .18s ease;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.upload-progress {
  flex: 1 1 100%; display: flex; flex-direction: column; gap: 8px;
  font-size: 13px; color: var(--ink-soft);
}
.progress-bar-wrap {
  width: 100%; height: 10px; border-radius: 10px;
  background: #e8e5df; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; width: 0%; border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), #12b5b0);
  transition: width .3s ease;
}
.form-msg { margin-top: 12px; font-size: 13.5px; min-height: 18px; }
.form-msg.ok { color: var(--accent-dark); }
.form-msg.err { color: #c0392b; }

.adm-list { display: flex; flex-direction: column; gap: 12px; }
.adm-empty { color: var(--ink-soft); font-size: 14px; padding: 20px 0; text-align: center; }
.adm-row {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 14px;
  align-items: center; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.adm-thumb {
  width: 56px; aspect-ratio: 707/1000; object-fit: cover;
  border-radius: 5px; background: #eee; border: 1px solid var(--line);
}
.adm-info .t { font-size: 14.5px; font-weight: 600; }
.adm-info .s { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.adm-info .m { font-size: 11.5px; color: #98938a; margin-top: 4px; }
.adm-btns { display: flex; gap: 8px; }
.mini-btn {
  font: inherit; font-size: 12.5px; text-decoration: none;
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 8px; padding: 7px 13px; cursor: pointer;
  transition: all .15s ease;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.mini-btn.danger:hover { border-color: #c0392b; color: #c0392b; }
.mini-btn.ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.adm-edit {
  grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap;
  padding-top: 12px; border-top: 1px dashed var(--line);
}
.adm-edit input {
  font: inherit; font-size: 13px; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; flex: 1 1 140px;
}
.adm-edit input[name="title"] { flex: 2 1 200px; }

@media (max-width: 680px) {
  .form-grid { grid-template-columns: 1fr; }
  .fld.span2 { grid-column: span 1; }
  .adm-row { grid-template-columns: 44px 1fr; }
  .adm-btns { grid-column: 1 / -1; }
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .v-stage { padding: 14px 8px; }
  .nav-arrow { width: 40px; height: 40px; }
  .nav-arrow.prev { left: 6px; }
  .nav-arrow.next { right: 6px; }
  .v-title .pub { display: none; }
  .page-indicator { min-width: 70px; }
}

/* ---------- Fullscreen mode ---------- */
:fullscreen .v-topbar,
:fullscreen .v-bottombar {
  position: fixed; left: 0; right: 0;
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
}
:fullscreen .v-topbar:hover,
:fullscreen .v-bottombar:hover {
  opacity: 1;
  pointer-events: auto;
}
:fullscreen .v-topbar { top: 0; }
:fullscreen .v-bottombar { bottom: 0; }

:fullscreen .v-stage {
  position: fixed; inset: 0;
  padding: 16px 60px;
}
:fullscreen .viewer-brand {
  bottom: 16px;
}
:fullscreen .nav-arrow.prev { left: 10px; }
:fullscreen .nav-arrow.next { right: 10px; }

/* ---------- Contact Modal ---------- */
.contact-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.contact-overlay[hidden] {
  display: none;
}
.contact-modal {
  background: #fff;
  border-radius: 16px;
  padding: 36px 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.contact-close {
  position: absolute;
  top: 12px; right: 16px;
  background: none; border: none;
  font-size: 28px; color: #999;
  cursor: pointer; line-height: 1;
}
.contact-close:hover { color: #333; }
.contact-logo {
  width: 80px; height: auto;
  margin-bottom: 12px;
}
.contact-modal h2 {
  font-size: 22px;
  color: #1a1d21;
  margin-bottom: 8px;
}
.contact-desc {
  font-size: 14px;
  color: #777;
  margin-bottom: 20px;
}
.contact-info {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: #333;
}
.contact-row svg {
  flex-shrink: 0;
  color: var(--accent);
}
