/* ─── ePaper Viewer CSS ─────────────────────────────────────── */
:root {
  --ep-bg: #e8e4dc;
  --ep-header-bg: #fff;
  --ep-header-border: rgba(0,0,0,0.08);
  --ep-sidebar-bg: #fff;
  --ep-sidebar-border: rgba(0,0,0,0.08);
  --ep-panel-bg: #fff;
  --ep-text: #1a1a1a;
  --ep-text-muted: #666;
  --ep-accent: #c0392b;
  --ep-accent-hover: #a93226;
  --ep-thumb-active: #c0392b;
  --ep-radius: 6px;
  --ep-shadow: 0 4px 24px rgba(0,0,0,.18);
  --ep-header-h: 56px;
  --ep-toolbar-h: 42px;
  --ep-strip-h: 90px;
  --ep-sidebar-w: 110px;
  --ep-panel-w: 240px;
  --ep-transition: .18s ease;
}

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

body.epaper-fullpage {
  margin: 0;
  background: var(--ep-bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ep-text);
  overflow: hidden;
  height: 100vh;
}

/* ── App wrapper ── */
.epaper-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.ep-header {
  background: var(--ep-header-bg);
  border-bottom: 1px solid var(--ep-header-border);
  z-index: 100;
  flex-shrink: 0;
}
.ep-header__inner {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: var(--ep-header-h);
  gap: 16px;
}
.ep-logo-link { text-decoration: none; }
.ep-logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--ep-accent);
  white-space: nowrap;
}
.ep-logo-link img { height: 36px; width: auto; }

/* Editions nav */
.ep-editions {
  display: flex;
  gap: 4px;
  flex: 1;
}
.ep-edition-tab {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--ep-text-muted);
  border: 1px solid transparent;
  transition: all var(--ep-transition);
  white-space: nowrap;
}
.ep-edition-tab:hover { color: var(--ep-text); background: #f4f4f4; }
.ep-edition-tab.active { background: var(--ep-accent); color: #fff; }

/* Header buttons */
.ep-header__actions { display: flex; gap: 6px; margin-left: auto; }
.ep-hbtn {
  width: 34px; height: 34px;
  border: 1px solid var(--ep-header-border);
  border-radius: var(--ep-radius);
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ep-text-muted);
  transition: all var(--ep-transition);
}
.ep-hbtn:hover { background: #f4f4f4; color: var(--ep-text); }
.ep-hbtn.active { background: var(--ep-accent); color: #fff; border-color: var(--ep-accent); }

/* ── Toolbar ── */
.ep-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--ep-toolbar-h);
  padding: 0 16px;
  background: #fafafa;
  border-top: 1px solid var(--ep-header-border);
  gap: 8px;
}
.ep-toolbar__left, .ep-toolbar__center, .ep-toolbar__right {
  display: flex; align-items: center; gap: 6px;
}
.ep-nav-arrow {
  width: 26px; height: 26px;
  border: 1px solid var(--ep-header-border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--ep-text);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--ep-transition);
}
.ep-nav-arrow:hover { background: #f0f0f0; }
.ep-nav-arrow:disabled { opacity: .35; cursor: default; }
.ep-date-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  background: #fff;
  border: 1px solid var(--ep-header-border);
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  color: var(--ep-text);
  transition: background var(--ep-transition);
}
.ep-date-pill:hover { background: #f4f4f4; }
.ep-page-indicator { font-size: 13px; color: var(--ep-text-muted); min-width: 70px; text-align: center; }
.ep-view-toggle {
  padding: 4px 12px;
  border: 1px solid var(--ep-header-border);
  background: transparent;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ep-text-muted);
  transition: all var(--ep-transition);
}
.ep-view-toggle.active { background: var(--ep-accent); color: #fff; border-color: var(--ep-accent); }

/* ── Loading / Error ── */
.ep-loading {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; color: var(--ep-text-muted);
}
.ep-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(0,0,0,.1);
  border-top-color: var(--ep-accent);
  border-radius: 50%;
  animation: ep-spin .8s linear infinite;
}
@keyframes ep-spin { to { transform: rotate(360deg); } }
.ep-error {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  color: var(--ep-text-muted);
}

/* ── Main layout ── */
.ep-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── Thumbnail strip (sidebar) ── */
.ep-thumbstrip {
  width: var(--ep-sidebar-w);
  background: var(--ep-sidebar-bg);
  border-right: 1px solid var(--ep-sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}
.ep-thumbstrip::-webkit-scrollbar { width: 4px; }
.ep-thumbstrip::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }
.ep-thumbstrip__inner { padding: 8px 6px; display: flex; flex-direction: column; gap: 6px; }
.ep-thumb-item {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  transition: border-color var(--ep-transition);
}
.ep-thumb-item:hover { border-color: rgba(192,57,43,.4); }
.ep-thumb-item.active { border-color: var(--ep-thumb-active); }
.ep-thumb-img {
  width: 100%;
  aspect-ratio: 0.707;
  object-fit: cover;
  display: block;
  background: #ddd;
}
.ep-thumb-placeholder {
  width: 100%;
  aspect-ratio: 0.707;
  background: linear-gradient(135deg,#ccc,#bbb);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
}
.ep-thumb-lbl {
  font-size: 9px; text-align: center;
  padding: 2px 0 4px;
  color: var(--ep-text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Viewer center ── */
.ep-viewer-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--ep-bg);
  padding: 12px;
}
.ep-flipbook-container {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
}
#ep-flipbook {
  box-shadow: var(--ep-shadow);
}
#ep-flipbook .page {
  background-color: #fff;
  overflow: hidden;
}
#ep-flipbook .page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Article click overlays */
.ep-article-overlays {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}
.ep-art-overlay {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 2px;
  cursor: pointer;
  pointer-events: all;
  transition: background var(--ep-transition), border-color var(--ep-transition);
}
.ep-art-overlay:hover {
  background: rgba(192,57,43,.08);
  border-color: rgba(192,57,43,.5);
}

/* ── Articles panel ── */
.ep-articles-panel {
  width: var(--ep-panel-w);
  background: var(--ep-panel-bg);
  border-left: 1px solid var(--ep-sidebar-border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.ep-articles-panel__header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--ep-sidebar-border);
}
.ep-articles-panel__header h3 {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--ep-text-muted);
}
.ep-articles-panel__list {
  flex: 1; overflow-y: auto; padding: 8px 0;
}
.ep-articles-panel__list::-webkit-scrollbar { width: 4px; }
.ep-articles-panel__list::-webkit-scrollbar-thumb { background: #ddd; }
.ep-article-item {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(0,0,0,.05);
  cursor: pointer;
  transition: background var(--ep-transition);
}
.ep-article-item:hover { background: #f9f5f0; }
.ep-article-item__hl {
  font-size: 12px; font-weight: 600; line-height: 1.4;
  color: var(--ep-text); margin-bottom: 3px;
}
.ep-article-item__meta { font-size: 11px; color: var(--ep-text-muted); }

/* ── Page strip (bottom) ── */
.ep-page-strip {
  height: var(--ep-strip-h);
  background: var(--ep-sidebar-bg);
  border-top: 1px solid var(--ep-sidebar-border);
  overflow-x: auto; overflow-y: hidden;
  flex-shrink: 0;
}
.ep-page-strip::-webkit-scrollbar { height: 4px; }
.ep-page-strip::-webkit-scrollbar-thumb { background: #ddd; }
.ep-page-strip__inner {
  display: flex; align-items: center;
  padding: 6px 12px; gap: 8px; height: 100%;
  min-width: max-content;
}
.ep-strip-item {
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: opacity var(--ep-transition);
}
.ep-strip-item:hover { opacity: .75; }
.ep-strip-item.active .ep-strip-thumb { border-color: var(--ep-thumb-active); }
.ep-strip-thumb {
  width: 44px; height: 62px;
  object-fit: cover; border-radius: 2px;
  border: 2px solid transparent;
  background: #ddd; display: block;
}
.ep-strip-lbl { font-size: 9px; color: var(--ep-text-muted); text-align: center; }

/* ── Modals ── */
.ep-modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; }
.ep-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.ep-modal__box {
  position: relative; z-index: 1;
  background: #fff; border-radius: 10px;
  width: min(500px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  overflow: hidden;
}
.ep-modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid #eee;
}
.ep-modal__header h3 { font-size: 16px; font-weight: 600; }
.ep-modal__close {
  width: 28px; height: 28px; border: none; background: #f4f4f4;
  border-radius: 50%; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  color: #666;
}
.ep-modal__close:hover { background: #e8e8e8; }
.ep-modal__body { padding: 20px; }

/* Article modal */
.ep-article-modal .ep-article-modal__box {
  position: relative; z-index: 1;
  background: #fff; border-radius: 10px;
  width: min(760px, calc(100vw - 32px));
  max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  padding: 24px;
}
.ep-art-close-btn {
  position: sticky; top: 0; float: right;
  width: 28px; height: 28px; border: none; background: #f4f4f4;
  border-radius: 50%; cursor: pointer; font-size: 13px;
}
.ep-art-crop { width: 100%; border-radius: 4px; margin-bottom: 16px; }
.ep-art-headline { font-size: 20px; font-weight: 700; line-height: 1.3; margin-bottom: 12px; }
.ep-art-body { font-size: 14px; line-height: 1.7; color: #444; white-space: pre-wrap; }

/* Calendar */
.ep-cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ep-cal-nav-btn {
  width: 30px; height: 30px; border: 1px solid #ddd; border-radius: 4px;
  background: #fff; cursor: pointer; font-size: 16px;
}
.ep-cal-label { font-weight: 600; font-size: 15px; }
.ep-calendar {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.ep-cal-day-name {
  text-align: center; font-size: 11px; font-weight: 600;
  color: #999; padding: 4px 0;
}
.ep-cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 13px; cursor: default; color: #ccc;
}
.ep-cal-day.has-issue {
  cursor: pointer; color: var(--ep-text);
  background: #fef0ef; font-weight: 500;
}
.ep-cal-day.has-issue:hover { background: var(--ep-accent); color: #fff; }
.ep-cal-day.today { border: 2px solid var(--ep-accent); }
.ep-cal-day.selected { background: var(--ep-accent); color: #fff; }

/* Share buttons */
.ep-share-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ep-share-btn {
  padding: 10px; border-radius: var(--ep-radius); font-size: 14px; font-weight: 500;
  text-align: center; text-decoration: none; cursor: pointer; border: none;
}
.ep-share-btn--wa { background: #25d366; color: #fff; }
.ep-share-btn--fb { background: #1877f2; color: #fff; }
.ep-share-btn--tw { background: #000; color: #fff; }
.ep-share-btn--copy { background: #f4f4f4; color: var(--ep-text); }
.ep-share-btn--copy.copied { background: #46b450; color: #fff; }

/* ── Archive ── */
.epaper-archive { min-height: 100vh; background: #f9f7f3; }
.ep-arch-header { background: #fff; border-bottom: 1px solid #eee; padding: 0 20px; }
.ep-arch-header__inner { max-width: 1100px; margin: 0 auto; height: 60px; display: flex; align-items: center; gap: 24px; }
.ep-arch-body { max-width: 1100px; margin: 0 auto; padding: 32px 20px; }
.ep-arch-title { font-size: 26px; font-weight: 700; margin-bottom: 28px; }
.ep-arch-month { margin-bottom: 36px; }
.ep-arch-month-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid #e8e0d8; }
.ep-arch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; }
.ep-arch-card { text-decoration: none; color: inherit; display: block; }
.ep-arch-card:hover .ep-arch-card__thumb { box-shadow: 0 6px 20px rgba(0,0,0,.18); transform: translateY(-2px); }
.ep-arch-card__thumb {
  aspect-ratio: 0.707; border-radius: 4px; overflow: hidden;
  position: relative; background: #ddd;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  transition: all .2s ease;
}
.ep-arch-card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ep-arch-card__placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#c0392b,#922b21); }
.ep-arch-card__placeholder span { font-size: 32px; font-weight: 800; color: rgba(255,255,255,.8); }
.ep-arch-card__pages { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 9px; padding: 2px 5px; border-radius: 3px; }
.ep-arch-card__info { margin-top: 6px; }
.ep-arch-card__date { display: block; font-size: 12px; font-weight: 500; }
.ep-arch-card__edition { font-size: 11px; color: #999; }
.ep-arch-empty { text-align: center; padding: 60px; color: #999; }
.ep-btn-primary { display: inline-block; padding: 10px 20px; background: var(--ep-accent); color: #fff; border-radius: var(--ep-radius); text-decoration: none; font-weight: 500; font-size: 14px; }
.ep-btn-primary:hover { background: var(--ep-accent-hover); color: #fff; }

/* ── Responsive ── */
@media (max-width: 900px) {
  :root { --ep-panel-w: 0px; }
  .ep-articles-panel { display: none; }
}
@media (max-width: 640px) {
  :root { --ep-sidebar-w: 0px; --ep-strip-h: 0px; }
  .ep-thumbstrip, .ep-page-strip { display: none; }
  .ep-toolbar__right { display: none; }
  .ep-header__inner { padding: 0 12px; }
  .ep-editions { gap: 2px; }
  .ep-edition-tab { padding: 4px 10px; font-size: 12px; }
}
@media (max-width: 400px) {
  .ep-toolbar { flex-wrap: wrap; height: auto; padding: 6px 12px; gap: 4px; }
  .ep-toolbar__center { order: -1; width: 100%; justify-content: center; }
}
