/* RBARM scan layer: header button, phone button, scan dialog, /scan page, result cards, printed barcodes.
   See app/Core/Scan.php and assets/js/scan.js. Colours come from the Liquid Glass tokens in app.css, so light and
   dark both follow the theme switch. */

/* ---------- Header button and phone button ---------- */
.scan-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 8px 0 14px; border-radius: 999px; background: var(--btn-bg); color: var(--btn-ink); font-weight: 600; font-size: 15px; box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .55); transition: transform .12s, box-shadow .15s; }
.scan-btn:hover { color: var(--btn-ink); box-shadow: 0 12px 26px -10px rgba(0, 0, 0, .6); }
.scan-btn:active { transform: scale(.97); }
.scan-btn .icon { width: 19px; height: 19px; }
.scan-kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 7px; font: 600 12px/1 var(--mono); background: rgba(255, 255, 255, .16); color: inherit; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .25); }
:root[data-theme="dark"] .scan-kbd { background: rgba(0, 0, 0, .10); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .scan-kbd { background: rgba(0, 0, 0, .10); } }
@media (pointer: coarse) { .scan-kbd { display: none; } .scan-btn { padding-right: 14px; } }

.scan-fab { display: none; }
@media (max-width: 720px) {
  .scan-btn { width: 40px; padding: 0; justify-content: center; }
  .scan-btn-text, .scan-kbd { display: none; }
  .scan-fab { position: fixed; z-index: 30; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); display: inline-flex; align-items: center; justify-content: center; width: 62px; height: 62px; border-radius: 50%;
    background: var(--btn-bg); color: var(--btn-ink); box-shadow: 0 14px 30px -10px rgba(0, 0, 0, .6), inset 0 0 0 .5px rgba(255, 255, 255, .12); }
  .scan-fab:hover, .scan-fab:active { color: var(--btn-ink); }
  .scan-fab .icon { width: 28px; height: 28px; }
  .nav-open .scan-fab, .scan-open .scan-fab { display: none; }
  /* Room below the last row of a page so the round button never hides its buttons. */
  .has-nav .content::after { content: ''; display: block; height: calc(76px + env(safe-area-inset-bottom, 0px)); }
}
/* Narrow phones: the header is full, the round button bottom-right does the job. */
@media (max-width: 520px) { .scan-btn { display: none; } }

/* ---------- Dialog ---------- */
.scan-dialog { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 28px; color: var(--ink); background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); box-shadow: 0 40px 90px -30px rgba(0, 0, 0, .55), var(--hairline); overflow: hidden; }
.scan-dialog::backdrop { background: rgba(8, 14, 10, .42); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.scan-dialog[open] { display: flex; flex-direction: column; animation: scan-pop .18s cubic-bezier(.2, .8, .2, 1); }
.scan-dialog .scanner { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px 20px; overflow-y: auto; max-height: calc(100vh - 40px); }
.scan-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.scan-dialog-head h2 { display: inline-flex; align-items: center; gap: 10px; font-size: 21px; }
.scan-dialog-head h2 .icon { width: 24px; height: 24px; color: var(--accent); }
.scan-dialog-tools { display: flex; gap: 2px; }
/* The button is "Sound": aria-pressed="true" while sound is on. */
.scan-mute .scan-icon-off, .scan-mute[aria-pressed="false"] .scan-icon-on { display: none; }
.scan-mute[aria-pressed="false"] .scan-icon-off { display: block; color: var(--bad); }
.scan-keys { font-size: 13px; color: var(--muted); }
@media (pointer: coarse) { .scan-keys { display: none; } }
@media (max-width: 720px) {
  .scan-dialog { width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border-radius: 0; }
  .scan-dialog .scanner { max-height: 100%; height: 100%; padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(20px + env(safe-area-inset-bottom, 0px)); }
}
@keyframes scan-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Input, tools, camera ---------- */
.scan-form { display: flex; flex-direction: column; gap: 10px; }
.scan-input-row { position: relative; display: flex; gap: 8px; align-items: stretch; }
.scan-input-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; display: inline-flex; }
.scan-input-icon .icon { width: 24px; height: 24px; }
input.scan-input { flex: 1; min-width: 0; min-height: 62px; padding: 10px 16px 10px 52px; border-radius: 18px; font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
input.scan-input::placeholder { font-family: var(--font); font-size: 17px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--muted); }
.scan-find { min-height: 62px; border-radius: 18px; padding: 0 20px; }
.scan-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.scan-camera-btn[aria-pressed="true"] { background: var(--mint); color: var(--mint-ink); }
.scan-tools-hint { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.scan-tools-hint .icon { width: 16px; height: 16px; }
@media (max-width: 520px) { .scan-find span { display: none; } .scan-find { padding: 0 16px; } .scan-tools-hint { display: none; } .scan-camera-btn { flex: 1; min-height: 52px; } }

.scan-camera { display: flex; flex-direction: column; gap: 10px; }
.scan-camera[hidden], .scan-camera-note[hidden], .scan-recent-list[hidden], .scan-recent-empty[hidden] { display: none; }
.scan-viewport { position: relative; aspect-ratio: 4 / 3; max-height: 52vh; border-radius: 20px; overflow: hidden; background: #000; box-shadow: inset 0 0 0 1px var(--line-strong); }
.scan-video { display: block; width: 100%; height: 100%; object-fit: cover; }
.scan-aim { position: absolute; inset: 16% 14%; pointer-events: none; }
.scan-aim i { position: absolute; width: 28px; height: 28px; border: 4px solid var(--gold); }
.scan-aim i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.scan-aim i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.scan-aim i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.scan-aim i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }
.scan-aim::after { content: ''; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; border-radius: 2px; background: rgba(233, 199, 102, .85); box-shadow: 0 0 12px rgba(233, 199, 102, .9); animation: scan-sweep 2.2s ease-in-out infinite alternate; }
@keyframes scan-sweep { from { top: 8%; } to { top: 92%; } }
.scan-camera-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.scan-camera-msg { flex: 1; min-width: 160px; font-size: 14px; color: var(--muted); }
[data-scan-torch][aria-pressed="true"] { background: var(--gold); color: #2A2410; }
.scan-camera-note { margin: 0; }

/* ---------- Results ---------- */
.scan-results { display: flex; flex-direction: column; gap: 10px; border-radius: 22px; }
.scan-results:empty { display: none; }
.scan-result { display: flex; flex-direction: column; gap: 10px; }
.scan-result-count { font-size: 14px; color: var(--muted); font-weight: 600; }
.scan-wait { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: 16px; background: var(--sunk); color: var(--muted); font-weight: 500; }
.scan-wait::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: scan-pulse .8s ease-in-out infinite alternate; }
@keyframes scan-pulse { from { opacity: .25; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }

.scan-flash-ok { animation: scan-flash-ok .9s ease-out; }
.scan-flash-warn { animation: scan-flash-warn .9s ease-out; }
.scan-flash-bad { animation: scan-flash-bad .9s ease-out; }
@keyframes scan-flash-ok { from { box-shadow: 0 0 0 4px var(--ok); background: var(--ok-bg); } to { box-shadow: 0 0 0 0 transparent; background: transparent; } }
@keyframes scan-flash-warn { from { box-shadow: 0 0 0 4px var(--warn); background: var(--warn-bg); } to { box-shadow: 0 0 0 0 transparent; background: transparent; } }
@keyframes scan-flash-bad { from { box-shadow: 0 0 0 4px var(--bad); background: var(--bad-bg); } to { box-shadow: 0 0 0 0 transparent; background: transparent; } }

.scan-card { --tone: var(--line-strong); position: relative; display: flex; flex-direction: column; gap: 8px; padding: 16px 18px 16px 22px; border-radius: 20px; background: var(--glass); box-shadow: var(--shadow), var(--hairline); overflow: hidden; }
.scan-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--tone); }
.scan-tone-ok { --tone: var(--ok); }
.scan-tone-warn { --tone: var(--warn); }
.scan-tone-bad { --tone: var(--bad); }
.scan-tone-info { --tone: var(--info); }
.scan-tone-none { --tone: var(--accent); }
.scan-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.scan-card-kind { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.scan-card-kind .icon { width: 16px; height: 16px; }
.scan-card-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.3; }
.scan-card-title a { color: var(--ink); }
.scan-card-title a:hover { color: var(--accent); }
.scan-card-sub { color: var(--ink-2); font-size: 16px; }
.scan-card-facts { font-size: 15px; }
.scan-card-facts li { padding: 7px 0; }
.scan-card-facts li > span:last-child { text-align: right; font-weight: 600; }
.scan-card-next { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 14px; background: var(--sunk); font-size: 15px; }
.scan-card-next .icon { width: 18px; height: 18px; margin-top: 3px; color: var(--accent); }
.scan-card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }
.scan-card-actions .icon { width: 16px; height: 16px; }
.scan-action { display: inline-flex; margin: 0; }
.scan-action.is-busy button { opacity: .55; pointer-events: none; }

.scan-miss { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px; border-radius: 18px; background: var(--bad-bg); color: var(--bad); }
.scan-miss-forbidden, .scan-miss-warn { background: var(--warn-bg); color: var(--warn); }
.scan-miss-icon { display: inline-flex; }
.scan-miss-icon .icon { width: 24px; height: 24px; }
.scan-miss-text { font-weight: 650; font-size: 17px; word-break: break-word; }
.scan-miss-hint { font-size: 14px; margin-top: 2px; } /* full colour: a faded hint fell below 4.5:1 on the light tint */

/* ---------- Recent scans (this device) ---------- */
.scan-recent { display: flex; flex-direction: column; gap: 6px; }
.scan-recent h3 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.scan-recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.scan-recent-item { width: 100%; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.scan-recent-item:hover { background: var(--sunk-2); }
.scan-recent-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tone); }
.scan-recent-code { font-family: var(--mono); font-weight: 600; font-size: 14px; }
.scan-recent-title { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-recent-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.scan-recent-empty { font-size: 14px; color: var(--muted); padding: 4px 0; }

/* ---------- Full page (/scan) ---------- */
.scan-flow { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.scan-flow li { position: relative; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--glass-soft); box-shadow: var(--hairline), inset 0 0 0 1px var(--line); }
.scan-flow li:not(:last-child)::after { content: ''; position: absolute; right: -10px; top: 50%; width: 8px; height: 8px; border-top: 2px solid var(--gold); border-right: 2px solid var(--gold); transform: translateY(-50%) rotate(45deg); }
.scan-flow li > span:last-child { display: flex; flex-direction: column; line-height: 1.35; }
.scan-flow small { color: var(--muted); font-size: 13px; }
.scan-flow-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 13px; flex: none; background: var(--mint); color: var(--mint-ink); }
.scan-flow-icon .icon { width: 21px; height: 21px; }
.scan-page { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.scan-main { padding: 24px; }
.scan-side { display: flex; flex-direction: column; gap: 20px; }
.scan-kinds { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.scan-kind { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--sunk-2); font-size: 14px; font-weight: 600; }
.scan-kind .icon { width: 15px; height: 15px; color: var(--accent); }
@media (max-width: 980px) { .scan-page { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .scan-flow { grid-template-columns: 1fr; gap: 8px; }
  .scan-flow li:not(:last-child)::after { right: auto; left: 34px; top: auto; bottom: -9px; transform: rotate(135deg); }
  .scan-main { padding: 16px; }
}

/* A field filled by a scan (data-scan-field) */
input.scan-filled { animation: scan-filled 1s ease-out; }
@keyframes scan-filled { from { box-shadow: inset 0 0 0 2px var(--ok), 0 0 0 5px var(--ok-bg); } }

/* ---------- Printed codes (App\Core\Barcode) ---------- */
svg.barcode { display: block; max-width: 100%; height: auto; }

@media (prefers-reduced-motion: reduce) {
  .scan-dialog[open], .scan-aim::after, .scan-wait::before, .scan-flash-ok, .scan-flash-warn, .scan-flash-bad, input.scan-filled { animation: none; }
}
@media print { .scan-btn, .scan-fab, .scan-dialog { display: none !important; } }
