/* Fast Document Scanner — Phase 1–2 gate UI */

.scanner-root {
    text-align: center;
    padding-bottom: 32px;
}

.scanner-hero-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 8px auto 24px;
    padding: 14px 22px;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    box-shadow: 0 10px 28px -12px rgba(15, 23, 42, 0.18);
}

.scanner-hero-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    object-fit: cover;
    flex-shrink: 0;
}

.scanner-hero-title {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: #0f172a;
    line-height: 1.2;
}

.scanner-hero-sub {
    margin: 4px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
}

.scanner-gate {
    max-width: 420px;
    margin: 0 auto;
}

.scanner-gate-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 28px 22px;
    box-shadow: 0 14px 36px -16px rgba(15, 23, 42, 0.14);
}

.scanner-gate-lead {
    margin: 0 0 18px;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.55;
}

.scanner-gate-note {
    margin: 16px 0 0;
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
}

/* ── PC QR gate ── */
.scanner-qr-wrap {
    display: flex;
    justify-content: center;
    margin: 8px auto 14px;
    padding: 16px;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 16px;
    min-height: 252px;
    align-items: center;
}

.scanner-qr-wrap canvas,
.scanner-qr-wrap img {
    display: block;
    border-radius: 8px;
}

.scanner-qr-loading {
    font-size: 14px;
    color: #94a3b8;
}

.scanner-pc-url {
    margin: 12px 0 0;
    font-size: 12px;
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    color: #475569;
    word-break: break-all;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 10px 12px;
}

/* ── Mobile PWA gate ── */
.scanner-pwa-logo {
    width: 112px;
    height: 112px;
    border-radius: 24px;
    object-fit: cover;
    margin: 0 auto 16px;
    display: block;
    box-shadow: 0 12px 30px -10px rgba(99, 102, 241, 0.45);
}

.scanner-pwa-title {
    margin: 0 0 10px;
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.3;
}

.scanner-pwa-copy {
    margin: 0 0 20px;
    font-size: 15px;
    color: #334155;
    line-height: 1.65;
}

.scanner-pwa-copy strong {
    color: #4f46e5;
}

.scanner-pwa-install-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    padding: 14px 18px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 24px -8px rgba(79, 70, 229, 0.55);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    touch-action: manipulation;
}

.scanner-pwa-install-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px -8px rgba(79, 70, 229, 0.6);
}

.scanner-pwa-install-btn:active {
    transform: scale(0.98);
}

.scanner-pwa-install-btn:disabled,
.scanner-pwa-install-btn[hidden] {
    display: none;
}

.scanner-ios-guide {
    margin-top: 18px;
    padding: 16px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 14px;
    text-align: left;
}

.scanner-ios-guide h3 {
    margin: 0 0 10px;
    font-size: 14px;
    font-weight: 700;
    color: #3730a3;
}

.scanner-ios-guide ol {
    margin: 0;
    padding-left: 20px;
    font-size: 14px;
    color: #334155;
    line-height: 1.7;
}

.scanner-standalone-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 auto 14px;
    padding: 8px 14px;
    border-radius: 999px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #047857;
    font-size: 13px;
    font-weight: 700;
}

.scanner-phase-note {
    margin-top: 18px;
    font-size: 13px;
    color: #94a3b8;
    line-height: 1.5;
}

.scanner-start-scan-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 320px;
    margin: 14px auto 0;
    padding: 14px 18px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 24px -8px rgba(16, 185, 129, 0.5);
    touch-action: manipulation;
}

.scanner-start-scan-btn:active {
    transform: scale(0.98);
}

/* ── Phase 3: Camera stage ── */
.scanner-camera-stage {
    max-width: 100%;
    margin: 0 auto;
    text-align: center;
}

.scanner-camera-toolbar {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.scanner-flash-btn {
    padding: 8px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    background: #ffffff;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.scanner-flash-btn[data-mode="on"] {
    border-color: #fbbf24;
    background: #fffbeb;
    color: #b45309;
}

.scanner-viewport {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    aspect-ratio: 3 / 4;
    border-radius: 18px;
    overflow: hidden;
    background: #0f172a;
    box-shadow: 0 16px 40px -16px rgba(15, 23, 42, 0.45);
}

.scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #000;
}

.scanner-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scanner-flash-fx {
    position: absolute;
    inset: 0;
    background: #ffffff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.05s ease-out;
}

.scanner-flash-fx.is-active {
    opacity: 0.85;
}

.scanner-camera-error {
    margin: 12px auto 0;
    max-width: 420px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 14px;
    line-height: 1.5;
}

.scanner-camera-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 16px 24px;
    margin-top: 18px;
    padding: 8px 0 4px;
}

.scanner-done-btn {
    padding: 10px 18px;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.scanner-done-btn[hidden] {
    display: none;
}

.scanner-done-btn:active {
    transform: scale(0.98);
}

.scanner-shot-counter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 8px 14px;
    border-radius: 999px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #3730a3;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.scanner-shutter-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid #ffffff;
    background: radial-gradient(circle at 30% 30%, #ffffff 0%, #ef4444 45%, #dc2626 100%);
    box-shadow: 0 0 0 4px #dc2626, 0 12px 28px -8px rgba(220, 38, 38, 0.55);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.1s ease;
}

.scanner-shutter-btn:active:not(:disabled) {
    transform: scale(0.94);
}

.scanner-shutter-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: 0 0 0 4px #94a3b8;
}

/* ── Filename modal (Phase 6 skeleton) ── */
.scanner-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.scanner-modal[hidden] {
    display: none !important;
}

.scanner-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.scanner-modal-card {
    position: relative;
    width: 100%;
    max-width: 380px;
    padding: 24px 20px;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 24px 48px -20px rgba(15, 23, 42, 0.45);
    text-align: left;
}

.scanner-modal-title {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
}

.scanner-modal-copy {
    margin: 0 0 16px;
    font-size: 14px;
    color: #64748b;
    line-height: 1.55;
}

.scanner-modal-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 700;
    color: #475569;
}

.scanner-modal-input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    font-size: 15px;
    color: #0f172a;
    margin-bottom: 16px;
}

.scanner-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.scanner-modal-btn {
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: none;
}

.scanner-modal-btn--ghost {
    background: #f1f5f9;
    color: #475569;
}

.scanner-modal-btn--primary {
    background: #4f46e5;
    color: #ffffff;
}

.scanner-modal-status {
    margin: -8px 0 14px;
    font-size: 13px;
    color: #6366f1;
    line-height: 1.5;
}

.scanner-modal-status.is-error {
    color: #dc2626;
}

/* ── Phase 5.5: Queue manipulation grid ── */
.scanner-manipulate-card {
    max-width: 420px;
}

.scanner-thumb-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 16px 0 18px;
}

.scanner-thumb-cell {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: 12px;
    overflow: hidden;
    background: #0f172a;
    border: 2px solid #e2e8f0;
    touch-action: none;
    cursor: grab;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.scanner-thumb-cell.is-dragging {
    opacity: 0.72;
    transform: scale(0.96);
    border-color: #6366f1;
}

.scanner-thumb-cell.is-drop-target {
    border-color: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
}

.scanner-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    user-select: none;
}

.scanner-thumb-badge {
    position: absolute;
    left: 6px;
    bottom: 6px;
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.4;
}

.scanner-thumb-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(220, 38, 38, 0.92);
    color: #ffffff;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    z-index: 2;
}

.scanner-manipulate-empty {
    grid-column: 1 / -1;
    margin: 8px 0;
    font-size: 14px;
    color: #64748b;
    text-align: center;
}

.scanner-manipulate-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.scanner-manipulate-btn {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    touch-action: manipulation;
}

.scanner-manipulate-btn--ghost {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.scanner-manipulate-btn--primary {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
}

.scanner-manipulate-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ── PDF export options ── */
.scanner-pdf-options {
    margin: 4px 0 14px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    text-align: left;
}

.scanner-option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    margin: 0;
}

.scanner-option-row + .scanner-option-hint {
    margin-top: 4px;
}

.scanner-option-hint {
    margin: 0 0 10px 28px;
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.45;
}

.scanner-option-hint:last-child {
    margin-bottom: 0;
}

.scanner-watermark-input {
    margin-top: 8px;
    margin-bottom: 0 !important;
}

.scanner-watermark-input[hidden] {
    display: none !important;
}

.scanner-complete-modal .scanner-modal-card {
    text-align: center;
}

.scanner-complete-icon {
    font-size: 42px;
    line-height: 1;
    margin-bottom: 8px;
}

.scanner-complete-copy {
    margin: 0 0 20px;
    font-size: 15px;
    color: #475569;
    line-height: 1.65;
    text-align: left;
}

.scanner-complete-copy strong {
    color: #4f46e5;
}

.scanner-complete-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.scanner-complete-btn {
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.scanner-complete-btn--primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    box-shadow: 0 10px 24px -8px rgba(16, 185, 129, 0.45);
}

.scanner-complete-btn--secondary {
    background: #eef2ff;
    color: #3730a3;
    border: 1px solid #c7d2fe;
}

/* ── Phase 4: Editor + OpenCV loading ── */
.scanner-editor-stage {
    max-width: 100%;
    margin: 0 auto;
}

.scanner-editor-loading {
    padding: 48px 20px;
    text-align: center;
}

.scanner-editor-loading p {
    margin: 16px 0 0;
    font-size: 15px;
    font-weight: 600;
    color: #475569;
}

.scanner-spinner {
    width: 44px;
    height: 44px;
    margin: 0 auto;
    border: 4px solid #e2e8f0;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: scanner-spin 0.85s linear infinite;
}

@keyframes scanner-spin {
    to { transform: rotate(360deg); }
}

.scanner-editor-hint {
    margin: 0 0 12px;
    font-size: 14px;
    color: #64748b;
    line-height: 1.5;
}

.scanner-editor-viewport {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    aspect-ratio: 3 / 4;
    border-radius: 16px;
    overflow: hidden;
    background: #0f172a;
    touch-action: none;
}

.scanner-editor-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    user-select: none;
    pointer-events: none;
}

.scanner-editor-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scanner-corner-handle {
    position: absolute;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid #ffffff;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    cursor: grab;
    touch-action: none;
    z-index: 2;
    padding: 0;
}

.scanner-corner-handle:active {
    cursor: grabbing;
    transform: scale(1.08);
}

.scanner-editor-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 16px;
}

.scanner-editor-btn {
    min-width: 120px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    touch-action: manipulation;
}

.scanner-editor-btn--ghost {
    background: #f1f5f9;
    color: #475569;
}

.scanner-editor-btn--primary {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
}

.scanner-editor-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

@media (max-width: 480px) {
    .scanner-hero-badge {
        flex-direction: column;
        gap: 10px;
        padding: 18px 16px;
    }

    .scanner-hero-title {
        font-size: 20px;
    }

    .scanner-gate-card {
        padding: 22px 16px;
    }
}

/* ── Landscape / tablet: keep the portrait capture box inside the screen.
   width is derived from the 3/4 aspect-ratio so the video stream and the
   overlay canvas remain a single, perfectly aligned box on rotation. ── */
@media (orientation: landscape) and (max-height: 720px) {
    .scanner-viewport,
    .scanner-editor-viewport {
        max-width: none;
        width: auto;
        height: min(74vh, 480px);
        margin-left: auto;
        margin-right: auto;
    }
}

/* ── Wide tablets (iPad / Galaxy Tab) in portrait: allow a larger box. ── */
@media (min-width: 768px) and (orientation: portrait) {
    .scanner-viewport,
    .scanner-editor-viewport {
        max-width: 520px;
    }
}
