:root {
    --bg: #f7f8fa;
    --fg: #222;
    --muted: #888;
    --muted-border: #eee;
    --muted-border-strong: #e1e4e8;
    --card-bg: #fff;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.04);
    --link: #0366d6;
    --link-hover: #0256b9;
    --btn-bg: #0366d6;
    --btn-fg: #fff;
    --btn-bg-hover: #0256b9;
    --btn-disabled: #aaa;
    --danger: #d73a49;
    --danger-hover: #b52c38;
    --success: #28a745;
    --input-bg: #fff;
    --input-border: #ccc;
    --dropzone-bg: #fafbfc;
    --dropzone-border: #b0b7c0;
    --dropzone-over-bg: #e6f0fb;
    --disk-warn-bg: #fff3cd;
    --disk-warn-fg: #5b4500;
    --debug-bg: #f5f5f5;
    --summary-bg: #fafafa;
    --progress-track: #eee;
    --progress-fill: #28a745;
    --row-hover: #f5f7fa;
    --accent-summary: #0f766e;
    --accent-summary-soft: #ccfbf1;
    --accent-summary-bg: #f0fdfa;
    --quote-mark: #99f6e4;
}

[data-theme="dark"] {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #8b949e;
    --muted-border: #21262d;
    --muted-border-strong: #30363d;
    --card-bg: #161b22;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.4);
    --link: #58a6ff;
    --link-hover: #79b8ff;
    --btn-bg: #238636;
    --btn-fg: #fff;
    --btn-bg-hover: #2ea043;
    --btn-disabled: #30363d;
    --danger: #f85149;
    --danger-hover: #ff6a61;
    --success: #3fb950;
    --input-bg: #0d1117;
    --input-border: #30363d;
    --dropzone-bg: #0d1117;
    --dropzone-border: #30363d;
    --dropzone-over-bg: #1f2a3e;
    --disk-warn-bg: #3a2a00;
    --disk-warn-fg: #ffd866;
    --debug-bg: #161b22;
    --summary-bg: #161b22;
    --progress-track: #21262d;
    --progress-fill: #3fb950;
    --row-hover: #1a1f28;
    --accent-summary: #5eead4;
    --accent-summary-soft: #134e4a;
    --accent-summary-bg: #0f2925;
    --quote-mark: #164e48;
}

* { box-sizing: border-box; }
body { font-family: system-ui, -apple-system, sans-serif; max-width: 1100px; margin: 2em auto; padding: 0 1em; color: var(--fg); background: var(--bg); transition: background 0.2s, color 0.2s; }

.topbar { display: flex; align-items: center; gap: 0.6em; margin-bottom: 1em; min-height: 2.4em; }
.topbar-spacer { flex: 1; }
#theme-toggle { background: var(--card-bg); color: var(--fg); border: 1px solid var(--muted-border-strong); border-radius: 50%; width: 2.4em; height: 2.4em; padding: 0; font-size: 1.1em; cursor: pointer; box-shadow: var(--card-shadow); display: flex; align-items: center; justify-content: center; }
#theme-toggle:hover { background: var(--row-hover); }

nav a { text-decoration: none; color: var(--link); }
nav a:hover { color: var(--link-hover); }
h1, h2 { font-weight: 600; }
h1 { margin-top: 0; }
a { color: var(--link); }
a:hover { color: var(--link-hover); }

.card { background: var(--card-bg); border: 1px solid var(--muted-border-strong); border-radius: 8px; padding: 1em 1.2em; box-shadow: var(--card-shadow); margin-bottom: 1em; }

form { display: flex; flex-direction: column; gap: 0.6em; }
label { display: flex; align-items: center; gap: 0.5em; }
input[type=text], select { padding: 0.4em; border: 1px solid var(--input-border); border-radius: 4px; background: var(--input-bg); color: var(--fg); }
button { padding: 0.5em 1em; background: var(--btn-bg); color: var(--btn-fg); border: 0; border-radius: 4px; cursor: pointer; font-size: 0.95em; }
button:hover { background: var(--btn-bg-hover); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }
button:disabled { background: var(--btn-disabled); cursor: not-allowed; }

.btn-inline { background: transparent; color: var(--link); border: 1px solid var(--link); padding: 0.1em 0.5em; font-size: 0.8em; margin-left: 0.3em; }
.btn-inline:hover { background: var(--link); color: var(--btn-fg); }

.btn-cta { display: inline-block; padding: 0.5em 1em; background: var(--success); color: #fff; text-decoration: none; border-radius: 4px; font-weight: 500; }
.btn-cta:hover { filter: brightness(1.1); color: #fff; }

.job-actions { display: flex; align-items: center; gap: 1em; margin-top: 1em; flex-wrap: wrap; }

.drop-zone { border: 2px dashed var(--dropzone-border); border-radius: 6px; padding: 1.5em; text-align: center; background: var(--dropzone-bg); transition: all 0.15s ease; }
.drop-zone-over { border-color: var(--link); background: var(--dropzone-over-bg); }
.drop-zone-hint { margin: 0 0 0.5em 0; color: var(--muted); }
.drop-zone-hint button { background: transparent; color: var(--link); padding: 0.1em 0.3em; border: 1px solid var(--link); }
.drop-zone-hint button:hover { background: var(--link); color: var(--btn-fg); }
.drop-zone-files { margin: 0.5em 0 0 0; font-size: 0.9em; color: var(--muted); word-break: break-word; }

.disk-warn { background: var(--disk-warn-bg); color: var(--disk-warn-fg); padding: 0.5em 1em; border-radius: 4px; margin-bottom: 1em; }
.disk-ok { color: var(--muted); font-size: 0.9em; margin-bottom: 1em; }
.cta-recover { color: var(--muted); font-size: 0.9em; margin-top: 0.25em; }
.anon-banner { background: var(--accent-summary-bg); padding: 1em 1.5em; margin-bottom: 1em; border-left: 3px solid var(--accent-summary, #3da9fc); }
.anon-banner p { margin: 0.3em 0; }
.anon-banner p:first-child { font-size: 1.1em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5em 0.6em; border-bottom: 1px solid var(--muted-border); text-align: left; font-size: 0.9em; vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--row-hover); }

.progress { display: inline-block; vertical-align: middle; width: 150px; background: var(--progress-track); border-radius: 3px; overflow: hidden; height: 10px; }
.progress > .bar { height: 100%; background: var(--progress-fill); transition: width 0.5s ease; }

.status-queued { color: var(--muted); }
.status-running { color: var(--link); }
.status-done { color: var(--success); }
.status-failed { color: var(--danger); }
.status-warning { color: #f0c040; }

.stages { list-style: none; padding: 0; margin: 0; }
.stage-row { display: flex; align-items: center; gap: 0.6em; padding: 0.5em 0.2em; border-bottom: 1px solid var(--muted-border); font-size: 0.95em; }
.stage-row:last-child { border-bottom: 0; }
.stage-icon { width: 1.4em; text-align: center; font-size: 1.1em; flex: 0 0 auto; }
.stage-label { flex: 0 0 auto; min-width: 8.5em; font-weight: 500; white-space: nowrap; }
.stage-meta { display: flex; align-items: center; gap: 0.6em; flex: 1; font-size: 0.85em; }
.stage-pct { min-width: 3em; }
.stage-eta, .stage-elapsed { color: var(--muted); }

.stage-pending { color: var(--muted); }
.stage-pending .stage-icon { color: var(--muted); opacity: 0.7; }
.stage-running { color: var(--link); font-weight: 500; }
.stage-running .stage-icon { animation: spin 1.8s linear infinite; display: inline-block; }
.stage-done { color: var(--success); }
.stage-done .stage-icon { color: var(--success); }
.stage-failed { color: var(--danger); }
.stage-skipped { color: var(--muted); opacity: 0.6; }
.stage-skipped .stage-icon { color: var(--muted); }

@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

.queued-wait { padding: 0.8em 0.2em; color: var(--muted); display: flex; align-items: center; gap: 0.5em; }
.pulse-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--link); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.9); } 50% { opacity: 1; transform: scale(1.1); } }

.artifacts { list-style: none; padding: 0; margin: 0; }
.artifacts li { padding: 0.3em 0; border-bottom: 1px solid var(--muted-border); overflow-wrap: anywhere; }
.artifacts li:last-child { border-bottom: 0; }
.muted { color: var(--muted); }

.summary-html { line-height: 1.6; background: var(--summary-bg); padding: 1.4em 1.6em; border-radius: 8px; border: 1px solid var(--muted-border-strong); }
.summary-html h2 { margin: 1.4em 0 0.5em; font-size: 1.2em; font-weight: 600; color: var(--accent-summary); padding-bottom: 0.25em; border-bottom: 2px solid var(--accent-summary-soft); }
.summary-html h2:first-child { margin-top: 0; }
.summary-html h3 { margin: 1em 0 0.3em; font-size: 1em; font-weight: 600; color: var(--fg); }
.summary-html p { margin: 0.5em 0; }
.summary-html h2:first-child + p::first-letter { font-size: 2.4em; float: left; line-height: 0.9; padding: 0.08em 0.12em 0 0; color: var(--accent-summary); font-weight: 600; }

.summary-html ul.speakers { list-style: none; padding-left: 0; margin: 0.6em 0; }
.summary-html ul.speakers li { padding: 0.7em 0.9em; background: var(--accent-summary-bg); border-left: 3px solid var(--accent-summary); border-radius: 0 5px 5px 0; margin-bottom: 0.4em; }
.summary-html ul.speakers li strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82em; color: var(--accent-summary); background: var(--card-bg); padding: 0.12em 0.4em; border-radius: 3px; margin-right: 0.3em; white-space: nowrap; }
.summary-html ul.speakers li em { font-style: normal; font-weight: 600; color: var(--fg); }

.summary-html ul.quotes { list-style: none; padding-left: 0; margin: 0.6em 0; }
.summary-html ul.quotes li { position: relative; padding: 0.9em 1.1em 0.9em 2.6em; background: var(--accent-summary-bg); border-radius: 6px; margin-bottom: 0.6em; line-height: 1.5; }
.summary-html ul.quotes li::before { content: '\201C'; position: absolute; left: 0.3em; top: -0.05em; font-size: 2.8em; color: var(--quote-mark); line-height: 1; font-weight: 700; }
.summary-html ul.quotes li strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78em; color: var(--accent-summary); font-weight: 500; margin-right: 0.3em; }
.summary-html ul.quotes li em { display: block; margin-top: 0.3em; font-style: italic; color: var(--muted); font-size: 0.88em; }

.summary-html ul.conclusions { list-style: none; padding-left: 0; margin: 0.6em 0; }
.summary-html ul.conclusions li { padding: 0.4em 0 0.4em 1.6em; position: relative; border-bottom: 1px dashed var(--muted-border); }
.summary-html ul.conclusions li:last-child { border-bottom: none; }
.summary-html ul.conclusions li::before { content: '\2192'; position: absolute; left: 0.3em; color: var(--accent-summary); font-weight: 700; }

pre.debug { background: var(--debug-bg); padding: 1em; overflow-x: auto; font-size: 0.8em; border-radius: 4px; color: var(--fg); }

/* Record widget */
.record-widget { margin: 1em 0; padding: 1em; background: var(--summary-bg); border: 1px solid var(--muted-border-strong); border-radius: 8px; }
.source-tiles { display: flex; gap: 0.6em; margin-bottom: 1em; flex-wrap: wrap; }
.source-tile { position: relative; flex: 1 1 100px; min-width: 100px; padding: 0.8em 0.4em; background: var(--card-bg); border: 1px solid var(--muted-border-strong); border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 0.3em; font: inherit; color: var(--fg); transition: background 0.15s, border-color 0.15s; }
.source-tile:hover { border-color: var(--link); }
.source-tile.active { border-color: var(--link); background: var(--row-hover); box-shadow: 0 0 0 2px var(--link) inset; }
.source-icon { font-size: 1.6em; }
.source-label { font-size: 0.9em; }
.source-desc { font-size: 0.72em; color: var(--muted); line-height: 1.2; text-align: center; }

@media (hover: hover) {
    .source-tile[data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: calc(100% + 8px);
        left: 50%;
        transform: translateX(-50%);
        background: var(--fg);
        color: var(--bg);
        padding: 0.55em 0.8em;
        border-radius: 5px;
        font-size: 0.78em;
        font-weight: normal;
        line-height: 1.4;
        white-space: normal;
        width: max-content;
        max-width: 280px;
        z-index: 100;
        pointer-events: none;
        text-align: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    }
    .source-tile[data-tooltip]:hover::before {
        content: "";
        position: absolute;
        bottom: calc(100% + 2px);
        left: 50%;
        transform: translateX(-50%);
        border: 6px solid transparent;
        border-top-color: var(--fg);
        z-index: 100;
        pointer-events: none;
    }
}

.record-preview { min-height: 100px; padding: 0.8em; margin-bottom: 1em; background: var(--card-bg); border: 1px dashed var(--muted-border); border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.record-preview video { max-width: 100%; max-height: 240px; border-radius: 4px; }
.record-hint { color: var(--muted); margin: 0; }
.mic-indicator { color: var(--muted); font-size: 1.1em; }

.record-controls { display: flex; align-items: center; gap: 0.8em; }
.record-btn { font-size: 1.05em; padding: 0.6em 1.2em; }
.stop-btn { font-size: 1.05em; padding: 0.6em 1.2em; }
.record-elapsed { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.1em; color: var(--muted); }

.record-status { color: var(--link); margin-top: 0.5em; }
.record-error { color: var(--danger); margin-top: 0.5em; }
.record-widget.recording-active .record-elapsed { color: var(--danger); font-weight: 600; }
.record-widget.record-unsupported .source-tiles, .record-widget.record-unsupported .record-controls { display: none; }

.advanced-upload { margin-top: 1.5em; }
.advanced-upload summary { cursor: pointer; color: var(--muted); padding: 0.4em 0; }
.advanced-upload summary:hover { color: var(--link); }

.mobile-screen-help { padding: 0.5em; }
.mobile-screen-help h3 { margin: 0 0 0.5em; font-size: 1em; }
.mobile-screen-help p { margin: 0.3em 0; color: var(--muted); }
.mobile-screen-help button { margin-top: 0.5em; }

.permission-blocked { width: 100%; padding: 1em 1.2em; background: var(--card-bg); border: 1px solid var(--danger); border-left: 4px solid var(--danger); border-radius: 6px; text-align: left; color: var(--fg); }
.permission-blocked h3 { margin: 0 0 0.5em; font-size: 1em; color: var(--danger); }
.permission-blocked .permission-hint { margin: 0 0 0.6em; color: var(--muted); }
.permission-blocked ol { margin: 0.5em 0 0.9em 1.4em; padding: 0; }
.permission-blocked li { margin: 0.35em 0; }
.permission-blocked .permission-alt { margin: 0.5em 0 0.8em; padding: 0.5em 0.7em; background: var(--debug-bg, rgba(127,127,127,0.08)); border-radius: 4px; font-size: 0.85em; color: var(--muted); line-height: 1.4; }
.permission-blocked .permission-alt code { background: rgba(127,127,127,0.15); padding: 0.05em 0.4em; border-radius: 3px; font-size: 0.95em; word-break: break-all; }
.permission-blocked .permission-actions { display: flex; gap: 0.6em; flex-wrap: wrap; }
.permission-blocked .permission-retry { padding: 0.5em 1em; }
.permission-blocked .permission-reload { padding: 0.5em 1em; background: transparent; border: 1px solid var(--muted-border-strong); color: var(--fg); border-radius: 4px; cursor: pointer; }
.permission-blocked .permission-reload:hover { border-color: var(--link); }

@media (max-width: 480px) {
    .source-tiles { flex-direction: column; }
    .source-tile { flex-direction: row; justify-content: flex-start; gap: 0.6em; flex-wrap: wrap; }
    .source-desc { text-align: left; flex-basis: 100%; }
}

.redroid-url-form {
    display: flex;
    gap: 0.5em;
    margin-bottom: 1em;
}
.redroid-url-form input[type="url"] {
    flex: 1;
    padding: 0.5em;
    font-size: 1em;
}
.redroid-url-form button {
    padding: 0.5em 1em;
    font-size: 1.2em;
}
.redroid-stream {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 0 auto 1em;
}
.redroid-iframe {
    width: 100%;
    aspect-ratio: 1 / 2;
    border: 1px solid var(--muted-border-strong);
    border-radius: 8px;
}
.redroid-preview {
    width: 100%;
    aspect-ratio: 1 / 2;
    object-fit: contain;
    background: #000;
    border: 1px solid var(--muted-border-strong);
    border-radius: 8px;
}
.redroid-controls {
    display: flex;
    align-items: center;
    gap: 1em;
    justify-content: center;
    padding: 0.75em;
    background: var(--card-bg);
    border: 1px solid var(--muted-border-strong);
    border-radius: 8px;
    position: sticky;
    bottom: 0;
}
.rec-indicator {
    color: #e53e3e;
    font-weight: bold;
    animation: rec-blink 1s infinite;
}
@keyframes rec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.rec-elapsed {
    font-family: monospace;
    font-size: 1.2em;
}
.flip-camera-btn {
    display: block;
    margin: 0.5em auto;
    padding: 0.4em 1em;
    font-size: 0.95em;
    border: 1px solid var(--muted-border-strong, #ccc);
    border-radius: 6px;
    background: var(--card-bg, #fff);
    cursor: pointer;
}
