:root {
    color-scheme: dark;
    --bg: #141817;
    --surface: #1c2220;
    --raised: #252d29;
    --border: #39433d;
    --text: #f0f1e9;
    --muted: #abb4aa;
    --accent: #b9d18b;
    --danger: #efa8a0;
    --success: #acd6a6;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.6rem, 3vw, 2rem); line-height: 1.2; }
h2 { font-size: 1.05rem; }
svg { width: 18px; height: 18px; flex: none; }
.muted, .hint { color: var(--muted); }
.eyebrow { color: var(--accent); font-size: .75rem; font-weight: 650; margin-bottom: .35rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.brand { display: flex; align-items: center; gap: .65rem; font-weight: 700; }
.brand-large { margin-bottom: 2rem; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; color: var(--accent); border: 1px solid var(--border); border-radius: 4px; }
.brand-mark svg { width: 18px; height: 18px; }
.login-shell { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.login-card { width: min(100%, 420px); padding: 2rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.login-card h1 { margin-bottom: .5rem; }
.login-card > .muted { margin-bottom: 1.5rem; }
.login-footnote { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 600; }
.field small { color: var(--muted); font-weight: 400; }
input { width: 100%; min-height: 46px; padding: .65rem .75rem; color: var(--text); background: var(--bg); border: 1px solid #56625a; border-radius: 4px; font: inherit; font-size: 16px; }
input::placeholder { color: #929c92; }
input:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.button, .pager-button, .icon-button { font: inherit; cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px; padding: .6rem .9rem; border: 1px solid var(--border); border-radius: 4px; font-size: .9rem; font-weight: 650; }
.button:disabled, .pager-button:disabled { opacity: .5; cursor: not-allowed; }
.button-primary { color: #182014; background: var(--accent); border-color: var(--accent); }
.button-primary:hover:not(:disabled) { background: #cbe1a0; }
.button-secondary { color: var(--text); background: var(--raised); }
.button-ghost { color: var(--text); background: transparent; }
.button-secondary:hover:not(:disabled), .button-ghost:hover:not(:disabled) { background: #303a34; }
.button-danger { color: #241311; background: var(--danger); }
.button-block { width: 100%; }
.button-small { min-height: 44px; font-size: .8rem; }
.button svg { width: 16px; height: 16px; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; color: var(--text); background: transparent; border: 1px solid var(--border); border-radius: 4px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 64px; padding: .5rem max(1.5rem, env(safe-area-inset-left)); border-bottom: 1px solid var(--border); }
.topbar-actions { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.server-pill { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .8rem; }
.user-chip { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.user-dot { display: none; }
.tabs { display: flex; gap: 1.5rem; padding: 0 max(1.5rem, env(safe-area-inset-left)); border-bottom: 1px solid var(--border); }
.tab { display: inline-flex; align-items: center; gap: .5rem; min-height: 50px; padding: .5rem 0; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; font: inherit; font-weight: 600; cursor: pointer; }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.tab-badge { min-width: 22px; padding: 1px 5px; color: #251411; background: var(--danger); border-radius: 3px; font-size: .7rem; text-align: center; }
.content { width: min(1280px, 100%); margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.75rem; }
.page-head .muted { max-width: 650px; margin-top: .4rem; }
.page-head .button { flex: none; }
.queue-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.panel { min-width: 0; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.panel-meta { color: var(--muted); font-size: .8rem; }
.panel-icon { color: var(--muted); }
.queue-search { margin-top: .8rem; }
.failed-search { margin-bottom: 1rem; }
.item-list { display: flex; flex-direction: column; }
.item { position: relative; min-width: 0; padding: .85rem 0 .85rem 2.4rem; border-bottom: 1px solid var(--border); }
.item-position { position: absolute; top: .85rem; left: 0; color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .65rem; }
.item-top > div { min-width: 0; }
.item-title, .failed-title { font-weight: 650; overflow-wrap: anywhere; }
.item-sub, .failed-sub, .tracking-sub { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.item-foot, .failed-meta { display: flex; flex-wrap: wrap; gap: .35rem .65rem; margin-top: .4rem; color: var(--muted); font-size: .75rem; }
.item-foot .dot::before { content: "·"; margin-right: .65rem; }
.status { flex: none; padding: .15rem .4rem; color: var(--text); background: var(--raised); border-radius: 3px; font-size: .7rem; white-space: nowrap; }
.status-queued, .status-processing { color: var(--accent); }
.status-failed, .status-partial { color: var(--danger); }
.status-downloaded, .status-skipped { color: var(--success); }
.empty { display: grid; gap: .25rem; padding: 1.5rem 0; color: var(--muted); font-size: .85rem; }
.empty strong { color: var(--text); }
.loading-row { height: 60px; margin: .5rem 0; background: var(--raised); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding-top: .75rem; color: var(--muted); font-size: .75rem; }
.pager:empty { display: none; }
.pager-button { min-height: 44px; padding: .4rem .6rem; color: var(--text); background: var(--raised); border: 1px solid var(--border); border-radius: 4px; font-size: .8rem; }
.tracking-section { margin-bottom: 1.5rem; padding: 1rem; border: 1px solid var(--border); border-radius: 5px; }
.tracking-section h2 { margin-bottom: .75rem; }
.tracking-list, .failed-list { display: grid; gap: .75rem; }
.tracking-card { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem; background: var(--surface); }
.tracking-title { font-weight: 600; overflow-wrap: anywhere; }
.tracking-state { display: inline-flex; align-items: center; gap: .5rem; flex: none; color: var(--muted); font-size: .8rem; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.pulse-success { background: var(--success); }
.pulse-danger { background: var(--danger); }
.failed-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, .8fr); gap: 1.25rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; }
.failed-main { min-width: 0; }
.failed-reason { display: flex; gap: .5rem; margin-top: .75rem; color: var(--danger); font-size: .8rem; overflow-wrap: anywhere; }
.failed-reason svg { width: 15px; height: 15px; margin-top: 2px; }
.retry-box { display: flex; flex-direction: column; justify-content: center; gap: .6rem; padding-left: 1.25rem; border-left: 1px solid var(--border); }
.retry-label { font-size: .85rem; font-weight: 600; }
.retry-url-row, .retry-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.retry-url-row input { min-width: 0; }
.retry-hint, .hint { font-size: .8rem; }
.modal { width: min(560px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.modal::backdrop { background: rgba(0, 0, 0, .7); }
.modal-card { padding: 1.25rem; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.modal-head h2 { font-size: 1.25rem; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 1.25rem; border: 1px solid var(--border); border-radius: 4px; }
.segment { min-height: 44px; padding: .5rem; color: var(--muted); background: transparent; border: 0; font: inherit; font-weight: 600; cursor: pointer; }
.segment + .segment { border-left: 1px solid var(--border); }
.segment.is-active { color: #182014; background: var(--accent); }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.feedback { display: flex; align-items: flex-start; gap: .5rem; padding: .7rem; border: 1px solid var(--border); border-radius: 4px; font-size: .85rem; white-space: pre-line; }
.feedback .button { flex: none; margin-left: auto; }
.feedback-error { color: var(--danger); border-color: var(--danger); }
.feedback-warning { color: #ead69e; border-color: #a59670; }
.feedback-info { color: var(--accent); }
.feedback-success { color: var(--success); }
.toasts { position: fixed; z-index: 60; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); left: 1rem; display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; pointer-events: none; }
.toast { max-width: 380px; padding: .8rem; background: var(--raised); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 4px; font-size: .85rem; pointer-events: auto; }
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }
@media (max-width: 1000px) { .queue-grid { grid-template-columns: 1fr; } }
@media (max-width: 650px) {
    .topbar { padding: .5rem 1rem; }
    .server-pill, .user-chip { display: none; }
    .tabs { gap: 1.25rem; padding: 0 1rem; }
    .content { padding: 1.5rem 1rem max(2rem, env(safe-area-inset-bottom)); }
    .page-head { flex-direction: column; gap: 1rem; }
    .page-head .button { width: 100%; }
    .failed-card { grid-template-columns: 1fr; }
    .retry-box { padding: 1rem 0 0; border-left: 0; border-top: 1px solid var(--border); }
    .retry-url-row { flex-direction: column; }
    .tracking-card { flex-direction: column; gap: .5rem; }
}
@media (max-width: 380px) {
    .login-card { padding: 1.25rem; }
    .brand { font-size: .9rem; }
    .tabs { gap: .8rem; }
    .tab { font-size: .85rem; }
    .field-row { grid-template-columns: 1fr; }
    .modal-foot { flex-direction: column-reverse; }
    .modal-foot .button { width: 100%; }
}
