/* Janabartta E-Paper — dedicated PDF reader */
:root {
  --brand: #0a2472;
  --brand-dark: #061539;
  --reader-bg: #d9dde2;
  --rail-bg: #eef1f4;
  --toolbar-bg: #14161a;
  --masthead-h: 96px;
  --toolbar-h: 56px;
  --rail-w: 340px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--reader-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1a1a1a;
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* Shared centered width for the top bars (matches the ~70% page width) */
:root { --reader-w: 85%; }

/* White masthead: logo (left) + hamburger (right) */
.reader-masthead {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: var(--reader-w); height: var(--masthead-h);
  background: #fff; border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; z-index: 101;
}
.mast-brand { display: inline-flex; align-items: center; height: 100%; }
.mast-brand img { height: 64px; width: auto; }

/* Inline nav in masthead (desktop / tablet) */
.mast-nav { display: flex; gap: 4px; align-items: center; margin-left: auto; }
.mast-nav a {
  color: #1a1a1a; padding: 8px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 600; text-decoration: none;
}
.mast-nav a:hover { background: #f2f4f7; }

/* Dark controls toolbar — sits directly below the masthead */
.reader-toolbar {
  position: fixed; top: var(--masthead-h); left: 50%; transform: translateX(-50%);
  width: var(--reader-w); height: var(--toolbar-h);
  background: var(--toolbar-bg); border-bottom: 3px solid var(--brand);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 0 12px; z-index: 100; color: #fff;
}
.tb-left, .tb-center, .tb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tb-left { flex: 1; }
.tb-right { justify-content: flex-end; }

.tb-title {
  font-weight: 700; font-size: 15px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 32vw; color: #fff;
}

.tb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 38px; height: 38px; padding: 0 10px;
  background: #222831; color: #fff; border: 1px solid #3a414d;
  border-radius: 8px; font-size: 18px; font-weight: 700;
  cursor: pointer; text-decoration: none; line-height: 1;
  transition: background .12s ease, opacity .12s ease;
}
.tb-btn:hover { background: #2e3742; }
.tb-btn:active { transform: translateY(1px); }
.tb-btn:disabled { opacity: .35; cursor: default; }
.tb-back { background: var(--brand); border-color: var(--brand); }
.tb-back:hover { background: var(--brand-dark); }
.tb-label { font-size: 14px; }
.tb-btn-lg { height: 44px; padding: 0 18px; font-size: 15px; }

.tb-page { font-size: 14px; font-weight: 600; white-space: nowrap; padding: 0 4px; color: #fff; }
.tb-zoom { font-size: 13px; font-weight: 600; min-width: 44px; text-align: center; color: #cbd5e1; }

/* Reader brand logo */
.tb-brand { display: inline-flex; align-items: center; height: 40px; }
.tb-brand img {
  height: 30px; width: auto; background: #fff; padding: 3px 6px; border-radius: 6px;
}

/* Page-jump select */
.tb-select {
  height: 38px; border-radius: 8px; border: 1px solid #3a414d; background: #222831;
  color: #fff; font-size: 14px; font-weight: 600; padding: 0 8px; cursor: pointer;
}
.tb-gridtoggle { font-size: 14px; letter-spacing: -3px; }
.tb-clip.active { background: var(--brand); border-color: var(--brand); }
.tb-dl { background: var(--brand); border-color: var(--brand); }
.tb-dl:hover { background: var(--brand-dark); }

/* Edition date badge = calendar trigger */
.tb-datewrap { position: relative; }
.tb-date {
  background: var(--brand); color: #fff; font-weight: 700; font-size: 13px;
  padding: 0 12px; height: 38px; display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 8px; white-space: nowrap; cursor: pointer;
}
.tb-date:hover { background: var(--brand-dark); }
.tb-cal-ico { font-size: 15px; }
.tb-caret { font-size: 10px; opacity: .85; }

/* Calendar popover */
.cal-popover {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 400;
  width: 280px; background: #fff; color: #1a1a1a; border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,.35); padding: 14px; border: 1px solid #e5e7eb;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-month { font-weight: 700; font-size: 15px; }
.cal-nav {
  width: 30px; height: 30px; border: 1px solid #e5e7eb; background: #f6f7f9;
  border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1; color: #1a1a1a;
}
.cal-nav:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-weekdays span {
  text-align: center; font-size: 11px; font-weight: 700; color: #9ca3af; padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 13px; border-radius: 8px; text-decoration: none;
}
.cal-empty { visibility: hidden; }
.cal-disabled { color: #cbd5e1; cursor: default; }
.cal-has {
  color: var(--brand); font-weight: 700; background: #eef2fb; cursor: pointer;
}
.cal-has:hover { background: var(--brand); color: #fff; text-decoration: none; }
.cal-current { background: var(--brand); color: #fff; }
.cal-current:hover { background: var(--brand-dark); color: #fff; }

/* Social share bar */
.share-bar {
  position: fixed; top: calc(var(--masthead-h) + var(--toolbar-h));
  left: 50%; transform: translateX(-50%); width: var(--reader-w); height: 42px;
  display: flex; z-index: 90;
}
.share-btn {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px; text-decoration: none;
  border: 0; cursor: pointer; transition: filter .12s ease;
}
.share-btn:hover { filter: brightness(1.1); text-decoration: none; }
.sh-fb { background: #3b5998; }
.sh-tw { background: #1da1f2; }
.sh-in { background: #0077b5; }
.sh-print { background: #334155; }
.sh-wa { background: #25d366; }
.sh-mail { background: #1e3a8a; }
.sh-dl { background: #111; }

/* Page holder wraps canvas + clip layer */
.page-holder { position: relative; display: inline-block; line-height: 0; }

/* Clip selection layer overlays the canvas exactly */
.clip-layer {
  position: absolute; inset: 0; z-index: 5; cursor: crosshair;
  touch-action: none;
}
.clip-rect {
  position: absolute; border: 2px dashed var(--brand);
  background: rgba(10,36,114,.16); box-shadow: 0 0 0 9999px rgba(0,0,0,.25);
  pointer-events: none;
}
.reader-stage.clipping { cursor: crosshair; }

/* Clip banner */
.clip-banner {
  position: fixed; top: calc(var(--masthead-h) + var(--toolbar-h) + 42px + 8px); left: 50%;
  transform: translateX(-50%); z-index: 120;
  background: #14161a; color: #fff; border: 1px solid var(--brand);
  padding: 8px 14px; border-radius: 24px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.clip-cancel {
  background: var(--brand); color: #fff; border: 0; border-radius: 16px;
  padding: 4px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
}

/* All-pages grid overlay */
.grid-overlay {
  position: fixed; inset: 0; z-index: 250; background: rgba(20,22,26,.96);
  display: flex; flex-direction: column;
}
.grid-overlay-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid #2a2f38; flex: 0 0 auto;
}
.grid-overlay-title { color: #fff; font-size: 18px; font-weight: 700; }
.grid-overlay-close {
  background: #222831; color: #fff; border: 1px solid #3a414d; border-radius: 8px;
  width: 40px; height: 40px; font-size: 24px; line-height: 1; cursor: pointer;
}
.grid-overlay-close:hover { background: var(--brand); border-color: var(--brand); }
.grid-overlay-inner {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 24px; display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  align-content: start;
}
.grid-cell {
  background: transparent; border: 0; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.grid-cell-canvas {
  display: block; width: 100%; background: #fff; border: 3px solid transparent;
  border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.4); overflow: hidden;
  transition: border-color .12s ease, transform .12s ease;
}
.grid-cell:hover .grid-cell-canvas { border-color: var(--brand); transform: translateY(-3px); }
.grid-cell canvas { display: block; width: 100%; height: auto; }
.grid-cell-label {
  color: #cbd5e1; font-size: 13px; font-weight: 600;
  background: #222831; padding: 3px 10px; border-radius: 20px;
}

/* Clip result modal */
.clip-modal {
  position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.66);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.clip-modal-inner {
  background: #fff; border-radius: 12px; max-width: 620px; width: 100%;
  max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.clip-preview-wrap { padding: 16px; background: #f1f3f5; text-align: center; }
.clip-preview-wrap img { max-width: 100%; max-height: 60vh; border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.clip-modal-actions { display: flex; gap: 10px; padding: 14px 16px; flex-wrap: wrap; }
.cm-btn {
  flex: 1; min-width: 96px; text-align: center; padding: 12px 14px; border-radius: 8px;
  border: 1px solid #d0d5db; background: #f8f9fa; color: #1a1a1a; font-weight: 700;
  font-size: 14px; cursor: pointer; text-decoration: none;
}
.cm-btn:hover { background: #eef1f4; text-decoration: none; }
.cm-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.cm-primary:hover { background: var(--brand-dark); }
.cm-close { flex: 0 0 auto; min-width: 80px; }

/* Body = rail + stage. Full width; fills the viewport below the fixed bars.
   The page scrolls so a footer can sit beneath it. */
.reader-body {
  position: relative;
  margin: calc(var(--masthead-h) + var(--toolbar-h) + 42px) auto 0;
  width: var(--reader-w);
  height: calc(100vh - var(--masthead-h) - var(--toolbar-h) - 42px);
  display: flex; align-items: stretch; overflow: hidden;
  background: var(--reader-bg);
}

/* Thumbnail rail */
.thumb-rail {
  width: var(--rail-w); flex: 0 0 var(--rail-w);
  background: var(--rail-bg); border-right: 1px solid #c7ccd2;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 10px; display: flex; flex-direction: column; gap: 14px;
}
.thumb-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: transparent; border: 0; padding: 0; cursor: pointer; width: 100%;
}
.thumb-canvas-wrap {
  display: block; width: 100%; border: 2px solid transparent; border-radius: 4px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); overflow: hidden;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.thumb-item canvas { display: block; width: 100%; height: auto; }
.thumb-item:hover .thumb-canvas-wrap { box-shadow: 0 3px 10px rgba(0,0,0,.28); }
.thumb-item.active .thumb-canvas-wrap { border-color: var(--brand); box-shadow: 0 3px 12px rgba(10,36,114,.4); }
.thumb-label {
  font-size: 12px; font-weight: 600; color: #52596180;
  color: #555b62; background: #dfe3e8; padding: 2px 8px; border-radius: 20px;
}
.thumb-item.active .thumb-label { background: var(--brand); color: #fff; }

/* Main stage (scrollable, zoomable) */
.reader-stage {
  flex: 1 1 auto; position: relative; overflow: auto;
  -webkit-overflow-scrolling: touch; background: var(--reader-bg);
}
.stage-inner {
  min-width: 100%; min-height: 100%;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 20px 40px;
}
#pdfCanvas {
  background: #fff; display: block;
  box-shadow: 0 6px 26px rgba(0,0,0,.28);
}

/* Loading overlay (over stage only) */
.reader-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: #555b62;
  pointer-events: none; background: rgba(217,221,226,.7);
}
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid rgba(0,0,0,.12); border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error / fallback */
.reader-error {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; text-align: center;
  padding: 24px; color: #1a1a1a; background: var(--reader-bg);
}
.reader-error.has-iframe { justify-content: flex-start; padding: 0; }
.reader-error iframe { width: 100%; flex: 1 1 auto; min-height: 60vh; border: 0; background: #fff; }
.reader-error.has-iframe #errorMsg {
  padding: 10px 16px; margin: 0; background: var(--toolbar-bg); width: 100%;
  font-size: 13px; color: #cbd5e1; text-align: center;
}
.reader-error.has-iframe .tb-btn-lg { margin: 10px; }

/* Rail hidden */
.reader-body.rail-hidden .thumb-rail { display: none; }

/* Full reading mode */
body.reading-mode .reader-masthead { display: none; }
body.reading-mode .reader-toolbar { display: none; }
body.reading-mode .share-bar { display: none; }
body.reading-mode .reader-body { top: 0; }
body.reading-mode .thumb-rail { display: none; }
body.reading-mode .stage-inner { padding: 8px; }

/* Hamburger menu (in the white masthead) — mobile only + slide-in sidebar */
.menu-toggle {
  width: 42px; height: 42px; border: 1px solid #e5e7eb; background: #fff;
  border-radius: 10px; cursor: pointer; padding: 0; flex: 0 0 auto; margin-left: 8px;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.menu-toggle:hover { background: #f6f7f9; }
.menu-toggle span {
  display: block; width: 22px; height: 2px; background: #1a1a1a; border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease;
}
.menu-toggle.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.active span:nth-child(2) { opacity: 0; }
.menu-toggle.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.side-nav {
  position: fixed; top: 0; right: 0; height: 100%; width: 300px; max-width: 84vw;
  background: #fff; color: #1a1a1a; z-index: 500; box-shadow: -8px 0 30px rgba(0,0,0,.3);
  transform: translateX(100%); transition: transform .28s ease;
  display: flex; flex-direction: column;
}
.side-nav.open { transform: translateX(0); }
.side-nav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid #e5e7eb;
}
.side-nav-logo { height: 34px; width: auto; }
.side-nav-close {
  background: none; border: none; font-size: 30px; line-height: 1; color: #1a1a1a;
  cursor: pointer; padding: 0 4px;
}
.side-nav-close:hover { color: var(--brand); }
.side-nav-links { display: flex; flex-direction: column; padding: 12px; gap: 2px; }
.side-nav-links a {
  color: #1a1a1a; padding: 14px 16px; border-radius: 10px;
  font-size: 16px; font-weight: 600; text-decoration: none;
}
.side-nav-links a:hover { background: #f6f7f9; }
.side-nav-links a.active { color: var(--brand); background: #eef2fb; }

.side-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 450;
  opacity: 0; transition: opacity .28s ease;
}
.side-backdrop.show { opacity: 1; }

/* Exit hint */
.exit-hint {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.72); color: #fff; padding: 8px 16px;
  border-radius: 20px; font-size: 13px; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
.exit-hint.show { opacity: 1; }

/* Responsive */
@media (max-width: 900px) {
  :root { --rail-w: 150px; }
  /* Below desktop, top bars + body go full width (70% is a desktop nicety) */
  .reader-masthead, .reader-toolbar, .share-bar, .reader-body {
    left: 0; right: 0; width: auto; transform: none;
  }
  .site-footer { width: auto; }
}

/* Tablet/mobile: swap masthead inline nav for the hamburger + sidebar */
@media (max-width: 768px) {
  .mast-nav { display: none; }
  .menu-toggle { display: inline-flex; }
}

/* ---- Mobile / tablet: stack the top chrome as normal flow so it never
   overflows or wraps under a fixed height. Toolbar + share bar become two
   tidy stacked rows; the body fills the rest. ---- */
@media (max-width: 640px) {
  :root { --rail-w: 132px; --masthead-h: 54px; }

  html, body { overflow: auto; }
  /* Stack the whole reader as a normal-flow column so nothing overflows. */
  body { display: flex; flex-direction: column; min-height: 100vh; }

  /* Masthead: normal-flow white row (logo left, hamburger right) */
  .reader-masthead { position: static; order: 0; height: 54px; }
  .mast-brand img { height: 32px; }

  /* Controls toolbar: normal flow, wraps into pager row + actions row */
  .reader-toolbar {
    position: static; order: 1; height: auto; min-height: 48px;
    flex-wrap: wrap; gap: 6px; padding: 8px 10px; justify-content: center;
  }
  .tb-left { display: none; }              /* rail/grid toggles hidden on mobile */
  .tb-center { flex: 1 1 100%; justify-content: center; }
  .tb-right { flex: 1 1 100%; justify-content: center; flex-wrap: wrap; }

  .tb-label, .tb-title, .tb-zoom { display: none; }

  .thumb-rail { display: none !important; }
  .tb-btn { min-width: 40px; height: 40px; padding: 0 10px; font-size: 17px; }
  .tb-select { height: 40px; }
  .tb-date { height: 40px; font-size: 12px; padding: 0 10px; }
  .tb-page { font-size: 13px; }

  /* Share bar: normal flow, full width */
  .share-bar { position: static; order: 2; height: 44px; width: 100%; }
  .share-btn { font-size: 19px; }

  /* Body fills the rest */
  .reader-body { position: static; order: 3; top: auto; height: auto; flex: 1 1 auto; min-height: 60vh; }
  .reader-stage { min-height: 60vh; }
  .stage-inner { padding: 12px 8px 28px; }
  .thumb-label { font-size: 11px; padding: 1px 6px; }

  /* Footer: normal flow, must render last (after the body), not default order:0 */
  .site-footer { order: 4; width: 100%; padding-top: 24px; }
  /* Mobile: footer shows only the logo + copyright/rights line */
  .footer-cols { display: none; }
  .footer-contact { display: none; }
  .footer-bottom { justify-content: center; }
  .footer-logo { order: -1; }

  .cal-popover { right: 0; width: min(280px, 88vw); }

  /* Full reading mode: stage becomes a full-viewport fixed overlay */
  body.reading-mode { overflow: hidden; }
  body.reading-mode .reader-body {
    position: fixed; inset: 0; z-index: 150; min-height: 0;
  }
  body.reading-mode .reader-stage { min-height: 0; height: 100%; }
}

/* ---- Site footer in the reader (ported from the public site) ---- */
.reader-body { box-shadow: none; }
.site-footer .container { width: 100%; margin: 0 auto; padding: 0 24px; }
.site-footer {
  background: #101826; color: #cbd5e1; margin: 0 auto;
  width: var(--reader-w);
  padding: 40px 0 24px; position: relative; z-index: 1;
}
.footer-cols {
  display: grid; grid-template-columns: 1fr 1.2fr 1.3fr; gap: 40px;
  padding-bottom: 28px; border-bottom: 1px solid #223049;
}
.footer-col h4 {
  color: #fff; margin: 0 0 14px; font-size: 17px; font-weight: 700;
  text-align: center; position: relative; padding-bottom: 10px;
}
.footer-col h4::after {
  content: ""; position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 80px; height: 2px; background: var(--brand);
}
.footer-col a {
  color: #cbd5e1; display: block; padding: 5px 0; font-size: 14px; text-align: center;
  text-decoration: none;
}
.footer-col a:hover { color: #fff; }
.footer-about { color: #9fb0c9; font-size: 14px; line-height: 1.7; margin: 0; }
.footer-bottom {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding-top: 22px; flex-wrap: wrap;
}
.footer-contact { color: #cbd5e1; font-weight: 700; font-size: 14px; text-decoration: none; }
.footer-contact:hover { color: #fff; }
.footer-copy { color: #9fb0c9; font-size: 13px; text-align: center; flex: 1; }
.footer-logo {
  height: 48px; width: auto; background: #fff; padding: 6px 10px;
  border-radius: 8px; object-fit: contain;
}
@media (max-width: 760px) {
  .footer-cols { grid-template-columns: 1fr; gap: 28px; text-align: center; }
  .footer-bottom { flex-direction: column; }
}
/* Hide the footer in full reading mode */
body.reading-mode .site-footer { display: none; }
