/* scan_to_pdf: the scan to PDF page (/tools/scan-to-pdf,
   marketing/office_tools/scan_to_pdf.html.erb, controllers/scan_to_pdf_controller.js).
   Prefix .ot-scan-. Shared pieces are in ../office_tools.css. */

.ot-scan [hidden] { display: none !important; }

/* Left: capture and edit. Right: pages and saving. */
.ot-scan-stage, .ot-scan-edit { scroll-margin-top: 84px; }
.ot-scan-stage { flex: 1 1 380px; min-width: 0; padding: 28px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px; }
.ot-scan-side { flex: 999 1 460px; min-width: 0; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 880px) { .ot-scan-stage { border-right: 0; border-bottom: 1px solid var(--border); } }
@media (max-width: 600px) { .ot-scan-stage, .ot-scan-side { padding: 20px 16px; } }

/* Start */
.ot-scan-drop { min-height: 300px; justify-content: center; cursor: default; }
.ot-scan-drop strong { font-size: 18px; color: var(--text); }
.ot-scan-drop > svg { color: var(--primary); }
.ot-scan-start-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 280px; margin-top: 4px; }
.ot-scan-file { position: relative; cursor: pointer; }
.ot-scan-file:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.ot-scan-file.ot-btn-primary { min-height: 48px; }
.ot-scan-take { display: none; }
@media (hover: none) and (pointer: coarse) {
  .ot-scan-take { display: inline-flex; }
  .ot-scan-drop-hint { display: none; }
}

/* Live camera */
.ot-scan-camera { background: #0c0a09; border-radius: var(--radius-xl); overflow: hidden; display: flex; flex-direction: column; }
.ot-scan-viewfinder { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 68vh; margin: 0 auto; background: #292524; }
.ot-scan-video, .ot-scan-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.ot-scan-video { object-fit: contain; }
.ot-scan-overlay { pointer-events: none; }
.ot-scan-viewfinder.is-flash::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0.6; }
.ot-scan-cam-status { position: absolute; top: 12px; left: 0; right: 0; margin: 0; text-align: center; pointer-events: none; }
.ot-scan-cam-status span { display: inline-block; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 14px; padding: 6px 12px; border-radius: var(--radius-full); }
.ot-scan-cam-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 18px; gap: 12px; }
.ot-scan-cam-thumb { justify-self: start; position: relative; width: 48px; height: 60px; border-radius: 4px; border: 2px solid rgba(255, 255, 255, 0.6); background: transparent; padding: 0; cursor: pointer; }
.ot-scan-cam-thumb:disabled { border-style: dashed; border-color: rgba(255, 255, 255, 0.3); cursor: default; }
.ot-scan-cam-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 2px; display: block; }
.ot-scan-cam-count { position: absolute; top: -9px; right: -9px; min-width: 22px; height: 22px; border-radius: var(--radius-full); background: var(--primary); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.ot-scan-shutter { width: 70px; height: 70px; border-radius: var(--radius-full); border: 4px solid #fff; background: #fff; box-shadow: inset 0 0 0 3px #0c0a09; cursor: pointer; }
.ot-scan-shutter:active { transform: scale(0.94); }
.ot-scan-shutter:focus-visible, .ot-scan-cam-thumb:focus-visible, .ot-scan-cam-done:focus-visible { outline: 3px solid #34d399; outline-offset: 3px; }
.ot-scan-cam-done { justify-self: end; min-height: 44px; min-width: 64px; padding: 0 12px; background: transparent; border: 0; color: #fff; font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; }

/* On phones the camera takes the whole screen, like a camera app. */
@media (hover: none) and (pointer: coarse) {
  .ot-scan-camera { position: fixed; inset: 0; z-index: 1000; border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
  .ot-scan-viewfinder { flex: 1 1 auto; min-height: 0; max-height: none; aspect-ratio: auto !important; }
  .ot-scan-cam-status { top: calc(12px + env(safe-area-inset-top)); }
}

/* Editing one page */
.ot-scan-edit { display: flex; flex-direction: column; gap: 12px; }
.ot-scan-edit-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.ot-section .ot-scan-edit-title, .ot-scan-edit-title { margin: 0; font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: 0; }
.ot-scan-edit-title:focus { outline: none; }
.ot-scan-crop-wrap { width: 100%; display: flex; justify-content: center; background: #1c1917; border-radius: var(--radius-lg); padding: 14px 0; }
.ot-scan-crop { position: relative; touch-action: none; }
.ot-scan-photo { display: block; }
.ot-scan-outline { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.ot-scan-outline polygon { fill: rgba(52, 211, 153, 0.14); stroke: #34d399; stroke-width: 2.5; stroke-linejoin: round; }
.ot-scan-handle { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none; border-radius: var(--radius-full); }
.ot-scan-handle::after { content: ""; position: absolute; inset: 11px; border-radius: var(--radius-full); background: rgba(255, 255, 255, 0.9); border: 3px solid #059669; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
.ot-scan-handle:active { cursor: grabbing; }
.ot-scan-handle:focus-visible { outline: none; }
.ot-scan-handle:focus-visible::after { border-color: var(--primary); box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--primary); }
.ot-scan-loupe { position: absolute; top: 8px; border-radius: var(--radius-full); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45); pointer-events: none; }
.ot-scan-result { display: flex; justify-content: center; background: var(--gray-200, #e7e5e4); border-radius: var(--radius-lg); padding: 14px; }
.ot-scan-result img { max-width: 100%; max-height: min(560px, 62vh); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); background: #fff; }
.ot-scan-nudge { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; }
.ot-scan-nudge-corner { flex: 1 1 160px; }
.ot-scan-nudge-pad { display: flex; gap: 6px; }
.ot-scan-nudge-pad .ot-btn { width: 44px; padding: 0; font-size: 18px; }

/* Pages */
.ot-scan-strip { display: flex; flex-wrap: wrap; gap: 14px 12px; align-items: flex-start; }
.ot-scan-pages { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 14px 12px; min-width: 0; }
.ot-scan-page { position: relative; width: 92px; display: flex; flex-direction: column; gap: 6px; touch-action: auto; }
.ot-scan-page.is-dragging { z-index: 2; opacity: 0.85; pointer-events: none; }
.ot-scan-page.is-dragging .ot-scan-thumb { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25); border-color: var(--primary); }
.ot-scan-page.is-drop-before::before, .ot-scan-page.is-drop-after::after { content: ""; position: absolute; top: 0; height: 118px; width: 3px; border-radius: 2px; background: var(--primary); }
.ot-scan-page.is-drop-before::before { left: -8px; }
.ot-scan-page.is-drop-after::after { right: -8px; }
.ot-scan-thumb { width: 92px; height: 118px; padding: 4px; box-sizing: border-box; background: var(--surface); border: 1px solid var(--border-hover); border-radius: var(--radius-sm, 4px); display: flex; align-items: center; justify-content: center; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.ot-scan-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); pointer-events: none; }
.ot-scan-thumb:hover { border-color: var(--primary); }
.ot-scan-thumb:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ot-scan-badge { position: absolute; top: 106px; left: 50%; transform: translateX(-50%); min-width: 22px; height: 22px; padding: 0 5px; box-sizing: border-box; border-radius: var(--radius-full); background: var(--primary); color: var(--text-inverse); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.ot-scan-badge.is-warning { background: #b45309; }
.ot-scan-moves { display: flex; gap: 4px; margin-top: 8px; }
.ot-scan-move { flex: 1 1 0; min-width: 44px; min-height: 44px; border-radius: var(--radius-md); border: 1px solid var(--border-hover); background: var(--surface); color: var(--text); font: inherit; font-size: 17px; cursor: pointer; }
.ot-scan-move:hover:not(:disabled) { border-color: var(--primary); }
.ot-scan-move:disabled { opacity: 0.35; cursor: default; }
.ot-scan-move:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.ot-scan-add { width: 92px; height: 118px; border-style: dashed; border-width: 2px; flex-direction: column; }

.ot-scan-next .ot-btn { flex: 1 1 150px; }

/* QR for opening the page on a phone */
.ot-scan-qr { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; display: flex; gap: 14px; align-items: center; font-size: 14px; color: var(--text-secondary); }
.ot-scan-qr strong { display: block; color: var(--text); font-size: 15px; }
.ot-scan-qr-code { width: 88px; height: 88px; flex: none; background: var(--surface); border-radius: 4px; }
.ot-scan-qr-code svg { display: block; }
@media (hover: none) and (pointer: coarse) { .ot-scan-qr { display: none; } }
