/* Skeniraj nalogo (public/scan/scan.js) */
#view-scan .scan-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
#view-scan .scan-body > *, .scan-steps li, .scan-step-title { min-width: 0; overflow-wrap: anywhere; }
/* matematika ostane od leve proti desni tudi v arabščini, perzijščini in urdu (RTL) */
#view-scan .katex, #scan-input { direction: ltr; unicode-bidi: isolate; }
.scan-label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 6px; }
.scan-h2 { font-size: 1rem; margin: 0 0 10px; }
.scan-hint { text-align: center; font-size: 0.9rem; margin: 10px 0 0; }
.scan-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.scan-actions > button { min-height: 44px; }

/* kamera in izrez */
.scan-cam { position: relative; padding: 10px; }
.scan-stage { position: relative; overflow: hidden; border-radius: var(--radius-sm); background: #0b0f17; aspect-ratio: 3 / 4; max-height: 62vh; width: 100%; margin: 0 auto; touch-action: none; user-select: none; -webkit-user-select: none; }
@media (min-width: 700px) { .scan-stage { aspect-ratio: 16 / 10; } }
@media (max-width: 699px) { .scan-stage { max-height: calc(100dvh - 400px); min-height: 240px; } }
.scan-stage video, .scan-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-stage.contain img { object-fit: contain; }
.scan-stage.busy .scan-frame { animation: scan-pulse 1.2s ease-in-out infinite; }
.scan-cam-off { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 20px; text-align: center; color: #e8edf5; z-index: 1; }
.scan-cam-off p { margin: 0; max-width: 34ch; }
.scan-cam-ic .i { width: 44px; height: 44px; opacity: 0.85; }
.scan-frame { position: absolute; z-index: 2; border: 2px solid #fff; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(5, 8, 15, 0.5); cursor: move; touch-action: none; }
.scan-cam-off:not([hidden]) ~ .scan-frame { display: none; }
.scan-h { position: absolute; width: 44px; height: 44px; touch-action: none; }
.scan-h::after { content: ""; position: absolute; width: 22px; height: 22px; border: 4px solid var(--accent-grad, #22b8f0); }
.scan-h.nw { left: -22px; top: -22px; cursor: nwse-resize; }
.scan-h.nw::after { left: 18px; top: 18px; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.scan-h.ne { right: -22px; top: -22px; cursor: nesw-resize; }
.scan-h.ne::after { right: 18px; top: 18px; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.scan-h.sw { left: -22px; bottom: -22px; cursor: nesw-resize; }
.scan-h.sw::after { left: 18px; bottom: 18px; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.scan-h.se { right: -22px; bottom: -22px; cursor: nwse-resize; }
.scan-h.se::after { right: 18px; bottom: 18px; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }
.scan-reading { position: absolute; z-index: 3; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 700; white-space: nowrap; }
@keyframes scan-pulse { 50% { opacity: 0.55; } }

.scan-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-top: 10px; }
.scan-side { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; min-height: 52px; padding: 6px 10px; background: transparent; border: 0; color: var(--text); font-weight: 700; font-size: 0.86rem; border-radius: var(--radius-sm); cursor: pointer; }
.scan-side:hover { background: var(--surface-2); }
.scan-side .i { width: 24px; height: 24px; }
.scan-shutter { width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--accent); background: var(--surface); padding: 5px; cursor: pointer; }
.scan-shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--accent); transition: transform 0.12s; }
.scan-shutter:active span { transform: scale(0.88); }
.scan-shutter:focus-visible, .scan-side:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.scan-torch { position: absolute; top: 18px; right: 18px; z-index: 3; background: rgba(5, 8, 15, 0.55); color: #fff; border-radius: 50%; width: 44px; height: 44px; }
.scan-torch[aria-pressed="true"] { background: var(--gold); color: #1a1a1a; }

.scan-hist-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 8px; }
.scan-hist-head h2 { font-size: 1rem; margin: 0; }
.scan-hist .list-row { min-height: 52px; }
.scan-hist .lr-text b, .scan-hist .lr-text small { display: block; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }

/* prepis */
.scan-note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin: 0; }
.scan-note .i { flex: none; color: var(--accent); margin-top: 2px; }
.scan-picks { display: grid; gap: 8px; }
.scan-pick { text-align: start; padding: 10px 14px; border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); overflow-x: auto; cursor: pointer; min-height: 48px; }
.scan-pick.on { border-color: var(--accent); background: var(--accent-soft); }
.scan-confirm { padding: 16px; }
.scan-preview { min-height: 52px; overflow-x: auto; overflow-y: hidden; padding: 4px 2px 10px; font-size: 1.15rem; }
.scan-preview .katex-display { margin: 0.3em 0; }
.scan-input-row { display: flex; gap: 8px; align-items: center; }
.scan-input-row input { flex: 1; min-width: 0; font-size: 1.1rem; min-height: 48px; font-variant-numeric: tabular-nums; }
.scan-input-row button { flex: none; width: 48px; height: 48px; }
.scan-sym { margin-top: 10px; }
.scan-err { color: var(--danger); font-weight: 600; margin: 8px 0 0; }

/* rešitev */
.scan-problem { display: flex; align-items: center; gap: 8px; padding-block: 10px; padding-inline: 16px 12px; }
.scan-problem-tex { flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; font-size: 1.1rem; }
.scan-problem-tex .katex-display { margin: 0.2em 0; }
.scan-problem > button { flex: none; width: 44px; height: 44px; }
.scan-goals { margin-top: -4px; }
.scan-answer { padding: 14px 16px; border: 2px solid var(--accent); background: var(--accent-soft); }
.scan-answer-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.scan-answer-head .scan-label { margin: 0; color: var(--accent); }
.scan-answer-tex { overflow-x: auto; overflow-y: hidden; font-size: 1.3rem; }
.scan-answer-tex p { margin: 6px 0 0; font-size: 1rem; font-weight: 700; }
.scan-answer-tex .katex-display { margin: 0.35em 0; }
.scan-approx { color: var(--muted); overflow-x: auto; }
.scan-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.scan-badge .i { width: 16px; height: 16px; flex: none; }
.scan-badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.scan-badge.warn { color: var(--text); background: color-mix(in srgb, var(--gold) 22%, var(--surface)); border-radius: var(--radius-sm); }
.scan-methods .seg { max-width: 100%; }

.scan-steps ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.scan-step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; animation: fade-up 0.25s ease both; }
.scan-step-head { display: flex; gap: 10px; align-items: flex-start; }
.scan-step-n { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-text, #fff); font-weight: 800; font-size: 0.9rem; }
.scan-step-title { margin: 3px 0 0; font-weight: 600; line-height: 1.45; }
.scan-step-math { display: flex; align-items: center; gap: 12px; overflow-x: auto; overflow-y: hidden; padding-block: 2px; padding-inline: 38px 0; }
.scan-step-math .katex-display { margin: 0.5em 0; text-align: left; }
.scan-step-math .katex-display > .katex { text-align: left; }
[dir="rtl"] .scan-step-math .katex-display > .katex, [dir="rtl"] .scan-why .katex-display > .katex { text-align: right; }
[dir="rtl"] .scan-step-math .katex-display, [dir="rtl"] .scan-why .katex-display { text-align: right; }
.scan-step-note { flex: none; color: var(--muted); font-size: 0.95rem; white-space: nowrap; }
.scan-step-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; padding-inline-start: 38px; }
.scan-step-actions .text-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.scan-step-actions .i { width: 16px; height: 16px; }
.scan-why { margin: 6px 0 0; margin-inline-start: 38px; padding: 10px 12px; border-inline-start: 3px solid var(--accent); background: var(--surface-2); border-start-end-radius: var(--radius-sm); border-end-end-radius: var(--radius-sm); overflow-x: auto; }
.scan-why p { margin: 0 0 6px; line-height: 1.5; }
.scan-why .katex-display { margin: 0.4em 0 0; text-align: left; }
.scan-more { justify-content: space-between; align-items: center; }
.scan-more .muted { font-weight: 600; margin-inline-start: 4px; color: inherit; opacity: 0.85; }
@media (max-width: 520px) {
  .scan-step-math, .scan-step-actions { padding-inline-start: 0; }
  .scan-why { margin-inline-start: 0; }
  .scan-actions > button { flex: 1 1 auto; justify-content: center; }
  .scan-step-math { flex-wrap: wrap; gap: 0 12px; }
  .scan-step-math .katex, .scan-why .katex { font-size: 1.02em; }
}

.scan-graph-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.scan-graph-head h2 { margin: 0; }
.scan-graph-head > button { min-height: 44px; }
.scan-graph-host, .scan-nl-svg { direction: ltr; }
.scan-graph-host { position: relative; height: 260px; margin-top: 10px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.scan-graph-host .gc-canvas { width: 100%; height: 100%; display: block; }
.scan-nl-svg { width: 100%; max-width: 520px; height: auto; display: block; margin: 0 auto; overflow: visible; }
.nl-axis { stroke: var(--muted); stroke-width: 2; fill: none; }
.nl-seg { stroke: var(--accent); stroke-width: 6; stroke-linecap: round; }
.nl-seg-head { stroke: var(--accent); stroke-width: 4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.nl-closed { fill: var(--accent); stroke: var(--accent); stroke-width: 2; }
.nl-open { fill: var(--surface); stroke: var(--accent); stroke-width: 3; }
.nl-label { text-align: center; font-size: 13px; color: var(--text); }
.scan-ai-state { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 20px; }
.scan-ai-state p { margin: 0; }
.scan-foot { justify-content: center; }

.scan-spin, .scan-body .spinner { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: scan-rot 0.8s linear infinite; }
@keyframes scan-rot { to { transform: rotate(360deg); } }
