/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: sans-serif; font-size: 12px; background: #e8e8e8; color: #333; }
body { display: flex; flex-direction: column; }

/* === Toolbar (two-row legacy table layout via CSS grid + subgrid) === */
/* 12-column grid: 1fr [5×70px] auto [4×70px] 1fr
   Row 1: spacer | logo(colspan5) | search-input | search-btn | print | download | share | spacer
   Row 2: spacer | 1up | thumbs | toc | first | prev | dropdown  | next | last   | zoom+ | zoom- | spacer
   subgrid ensures both rows share the same column tracks (auto col 7 sized by widest content) */
header#toolbar {
  display: grid;
  grid-template-columns: 1fr repeat(5, 70px) auto repeat(5, 70px) 1fr;
  flex-shrink: 0; z-index: 100;
}

/* Row 1: Logo bar — subgrid inherits parent columns */
.toolbar-logo-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  justify-items: center;
  height: 74px; background: #fff; color: #000;
}
/* Flatten wrappers so children become grid items */
.action-section, .search-group { display: contents; }

.logo-section {
  grid-column: 2 / 7;
  display: flex; align-items: center; justify-content: center;
  height: 74px; padding: 0 20px;
  width: 100%;
}
#header-logo { height: 70px; border: 0; }

#search-input {
  grid-column: 7; justify-self: end;
  width: 140px; padding: 4px 8px;
  border: 1px solid #ccc; border-radius: 0;
  font-family: sans-serif; font-size: 12px;
  height: 22px; outline: none; background: #fff;
}
#search-btn { grid-column: 8; }
#btn-print  { grid-column: 9; }
#btn-download { grid-column: 10; }
#btn-share  { grid-column: 11; }

/* Row 2: Navigation bar — subgrid inherits parent columns */
.toolbar-nav-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  justify-items: center;
  height: 50px; background: var(--brand-color, transparent);
}
.nav-spacer { width: 100%; }
.toolbar-nav-row > .nav-spacer:first-child { grid-column: 1; }
#btn-1up    { grid-column: 2; }
#btn-thumbs { grid-column: 3; }
#btn-toc    { grid-column: 4; }
#btn-first  { grid-column: 5; }
#btn-prev   { grid-column: 6; }
#page-select { grid-column: 7; }
#btn-next   { grid-column: 8; }
#btn-last   { grid-column: 9; }
#btn-zoom-in  { grid-column: 10; }
#btn-zoom-out { grid-column: 11; }
#btn-fit-width { grid-column: 12; }
.toolbar-nav-row > .nav-spacer:last-child { grid-column: 13; }

/* Fit-to-width SVG icon — match nav icon hover behavior */
#btn-fit-width svg rect,
#btn-fit-width svg path { transition: fill 0.1s, stroke 0.1s; }
#btn-fit-width:hover svg rect[fill="white"] { fill: #ccc; }
#btn-fit-width:hover svg rect[stroke="white"] { stroke: #ccc; }
#btn-fit-width:hover svg path { stroke: #ccc; }

/* Icon buttons (shared) */
.icon-btn {
  background: none; border: none; cursor: pointer;
  width: 70px; height: 100%; display: flex;
  align-items: center; justify-content: center;
  padding: 0;
}
.icon-btn img { border: 0; }

/* Top row icon buttons: 74px tall */
.icon-btn.top-icon { height: 74px; }

/* Nav row icon buttons: 50px tall */
.icon-btn.nav-icon { height: 50px; width: 70px; }

/* Page select dropdown in nav row */
#page-select {
  padding: 2px 4px; border: none; border-radius: 3px;
  font-family: sans-serif; font-size: 11px;
  width: 100%; max-width: 370px; min-width: 120px; height: 24px;
}

/* === Full-page panels (replace viewer when open) === */
.panel {
  flex: 1; overflow-y: auto; background: #fff;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px; border-bottom: 1px solid #eee;
  position: sticky; top: 0; background: #fff; z-index: 10;
}
.panel-header h3 { font-size: 14px; font-weight: 600; }
.panel-close {
  background: none; border: 1px solid #ccc; border-radius: 3px;
  padding: 4px 12px; cursor: pointer; font-size: 12px; color: #333;
}
.panel-close:hover { background: #f0f0f0; }

/* Thumbnails */
.thumbnail-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; padding: 20px;
}
.thumb-item {
  cursor: pointer; border: 2px solid transparent; border-radius: 4px;
  text-align: center; padding: 4px;
}
.thumb-item:hover { border-color: var(--brand-color, transparent); }
.thumb-item.active { border-color: var(--brand-color, transparent); background: #f0f0f0; }
.thumb-item canvas, .thumb-item img { width: 100%; height: auto; display: block; }
.thumb-label { font-size: 11px; color: #666; margin-top: 2px; }

/* TOC */
.toc-list { padding: 8px 0; }
.toc-item {
  display: block; padding: 6px 12px; cursor: pointer;
  text-decoration: none; color: #333; font-size: 13px;
  border-left: 3px solid transparent;
}
.toc-item:hover { background: #f5f5f5; }
.toc-item.level-1 { font-weight: 600; }
.toc-item.level-2 { padding-left: 24px; }
.toc-item.level-3 { padding-left: 36px; font-size: 12px; }
.toc-item .toc-page { float: right; color: #999; font-size: 12px; }

/* Search results */
.search-results { padding: 8px 12px; }
.search-result-item {
  padding: 8px 0; border-bottom: 1px solid #eee; cursor: pointer;
}
.search-result-item:hover { background: #f9f9f9; }
.search-result-page { font-weight: 600; font-size: 12px; color: var(--brand-color, transparent); }
.search-result-heading { font-size: 11px; color: #999; }
.search-result-snippet { font-size: 13px; margin-top: 2px; }
.search-result-snippet mark { background: #ff0; }
.search-no-results { color: #999; font-style: italic; padding: 20px 0; }

/* === Main viewer === */
#viewer-container {
  flex: 1; overflow: auto;
  background: #999;
  padding: 16px 20px;
  min-width: 0;
}
#page-container {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
#page-container.two-up {
  flex-direction: row; flex-wrap: nowrap; justify-content: center;
  width: fit-content; min-width: 100%;
}
#page-container.two-up .page-wrapper {
  flex-shrink: 0;
}

.page-wrapper {
  background: #fff;
  border: 1px solid #000; border-right-width: 2px; border-bottom-width: 2px;
  position: relative; line-height: 0;
}
.page-wrapper canvas { display: block; }
.page-wrapper .text-layer { overflow: hidden; opacity: 0.25; line-height: 1; }
.page-wrapper .text-layer span { position: absolute; white-space: pre; color: transparent; }
.page-wrapper .text-layer ::selection { background: rgba(0, 0, 255, 0.3); }
.page-wrapper .text-layer mark.search-highlight { background: rgba(255, 255, 0, 0.6); color: transparent; border-radius: 2px; padding: 1px 0; }

/* === Bottom nav (matches header nav bar) === */
#bottom-nav {
  display: flex; align-items: center;
  background: var(--brand-color, transparent);
  padding-inline: max(0px, calc((100% - 955px) / 2));
  height: 40px; flex-shrink: 0;
  position: relative;
}
/* Nav buttons + page info centered via auto margins */
#bottom-nav .icon-btn {
  height: 40px; width: auto; min-width: 36px; padding: 0 6px;
}
#bot-first { margin-left: auto; }
#bot-last  { margin-right: auto; }
#bot-page-info { font-size: 12px; color: #fff; font-family: sans-serif; padding: 0 8px; white-space: nowrap; }
/* "View This Page in PDF" — right-aligned, pulled out of flow so nav stays centered */
.view-pdf-link {
  position: absolute; right: 20px;
  display: flex; align-items: center; gap: 4px;
  color: #fff; text-decoration: none; font-size: 14px;
  white-space: nowrap; opacity: 0.85;
  height: 100%;
}
.view-pdf-link:hover { opacity: 1; text-decoration: underline; }

/* === IR Solutions footer === */
#ir-footer {
  background: rgb(204,204,204);
  padding: 4px 12px;
  flex-shrink: 0; border-top: 1px solid #ddd;
  display: flex; align-items: center; justify-content: flex-end;
}
#ir-footer a { display: inline-block; line-height: 0; }
#ir-footer img { height: 37px; width: auto;}

/* === Modal === */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-content {
  background: #fff; padding: 24px; border-radius: 8px;
  min-width: 320px; max-width: 460px; width: 90%;
}
.modal-content h2, .modal-content h3 { margin-bottom: 16px; }
.modal-content label { display: block; margin-bottom: 12px; font-size: 13px; }
.modal-content input, .modal-content textarea {
  display: block; width: 100%; padding: 8px; margin-top: 4px;
  border: 1px solid #ccc; border-radius: 4px; font-size: 14px;
}
.modal-content button {
  padding: 8px 16px; border: none; border-radius: 4px;
  cursor: pointer; font-size: 14px;
}
.modal-content button[type="submit"] { background: var(--brand-color, transparent); color: #fff; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.print-options { display: flex; flex-direction: column; gap: 8px; }
.print-options button { text-align: left; padding: 12px; background: #f5f5f5; border: 1px solid #ddd; }
.print-options button:hover { background: #e8e8e8; }

/* === Responsive === */
@media (max-width: 768px) {
  header#toolbar { display: flex; flex-direction: column; }
  .toolbar-logo-row,
  .toolbar-nav-row {
    display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
    height: auto; padding: 4px;
  }
  .action-section, .search-group { display: flex; }
  .action-section { gap: 0; }
  .search-group { align-items: center; }
  .logo-section { height: auto; min-height: 50px; flex-grow: 1; }
  .toolbar-nav-row { min-height: 40px; }
  .nav-spacer { display: none; }
  .icon-btn { width: 40px; }
  .icon-btn.top-icon { height: 50px; }
  .icon-btn.nav-icon { height: 40px; width: 40px; }
  .icon-btn img { width: 24px; height: 24px; }
  #search-input { width: 100px; }
  #viewer-container { padding: 8px; }
  #page-container.two-up { flex-direction: column; }
  #bottom-nav { flex-wrap: wrap; height: auto; min-height: 40px; }
  .view-pdf-link {
    position: static;
    width: 100%; justify-content: center;
    height: 32px;
  }
}
