/**
 * WebSend CSS
 * Designed for simplicity and accessibility, especially for older users.
 * Large touch targets, high contrast, clear typography.
 */

/* Maintenance banner shown when server is in DEV mode */
.maintenance-banner {
    display: none;
    background: #ff9800;
    color: #000;
    text-align: center;
    padding: 12px 16px;
    font-size: 1rem;
    font-weight: 600;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: opacity 0.3s ease;
}
.maintenance-banner.visible {
    display: block;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    /* System font stack for fast rendering without web font downloads */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #ffffff;
    min-height: 100vh;
    line-height: 1.6;
    /* Prevent double-tap-to-zoom on mobile, keeping single-tap responsive.
       Does NOT disable pinch-to-zoom (that's handled per-element in JS). */
    touch-action: manipulation;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1 {
    text-align: center;
    font-size: 2.5rem;
    margin-top: 40px;
    margin-bottom: 10px;
    color: #e94560;
}

.subtitle {
    text-align: center;
    font-size: 1.2rem;
    color: #a0a0a0;
    margin-bottom: 15px;
}

/* E2E encryption notice shown between title and buttons on index page */
.e2e-notice {
    text-align: center;
    font-size: 0.95rem;
    color: #888;
    margin-bottom: 30px;
    line-height: 1.5;
}

/* Large button styling for accessibility */
.button-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    justify-content: center;
    padding: 20px 0;
}

.btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px 16px;
    border-radius: 14px;
    text-decoration: none;
    font-weight: bold;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    border: none;
    min-height: 70px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-large {
    min-height: 90px;
}

.btn-primary {
    background: linear-gradient(135deg, #e94560 0%, #c23a51 100%);
    color: white;
    box-shadow: 0 8px 20px rgba(233, 69, 96, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 12px 30px rgba(233, 69, 96, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
    color: white;
    border: 2px solid #e94560;
    box-shadow: 0 8px 20px rgba(15, 52, 96, 0.3);
}

.btn-secondary:hover {
    box-shadow: 0 12px 30px rgba(15, 52, 96, 0.4);
}

.btn-icon {
    font-size: 2rem;
    margin-bottom: 6px;
}

.btn-text {
    font-size: 1.3rem;
}

.btn-hint {
    font-size: 0.9rem;
    font-weight: normal;
    opacity: 0.8;
    margin-top: 5px;
}

/* Action buttons (smaller, for in-page actions) */
.btn-action {
    padding: 12px 24px;
    font-size: 1rem;
    min-height: 48px;
    width: 100%;
    margin: 6px 0;
}

.btn-success {
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
    color: white;
    box-shadow: 0 6px 15px rgba(40, 167, 69, 0.3);
}

.btn-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
    color: #000;
    box-shadow: 0 6px 15px rgba(255, 193, 7, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: white;
    box-shadow: 0 6px 15px rgba(220, 53, 69, 0.3);
}

.btn-info {
    background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
    color: white;
    box-shadow: 0 6px 15px rgba(23, 162, 184, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    /* Override :active scale transform to prevent visual feedback on disabled buttons */
    transform: none !important;
}

/* QR Code display */
.qr-container {
    background: white;
    padding: 20px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 20px auto;
    max-width: 320px;
}

.qr-container canvas,
.qr-container img {
    max-width: 100%;
    height: auto;
}

/* Camera/Video display */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 20px auto;
    border-radius: 20px;
    overflow: hidden;
    background: #000;
    /* Hide container when video is not active (no srcObject) */
    display: none;
}

/* Show camera container only when it has an active video */
.camera-container.active {
    display: block;
}

.camera-container video {
    width: 100%;
    height: auto;
    display: block;
    /* Allow single-finger vertical scrolling (pan-y) while JS handles
       two-finger pinch-to-zoom via touchstart/touchmove preventDefault */
    touch-action: pan-y;
}

/* Flash toggle button - top-left corner of camera view */
.flash-toggle-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 11;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.flash-toggle-btn:active {
    background: rgba(255, 255, 255, 0.3);
}
/* Highlight when torch or flash mode is active */
.flash-toggle-btn.flash-active {
    background: rgba(255, 193, 7, 0.6);
    border-color: rgba(255, 193, 7, 0.8);
}

/* Document detection toggle button - top-right corner of camera view */
.detect-toggle-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 11;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.detect-toggle-btn:active {
    background: rgba(255, 255, 255, 0.3);
}
.detect-toggle-btn.detect-active {
    background: rgba(33, 150, 243, 0.6);
    border-color: rgba(33, 150, 243, 0.8);
}

/* SVG overlay showing detected document outline on live camera feed */
.detect-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}
.detect-overlay polygon {
    fill: rgba(255, 255, 255, 0.2);
    stroke: rgba(33, 150, 243, 0.8);
    stroke-width: 2;
    stroke-dasharray: 8 4;
}

/* Bottom bar inside camera view: gallery | capture | done */
.camera-bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: transparent;
}

.camera-bar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.camera-bar-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

.camera-done-btn {
    font-size: 1.5rem;
    font-weight: bold;
    background: rgba(40, 167, 69, 0.35);
    border-color: rgba(40, 167, 69, 0.5);
}
.camera-done-btn:active {
    background: rgba(40, 167, 69, 0.9);
}

.gallery-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: bold;
    line-height: 20px;
    text-align: center;
    color: #fff;
    background: #e94560;
    border-radius: 10px;
}

/* Floating capture button overlay - centered in bottom bar */
.capture-btn-floating {
    padding: 10px 24px;
    font-size: 0.95rem;
    min-height: auto;
    max-width: 45%;
    background: rgba(220, 53, 69, 0.4) !important;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 50px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* ============ Gallery Modal ============ */
.gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
}
.gallery-modal.hidden {
    display: none !important;
}
.gallery-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #16213e;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.gallery-modal-header h2 {
    color: #fff;
    font-size: 1.1rem;
    margin: 0;
}
.gallery-back-btn, .gallery-clear-btn, .gallery-delete-btn {
    background: none;
    border: none;
    color: #90caf9;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
}
.gallery-back-btn:active, .gallery-clear-btn:active, .gallery-delete-btn:active {
    background: rgba(255, 255, 255, 0.1);
}
.gallery-grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    align-content: start;
}
.gallery-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.gallery-thumb .gallery-thumb-index {
    position: absolute;
    top: 4px;
    left: 4px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: bold;
    line-height: 22px;
    text-align: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 11px;
}
.gallery-thumb .gallery-thumb-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    line-height: 24px;
    text-align: center;
    color: #fff;
    background: rgba(220, 53, 69, 0.8);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}
.gallery-thumb.dragging {
    opacity: 0.5;
    border-color: #90caf9;
}
.gallery-thumb.drag-over {
    border-color: #e94560;
}
.gallery-modal-footer {
    padding: 12px 16px;
    background: #16213e;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Gallery edit view */
.gallery-edit-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    z-index: 1;
}
.gallery-edit-view.hidden {
    display: none !important;
}
.gallery-edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #16213e;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.gallery-edit-header h2 {
    color: #fff;
    font-size: 1.1rem;
    margin: 0;
}
.gallery-edit-view .image-preview {
    flex: 1;
    min-height: 0;
    object-fit: contain;
    max-height: none;
    margin: 0;
    border-radius: 0;
}
.gallery-edit-view .edit-toolbar {
    padding: 12px 16px;
    background: #16213e;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Status messages */
.status {
    text-align: center;
    padding: 15px 20px;
    border-radius: 10px;
    margin: 20px 0;
    font-size: 1.1rem;
}

.status-waiting {
    background: rgba(255, 193, 7, 0.2);
    border: 1px solid #ffc107;
    color: #ffc107;
}

.status-connected {
    background: rgba(40, 167, 69, 0.2);
    border: 1px solid #28a745;
    color: #28a745;
}

.status-error {
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid #dc3545;
    color: #dc3545;
}

.status-info {
    background: rgba(23, 162, 184, 0.2);
    border: 1px solid #17a2b8;
    color: #17a2b8;
}

/* ============ Kebab Menu & Sidebar ============ */
/*
 * Top-right settings (cogwheel) button that opens a slide-in sidebar.
 * The sidebar consolidates language switching, logs, connection info, and about.
 * z-index 1500 matches the old lang-switcher level.
 */

.kebab-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 1500;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    line-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.kebab-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Dark overlay behind sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: #1a1a2e;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    z-index: 2000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar.visible {
    transform: translateX(0);
}

.sidebar-close {
    align-self: flex-end;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand-icon {
    border-radius: 12px;
    flex-shrink: 0;
}

.sidebar-brand-name {
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sidebar-section {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
    margin-bottom: 10px;
}

/* Language options in sidebar */
.sidebar .lang-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    cursor: pointer;
    color: white;
    font-size: 0.95rem;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    border-radius: 8px;
}

.sidebar .lang-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar .lang-option.active {
    background: rgba(233, 69, 96, 0.2);
    color: #e94560;
}

/* Connection type in sidebar */
.sidebar-connection-info {
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
}

/* Sidebar action buttons (logs, about) */
.sidebar-action {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    cursor: pointer;
    color: white;
    font-size: 1rem;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    border-radius: 8px;
}

.sidebar-action:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* DEV/production mode indicator at bottom of sidebar */
.sidebar-dev-badge {
    font-size: 0.75rem;
    padding: 6px 10px;
    border-radius: 6px;
    text-align: center;
    color: #888;
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-dev-badge.dev-active {
    color: #ff9800;
    background: rgba(255, 152, 0, 0.15);
    border: 1px solid rgba(255, 152, 0, 0.3);
}

/* App version line shown under the DEV/production badge */
.sidebar-version {
    margin-top: 8px;
    text-align: center;
    color: #888;
    font-size: 0.75rem;
}

/* Fullscreen logs panel (replaces old half-height panel) */
.logs-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    padding: 60px 15px 15px 15px; /* top padding for close/copy buttons */
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 2500; /* Above sidebar */
}

/* Logs panel toolbar (close + copy buttons) */
.logs-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: rgba(0, 0, 0, 0.98);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    z-index: 2501;
    border-bottom: 1px solid #333;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.logs-toolbar.visible {
    opacity: 1;
    pointer-events: auto;
}

.logs-toolbar button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.logs-toolbar button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.logs-panel.visible {
    transform: translateY(0);
}

.logs-panel .log-entry {
    margin: 5px 0;
    word-wrap: break-word;
}

.logs-panel .log-time {
    color: #888;
}

.logs-panel .log-error {
    color: #f55;
}

.logs-panel .log-success {
    color: #5f5;
}

.logs-panel .log-info {
    color: #5af;
}

.logs-panel .log-debug {
    color: #a0a; /* Purple for debug messages */
}

/* Image preview */
.image-preview {
    max-width: 100%;
    border-radius: 10px;
    margin: 10px 0;
}

/* Edit toggle button */
.edit-toggle-btn {
    margin-top: 0;
    margin-bottom: 0;
}

/* Edit toolbar: three icon+label buttons side by side */
.edit-toolbar {
    display: flex;
    flex-direction: row;
    gap: 6px;
    margin-bottom: 10px;
}

.edit-tool-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    background: #2a2a4a;
    border: 1px solid #4a4a7a;
    border-radius: 10px;
    color: #ffffff;
    font-size: 0.7rem;
    cursor: pointer;
    min-height: 48px;
    min-width: 0;
    transition: background 0.15s;
}

.edit-tool-btn.active {
    background: #4a4a7a;
    border-color: #7a7aff;
    box-shadow: 0 0 8px rgba(122, 122, 255, 0.3);
}

.edit-tool-btn span:first-child {
    font-size: 1.2rem;
}

.edit-tool-btn:active,
.edit-tool-btn:hover {
    background: #3a3a6a;
}

/* Received images list */
.received-images {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 20px 0;
}

/* Collection sections */
.collection-section {
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    overflow: hidden;
}

.collection-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
    gap: 8px;
}

.collection-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.collection-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.collection-collapse-btn {
    background: none;
    border: none;
    color: #ccc;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 2px 6px;
}

.collection-name {
    color: #fff;
    font-weight: bold;
    font-size: 1rem;
    cursor: text;
    padding: 2px 6px;
    border-radius: 4px;
    min-width: 60px;
    outline: none;
}

.collection-name:focus {
    background: rgba(255, 255, 255, 0.15);
    outline: 1px solid #1565c0;
}

.collection-time {
    color: #999;
    font-size: 0.85rem;
}

.collection-count {
    background: #1565c0;
    color: #fff;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.collection-select-all-btn {
    font-size: 0.75rem !important;
    padding: 4px 8px !important;
}

.collection-export-btn {
    font-size: 0.75rem !important;
    padding: 4px 10px !important;
    background: #e94560 !important;
    color: white !important;
}

.collection-images {
    padding: 12px;
}

.collection-drop-target {
    background: rgba(21, 101, 192, 0.3) !important;
    outline: 2px dashed #1565c0;
}

.new-document-drop-zone {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    margin: 12px;
    border: 2px dashed #888;
    border-radius: 12px;
    color: #aaa;
    font-size: 1.1em;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    cursor: default;
}

.new-document-drop-zone-active {
    background: rgba(21, 101, 192, 0.3);
    border-color: #1565c0;
    color: #fff;
}

.received-image-item {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px;
    transition: opacity 0.2s;
}

.received-image-item.deselected {
    opacity: 0.4;
}

.received-image-item.dragging {
    opacity: 0.4;
    outline: 2px dashed #1565c0;
}

.received-image-item.drag-over {
    border-top: 3px solid #1565c0;
}

.drag-handle {
    cursor: grab;
    user-select: none;
    font-size: 1.3em;
    padding: 4px 8px;
    color: #888;
    touch-action: none;
}

.drag-handle:active {
    cursor: grabbing;
}

.image-select-checkbox input[type="checkbox"] {
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
}

.received-image-item img {
    width: 100%;
    border-radius: 10px;
    margin-bottom: 10px;
}

/* Horizontal compact layout for wide screens */
@media (min-width: 900px) {
    .collection-images {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }

    .received-image-item {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 12px;
        padding: 10px;
    }

    .drag-handle {
        align-self: center;
        flex-shrink: 0;
    }

    .received-image-item .image-thumb-container {
        flex: 7;
        min-width: 0;
    }

    .received-image-item .image-thumb-container img {
        width: 100%;
        height: auto;
        object-fit: cover;
        margin-bottom: 0;
        cursor: pointer;
    }

    .received-image-item .card-menu {
        flex: 3;
        min-width: 0;
    }
}

/* ===== Receiver cards ===== */

.discard-confirm {
    margin-top: 8px;
    padding: 12px;
    background: #fff3e0;
    border-radius: 8px;
    border: 1px solid #ffcc80;
    text-align: center;
}
.discard-confirm-msg {
    margin: 0 0 10px 0;
    color: #e65100;
    font-weight: bold;
}
.discard-confirm-row {
    display: flex;
    gap: 10px;
}
.discard-confirm-row .btn { flex: 1; }
.discard-confirm-yes {
    background: #c62828;
    color: white;
}

.card-select-checkbox { display: none; }

.image-badge {
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 1.05em;
    font-weight: bold;
    padding: 3px 10px;
    border-radius: 6px;
}
.image-badge-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    pointer-events: none;
}
.image-badge-stacked {
    margin-top: 4px;
}

.image-thumb-container {
    position: relative;
    display: block;
}
.image-thumb-container img {
    width: 100%;
    display: block;
    cursor: pointer;
}

.file-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 10px;
    background: #f5f5f5;
    border-radius: 8px;
    position: relative;
}
.file-card-icon { font-size: 3em; }
.file-card-name {
    margin: 8px 0 4px;
    font-weight: bold;
    word-break: break-all;
    text-align: center;
    font-size: 0.9em;
}
.file-card-size {
    margin: 0;
    color: #666;
    font-size: 0.85em;
}

/* Card kebab menu */
.card-kebab-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.15s;
    line-height: 1;
}

.card-kebab-btn:hover {
    background: rgba(0, 0, 0, 0.75);
}

.card-menu {
    position: absolute;
    top: 44px;
    right: 8px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    background: #1e1e3a;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    min-width: 160px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.card-menu.hidden {
    display: none;
}

.card-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s;
}

.card-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.card-menu-item-danger {
    color: #ef5350;
}

.card-menu-item-danger:hover {
    background: rgba(239, 83, 80, 0.15);
}

/* Image preview lightbox */
.image-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.image-lightbox.active {
    display: flex;
}

.image-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

/* Progress indicator */
.progress-bar {
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    overflow: hidden;
    margin: 10px 0;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #e94560, #28a745);
    transition: width 0.3s ease;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 0.9rem;
}

/* Back link */
.back-link {
    display: inline-block;
    color: #e94560;
    text-decoration: none;
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.back-link:hover {
    text-decoration: underline;
}

/* Section titles */
.section-title {
    font-size: 1.5rem;
    margin: 20px 0 10px 0;
    color: #e94560;
}

/* Hidden utility class - !important overrides flex/block/etc display values
   set by inline styles or other classes. Used for step-based wizard visibility. */
.hidden {
    display: none !important;
}

/* Choice buttons (for sender to choose camera vs file) */
.choice-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

/* ============ Image Cropping Modal ============ */
/*
 * Minimal document cropping UI for perspective-correcting scanned documents.
 * Four draggable corner handles allow marking document edges.
 * Pure CSS + vanilla JS, no external dependencies.
 */

.crop-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000; /* Above everything including logs panel (z-index: 1000) */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px;
}

.crop-modal-header {
    color: white;
    text-align: center;
    margin-bottom: 10px;
}

.crop-modal-header h2 {
    font-size: 1.3rem;
    margin: 0 0 5px 0;
}

.crop-modal-header p {
    font-size: 0.9rem;
    color: #aaa;
    margin: 0;
}

/* Container for image + corner handles, sized to fit viewport */
.crop-canvas-container {
    position: relative;
    max-width: 100%;
    max-height: 60vh;
    touch-action: none; /* Prevent scrolling while dragging handles */
}

.crop-canvas-container img {
    max-width: 100%;
    max-height: 60vh;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

/* SVG overlay for corner lines - sits exactly over the image */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.crop-overlay polygon {
    fill: rgba(0, 0, 0, 0.4);
    stroke: #e94560;
    stroke-width: 2;
}

/* Draggable corner handles */
.crop-handle {
    position: absolute;
    width: 40px;
    height: 40px;
    background: #e94560;
    border: 3px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    touch-action: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.crop-handle:active {
    cursor: grabbing;
    background: #ff6b8a;
}

/* Button row at bottom of modal */
.crop-buttons {
    display: flex;
    gap: 15px;
    margin-top: 15px;
    width: 100%;
    max-width: 400px;
}

.crop-buttons button {
    flex: 1;
    padding: 10px;
    font-size: 0.95rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
}

.crop-btn-apply {
    background: #28a745;
    color: white;
}

.crop-btn-cancel {
    background: #6c757d;
    color: white;
}

/* Magnifier loupe: zoomed preview of the area under the dragged crop handle,
 * positioned away from the thumb so users can see exactly where the corner lands. */
.crop-magnifier {
    position: absolute;
    width: 124px;
    height: 124px;
    border: 2px solid #e94560;
    border-radius: 50%;
    overflow: hidden;
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.6);
    transform: translate(-50%, -50%);
}

.crop-magnifier canvas {
    display: block;
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

/* Crosshair overlay in the center of the magnifier */
.crop-magnifier-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.crop-magnifier-crosshair::before,
.crop-magnifier-crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
}

/* Vertical crosshair line */
.crop-magnifier-crosshair::before {
    width: 1px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

/* Horizontal crosshair line */
.crop-magnifier-crosshair::after {
    width: 100%;
    height: 1px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

/* ============ Export Modal ============ */
/*
 * Modal dialog for choosing export format (ZIP, PDF) and options (B&W, OCR).
 * Reuses visual patterns from the crop modal (dark overlay, centered content).
 */

.export-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
}

.export-modal-content {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 25px;
    max-width: 400px;
    width: 100%;
}

.export-modal-content h3 {
    color: #e94560;
    font-size: 1.3rem;
    margin-bottom: 20px;
    text-align: center;
}

.export-format-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

/* Segmented control for format selection (ZIP / PDF) */
.export-segmented {
    display: flex;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.export-seg-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.export-seg-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.export-seg-btn.active {
    background: rgba(233, 69, 96, 0.25);
    color: #fff;
    font-weight: 600;
}

/* Toggle buttons for options (B&W, OCR) */
.export-toggle-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    margin-bottom: 8px;
}

.export-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.export-toggle-btn.active {
    background: rgba(233, 69, 96, 0.2);
    border-color: #e94560;
    color: #fff;
}

.coming-soon {
    font-size: 0.8rem;
    color: #888;
    font-style: italic;
}

.export-pdf-options {
    margin-left: 20px;
    margin-bottom: 15px;
    padding-left: 10px;
    border-left: 2px solid rgba(233, 69, 96, 0.3);
}

.export-modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.export-modal-buttons button {
    flex: 1;
}

/* ============ About Modal ============ */
/*
 * Themed to match the app's dark palette (it used to be a white card that
 * clashed with the rest of the UI). The scroll lives on an inner wrapper so
 * the card's rounded corners are never clipped square by a chunky native
 * scrollbar track; the outer box keeps overflow:hidden + border-radius and
 * the inner wrapper owns the (thin, themed) scrollbar.
 */
.about-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.about-modal.hidden {
    display: none;
}

.about-modal-content {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 15px;
    max-width: 600px;
    width: 90vw;
    max-height: 80vh;
    overflow: hidden; /* clip the inner scroll wrapper to the rounded corners */
    display: flex;
    flex-direction: column;
}

.about-modal-scroll {
    overflow-y: auto;
    padding: 25px;
    color: rgba(255, 255, 255, 0.75);
    /* Thin themed scrollbar instead of the chunky default that squared off
       the right-hand corners (Firefox properties + WebKit pseudo-elements). */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.about-modal-scroll::-webkit-scrollbar {
    width: 8px;
}

.about-modal-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.about-modal-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 8px;
}

.about-modal-scroll h2 {
    margin: 0 0 15px 0;
    color: #e94560;
}

.about-modal-scroll h3 {
    margin: 15px 0 10px 0;
    color: #fff;
    font-size: 1rem;
}

.about-modal-scroll p {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 15px;
}

.about-modal-scroll ul {
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 0;
    padding-left: 20px;
}

.about-modal-scroll a {
    color: #ff6b81; /* lighter than the #e94560 accent for contrast on dark */
}

.about-instance-line {
    margin: -5px 0 15px 0;
    font-size: 0.95rem;
}

.about-thirdparty-note {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.8rem;
    line-height: 1.4;
    margin: 8px 0 0 0;
}

.about-close-btn {
    margin-top: 20px;
    width: 100%;
    padding: 12px;
    background: #e94560;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

/* ============ Toast Notifications ============ */
/*
 * Non-blocking inline notifications that replace alert() popups.
 * Toasts slide in from the top and auto-dismiss after a few seconds.
 * They don't block the UI, so users can still read logs and eruda output.
 */

.toast-container {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000; /* Above everything including crop modal (2000) */
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 450px;
    pointer-events: none; /* Allow clicks through the container */
}

.toast {
    position: relative;
    padding: 15px 30px 15px 20px;
    border-radius: 12px;
    font-size: 1rem;
    line-height: 1.4;
    white-space: pre-line;
    pointer-events: auto; /* Toasts themselves are clickable (to dismiss) */
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    animation: toast-slide-in 0.3s ease-out;
    /* Backdrop blur for visual separation from content behind */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.toast-close {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 0.75rem;
    opacity: 0.7;
    cursor: pointer;
    line-height: 1;
}

.toast-close:hover {
    opacity: 1;
}

.toast-success {
    background: rgba(40, 167, 69, 0.9);
    border: 1px solid #28a745;
    color: white;
}

.toast-error {
    background: rgba(220, 53, 69, 0.9);
    border: 1px solid #dc3545;
    color: white;
}

.toast-warn {
    background: rgba(255, 152, 0, 0.9);
    border: 1px solid #ff9800;
    color: white;
}

.toast-info {
    background: rgba(23, 162, 184, 0.9);
    border: 1px solid #17a2b8;
    color: white;
}

.toast-fade-out {
    animation: toast-fade-out 0.3s ease-in forwards;
}

@keyframes toast-slide-in {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Wider screens (tablets, landscape phones, desktops): use available space
   instead of being locked to a narrow 500px column */
@media (min-width: 700px) {
    .container {
        max-width: 800px;
    }

    .camera-container {
        max-width: 700px;
    }

    .qr-container {
        max-width: 400px;
    }

    /* Side-by-side choice buttons on wide screens */
    .choice-container {
        flex-direction: row;
    }

    .choice-container .btn-action {
        flex: 1;
    }
}

/* Very wide screens (desktops): cap at reasonable width */
@media (min-width: 1200px) {
    .container {
        max-width: 1000px;
    }

    .camera-container {
        max-width: 800px;
    }
}

/* Responsive adjustments for small screens (older/budget smartphones).
   Reduces font sizes to prevent text overflow while keeping touch targets large. */
@media (max-width: 400px) {
    h1 {
        font-size: 2rem;
    }

    .btn-text {
        font-size: 1.1rem;
    }

    .btn-icon {
        font-size: 1.8rem;
    }
}

/* ===== Sender page ===== */

#queue-banner {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #e3f2fd;
    border-bottom: 2px solid #90caf9;
    padding: 10px 15px;
    text-align: center;
    color: #1565c0;
    font-size: 0.9rem;
}
#queue-progress-bar {
    margin: 6px 0 0 0;
    height: 4px;
}
#queue-progress-fill {
    width: 0%;
    transition: width 0.3s;
}
#queue-transfer-stats {
    font-size: 0.75rem;
    color: #1565c0;
    margin-top: 3px;
    opacity: 0.85;
}

.link-paste-wrapper {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}
.link-paste-label {
    text-align: center;
    color: #666;
    margin: 0 0 10px 0;
}
.link-paste-row {
    display: flex;
    gap: 6px;
    align-items: center;
}
.link-paste-input {
    flex: 1;
    padding: 10px;
    font-size: 0.85rem;
    border-radius: 5px;
    border: 1px solid #ccc;
    font-family: monospace;
}
.link-paste-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 5px;
    background: #e94560;
    color: white;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Verification modal (overlay/display toggles remain inline for JS show/hide) */
.verify-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    max-width: 350px;
    margin: 20px;
    text-align: center;
}
.verify-title {
    margin: 0 0 15px 0;
    color: #1565c0;
}
.verify-instruction {
    margin: 0 0 20px 0;
    color: #555;
    font-size: 0.95rem;
}
.verify-codes {
    background: #f5f5f5;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}
.verify-code-block {
    margin-bottom: 15px;
}
.verify-code-label {
    font-size: 0.85rem;
    color: #666;
}
.verify-fingerprint {
    font-family: monospace;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 5px 0;
    letter-spacing: 2px;
    color: #1565c0;
}
.verify-warning {
    margin: 0 0 20px 0;
    color: #d32f2f;
    font-size: 0.85rem;
}
.verify-confirm-btn {
    width: 100%;
    margin-bottom: 20px;
    padding: 20px;
    font-size: 1.15rem;
}
.verify-deny-btn {
    width: 100%;
    padding: 20px;
    font-size: 1.15rem;
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

.send-confirm-banner {
    margin: 15px 0;
    padding: 20px;
    background: #e3f2fd;
    border-radius: 10px;
    border: 1px solid #90caf9;
    text-align: center;
}
.send-confirm-msg {
    margin: 0;
    color: #1565c0;
    font-weight: bold;
}

.send-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.send-control-btn {
    flex: 1;
    min-width: 80px;
}
.send-control-btn-primary {
    flex: 2;
    min-width: 120px;
}

.status-pre-line { white-space: pre-line; }
.retry-btn { margin-top: 15px; }
