/* scanner.css — styles for scanner.js (Local 651 Portal document scanner, SPEC §12).
   Every selector is scoped under .scn-overlay (or .scn-lock on <html>), so nothing
   here leaks into the rest of the app. Dark, camera-style surface; AFSCME green
   accents. No external fonts: inherits the app's font stack, then system fonts. */

html.scn-lock,
html.scn-lock body {
  overflow: hidden;
}

.scn-overlay {
  --scn-bg: #0d1117;
  --scn-panel: #161d26;
  --scn-raised: #222c38;
  --scn-raised-hi: #2c3846;
  --scn-line: #33404f;
  --scn-fg: #f3f6f4;
  --scn-muted: #aab5c0;
  --scn-primary: #0a7f3e;      /* AFSCME green, darkened for 5:1 contrast with white text */
  --scn-primary-hi: #046a35;
  --scn-accent: #12b85a;
  --scn-blue: #0032a0;
  --scn-danger: #c62f35;
  --scn-danger-hi: #a8262b;
  --scn-danger-text: #ff9a9e;
  --scn-focus: #ffd34d;

  position: fixed;
  inset: 0;
  z-index: 2147483000;          /* only matters for the non-modal fallback */
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--scn-bg);
  color: var(--scn-fg);
  font-family: var(--body, 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}

.scn-overlay[open] {
  display: flex;
  flex-direction: column;
}

.scn-overlay:not([open]) {
  display: none;
}

.scn-overlay::backdrop {
  background: #000;
}

.scn-overlay *,
.scn-overlay *::before,
.scn-overlay *::after {
  box-sizing: border-box;
}

.scn-overlay [hidden] {
  display: none !important;
}

.scn-overlay p,
.scn-overlay h2,
.scn-overlay ol {
  margin: 0;
  padding: 0;
}

/* ---- Buttons ---------------------------------------------------------- */

.scn-overlay .scn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--scn-raised);
  color: var(--scn-fg);
  font: inherit;
  font-family: var(--disp, 'Montserrat', 'Trebuchet MS', system-ui, Arial, sans-serif);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.scn-overlay .scn-btn:hover:not(:disabled) {
  background: var(--scn-raised-hi);
}

.scn-overlay .scn-btn:focus-visible,
.scn-overlay .scn-seg-btn:focus-visible,
.scn-overlay .scn-thumb:focus-visible,
.scn-overlay .scn-handle:focus-visible {
  outline: 3px solid var(--scn-focus);
  outline-offset: 2px;
}

.scn-overlay .scn-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.scn-overlay .scn-btn-primary {
  background: var(--scn-primary);
  color: #fff;
}

.scn-overlay .scn-btn-primary:hover:not(:disabled) {
  background: var(--scn-primary-hi);
}

.scn-overlay .scn-btn-secondary {
  background: var(--scn-raised);
  border-color: var(--scn-line);
}

.scn-overlay .scn-btn-ghost {
  background: transparent;
}

.scn-overlay .scn-btn-danger {
  background: var(--scn-danger);
  color: #fff;
}

.scn-overlay .scn-btn-danger:hover:not(:disabled) {
  background: var(--scn-danger-hi);
}

.scn-overlay .scn-btn-danger-ghost {
  color: var(--scn-danger-text);
}

.scn-overlay .scn-btn-wide {
  flex: 1 1 0;
  min-height: 52px;
  padding-inline: 12px;
  white-space: nowrap;
}

.scn-overlay .scn-icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.scn-overlay .scn-icon-btn {
  padding: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: transparent;
}

.scn-overlay .scn-invisible {
  visibility: hidden;
}

/* ---- Top bar & status -------------------------------------------------- */

.scn-overlay .scn-topbar {
  flex: none;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  background: var(--scn-panel);
  border-bottom: 1px solid var(--scn-line);
}

.scn-overlay .scn-topbar .scn-btn {
  padding: 8px 12px;
}

.scn-overlay .scn-title {
  overflow: hidden;
  font-family: var(--disp, 'Montserrat', 'Trebuchet MS', system-ui, Arial, sans-serif);
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scn-overlay .scn-title:focus {
  outline: none;
}

.scn-overlay .scn-status {
  flex: none;
  min-height: 1.6em;
  padding: 4px 16px 0;
  color: var(--scn-muted);
  font-size: 0.88rem;
  text-align: center;
}

.scn-overlay .scn-status-error {
  color: var(--scn-danger-text);
  font-weight: 600;
}

/* ---- Views ------------------------------------------------------------- */

.scn-overlay .scn-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scn-overlay .scn-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}

.scn-overlay .scn-actions {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: var(--scn-panel);
  border-top: 1px solid var(--scn-line);
}

/* Icon-over-label tool buttons (corner editor / clean-up toolbars) */
.scn-overlay .scn-toolbar {
  flex-wrap: nowrap;
  justify-content: space-between;
}

.scn-overlay .scn-tool {
  flex: 1 1 0;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 6px 4px;
  border-radius: 12px;
  background: transparent;
  font-size: 0.75rem;
  font-weight: 700;
}

.scn-overlay .scn-tool .scn-btn-label {
  max-width: 100%;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.scn-overlay .scn-toolbar .scn-btn-primary {
  flex: 1.4 1 0;
  min-height: 48px;
  padding: 10px 12px;
}

/* ---- Pages list -------------------------------------------------------- */

.scn-overlay .scn-empty {
  max-width: 30rem;
  margin: 8vh auto 0;
  text-align: center;
}

.scn-overlay .scn-empty-title {
  margin-bottom: 10px;
  font-family: var(--disp, 'Montserrat', 'Trebuchet MS', system-ui, Arial, sans-serif);
  font-size: 1.25rem;
  font-weight: 800;
}

.scn-overlay .scn-empty-text {
  margin-bottom: 10px;
  color: var(--scn-muted);
}

.scn-overlay .scn-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  list-style: none;
}

.scn-overlay .scn-page {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--scn-line);
  border-radius: 14px;
  background: var(--scn-panel);
}

.scn-overlay .scn-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 170px;
  margin: 0;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: #0a0e13;
  cursor: pointer;
  touch-action: manipulation;
}

.scn-overlay .scn-thumb-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.scn-overlay .scn-page-num {
  position: absolute;
  top: 14px;
  left: 14px;
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--scn-blue);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
}

.scn-overlay .scn-page-mode {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
}

.scn-overlay .scn-page-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  justify-items: center;
}

/* ---- Stages (photo areas) ---------------------------------------------- */

.scn-overlay .scn-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.scn-overlay .scn-crop-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.scn-overlay .scn-hint {
  flex: none;
  padding: 2px 16px 4px;
  color: var(--scn-muted);
  font-size: 0.85rem;
  text-align: center;
}

.scn-overlay .scn-imgbox {
  position: relative;
  flex: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.scn-overlay .scn-crop-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.scn-overlay .scn-quad {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.scn-overlay .scn-quad-shade {
  fill: rgba(0, 0, 0, 0.5);
}

.scn-overlay .scn-quad-line {
  fill: rgba(18, 184, 90, 0.08);
  stroke: var(--scn-accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* 48×48 touch target; the visible dot is smaller. Position comes from JS (CSSOM). */
.scn-overlay .scn-handle {
  position: absolute;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.scn-overlay .scn-handle.scn-active {
  cursor: grabbing;
}

.scn-overlay .scn-handle-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: rgba(14, 156, 76, 0.45);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.65), 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease;
  pointer-events: none;
}

.scn-overlay .scn-handle.scn-active .scn-handle-dot {
  transform: scale(1.3);
  background: rgba(18, 184, 90, 0.7);
}

.scn-overlay .scn-loupe {
  position: absolute;
  top: 10px;
  width: 120px;
  height: 120px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #111;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.scn-overlay .scn-loupe-left {
  left: 10px;
}

.scn-overlay .scn-loupe-right {
  right: 10px;
}

.scn-overlay .scn-edit-stage {
  margin: 10px 14px;
}

.scn-overlay .scn-result {
  position: absolute;
  inset: 0;
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
}

/* ---- Enhance segmented control ------------------------------------------ */

.scn-overlay .scn-seg {
  flex: none;
  display: flex;
  gap: 4px;
  margin: 0 14px 10px;
  padding: 4px;
  border: 1px solid var(--scn-line);
  border-radius: 999px;
  background: #0a0e13;
}

.scn-overlay .scn-seg-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 8px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--scn-muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.scn-overlay .scn-seg-btn[aria-pressed="true"] {
  background: var(--scn-primary);
  color: #fff;
}

/* ---- Confirm panel ------------------------------------------------------ */

.scn-overlay .scn-confirm {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.65);
}

.scn-overlay .scn-confirm-box {
  width: 100%;
  max-width: 360px;
  padding: 22px 20px 18px;
  border: 1px solid var(--scn-line);
  border-radius: 16px;
  background: var(--scn-panel);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.scn-overlay .scn-confirm-title {
  margin-bottom: 8px;
  font-family: var(--disp, 'Montserrat', 'Trebuchet MS', system-ui, Arial, sans-serif);
  font-size: 1.1rem;
  font-weight: 800;
}

.scn-overlay .scn-confirm-text {
  margin-bottom: 18px;
  color: var(--scn-muted);
}

.scn-overlay .scn-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

/* ---- Busy overlay ------------------------------------------------------- */

.scn-overlay .scn-busy {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(13, 17, 23, 0.75);
  cursor: progress;
}

.scn-overlay .scn-spinner {
  width: 46px;
  height: 46px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: scn-spin 0.9s linear infinite;
}

.scn-overlay .scn-busy-text {
  font-weight: 700;
}

@keyframes scn-spin {
  to { transform: rotate(360deg); }
}

/* ---- Hidden file inputs (kept clickable from JS on iOS) ------------------ */

.scn-overlay .scn-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  clip-path: inset(50%);
  pointer-events: none;
}

/* ---- Wider screens -------------------------------------------------------- */

@media (min-width: 720px) {
  .scn-overlay .scn-actions {
    justify-content: center;
  }

  .scn-overlay .scn-btn-wide {
    flex: 0 1 260px;
  }

  .scn-overlay .scn-toolbar {
    justify-content: center;
  }

  .scn-overlay .scn-tool,
  .scn-overlay .scn-toolbar .scn-btn-primary {
    flex: 0 1 140px;
  }

  .scn-overlay .scn-seg {
    align-self: center;
    width: min(520px, 100% - 28px);
  }
}

/* ---- Preferences ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .scn-overlay .scn-spinner {
    animation-duration: 3s;
  }

  .scn-overlay .scn-handle-dot {
    transition: none;
  }
}

@media (forced-colors: active) {
  .scn-overlay .scn-btn,
  .scn-overlay .scn-seg-btn,
  .scn-overlay .scn-thumb {
    border: 1px solid ButtonText;
  }

  .scn-overlay .scn-seg-btn[aria-pressed="true"] {
    background: Highlight;
    color: HighlightText;
  }

  .scn-overlay .scn-handle-dot {
    forced-color-adjust: none;
    border-color: Canvas;
    background: Highlight;
  }

  .scn-overlay .scn-quad-line {
    stroke: Highlight;
  }
}
