:root {
  --pl-purple: #660066;
  --pl-deep: #3c003f;
  --pl-cream: #f5dfbd;
  --pl-paper: #fffdfa;
  --pl-ink: #231d23;
  --pl-muted: #706772;
  --pl-green: #237a57;
}

html, body, #mainpage { min-height: 100%; }
#mainpage { background: linear-gradient(145deg, var(--pl-deep), var(--pl-purple) 48%, #8b187f); color: var(--pl-ink); padding: 0 0 40px; }
.hero { color: white; text-align: center; padding: 34px 20px 27px; }
.hero h1 { font-size: clamp(35px, 5vw, 58px); font-weight: 800; letter-spacing: -1.5px; margin: 3px 0 8px; }
.hero p { font-size: 18px; max-width: 760px; margin: auto; opacity: .9; }
.hero-kicker { font-size: 12px; font-weight: 800; letter-spacing: 3px; opacity: .72; }
.app-shell { max-width: 1450px; margin: 0 auto; padding: 0 24px; display: grid; grid-template-columns: minmax(290px, 360px) minmax(0, 1fr); gap: 22px; align-items: start; }
.controls-card, .preview-card, .results-card { background: var(--pl-paper); border-radius: 16px; box-shadow: 0 18px 48px rgba(20,0,20,.28); }
.controls-card { min-width: 0; padding: 24px; position: sticky; top: 16px; }
.controls-card h3 { font-size: 18px; font-weight: 750; margin: 3px 0 14px; }
.controls-card hr { border-color: #e8dfdf; margin: 20px 0; }
.controls-card .well { background: var(--pl-cream); border: 0; }
.controls-card .btn-block { width: 100%; margin: 8px 0; }
.advanced-fold { margin-top: 10px; border: 1px solid #e2d8e3; border-radius: 10px; background: #fbf8fb; overflow: hidden; }
.advanced-fold > summary { display: flex; align-items: center; gap: 9px; padding: 10px 12px; cursor: pointer; color: var(--pl-purple); font-weight: 700; list-style: none; user-select: none; }
.advanced-fold > summary::-webkit-details-marker { display: none; }
.advanced-fold > summary:hover, .advanced-fold > summary:focus { background: #f4edf4; outline: none; }
.advanced-fold > summary span, .advanced-fold > summary small { display: block; }
.advanced-fold > summary small { margin-top: 1px; color: var(--pl-muted); font-size: 11px; font-weight: 500; }
.advanced-chevron { transition: transform .18s ease; font-size: 12px; }
.advanced-fold[open] .advanced-chevron { transform: rotate(90deg); }
.advanced-body { border-top: 1px solid #e8dfe8; padding: 14px 14px 4px; }
.advanced-control { margin-bottom: 19px; }
.advanced-control .form-group { margin-bottom: 5px; }
.advanced-why { color: var(--pl-muted); font-size: 12px; line-height: 1.45; }
.advanced-why strong { color: #5c525d; }
.process-button { font-weight: 700; font-size: 16px; padding: 11px 14px; }
#process.btn-success { background: #237a57 !important; border-color: #237a57 !important; color: #ffffff !important; opacity: 1 !important; filter: none !important; }
#process.btn-success:hover { background: #1c6246 !important; }
#process.btn-success:active { background: #174f39 !important; }
#process.btn-success:focus-visible { background: #237a57 !important; outline: 3px solid #660066; outline-offset: 3px; }
#process.btn-success:disabled { background: #706772 !important; opacity: 1 !important; }
.results-column { min-width: 0; }
.preview-card, .results-card { padding: 24px; margin-bottom: 22px; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 1px solid #eee5eb; margin-bottom: 16px; }
.section-heading h2 { font-size: 24px; margin: 0 0 10px; }
.section-heading span { color: var(--pl-muted); font-size: 13px; }
.preview-heading { align-items: center; }
.preview-navigation { display: flex; align-items: flex-end; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.preview-navigation .form-group { margin: 0; }
.preview-navigation label { margin: 0 0 4px; color: var(--pl-muted); font-size: 12px; white-space: nowrap; }
.preview-navigation input { height: 34px; }
.preview-navigation .selectize-control { margin-bottom: 0; }
.preview-navigation .selectize-input { min-height: 34px; padding-top: 6px; padding-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-step-buttons { display: flex; gap: 5px; padding-bottom: 1px; }
.preview-step-buttons .btn { min-width: 38px; height: 34px; padding: 6px 10px; }
.preview-position { color: var(--pl-muted); font-size: 13px; margin: -7px 0 14px; text-align: right; }
.preview-stage { position: relative; min-height: 240px; }
.processed-preview-stage { position: relative; min-height: 240px; }
#preview_loader { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: rgba(255,255,255,.92); }
#preview_loader:empty { display: none; }
.preview-loading { display: flex; align-items: center; gap: 10px; max-width: 360px; padding: 14px 18px; border: 1px solid #e4d8e5; border-radius: 999px; background: white; color: var(--pl-purple); box-shadow: 0 8px 24px rgba(45,10,47,.15); font-weight: 700; }
.preview-loading i { font-size: 18px; }
.preview-card h4 { text-align: center; color: var(--pl-muted); font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }
.preview-card img { max-width: 100%; height: auto; background: white; border: 1px solid #ddd; box-shadow: 0 5px 18px rgba(0,0,0,.09); }
.upload-summary, .process-note, .empty-state, .inline-error, .result-explanation { border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.upload-summary { background: #f4edf4; }
.page-ranges { margin-top: 12px; padding: 12px; border: 1px solid #d9c7db; border-radius: 8px; background: #faf6fb; }
.page-ranges h4 { margin: 0 0 8px; font-weight: 700; }
.page-ranges p { font-size: 13px; line-height: 1.45; }
.page-range-file { min-width: 0; margin-top: 12px; padding-top: 9px; border-top: 1px solid #dfd2e1; }
.page-range-file legend { width: 100%; margin: 0 0 5px; border: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.page-range-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.page-range-fields .shiny-input-container { width: 100%; min-width: 0; }
.process-note, .empty-state { color: var(--pl-muted); background: #f7f4f7; font-size: 13px; }
.process-note.success { background: #e7f4ed; color: var(--pl-green); font-weight: 700; }
.inline-error { background: #fde9e8; color: #9f2c28; }
.input-needs-attention { outline: 3px solid #9f2c28 !important; outline-offset: 3px; }
.input-validation-message { grid-column: 1 / -1; min-width: 0; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.result-explanation { background: #f4edf4; color: #554b56; }
.account-area { text-align: center; margin-top: 12px; }
.account-area[hidden], .account-area [hidden] { display: none !important; }
.account-area p { margin-bottom: 8px; }
.account-action { width: 50%; margin: 3%; font-size: 100%; }
.account-action-wide { width: 75%; margin: 2%; }
#download_wrap { margin-top: 12px; }
.signup-surface { min-width: 0; min-height: 0; padding: 1px 0 24px; overflow-x: clip; background: var(--pl-purple); }
.signup-surface .shinybusy { display: none !important; }
.signup-surface .row { min-width: 0; margin-left: 0; margin-right: 0; }
.signup-surface [class*="col-"] { min-width: 0; }
.signup-surface .well { height: auto !important; min-height: 650px; overflow-wrap: anywhere; }
.access-reason { max-width: 880px; margin: 22px auto 0; padding: 15px 18px; border: 2px solid #f0c36b; border-radius: 10px; background: #fff8e8; color: #4b3510; box-shadow: 0 8px 24px rgba(20,0,20,.18); }
.access-reason strong { display: block; margin-bottom: 4px; font-size: 18px; }
.access-reason p { margin: 0; font-size: 14px; line-height: 1.45; }
.table { background: white; }
.table th { color: var(--pl-purple); }
#batch_results { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; padding: 0 12px; }
  .controls-card { position: static; }
  .section-heading { display: block; }
  .preview-navigation { justify-content: flex-start; margin: 8px 0 12px; }
  .preview-position { text-align: left; }
}

@media (max-width: 767px) {
  .hero { padding: 24px 14px 20px; }
  .hero h1 { font-size: 36px; letter-spacing: -.8px; }
  .hero p { font-size: 16px; }
  .controls-card, .preview-card, .results-card { padding: 18px; border-radius: 12px; }
  .signup-surface [id$="-plan_page"] { margin: 0 !important; }
  .signup-surface [id$="-plan_page"] > .row:first-of-type [class*="col-"] { padding-left: 12px !important; padding-right: 12px !important; text-align: center !important; }
  .signup-surface [id$="-plan_page"] > .row:nth-of-type(2) [class*="col-"] { padding: 12px !important; }
  .signup-surface .well { min-height: 0; padding: 18px 14px; }
  .signup-surface h2 { font-size: 24px; }
  .signup-surface h3 { font-size: 19px; }
  .signup-surface h4 { font-size: 15px; }
  .account-action, .account-action-wide { width: 100%; margin: 5px 0; }
}

/* Scroll original-resolution preview pixels without recomputing the PDF. */
.preview-stage.inspect-detail .shiny-image-output { overflow: auto; max-height: 75vh; }
.preview-stage.inspect-detail .shiny-image-output img { max-width: none !important; width: auto !important; }

/* Keep the common path short; group less common controls in one disclosure. */
.control-hint { color: var(--pl-muted); font-size: 12px; line-height: 1.4; margin: 3px 0 12px; }
.adjustment-group { min-width: 0; border: 0; padding: 0; margin: 0 0 20px; }
.adjustment-group legend { font-size: 13px; font-weight: 750; color: var(--pl-purple); border-bottom: 1px solid #e8dfe8; margin-bottom: 12px; }
.download-bar { background: var(--pl-paper); padding: 16px 24px; border-radius: 12px; margin: 0 0 16px; }
.download-bar .process-button { max-width: 360px; margin: 0 auto; }
.download-bar .account-area { margin-top: 8px; }
.results-card > summary, .page-ranges > summary { cursor: pointer; font-weight: 650; }
.preview-card { margin-bottom: 14px; }
@media(max-width:900px) {
 .controls-card { padding-bottom: 14px; }
 .download-bar { padding: 14px 18px; }
}

.control-title { display:block; font-size:14px; font-weight:500; margin:16px 0 10px; }

/* Intent controls and optional corrections share the comparison's visual order. */
.controls-card .shiny-options-group { display: flex; flex-wrap: wrap; gap: 5px 12px; }
.controls-card .radio-inline { margin: 0; }
.controls-card .shiny-input-radiogroup { margin-bottom: 19px; }
.page-correction { border: 1px solid #e2d8e3; border-radius: 8px; margin: 0 0 15px; }
.page-correction > summary { padding: 9px 12px; cursor: pointer; color: #660066; font-weight: 650; }
.page-correction .btn { white-space: normal; margin-bottom: 10px; }
.page-attention { background: #fff4d8; border: 1px solid #eed49c; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.page-attention a { margin-left: 12px; color: #660066; text-decoration: underline; }
/* Compact estimate; explanation is revealed by hover, keyboard focus or touch. */
.ink-estimate { position: relative; display: inline-flex; align-items: center;
  gap: .4rem; max-width: 100%; margin: .35rem 0 .6rem; color: #264b3b;
  font-size: 13px; cursor: help; border-bottom: 1px dotted currentColor; }
.ink-estimate .fa-circle-info { font-size: .85em; }
.ink-estimate:focus { outline: 2px solid #246b50; outline-offset: 3px; }
.ink-estimate-help { display: none; position: absolute; z-index: 20; top: calc(100% + .5rem);
  left: 0; width: 320px; max-width: min(320px, calc(100vw - 80px)); padding: .75rem;
  border-radius: .4rem; background: #20372d; color: #fff; font-size: 12px;
  line-height: 1.45; font-weight: normal; box-shadow: 0 3px 12px #0003; }
.ink-estimate:hover .ink-estimate-help, .ink-estimate:focus .ink-estimate-help,
.ink-estimate:focus-within .ink-estimate-help { display: block; }
.ink-estimate-pending { color: #626b66; font-size: 12px; }

/* Keep the working comparison visible while adjusting cleanup settings. */
.has-documents .hero { padding: 10px 20px; text-align: left; max-width: 1450px; margin: auto; }
.has-documents .hero h1 { font-size: 24px; letter-spacing: -.5px; margin: 0; }
.has-documents .hero-kicker, .has-documents .hero p { display: none; }
.preview-card { padding: 16px; }
.preview-toolbar { position: sticky; top: 0; z-index: 10; background: var(--pl-paper); padding: 0 0 8px; border-bottom: 1px solid #eee5eb; }
.preview-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.preview-heading { padding-right: 120px; min-height: 34px; }
.preview-heading .preview-navigation { margin-right: auto; }
.preview-navigation { align-items: center; margin: 0; gap: 6px; }
.preview-navigation label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
.preview-step-buttons { align-items: center; padding: 0; }
.preview-position { margin: 0; white-space: nowrap; }
.preview-heading .ink-estimate { font-size: 12px; margin: 0; }
.page-correction { position: static; margin: 0; border: 0; }
.page-correction > summary { position: absolute; right: 0; top: 0; padding: 7px 9px; font-size: 13px; border: 1px solid #e2d8e3; border-radius: 8px; }
.page-correction > summary:focus-visible { outline: 2px solid var(--pl-purple); outline-offset: 2px; }
.page-correction > .advanced-body { position: static; margin-top: 8px; width: 100%; background: #fbf8fb; border: 1px solid #e2d8e3; border-radius: 8px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 20px; }
/* Expanded controls take real layout space, never overlap either PDF. */
.preview-toolbar:has(.page-correction[open]) { position: relative; }
.page-options-main, .page-options-actions { min-width: 0; }
.page-options-main .shiny-input-container { max-width: 100%; }
@media(max-width:700px) {
  .page-correction > .advanced-body { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
.page-correction h3 { font-size: 15px; margin: 6px 0 12px; }
.preview-heading .ink-estimate-help { left: auto; right: 0; }
@media(max-width:900px) {
  .preview-heading { display: flex; }
  .preview-navigation { margin: 0; }
  .preview-toolbar { position: relative; }
  .page-correction { position: static; }
  .preview-heading .ink-estimate-help { left: 0; right: auto; }
}
