:root {
    --bg: #0f1115;
    --card: #171a21;
    --card-2: #1e222b;
    --text: #e6e8ec;
    --muted: #9aa2af;
    --border: #2a2f3a;
    --accent: #4f8cff;
    --accent-press: #3d74e0;
    --ok: #37c07a;
    --err: #ff6b6b;
    --warn: #ffb547;
    --radius: 10px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f6f9; --card: #ffffff; --card-2: #f0f2f6; --text: #1a1d24;
        --muted: #5b6472; --border: #dfe3ea;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg); color: var(--text); font-family: var(--font);
    line-height: 1.5; font-size: 15px;
}
.wrap { max-width: 820px; margin: 0 auto; padding: 32px 20px 80px; }
.head { position: relative; }
.head h1 { margin: 0 0 4px; font-size: 26px; }
.sub { margin: 0 0 24px; color: var(--muted); }

.logout-link {
    position: absolute; top: 2px; right: 0; font-size: 13px; font-weight: 600;
    color: var(--muted); text-decoration: none; border: 1px solid var(--border);
    padding: 6px 12px; border-radius: 8px;
}
.logout-link:hover { color: var(--text); }

.login-wrap { max-width: 420px; margin-top: 8vh; }
.login-title { margin: 0 0 4px; font-size: 22px; }

.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
code { background: var(--card-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

input, textarea, select {
    width: 100%; background: var(--card-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
    font-family: inherit; font-size: 14px; resize: vertical;
}
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--accent);
}
select { cursor: pointer; }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.small { flex: 1; min-width: 160px; }
.plan { display: flex; flex-direction: column; justify-content: center; }
.plan-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.plan-total { font-size: 24px; font-weight: 700; }

.actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
button {
    font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
    border-radius: 8px; padding: 10px 18px; border: 1px solid transparent;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-press); }
.primary:disabled { opacity: .55; cursor: not-allowed; }
.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.ghost:hover { color: var(--text); }
.warn { color: var(--warn); font-size: 13px; }

.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: auto; }

.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.results-head h2 { margin: 0; }
.results-actions { display: flex; gap: 8px; }

.cell .meta .badge {
    display: inline-block; margin-top: 3px; font-size: 10.5px; color: var(--muted);
    background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
    padding: 0 5px; letter-spacing: .2px;
}

/* Dim the input form while a job is running so the progress panel leads. */
#formCard { transition: opacity .3s ease, filter .3s ease; }
body.busy #formCard { opacity: .25; filter: saturate(.6); pointer-events: none; }

/* Step-by-step preflight checklist */
.steps { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.step { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
.step .ico { width: 16px; height: 16px; flex: 0 0 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.step.pending .ico::before { content: '○'; }
.step.done { color: var(--text); }
.step.done .ico { color: var(--ok); }
.step.done .ico::before { content: '✓'; }
.step.error { color: var(--err); }
.step.error .ico::before { content: '✕'; }
.step.running { color: var(--text); }
.step.running .ico {
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite;
}

.created-line { margin-top: 12px; font-size: 16px; font-weight: 700; }

.progress-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.bar { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.bar-fill {
    height: 100%; width: 0%; background: var(--accent);
    transition: width .25s ease;
}
.counters { margin-top: 10px; font-size: 13px; color: var(--muted); display: flex; gap: 16px; }
.counters .ok { color: var(--ok); }
.counters .err { color: var(--err); }

.grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}
.cell {
    background: var(--card-2); border: 1px solid var(--border); border-radius: 8px;
    overflow: hidden; display: flex; flex-direction: column; min-height: 150px;
}
.cell img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.cell .meta { padding: 7px 9px; font-size: 12px; }
.cell .meta .kw { font-weight: 600; }
.cell .meta .tag { color: var(--muted); }
.cell.pending, .cell.failed {
    align-items: center; justify-content: center; text-align: center;
    padding: 12px; font-size: 12.5px; color: var(--muted);
}
.cell.failed { color: var(--err); }
.cell.cached .meta .tag::after { content: " · cached"; }

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

.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.history-list li:last-child { border-bottom: none; }
.history-list .h-main { min-width: 0; }
.history-list .h-tpl { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-list .h-sub { color: var(--muted); font-size: 12.5px; }
.history-list button { padding: 6px 12px; font-size: 13px; }
