/* Bouraq — Mobile-first styles */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --success-dark: #15803d;
    --danger: #dc2626;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --progress-bg: #e2e8f0;
    --page-decoded: #bbf7d0;
    --page-missing: #fecaca;
    --page-pending: #e2e8f0;
    --radius: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* Header */
header {
    text-align: center;
    padding: 24px 16px 8px;
}
header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* Screens */
.screen {
    display: none;
    padding: 16px;
    max-width: 480px;
    margin: 0 auto;
}
.screen.active {
    display: block;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card h2 {
    font-size: 20px;
    margin-bottom: 12px;
}
.card p {
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 20px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:active {
    transform: scale(0.97);
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-dark);
}
.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover {
    background: var(--success-dark);
}
.btn-secondary {
    background: var(--border);
    color: var(--text);
}
.btn-large {
    width: 100%;
    padding: 16px;
    font-size: 18px;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Session info */
.session-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.badge {
    background: var(--primary);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    font-family: monospace;
}
.status-text {
    color: var(--text-muted);
    font-size: 14px;
}

/* Progress */
.progress-section {
    margin-bottom: 20px;
}
.progress-bar-container {
    background: var(--progress-bg);
    border-radius: 8px;
    height: 12px;
    overflow: hidden;
    margin-bottom: 8px;
}
.progress-bar {
    background: var(--success);
    height: 100%;
    border-radius: 8px;
    transition: width 0.3s ease;
    width: 0%;
}
.progress-label {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* Page grid */
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    margin-bottom: 20px;
}
.page-cell {
    aspect-ratio: 1;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    font-family: monospace;
}
.page-cell.decoded {
    background: var(--page-decoded);
    color: #166534;
}
.page-cell.missing {
    background: var(--page-missing);
    color: #991b1b;
}
.page-cell.pending {
    background: var(--page-pending);
    color: var(--text-muted);
}

/* Capture */
.capture-section {
    margin-bottom: 16px;
}
.capture-btn {
    position: relative;
}
.hidden-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
}
.hint {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
    margin-bottom: 0;
}

/* Upload status */
.upload-status {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.5;
}
.upload-status.success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}
.upload-status.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.upload-status.processing {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* Done screen */
.done-icon {
    text-align: center;
    font-size: 48px;
    margin-bottom: 16px;
}
.done-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}
#result-info {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-muted);
}
#result-info strong {
    color: var(--text);
}

/* Error card */
.error-card p {
    color: var(--danger);
}

/* Utility */
.hidden {
    display: none !important;
}

/* Complete section */
.complete-section {
    margin-top: 8px;
}
.divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}
.complete-hint {
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 12px;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (min-width: 600px) {
    .screen {
        padding: 32px;
    }
    .card {
        padding: 32px;
    }
    header h1 {
        font-size: 32px;
    }
}

/* ══ GitHub Upload Styles ══ */

.btn-github {
    background: #24292f;
    color: white;
}
.btn-github:hover {
    background: #1b1f23;
}

.badge-github {
    background: #24292f;
}

/* Tabs */
.gh-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.gh-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.gh-tab.active {
    background: var(--card-bg);
    color: var(--text);
    box-shadow: inset 0 -2px 0 #24292f;
}
.gh-tab-content {
    display: none;
}
.gh-tab-content.active {
    display: block;
}

/* Form elements */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.form-label .optional {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 12px;
}
.form-label .required {
    color: var(--danger);
}
.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.15s;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    color: var(--text);
    background: var(--bg);
    resize: vertical;
    min-height: 120px;
    transition: border-color 0.15s;
}
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.btn-file-pick {
    display: block;
    text-align: center;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Upload log */
.upload-log {
    max-height: 160px;
    overflow-y: auto;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    font-size: 13px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
.log-entry {
    padding: 3px 8px;
    border-radius: 4px;
    margin-bottom: 3px;
    line-height: 1.4;
}
.log-entry:last-child { margin-bottom: 0; }
.log-idx { font-weight: 700; margin-right: 6px; }
.log-success { color: #166534; background: #f0fdf4; }
.log-warning { color: #92400e; background: #fefce8; }
.log-error { color: #991b1b; background: #fef2f2; }
.log-processing { color: #1e40af; background: #eff6ff; }

/* Retake guidance */
.retake-guidance {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.6;
}
.retake-ok {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    font-weight: 600;
}
.retake-missing {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.retake-title { font-weight: 700; margin-bottom: 4px; }

/* ══ Live Scanner ══ */

.mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 16px;
}
.mode-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.mode-btn.active {
    background: var(--card-bg);
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--primary);
}

/* Fullscreen scanner overlay */
.live-fullscreen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    background: #000;
}
.live-fullscreen video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.live-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}
.live-overlay > * { pointer-events: auto; }

.live-bottom {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
}

.live-page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 4px;
    margin-bottom: 8px;
}
.live-page-grid .page-cell {
    font-size: 11px;
    padding: 3px;
    background: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7);
}
.live-page-grid .page-cell.decoded {
    background: var(--page-decoded);
    color: #166534;
}
.live-status {
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
}
.scan-instruction {
    text-align: center;
    color: white;
    font-size: 20px;
    font-weight: 600;
    text-shadow: 0 2px 8px rgba(0,0,0,0.8);
    padding: 40px 20px;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #b91c1c;
}
