/* ==========================================================================
   THE PARCHMENT — SCRIPTURE MEMORIZATION TRACKER STYLESHEET
   11px Logo, 30px Circles with 5px Margin (Max 15 per Line),
   Exact Screen-to-Print Replica, Non-Breaking Pinned Footer,
   Auto-Fit Responsive Mobile Canvas
   ========================================================================== */

:root {
  --ht-gold: #b87c24;
  --ht-gold-soft: #fbf7ee;
  --ht-gold-line: #e3c78d;
  --ht-gold-deep: #8a5a1e;
  --ht-ink: #1f1b16;
  --ht-muted: #6b645b;
  --ht-surface: #ffffff;
  --ht-surface-2: #f7f4ed;
  --ht-line: #e0d8cb;
  --ht-circle-border: #2c2822;
}

.scribe-main {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* ==========================================================================
   1. TOOLBAR & CONTROLS
   ========================================================================== */
.tracker-toolbar {
  width: 100%;
  background: var(--ui-surface, var(--ht-surface));
  border: 1px solid var(--ui-line, var(--ht-line));
  border-radius: 1rem;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  box-sizing: border-box;
}

.toolbar-cluster-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.toolbar-cluster-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.control-unit {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-label {
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ui-muted, var(--ht-muted));
}

.ledger-select {
  font-family: var(--font-ui, sans-serif);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ui-ink, var(--ht-ink));
  background: var(--ui-surface-2, var(--ht-surface-2));
  border: 1px solid var(--ui-line, var(--ht-line));
  padding: 6px 12px;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

/* Segmented Controls (Scope & Orientation) */
.seg-controls {
  display: inline-flex;
  background: var(--ui-surface-2, var(--ht-surface-2));
  padding: 3px;
  border-radius: 9999px;
  border: 1px solid var(--ui-line, var(--ht-line));
  gap: 2px;
}

.seg-controls .seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 5px 14px;
  border-radius: 9999px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ui-muted, var(--ht-muted));
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms ease;
}

.seg-controls .seg-btn.active {
  background: var(--ui-surface, #ffffff);
  color: var(--ht-gold-deep);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Gilded Pill Print Button */
.pill-btn-action {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 20px !important;
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif) !important;
  font-size: 0.86rem !important;
  font-weight: 700 !important;
  border-radius: 9999px !important;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: 0 2px 5px rgba(141, 91, 18, 0.12) !important;
  transition: all 140ms ease;
  touch-action: manipulation;
}

.pill-btn-action.primary-gilded {
  background: #fbf5ea !important;
  border: 1.5px solid #8d5b12 !important;
  color: #8d5b12 !important;
}

.pill-btn-action.primary-gilded:hover {
  background: #b87c24 !important;
  border-color: #7b4d0e !important;
  color: #ffffff !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(184, 124, 36, 0.25) !important;
}

/* ==========================================================================
   2. SCREEN PREVIEW VIEWPORT & AUTO-SCALING
   ========================================================================== */
.sheet-preview-viewport {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 50px;
  box-sizing: border-box;
  overflow-x: auto;
}

.preview-zoom-instruction {
  display: flex;
  gap: 12px;
  font-family: var(--font-ui, sans-serif);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ui-muted, var(--ht-muted));
  margin-bottom: 12px;
}

.preview-hint {
  color: var(--ht-gold-deep);
}

.sheet-pages-stack {
  --sheet-scale: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  width: 100%;
}

/* Responsive Zoom: Scales proportionally on mobile */
.ledger-sheet-page {
  zoom: var(--sheet-scale, 1);
  margin: 0 auto;
}

/* Fallback for browsers not supporting CSS zoom */
@supports not (zoom: 1) {
  .ledger-sheet-page {
    transform: scale(var(--sheet-scale, 1));
    transform-origin: top center;
  }
}

/* Sheet Dimensions (Portrait: 8.5x11, 0.75" Left Gutter, 0.5" Other) */
.ledger-sheet-page.portrait {
  position: relative;
  width: 8.5in;
  height: 11in;
  min-height: 11in;
  max-height: 11in;
  background: #ffffff !important;
  color: #1a1a1a !important;
  box-sizing: border-box;
  padding: 0.5in 0.5in 0.5in 0.75in;
  border-radius: 2px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
  display: block;
  overflow: hidden;
}

/* Sheet Dimensions (Landscape: 11x8.5, 0.75" Top Gutter, 0.5" Other) */
.ledger-sheet-page.landscape {
  position: relative;
  width: 11in;
  height: 8.5in;
  min-height: 8.5in;
  max-height: 8.5in;
  background: #ffffff !important;
  color: #1a1a1a !important;
  box-sizing: border-box;
  padding: 0.75in 0.5in 0.5in 0.5in;
  border-radius: 2px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
  display: block;
  overflow: hidden;
}

/* Binder Holes (Screen Only) */
.ledger-sheet-page.portrait .binder-holes-guide {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0.75in;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.25in 0;
  align-items: center;
  opacity: 0.28;
}

.ledger-sheet-page.landscape .binder-holes-guide {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0.75in;
  pointer-events: none;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 0 1.6in;
  align-items: center;
  opacity: 0.28;
}

.binder-hole-pip {
  width: 18px;
  height: 18px;
  border: 1.5px dashed #777777;
  border-radius: 50%;
}

/* ==========================================================================
   3. SHEET INTERIOR
   ========================================================================== */
.sheet-header-block {
  border-bottom: 2px solid #222222;
  padding-top: 8px;
  margin-bottom: 8px;
  width: 100%;
  display: block !important;
  box-sizing: border-box;
}

/* Spacing when book header follows a chapter row on the same page */
.sheet-header-block.subsequent-book {
  margin-top: 18px !important;
  padding-top: 4px !important;
}

.sheet-title {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 20pt;
  font-weight: 700;
  color: #111111;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.1;
  padding-bottom: 4px;
  box-sizing: border-box;
}

/* Habit Rows Container */
.sheet-habit-body {
  width: 100%;
  display: block;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

/* Chapter Row */
.habit-chapter-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  border-bottom: 0.5px dashed #dddddd;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

/* Remove bottom divider when a book header immediately follows */
.habit-chapter-row:has(+ .sheet-header-block),
.habit-chapter-row:has(+ .subsequent-book) {
  border-bottom: none;
}

.habit-chapter-label {
  flex: 0 0 52px;
  width: 52px;
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 9.5pt;
  font-weight: 700;
  color: #111111;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding-top: 10px;
  box-sizing: border-box;
  white-space: nowrap;
}

/* Circles Track (Strict 15 Bubbles Per Line: 15 * 40px = 600px + buffer) */
.habit-circles-track {
  flex: 0 0 605px;
  width: 605px;
  max-width: 605px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

/* 30px Circle with 5px Margin (40px Footprint) */
.habit-circle {
  width: 30px;
  height: 30px;
  margin: 5px;
  border-radius: 50%;
  border: 1.2px solid var(--ht-circle-border);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 7.5pt;
  font-weight: 600;
  color: #222222;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  transition: all 120ms ease;
  line-height: 1;
}

.habit-circle:hover {
  border-color: #b87c24;
  background: #fbf5ea;
  transform: scale(1.12);
}

/* Filled Circle: Always Solid Black (Screen & Print) */
.habit-circle.filled {
  background-color: #000000 !important;
  background: #000000 !important;
  border-color: #000000 !important;
  color: #ffffff !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* ==========================================================================
   4. OUT-OF-FLOW ABSOLUTE FOOTER (Non-Breaking, Exact Pinning)
   ========================================================================== */
.sheet-footer-strip {
  position: absolute;
  border-top: 1.5px solid #222222;
  padding-top: 4px;
  display: grid !important;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  box-sizing: border-box;
}

/* Anchored exactly against the 0.5" bottom margin */
.ledger-sheet-page.portrait .sheet-footer-strip {
  bottom: 0.5in;
  left: 0.75in;
  right: 0.5in;
}

.ledger-sheet-page.landscape .sheet-footer-strip {
  bottom: 0.5in;
  left: 0.5in;
  right: 0.5in;
}

.sheet-footer-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

/* Exact 11px Logo Height */
.sheet-footer-logo {
  height: 11px !important;
  max-height: 11px !important;
  width: auto !important;
  object-fit: contain;
  display: block;
}

.sheet-page-num {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 9.5pt;
  font-weight: 600;
  color: #222222;
  text-align: center;
  line-height: 1;
}

.sheet-footer-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.sheet-brand-link {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 9pt;
  color: #222222;
  text-decoration: none;
  letter-spacing: 0.04em;
  font-weight: 500;
  line-height: 1;
}

/* ==========================================================================
   5. MOBILE RESPONSIVE OPTIMIZATIONS (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
  .tracker-toolbar {
    padding: 12px 14px;
    gap: 12px;
  }

  .toolbar-cluster-left {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .control-unit {
    width: 100%;
  }

  .seg-controls {
    display: flex;
    width: 100%;
    box-sizing: border-box;
  }

  .seg-controls .seg-btn {
    flex: 1 1 0;
    text-align: center;
    padding: 7px 6px;
    font-size: 0.74rem;
  }

  .ledger-select {
    width: 100%;
    box-sizing: border-box;
  }

  /* Full-Width Print Sheet Button on Mobile */
  .toolbar-cluster-right {
    width: 100%;
    margin-left: 0;
  }

  .pill-btn-action,
  #printSheetBtn {
    width: 100% !important;
    justify-content: center !important;
    padding: 11px 18px !important;
    font-size: 0.94rem !important;
    box-sizing: border-box !important;
  }

  .preview-zoom-instruction {
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
    margin-bottom: 8px;
  }
}

/* ==========================================================================
   6. DEDICATED PRINT STYLESHEET (@media print)
   Exact Replica of Preview Canvas, Zero Ghost Pages, No Broken Footers
   ========================================================================== */
@media print {
  @page {
    margin: 0;
  }

  body, html {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Always force 100% scale in print */
  .sheet-pages-stack {
    --sheet-scale: 1 !important;
  }

  .ledger-sheet-page {
    zoom: 1 !important;
    transform: none !important;
  }

  /* Suppress site navigation, headers, support buttons */
  .site-header-wrapper,
  .site-footer-wrapper,
  header.site-header,
  footer.site-footer,
  nav,
  aside,
  .no-print,
  .passage-header-strip,
  .tracker-toolbar,
  .preview-zoom-instruction,
  .binder-holes-guide,
  #toastHost,
  .cookie-banner,
  [class*="support"],
  [id*="support"] {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  main,
  .editorial-main,
  .workspace-column,
  .sheet-preview-viewport,
  .sheet-pages-stack {
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    display: block !important;
    background: transparent !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* Print containers: Exact replica of screen dimensions and padding */
  .ledger-sheet-page.portrait {
    width: 8.5in !important;
    height: 11in !important;
    min-height: 11in !important;
    max-height: 11in !important;
    padding: 0.5in 0.5in 0.5in 0.75in !important;
    margin: 0 auto !important;
    box-shadow: none !important;
    border: none !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
    position: relative !important;
    display: block !important;
    box-sizing: border-box !important;
  }

  .ledger-sheet-page.landscape {
    width: 11in !important;
    height: 8.5in !important;
    min-height: 8.5in !important;
    max-height: 8.5in !important;
    padding: 0.75in 0.5in 0.5in 0.5in !important;
    margin: 0 auto !important;
    box-shadow: none !important;
    border: none !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
    position: relative !important;
    display: block !important;
    box-sizing: border-box !important;
  }

  /* Prevent trailing blank sheets */
  .ledger-sheet-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  /* Footer stays at the EXACT same position as preview, 0.5in from sheet bottom */
  .ledger-sheet-page.portrait .sheet-footer-strip {
    position: absolute !important;
    bottom: 0.5in !important;
    left: 0.75in !important;
    right: 0.5in !important;
    width: auto !important;
    margin: 0 !important;
    display: grid !important;
  }

  .ledger-sheet-page.landscape .sheet-footer-strip {
    position: absolute !important;
    bottom: 0.5in !important;
    left: 0.5in !important;
    right: 0.5in !important;
    width: auto !important;
    margin: 0 !important;
    display: grid !important;
  }

  /* Ensure rows never split across pages */
  .habit-chapter-row {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .sheet-header-block {
    display: block !important;
  }

  /* Checked off circles remain solid black in print */
  .habit-circle.filled {
    background-color: #000000 !important;
    background: #000000 !important;
    border-color: #000000 !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .habit-circle {
    border-color: #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}