:root {
    --bg: #0f1115;
    --panel: #1a1d24;
    --text: #e6e8eb;
    --muted: #8a93a2;
    --accent: #4a9eff;
    --border: #262a33;
    --ok: #4caf50;
    --warn: #f0ad4e;
    --err: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.topbar-actions { display: flex; gap: 1rem; }
.logout-link, .back-link { color: var(--muted); font-size: 0.9rem; }
.logout-link:hover, .back-link:hover { color: var(--text); }
.link-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
    color: var(--muted);
    font-size: 0.9rem;
}
.link-btn:hover { color: var(--text); }

.history-panel {
    position: absolute;
    top: 56px;
    right: 1rem;
    width: 340px;
    max-width: calc(100vw - 2rem);
    max-height: 70vh;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 50;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.history-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.history-list {
    list-style: none;
    margin: 0;
    padding: 0.25rem;
    overflow-y: auto;
    flex: 1;
}
.history-empty {
    margin: 1rem;
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
}
.history-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
}
.history-row:hover { background: var(--bg); }
.history-row.active { background: rgba(74, 158, 255, 0.12); }
.history-row-main { flex: 1; min-width: 0; }
.history-row-title {
    color: var(--text);
    font-size: 0.88rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.history-row.active .history-row-title { color: var(--accent); }
.history-row-when {
    color: var(--muted);
    font-size: 0.7rem;
    margin-top: 0.1rem;
    font-family: "SFMono-Regular", Consolas, monospace;
}
.history-del {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.1s;
}
.history-row:hover .history-del { opacity: 1; }
.history-del:hover { color: var(--err); background: rgba(255, 107, 107, 0.1); }

main { max-width: 1400px; margin: 0 auto; padding: 0.8rem; }
.empty { color: var(--muted); }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.card {
    display: block;
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.1s ease, border-color 0.1s ease;
}
.card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}
.card img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #000;
}
.card-media {
    position: relative;
    display: block;
    line-height: 0;
}
.card h2 {
    margin: 0;
    padding: 0.75rem 0.9rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
}
.card-date {
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 400;
    margin-top: 0.25rem;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.card-duration {
    position: absolute;
    right: 6px;
    bottom: 6px;
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.18rem 0.32rem;
    border-radius: 3px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    pointer-events: none;
    z-index: 2;
}
.card-missing { opacity: 0.55; cursor: default; }
.badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    background: var(--border);
    color: var(--muted);
    vertical-align: middle;
}
.badge-missing { background: rgba(240, 173, 78, 0.2); color: var(--warn); }

/* Collection cards */
.collection-card { display: flex; flex-direction: column; padding: 0; }

/* Condensed one-line-per-collection list */
.collection-list {
    list-style: none;
    margin: 1.5rem 0 0;
    padding: 0;
    max-width: 760px;
}
.collection-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0.4rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.collection-row:last-child { border-bottom: none; }
.drag-handle {
    cursor: grab;
    color: var(--muted);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;       /* prevent page scroll while dragging on touch */
    line-height: 0;
    padding: 0.55rem 0.5rem;  /* generous hit target for fingers */
    margin: -0.55rem -0.1rem -0.55rem 0;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}
.drag-handle svg { display: block; fill: currentColor; }
.drag-handle:active { cursor: grabbing; color: var(--accent); }
.collection-row.dragging { opacity: 0.4; }
.collection-row.drop-above::before,
.collection-row.drop-below::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
    pointer-events: none;
}
.collection-row.drop-above::before { top: -1px; }
.collection-row.drop-below::after  { bottom: -1px; }
.collection-name {
    color: var(--text);
    text-decoration: none;
    font-size: 1rem;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.collection-name:hover { color: var(--accent); }
.row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; align-items: center; }
.row-actions .inline { margin: 0; }

/* Rename lightbox */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem 1.8rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.modal h2 { margin: 0 0 1rem; font-size: 1.05rem; }
.modal-field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1.1rem; }
.modal-label { font-size: 0.8rem; color: var(--muted); }
.modal-field input[type="text"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    font: inherit;
}
.modal-field input[type="text"]:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.collection-main {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1.1rem 1.1rem 0.8rem;
    color: var(--text);
    flex: 1;
}
.collection-main:hover { color: var(--text); }
.folder-icon { font-size: 2.2rem; line-height: 1; margin-bottom: 0.4rem; }
.collection-main h2 { padding: 0; margin: 0 0 0.35rem; font-size: 1.05rem; }
.count { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.85rem; }
.collection-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem 1rem;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    align-items: center;
}
.inline { display: flex; gap: 0.3rem; margin: 0; align-items: center; }
.rename-input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    width: 9rem;
}
.rename-input:focus { outline: none; border-color: var(--accent); }
.mini-btn {
    background: var(--border);
    color: var(--text);
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
}
.mini-btn:hover { filter: brightness(1.2); }
.mini-btn.danger { background: rgba(255, 107, 107, 0.18); color: var(--err); }

/* Status badges */
.status-badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: lowercase;
}
.status-uploaded  { background: rgba(138, 147, 162, 0.2); color: var(--muted); }
.status-processing{ background: rgba(74, 158, 255, 0.2); color: var(--accent); }
.status-done      { background: rgba(76, 175, 80, 0.2); color: var(--ok); }
.status-error     { background: rgba(255, 107, 107, 0.2); color: var(--err); }
.status-stopped   { background: rgba(240, 173, 78, 0.2); color: var(--warn); }

.collection-title { font-size: 1.4rem; margin: 0 0 0.3rem; display: flex; align-items: center; gap: 0.7rem; }
.section-h { font-size: 1.1rem; margin: 1.5rem 0 0.8rem; color: var(--muted); font-weight: 500; }

/* Action bar (fetch / processing / error) */
.action-bar {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin: 1rem 0;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.action-bar .hint, .action-bar p { margin: 0; color: var(--muted); }
.sleep-field {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--muted);
    margin-right: 0.75rem;
}
.sleep-field input {
    width: 4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
}
.sleep-field input:focus { outline: none; border-color: var(--accent); }
.action-bar form { margin: 0; }
.action-bar button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.55rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
.action-bar button:hover { filter: brightness(1.1); }
.action-bar .stop-form { margin-left: auto; }
.stop-btn {
    background: rgba(255, 107, 107, 0.15) !important;
    color: var(--err) !important;
    border: 1px solid rgba(255, 107, 107, 0.4);
}
.stop-btn:hover { background: var(--err) !important; color: #fff !important; }

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.log {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--muted);
    max-height: 320px;
    overflow: auto;
}

.card-staged { opacity: 0.85; position: relative; }
.card-staged:hover { border-color: var(--accent); }
.card-staged h2 { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 0.85rem; }
.card-staged > a { display: block; text-decoration: none; color: inherit; border: 0; background: transparent; border-radius: 0; transition: transform 0.1s ease; }
.card-staged > a:hover { text-decoration: none; border: 0; background: transparent; }

.card-check {
    position: absolute;
    top: 0.4rem;
    left: 0.4rem;
    z-index: 2;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    background: rgba(0,0,0,0.55);
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.25);
}
.card-check input { margin: 0; cursor: pointer; width: 1.05rem; height: 1.05rem; }
.card-staged:has(input:checked) { outline: 2px solid var(--accent); outline-offset: 2px; opacity: 1; }
.card-fetch-one {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    z-index: 2;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: rgba(0,0,0,0.6);
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
}
.card-fetch-one:hover { background: var(--accent); color: #fff; }

.staged-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1.5rem 0 0.8rem;
}
.staged-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

/* Channel URL add bar */
.channel-add-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0 0;
    padding: 0.75rem 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.channel-add-bar .channel-url-field {
    flex: 1 1 320px;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.channel-add-bar .channel-url-field input[type="url"] {
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    font: inherit;
    color: var(--fg);
}

/* Upload form */
.upload-form { max-width: 480px; }
.upload-form .hint { color: var(--muted); font-size: 0.85rem; margin: -0.25rem 0 0; }
.upload-form .source-toggle {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.9rem;
    margin: 0.25rem 0;
}
.upload-form .source-toggle legend {
    font-size: 0.8rem;
    color: var(--muted);
    padding: 0 0.4rem;
}
.upload-form .radio-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    padding: 0.15rem 0;
    color: var(--fg);
}
.upload-form .radio-line input[type="radio"] { margin: 0; }
.upload-form label input[type="file"] {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.45rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.refresh-interstitial {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem 2.5rem;
    text-align: center;
    max-width: 420px;
}
.refresh-interstitial h1 { font-size: 1.15rem; margin: 0 0 0.4rem; }
.refresh-interstitial p { color: var(--muted); margin: 0 0 1.2rem; font-size: 0.9rem; }
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-form {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.login-form h1 { margin: 0 0 0.5rem; font-size: 1.25rem; text-align: center; }
.login-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.login-form input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    font-size: 0.95rem;
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-form button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.65rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.25rem;
}
.login-form button:hover { filter: brightness(1.1); }
.error {
    color: var(--err);
    background: rgba(255, 107, 107, 0.1);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
}
.error-detail {
    color: var(--muted);
    font-size: 0.78rem;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    margin: 0.3rem 0 0 !important;
    max-width: 540px;
    word-break: break-word;
}
}

/* Transcript view */
.transcript-page { max-width: 1000px; }
.transcript-page h1 { font-size: 1.4rem; margin: 0.8rem 0 0.4rem; }
.transcript-hero {
    display: block;
    margin: 0 0 1.5rem;
}
.transcript-thumb {
    display: block;
    width: 360px;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #000;
}
.transcript-meta { margin-top: 0.6rem; }
.transcript-duration, .transcript-published, .transcript-watch {
    color: var(--muted);
    margin: 0 0 0.4rem;
    font-size: 0.85rem;
    word-break: break-all;
}
.transcript-watch a { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.transcript {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
}

/* Fetch (sub) page for unfetched videos */
.fetch-page {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
}
.fetch-thumb {
    width: 360px;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #000;
}
.fetch-info { flex: 1; min-width: 260px; }
.fetch-info .hint { color: var(--muted); margin: 0 0 0.8rem; }
.fetch-watch { margin: 0 0 1.2rem; word-break: break-all; }
.fetch-form { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.fetch-form button {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 0.55rem 1rem;
    font: inherit;
    cursor: pointer;
}
.fetch-form button:hover { filter: brightness(1.1); }

/* Small "open on YouTube" arrow on staged cards */
.card-staged .card-watch-link {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 0.95rem;
    opacity: 0;
    transition: opacity 0.15s;
}
.card-staged:hover .card-watch-link { opacity: 1; }

/* App log: dismissible top banner + topbar Log button + full-log modal */
/* The `hidden` HTML attribute must beat the explicit `display:flex` below. */
[hidden] { display: none !important; }

.app-log-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(240, 173, 78, 0.12);
    color: var(--text);
    font-size: 0.88rem;
}
.app-log-banner.level-info  { background: rgba(74, 158, 255, 0.10); border-bottom-color: rgba(74, 158, 255, 0.30); }
.app-log-banner.level-warn  { background: rgba(240, 173, 78, 0.14); border-bottom-color: rgba(240, 173, 78, 0.40); }
.app-log-banner.level-error { background: rgba(255, 107, 107, 0.16); border-bottom-color: rgba(255, 107, 107, 0.45); }
.app-log-banner-text { flex: 1; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; }
.app-log-banner-label { font-weight: 500; }
.app-log-banner-meta  { color: var(--muted); font-size: 0.78rem; font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.app-log-banner-hide {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.25rem 0.7rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}
.app-log-banner-hide:hover { background: var(--panel); border-color: var(--accent); color: var(--accent); }

.app-log-btn { cursor: pointer; }
.app-log-btn:hover { color: var(--accent); }

.app-log-modal {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
body.app-log-modal-open { overflow: hidden; }
.app-log-modal-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 100%;
    max-width: 820px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.app-log-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border);
}
.app-log-modal-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.app-log-modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.2rem;
}
.app-log-modal-close:hover { color: var(--text); }
.app-log-entries {
    overflow-y: auto;
    padding: 0.5rem 1.1rem 1.1rem;
    flex: 1;
}
.app-log-empty { color: var(--muted); text-align: center; padding: 2rem 0; }
.app-log-entry {
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 0;
}
.app-log-entry:last-child { border-bottom: none; }
.app-log-entry-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.9rem;
    align-items: baseline;
    margin-bottom: 0.25rem;
}
.app-log-entry-lvl {
    display: inline-block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.05rem 0.4rem;
    border-radius: 3px;
    font-weight: 700;
    background: var(--border);
    color: var(--muted);
}
.app-log-entry.level-info  .app-log-entry-lvl { background: rgba(74, 158, 255, 0.2); color: var(--accent); }
.app-log-entry.level-warn  .app-log-entry-lvl { background: rgba(240, 173, 78, 0.2); color: var(--warn); }
.app-log-entry.level-error .app-log-entry-lvl { background: rgba(255, 107, 107, 0.2); color: var(--err); }
.app-log-entry-ev {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.9rem;
    color: var(--text);
}
.app-log-entry-ts {
    color: var(--muted);
    font-size: 0.75rem;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    margin-left: auto;
}
.app-log-entry-det {
    margin: 0.25rem 0 0;
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--muted);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ---- OpenCode chat page ---- */
body.chat-page { display: flex; flex-direction: column; min-height: 100vh; }
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0.8rem;
    min-height: 0;
}
.chat-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    padding: 0.5rem 0 1.5rem;
    scroll-behavior: smooth;
}
.chat-empty { color: var(--muted); text-align: center; margin-top: 2rem; }
.chat-error {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid var(--err);
    color: var(--err);
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}
.chat-error code { font-family: "SFMono-Regular", Consolas, monospace; }
.chat-msg {
    max-width: 80%;
    padding: 0.6rem 0.85rem;
    border-radius: 10px;
    line-height: 1.45;
    word-wrap: break-word;
}
.chat-msg-user {
    align-self: flex-end;
    background: rgba(74, 158, 255, 0.15);
    border: 1px solid rgba(74, 158, 255, 0.3);
    color: var(--text);
}
.chat-msg-assistant {
    align-self: flex-start;
    background: var(--panel);
    border: 1px solid var(--border);
}
.chat-msg-role {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 0.25rem;
    font-weight: 600;
}
.chat-msg-user .chat-msg-role { color: var(--accent); }
.chat-msg-text { white-space: pre-wrap; }
.chat-msg-tool {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.35rem;
    font-style: italic;
}
.chat-tool-detail {
    margin-top: 0.2rem;
    padding: 0.35rem 0.55rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.72rem;
    color: var(--muted);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-style: normal;
}
.chat-msg-tool-out {
    margin-top: 0.25rem;
    font-size: 0.72rem;
}
.chat-msg-tool-out summary {
    cursor: pointer;
    color: var(--muted);
    opacity: 0.85;
}
.chat-msg-tool-out pre {
    margin: 0.3rem 0 0;
    padding: 0.45rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 280px;
    overflow-y: auto;
}
.chat-msg-reasoning {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--muted);
}
.chat-msg-reasoning summary { cursor: pointer; opacity: 0.8; }
.chat-msg-reasoning div {
    margin-top: 0.3rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    border-radius: 6px;
    white-space: pre-wrap;
}
.chat-msg.streaming::after {
    content: '▌';
    display: inline-block;
    margin-left: 2px;
    color: var(--accent);
    animation: oc-blink 1s steps(2, start) infinite;
}
@keyframes oc-blink { to { opacity: 0; } }

.chat-thinking .chat-thinking-dots {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.15rem 0;
}
.chat-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: oc-bounce 1.2s infinite ease-in-out;
}
.chat-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes oc-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-5px); opacity: 1; }
}
.chat-status {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.3rem 0.9rem;
    font-size: 0.78rem;
    color: var(--muted);
    font-family: "SFMono-Regular", Consolas, monospace;
    text-align: center;
}
.chat-perms {
    max-width: 900px;
    margin: 0 auto 0.4rem;
    padding: 0 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.chat-perm {
    background: rgba(240, 173, 78, 0.08);
    border: 1px solid var(--warn);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}
.chat-perm-head {
    color: var(--warn);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}
.chat-perm-cmd {
    margin: 0 0 0.5rem;
    padding: 0.4rem 0.55rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.74rem;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 160px;
    overflow-y: auto;
}
.chat-perm-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.chat-perm-btn {
    padding: 0.3rem 0.7rem;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}
.chat-perm-btn:hover { border-color: var(--accent); }
.chat-perm-btn.allow-once { border-color: var(--accent); color: var(--accent); }
.chat-perm-btn.allow-always { background: var(--accent); color: #0f1115; border-color: var(--accent); font-weight: 600; }
.chat-perm-btn.deny { color: var(--err); border-color: var(--err); }
.chat-perm-btn:disabled { opacity: 0.5; cursor: default; }
.chat-status.busy { color: var(--accent); }
.chat-status.err  { color: var(--err); }
.chat-status.busy::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 0.45rem;
    vertical-align: middle;
    animation: oc-pulse 1.2s infinite ease-in-out;
}
@keyframes oc-pulse {
    0%, 100% { opacity: 0.35; transform: scale(0.85); }
    50%      { opacity: 1;    transform: scale(1.1); }
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    padding: 0.6rem 0 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    bottom: 0;
}
.chat-form textarea {
    flex: 1;
    resize: vertical;
    min-height: 2.6rem;
    max-height: 12rem;
    padding: 0.55rem 0.75rem;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    line-height: 1.4;
}
.chat-form textarea:focus { outline: none; border-color: var(--accent); }
.chat-form button {
    padding: 0 1.2rem;
    background: var(--accent);
    color: #0f1115;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
.chat-form button:disabled { opacity: 0.6; cursor: default; }
