/* Bouraq — mobile-first styles (v7). Light by default, dark via prefers-color-scheme. */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #dbeafe;
    --success: #16a34a;
    --success-dark: #15803d;
    --success-soft: #dcfce7;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --github: #24292f;
    --github-dark: #0f1216;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 6px 20px rgba(15, 23, 42, 0.05);
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --surface-2: #f1f5f9;
    --surface-3: #e2e8f0;
    --page-found: #86efac;
    --page-found-text: #14532d;
    --page-seen: #bfdbfe;
    --page-seen-text: #1e3a8a;
    --page-missing: #fecaca;
    --page-missing-text: #7f1d1d;
    --page-pending: #e2e8f0;
    --page-pending-text: #64748b;
    --radius: 14px;
    --radius-sm: 10px;
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --dur: 180ms;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #3b82f6;
        --primary-dark: #2563eb;
        --primary-soft: #1e3a8a;
        --success: #22c55e;
        --success-dark: #16a34a;
        --success-soft: #14532d;
        --warn: #f59e0b;
        --warn-soft: #78350f;
        --danger: #ef4444;
        --danger-soft: #7f1d1d;
        --github: #30363d;
        --github-dark: #21262d;
        --bg: #0f172a;
        --card-bg: #1e293b;
        --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
        --text: #e2e8f0;
        --text-muted: #94a3b8;
        --border: #334155;
        --surface-2: #273449;
        --surface-3: #334155;
        --page-found: #166534;
        --page-found-text: #bbf7d0;
        --page-seen: #1e3a8a;
        --page-seen-text: #bfdbfe;
        --page-missing: #7f1d1d;
        --page-missing-text: #fecaca;
        --page-pending: #334155;
        --page-pending-text: #94a3b8;
    }
}

@media (prefers-reduced-motion: reduce) {
    :root { --dur: 0ms; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
    overscroll-behavior-y: none;
}

body.scanning { overflow: hidden; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--primary); }

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

#app-header { text-align: center; padding: 8px 0 20px; }
#app-header h1 {
    font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em;
    display: inline-flex; align-items: center; gap: 10px;
}
.logo {
    display: inline-block; width: 30px; height: 30px; border-radius: 8px;
    background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M56 14 26 58h20l-4 28 32-46H54z' fill='%23fff'/%3E%3C/svg%3E") center/contain no-repeat;
}
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 2px; }

h2 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 8px; }
h3.card-title, .card-title { font-size: 1rem; font-weight: 700; margin-bottom: 10px; }

.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hint { color: var(--text-muted); font-size: 0.85rem; text-align: center; margin-top: 10px; }
.hidden { display: none !important; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ------------------------------------------------------------------ */
/* Screens & cards                                                     */
/* ------------------------------------------------------------------ */

.screen { display: none; }
.screen.active { display: block; animation: screen-in var(--dur) var(--ease); }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.card.center { text-align: center; }
.card.center .btn { margin-left: auto; margin-right: auto; }
.card > p { margin-bottom: 12px; }

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; min-height: 44px; padding: 10px 18px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    font-weight: 600; font-size: 1rem; line-height: 1.2; text-decoration: none; text-align: center;
    -webkit-tap-highlight-color: transparent; user-select: none;
    transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    position: relative;
}
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn + .btn { margin-top: 10px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-link { background: none; color: var(--primary); font-weight: 500; min-height: 36px; padding: 6px 10px; }
.btn-link.small { font-size: 0.85rem; }
.btn-github { background: var(--github); color: #fff; }
.btn-github:hover:not(:disabled) { background: var(--github-dark); }
.btn-large { min-height: 52px; font-size: 1.05rem; }
.btn-small { width: auto; min-height: 36px; padding: 6px 14px; font-size: 0.9rem; }
.btn-hero { min-height: 64px; font-size: 1.2rem; border-radius: 16px; box-shadow: 0 8px 24px rgba(37, 99, 235, 0.25); }
.btn-hero .btn-icon { display: inline-flex; }
.btn-danger-text { color: var(--danger) !important; }
.btn-pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.45); } 50% { box-shadow: 0 0 0 10px rgba(22, 163, 74, 0); } }

.btn.busy { color: transparent !important; pointer-events: none; }
.btn.busy::after {
    content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}
.btn-secondary.busy::after, .btn-ghost.busy::after, .capture-btn.busy::after { border-color: var(--border); border-top-color: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ */
/* Forms                                                               */
/* ------------------------------------------------------------------ */

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.form-label .optional { color: var(--text-muted); font-weight: 400; }
.form-label .required { color: var(--danger); }
.form-input, .form-textarea {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--card-bg); color: var(--text); font-size: 1rem;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.form-input:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); }
.form-textarea { resize: vertical; min-height: 120px; line-height: 1.45; }
.field-error { color: var(--danger); font-size: 0.9rem; margin: 6px 0 10px; }
#login-form .btn, #password-form .btn { margin-top: 4px; }
.field-ok { color: var(--success-dark); font-size: 0.9rem; margin: 6px 0 10px; }

/* ------------------------------------------------------------------ */
/* Home                                                                */
/* ------------------------------------------------------------------ */

.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.greeting { margin: 0; font-size: 1.35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
    flex: none; display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-on { background: var(--success-soft); color: var(--success-dark); }
.pill-off { background: var(--surface-2); color: var(--text-muted); }

.banner {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
    background: var(--primary-soft); border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 12px 14px; margin-bottom: 14px;
}
.banner-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.banner-actions { display: flex; gap: 6px; }
.banner-actions .btn + .btn { margin-top: 0; }

.setting-row {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.row-title { display: block; font-weight: 600; }
.setting-row { padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.setting-row:last-of-type { border-bottom: 0; }
.setting-row > span:first-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* Toggle switch */
.switch { position: relative; flex: none; width: 48px; height: 28px; display: inline-block; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.slider {
    position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3);
    transition: background-color var(--dur) var(--ease);
}
.slider::before {
    content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform var(--dur) var(--ease);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:disabled + .slider { opacity: 0.5; }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3); }

/* Disclosure (details) */
.disclosure summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
    font-weight: 600; padding: 10px 0; user-select: none; -webkit-tap-highlight-color: transparent;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::after {
    content: ''; margin-left: auto; width: 8px; height: 8px; flex: none;
    border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg); transition: transform var(--dur) var(--ease);
}
.disclosure[open] summary::after { transform: rotate(-135deg); }
.disclosure-body { padding: 4px 0 6px; }
.disclosure.inbox summary { padding: 0; }
.disclosure.inbox summary .card-title { margin: 0; }
.disclosure.inbox .disclosure-body { padding-top: 12px; }
.disclosure.compact summary { font-size: 0.9rem; color: var(--text-muted); padding: 6px 0; }

.radio-group { display: flex; gap: 8px; margin: 8px 0 10px; }
.radio {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
    font-weight: 600; transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.radio:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio input { accent-color: var(--primary); }

.count-badge {
    display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px;
    padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted);
    font-size: 0.78rem; font-weight: 700;
}

/* Inbox */
.inbox-list { list-style: none; }
.inbox-item {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 0; border-bottom: 1px solid var(--border);
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.inbox-item:last-child { border-bottom: 0; }
.inbox-item.removing { opacity: 0; transform: translateX(12px); }
.inbox-main { min-width: 0; flex: 1; }
.inbox-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.inbox-actions { display: flex; flex-direction: column; gap: 4px; flex: none; }
.inbox-actions .btn + .btn { margin-top: 0; }
.inbox-actions .btn-small { min-height: 32px; padding: 4px 10px; font-size: 0.82rem; }

.chip {
    display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px;
    font-size: 0.72rem; font-weight: 600; background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.chip-ok { background: var(--success-soft); color: var(--success-dark); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }

.footer-links { text-align: center; margin-top: 4px; }
.footer-links .btn { width: auto; margin: 0 auto; }

/* Skeleton */
.skeleton-card { min-height: 180px; }
.skeleton {
    border-radius: 8px; background: var(--surface-2); position: relative; overflow: hidden;
}
.skeleton::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
    animation: shimmer 1.3s infinite;
}
@media (prefers-color-scheme: dark) { .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent); } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skeleton-title { width: 45%; height: 24px; margin-bottom: 14px; }
.skeleton-line { width: 80%; height: 14px; margin-bottom: 22px; }
.skeleton-button { width: 100%; height: 64px; border-radius: 16px; }

/* ------------------------------------------------------------------ */
/* Capture (photo mode)                                                */
/* ------------------------------------------------------------------ */

.session-info { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.badge {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.75rem;
    background: var(--surface-2); color: var(--text-muted); padding: 3px 8px; border-radius: 6px;
}
.badge-github { background: var(--github); color: #fff; font-family: inherit; font-weight: 600; }
.status-text { color: var(--text-muted); font-size: 0.95rem; }

.progress-section { margin-bottom: 12px; }
.progress-bar-container { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--success); border-radius: 999px; transition: width 300ms var(--ease); }
.progress-label { text-align: center; font-weight: 600; margin-top: 8px; font-variant-numeric: tabular-nums; }

/* Page grid (shared with the live overlay) */
.page-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; margin: 10px 0 14px;
}
.page-cell {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    border-radius: 6px; font-size: 0.72rem; font-weight: 600; font-variant-numeric: tabular-nums;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.page-cell.pending { background: var(--page-pending); color: var(--page-pending-text); }
.page-cell.seen { background: var(--page-seen); color: var(--page-seen-text); }
.page-cell.found { background: var(--page-found); color: var(--page-found-text); animation: pop var(--dur) var(--ease); }
.page-cell.missing { background: var(--page-missing); color: var(--page-missing-text); }
@keyframes pop { from { transform: scale(0.8); } to { transform: none; } }
.page-grid.dense { grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 3px; }
.page-grid.dense .page-cell { font-size: 0.6rem; border-radius: 4px; }
.page-grid.very-dense { grid-template-columns: repeat(auto-fill, minmax(14px, 1fr)); gap: 2px; }
.page-grid.very-dense .page-cell { font-size: 0; border-radius: 3px; }

.retake-guidance {
    background: var(--warn-soft); color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 14px; font-size: 0.95rem;
}
.capture-section { display: flex; flex-direction: column; gap: 10px; }
.capture-section .btn + .btn { margin-top: 0; }
.capture-section .hint { margin-top: 0; }
.capture-btn { position: relative; cursor: pointer; }
.upload-log { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem; max-height: 180px; overflow-y: auto; padding: 4px 0; }
.log-line { padding: 3px 0; border-bottom: 1px dashed var(--border); color: var(--text-muted); }
.log-line.ok { color: var(--success-dark); }
.log-line.warn { color: var(--warn); }
.log-line.err { color: var(--danger); }
.complete-hint { text-align: center; color: var(--text-muted); margin-bottom: 12px; }

/* ------------------------------------------------------------------ */
/* Done / result                                                       */
/* ------------------------------------------------------------------ */

.done-icon {
    width: 72px; height: 72px; border-radius: 50%; margin: 4px auto 14px;
    display: flex; align-items: center; justify-content: center; color: #fff;
    animation: pop 260ms var(--ease);
}
.done-icon.success { background: var(--success); }
.done-icon.github { background: var(--github); }
.done-icon.danger { background: var(--danger); }
#screen-done h2, #screen-github-done h2, #screen-error h2 { text-align: center; margin-bottom: 16px; }
#screen-error p { text-align: center; margin-bottom: 16px; word-break: break-word; }

.info-list { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 14px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.info-row:last-child { border-bottom: 0; }
.info-key { color: var(--text-muted); flex: none; }
.info-val { text-align: right; overflow-wrap: anywhere; }

.upload-status {
    padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 0.95rem;
    transition: background-color var(--dur) var(--ease);
}
.upload-status.success { background: var(--success-soft); color: var(--success-dark); }
.upload-status.error { background: var(--danger-soft); color: var(--danger); }
.upload-status.processing, .upload-status.info { background: var(--primary-soft); color: var(--primary-dark); }
@media (prefers-color-scheme: dark) {
    .upload-status.success { color: #bbf7d0; }
    .upload-status.error { color: #fecaca; }
    .upload-status.processing, .upload-status.info { color: #bfdbfe; }
    .chip-ok { color: #bbf7d0; }
    .chip-warn { color: #fde68a; }
    .pill-on { color: #bbf7d0; }
    .log-line.ok { color: #86efac; }
}
.done-actions { display: flex; flex-direction: column; gap: 10px; }
.done-actions .btn + .btn { margin-top: 0; }

/* ------------------------------------------------------------------ */
/* GitHub screen                                                       */
/* ------------------------------------------------------------------ */

.gh-tabs { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 16px; }
.gh-tab {
    flex: 1; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--text-muted);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.gh-tab.active { background: var(--card-bg); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.gh-tab-content { display: none; }
.gh-tab-content.active { display: block; }
.btn-file-pick { position: relative; cursor: pointer; }

/* ------------------------------------------------------------------ */
/* Live scanner overlay (always dark)                                  */
/* ------------------------------------------------------------------ */

.live-fullscreen {
    position: fixed; inset: 0; z-index: 100; background: #000; color: #fff;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    animation: fade-in var(--dur) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
#live-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

.live-overlay {
    position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
    padding: calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(12px + var(--safe-left));
    pointer-events: none;
}
.live-overlay > * { pointer-events: auto; }
.live-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.live-counter {
    display: flex; flex-direction: column; align-items: flex-start; line-height: 1;
    background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-radius: 14px; padding: 10px 16px; color: #fff; text-align: left;
}
.live-counter-value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.live-counter-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; margin-top: 4px; }
.icon-btn {
    width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.55); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn.on { background: #fbbf24; color: #1c1917; }
.live-debug {
    position: absolute; top: calc(84px + var(--safe-top)); left: calc(12px + var(--safe-left));
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.72rem;
    background: rgba(0, 0, 0, 0.6); padding: 4px 8px; border-radius: 6px; color: #d4d4d8; max-width: calc(100% - 24px);
}
.live-bottom { display: flex; flex-direction: column; gap: 10px; }
.live-status { text-align: center; font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); min-height: 1.5em; transition: opacity var(--dur) var(--ease); }
.live-status.subtle { opacity: 0.7; font-weight: 500; }
.live-page-grid {
    margin: 0; padding: 8px; border-radius: 12px; background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    grid-template-columns: repeat(auto-fill, minmax(28px, 1fr)); gap: 3px; max-height: 26vh; overflow-y: auto;
}
.live-page-grid:empty { display: none; }
.live-page-grid .page-cell { font-size: 0.66rem; border-radius: 5px; }
.live-page-grid .page-cell.pending { background: rgba(255, 255, 255, 0.18); color: rgba(255, 255, 255, 0.8); }
.live-page-grid .page-cell.seen { background: #60a5fa; color: #0c1a3a; }
.live-page-grid .page-cell.found { background: #4ade80; color: #052e16; }
.live-page-grid .page-cell.missing { background: rgba(248, 113, 113, 0.75); color: #fff; }
.live-page-grid.dense { grid-template-columns: repeat(auto-fill, minmax(20px, 1fr)); gap: 2px; }
.live-page-grid.very-dense { grid-template-columns: repeat(auto-fill, minmax(11px, 1fr)); gap: 2px; }
#btn-stop-scan { max-width: 320px; margin: 0 auto; width: 100%; }

.live-done {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
    background: rgba(5, 46, 22, 0.82); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    animation: fade-in var(--dur) var(--ease);
}
.live-done-mark {
    width: 112px; height: 112px; border-radius: 50%; background: var(--success); color: #fff;
    display: flex; align-items: center; justify-content: center; animation: pop 320ms var(--ease);
    box-shadow: 0 0 0 12px rgba(74, 222, 128, 0.25);
}
.live-done-text { font-size: 1.4rem; font-weight: 700; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }

/* ------------------------------------------------------------------ */
/* Toasts                                                              */
/* ------------------------------------------------------------------ */

.toasts {
    position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-bottom)); z-index: 200;
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none;
}
.toast {
    pointer-events: none; max-width: 440px; width: 100%; padding: 12px 16px; border-radius: 12px;
    background: #1e293b; color: #f8fafc; font-size: 0.95rem; font-weight: 500;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28); border-left: 4px solid var(--primary);
    opacity: 0; transform: translateY(12px) scale(0.98);
    transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast-success { border-left-color: var(--success); }
.toast-warn { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--danger); }
@media (prefers-color-scheme: dark) { .toast { background: #f1f5f9; color: #0f172a; } }
body.scanning .toasts { z-index: 150; bottom: calc(96px + var(--safe-bottom)); }

/* ------------------------------------------------------------------ */
/* Small screens                                                       */
/* ------------------------------------------------------------------ */

@media (max-width: 360px) {
    #app { padding-left: calc(12px + var(--safe-left)); padding-right: calc(12px + var(--safe-right)); }
    .card { padding: 16px; }
    .link-code { font-size: 1.8rem; }
}


/* ------------------------------------------------------------------ */
/* Storage quota                                                       */
/* ------------------------------------------------------------------ */

.quota-bar {
    display: block; height: 8px; border-radius: 999px; overflow: hidden;
    background: var(--surface-3); margin: 6px 0 8px;
}
.quota-fill {
    display: block; height: 100%; width: 0; border-radius: 999px;
    background: var(--primary); transition: width var(--dur) var(--ease);
}
.quota-fill.warn { background: var(--warn); }
.quota-fill.full { background: var(--danger); }
.hint.warn { color: var(--warn); text-align: left; }

/* Over-quota transfers: delivered, but not kept. */
.chip-temp { background: var(--warn-soft); color: var(--warn); }
.chip-admin { background: var(--primary-soft); color: var(--primary-dark); }
.inbox-item-temp { border-left: 3px solid var(--warn); padding-left: 8px; }

/* ------------------------------------------------------------------ */
/* Admin console                                                       */
/* ------------------------------------------------------------------ */

.admin-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.admin-toolbar .btn { width: auto; flex: 0 1 auto; }

.field-row { display: flex; flex-wrap: wrap; gap: 10px; }
.field-col { flex: 1 1 140px; display: flex; flex-direction: column; }

.admin-users { display: flex; flex-direction: column; gap: 8px; }
.admin-user {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface-2); overflow: hidden;
}
.admin-user > summary {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    padding: 10px 12px; cursor: pointer; list-style: none;
}
.admin-user > summary::-webkit-details-marker { display: none; }
.admin-user-name { font-weight: 600; word-break: break-all; }
.admin-user-usage { margin-left: auto; white-space: nowrap; }
.quota-bar-mini { flex: 1 0 100%; height: 5px; margin: 2px 0 0; }
.admin-user-body {
    padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px;
    border-top: 1px solid var(--border);
}
.admin-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.admin-row .btn { width: auto; flex: 0 1 auto; }
.admin-row label { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; font-size: 0.85rem; }
.admin-user-inbox { border-top: 1px dashed var(--border); padding-top: 8px; }

/* Credentials shown exactly once after create/reset. */
.cred-box {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 12px; margin: 8px 0;
}
.cred-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; align-items: baseline; }
.cred-label { color: var(--text-muted); font-size: 0.8rem; min-width: 80px; }
.cred-row code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.95rem; word-break: break-all; user-select: all;
}

.footer-links { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; }
.footer-links #signed-in-as { flex: 1 0 100%; text-align: center; margin-bottom: 2px; }

@media (prefers-color-scheme: dark) {
    .chip-temp { color: #fde68a; }
    .chip-admin { color: #bfdbfe; }
    .field-ok { color: #86efac; }
}
