:root {
  --bg: #f5f4f0; --surface: #fff; --text: #1f2421; --muted: #55605a; --line: #e3e1da; --line-strong: #8a928d;
  --brand: #1f5f45; --brand-dark: #174a37; --brand-soft: #e3f0e9; --link: #1f5f45; --on-brand: #fff;
  --warn: #7a4a00; --warn-soft: #fbefd5; --warn-line: #e0b35a; --bad: #a3001b; --bad-soft: #fde8eb; --info-soft: #e6eefb; --info: #1d4a96;
  --track: #d4d8d4; --queued-bg: #ececea; --queued-fg: #4a524d; --code-bg: #f4f3ef; --focus: #1d5fd1; --btn-alt: #4a524d;
  --radius: .75rem; --tabbar-h: 3.5rem;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111613; --surface: #1a211d; --text: #e8ece9; --muted: #a7b2ab; --line: #2b352f; --line-strong: #7e8a83;
  --brand: #2c7f5c; --brand-dark: #236a4b; --brand-soft: #1d3a2d; --link: #7fd1a8; --on-brand: #fff;
  --warn: #f1c978; --warn-soft: #3a2d10; --warn-line: #8a6a24; --bad: #ff9aa8; --bad-soft: #3d1a20; --info-soft: #18283f; --info: #9dc0ff;
  --track: #34403a; --queued-bg: #2a332e; --queued-fg: #c3ccc6; --code-bg: #151b17; --focus: #7aa8ff; --btn-alt: #3b4640;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111613; --surface: #1a211d; --text: #e8ece9; --muted: #a7b2ab; --line: #2b352f; --line-strong: #7e8a83;
    --brand: #2c7f5c; --brand-dark: #236a4b; --brand-soft: #1d3a2d; --link: #7fd1a8; --on-brand: #fff;
    --warn: #f1c978; --warn-soft: #3a2d10; --warn-line: #8a6a24; --bad: #ff9aa8; --bad-soft: #3d1a20; --info-soft: #18283f; --info: #9dc0ff;
    --track: #34403a; --queued-bg: #2a332e; --queued-fg: #c3ccc6; --code-bg: #151b17; --focus: #7aa8ff; --btn-alt: #3b4640;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
/* overflow-x: clip on body (not hidden) so it does not become a scroll container and break the sticky topbar */
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body { overflow-x: clip; margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { text-wrap: balance; font-size: clamp(1.35rem, 1rem + 1.6vw, 1.75rem); line-height: 1.2; margin: 0 0 1rem; letter-spacing: -.01em; }
h2 { font-size: clamp(1rem, .9rem + .5vw, 1.1rem); margin: 0 0 .75rem; }
a { color: var(--link); overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); color: var(--text); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

main { max-width: 46rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; min-width: 0; }
body:not(.has-shell) main { padding-top: 3rem; max-width: 26rem; }
body.has-shell main { padding-bottom: calc(var(--tabbar-h) + 2rem + env(safe-area-inset-bottom)); }

/* top bar (desktop) / bottom tab bar (phone) */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1rem; background: var(--surface); border-bottom: 1px solid var(--line); padding: .5rem max(1rem, env(safe-area-inset-left)); min-height: 3.5rem; }
.brand { display: flex; align-items: center; gap: .5rem; color: var(--brand); font-weight: 700; font-size: 1.1rem; text-decoration: none; min-height: 2.75rem; }
:root[data-theme="dark"] .brand { color: var(--link); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand { color: var(--link); } }
.brand-logo { width: 24px; height: 24px; flex-shrink: 0; }
.tabs ul { list-style: none; margin: 0; padding: 0; display: flex; gap: .25rem; }
.tabs a { white-space: nowrap; display: flex; align-items: center; min-height: 2.75rem; padding: 0 .9rem; border-radius: .5rem; color: var(--text); text-decoration: none; font-weight: 500; }
.tabs a:hover { background: var(--brand-soft); }
.tabs a[aria-current="page"] { background: var(--brand-soft); color: var(--link); font-weight: 700; box-shadow: inset 0 -3px 0 var(--brand); }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.conn { min-width: 2.75rem; justify-content: center; display: inline-flex; gap: .5rem; align-items: center; min-height: 2.75rem; padding: 0 .8rem; border: 1px solid var(--line-strong); border-radius: 999px; font-size: .88rem; color: var(--text); text-decoration: none; background: var(--surface); }
.conn:hover { background: var(--brand-soft); }
.dot { width: .65rem; height: .65rem; border-radius: 50%; background: #d99a1f; flex: none; }
.conn.on .dot { background: #2fa36b; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; display: inline-flex; align-items: center; gap: .5rem; min-height: 2.75rem; min-width: 2.75rem; padding: 0 .8rem; border: 1px solid var(--line-strong); border-radius: .5rem; cursor: pointer; font-weight: 600; }
.usermenu summary::-webkit-details-marker { display: none; }
.burger, .burger::before, .burger::after { display: block; width: 1.1rem; height: 2px; background: currentColor; border-radius: 2px; content: ""; position: relative; }
.burger::before { position: absolute; top: -6px; } .burger::after { position: absolute; top: 6px; }
.menu-panel { position: absolute; right: 0; top: calc(100% + .4rem); width: min(19rem, calc(100vw - 1.5rem)); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 1rem; box-shadow: 0 10px 30px #0006; display: grid; gap: .8rem; z-index: 60; }
.who { margin: 0; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.menu-links { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.menu-links a { display: flex; align-items: center; min-height: 2.75rem; padding: 0 .6rem; border-radius: .5rem; color: var(--text); text-decoration: none; }
.menu-links a:hover, .menu-links a[aria-current="page"] { background: var(--brand-soft); }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.menu-title { font-size: .85rem; color: var(--muted); font-weight: 600; }
.lang-switch, .theme-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: .5rem; overflow: hidden; }
.lang-switch button, .theme-switch button { background: transparent; color: var(--text); border-radius: 0; font-size: .85rem; min-height: 2.75rem; min-width: 2.75rem; padding: 0 .7rem; }
.lang-switch button:hover, .theme-switch button:hover { background: var(--brand-soft); }
.lang-switch button[aria-pressed="true"], .theme-switch button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); cursor: default; }

@media (max-width: 767px) {
  .topbar { min-height: 3.25rem; gap: .5rem; }
  .conn-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .conn { padding: 0 .75rem; }
  .menu-label { display: none; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--line-strong); padding-bottom: env(safe-area-inset-bottom); }
  .tabs ul { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
  .tabs a { justify-content: center; min-height: var(--tabbar-h); border-radius: 0; font-size: .9rem; box-shadow: none; }
  .tabs a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--brand); }
}

/* device tuning: data-device is set on <html> by device.js */
[data-device="tablet"] main { max-width: 52rem; padding: 2rem 2rem 3rem; }
[data-device="tablet"] body:not(.has-shell) main { max-width: 30rem; }
[data-device="phone"] main { padding: 1rem .75rem; }
[data-device="phone"] body.has-shell main { padding-bottom: calc(var(--tabbar-h) + 2rem + env(safe-area-inset-bottom)); }
[data-device="phone"] body:not(.has-shell) main { padding-top: 2rem; }
[data-device="phone"] .card { padding: 1rem; border-radius: .6rem; }
[data-device="phone"] .actions > button { flex: 1 1 100%; }
[data-device="phone"] .job-source a { min-height: 2.75rem; line-height: 2.75rem; }

/* paste bar */
.paste { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem 1.25rem 1.1rem; margin-bottom: 1.5rem; }
.paste h1 { margin-bottom: 1rem; }
.paste-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.paste-row input { flex: 1 1 16rem; min-height: 3.25rem; font-size: 1.05rem; border: 2px solid var(--line-strong); }
.paste-row button { min-height: 3.25rem; }
button.secondary-outline { background: transparent; color: var(--link); border: 2px solid var(--brand); }
button.secondary-outline:hover { background: var(--brand-soft); }
.go { padding-inline: 1.6rem; }
[data-device="phone"] .go { flex: 1 1 100%; }
.sources { margin: .6rem 0 0; }
.prefs-row { display: flex; gap: 1.25rem 2rem; flex-wrap: wrap; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.seg-group { display: grid; gap: .35rem; }
.seg-title { font-size: .8rem; color: var(--muted); font-weight: 600; }
.seg-buttons { display: inline-flex; border: 1px solid var(--line-strong); border-radius: .5rem; overflow: hidden; width: max-content; max-width: 100%; }
button.seg { background: transparent; color: var(--text); border-radius: 0; min-height: 2.75rem; min-width: 2.75rem; padding: 0 .9rem; font-weight: 600; }
button.seg + button.seg { border-left: 1px solid var(--line-strong); }
button.seg:hover { background: var(--brand-soft); }
button.seg[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); cursor: default; }
.recent { margin-bottom: 1rem; }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.1rem; }
.card-head > *, .actions > *, .job-head > *, .jobs > * { min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.card.danger { border-color: var(--bad); }
label { display: block; margin: .9rem 0 .3rem; font-weight: 600; font-size: .95rem; }
label.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
label.check input { margin-top: .3rem; flex: none; }
input:not([type=checkbox]), select, textarea { display: block; width: 100%; padding: .65rem .75rem; font: inherit; border: 1px solid var(--line-strong); border-radius: .5rem; background: var(--surface); color: inherit; }
button { font: inherit; padding: .65rem 1.1rem; min-height: 2.75rem; border: 0; border-radius: .5rem; background: var(--brand); color: var(--on-brand); cursor: pointer; font-weight: 600; }
button:hover { background: var(--brand-dark); }
button.secondary { background: var(--btn-alt); color: #fff; }
button.block { width: 100%; }
.danger-button { background: var(--bad); }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
form > button[type=submit] { margin-top: 1rem; }
.hint, .muted { font-size: .85rem; color: var(--muted); }
.hint { margin: .4rem 0; }
.error { color: var(--bad); background: var(--bad-soft); padding: .6rem .8rem; border-radius: .5rem; }
.notice { background: var(--warn-soft); color: var(--warn); padding: .7rem .9rem; border-radius: .5rem; }
.cta { display: inline-block; margin-top: .4rem; padding: .65rem 1.1rem; border-radius: .5rem; background: var(--brand); color: var(--on-brand); font-weight: 600; text-decoration: none; }
.cta:hover { background: var(--brand-dark); }
.success { color: var(--link); background: var(--brand-soft); padding: .6rem .8rem; border-radius: .5rem; }
textarea { resize: vertical; }
.form-msg { margin: .5rem 0 0; }
.form-msg:empty { display: none; }

/* feedback */
.feedback-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.feedback-item { border: 1px solid var(--line); border-radius: .6rem; padding: .8rem .95rem; min-width: 0; }
.feedback-item p { margin: .25rem 0; }
.feedback-message { white-space: pre-wrap; overflow-wrap: anywhere; }
.thumb { display: block; max-width: 10rem; max-height: 8rem; margin-top: .4rem; border: 1px solid var(--line); border-radius: .4rem; }

/* jobs */
.jobs { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.job { border: 1px solid var(--line); border-radius: .6rem; padding: .8rem .95rem; min-width: 0; overflow-wrap: anywhere; }
.job p { margin: .25rem 0; }
.job-head { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.job-title { overflow-wrap: anywhere; }
.job-source { font-size: .88rem; overflow-wrap: anywhere; min-width: 0; }
/* the label is already shortened server/client side; ellipsis is the backstop so a URL never widens the card */
.job-source a { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.job-message { font-size: .9rem; }
.job-message.reason { color: var(--bad); font-weight: 600; }
.job-meta { font-size: .78rem; }
li { overflow-wrap: anywhere; }
.warnings { margin: .4rem 0; padding: .5rem .8rem .5rem 1.6rem; background: var(--warn-soft); color: var(--warn); border-radius: .5rem; font-size: .85rem; }
.pill { flex: none; font-size: .75rem; font-weight: 700; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.pill-queued { background: var(--queued-bg); color: var(--queued-fg); }
.pill-running { background: var(--info-soft); color: var(--info); }
.pill-done { background: var(--brand-soft); color: var(--link); }
.pill-failed { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem 1rem; border: 1px dashed var(--line-strong); border-radius: .6rem; margin: 0; }
.empty[hidden] { display: none; }

/* admin */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .75rem; margin: 0; }
.stats > div { border: 1px solid var(--line); border-radius: .6rem; padding: .6rem .8rem; }
.stats dt { font-size: .8rem; color: var(--muted); }
.stats dd { margin: .2rem 0 0; font-size: 1.25rem; font-weight: 700; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: .8rem 0; }
.details dt { font-weight: 600; font-size: .9rem; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.traceback { background: var(--code-bg); border: 1px solid var(--line); border-radius: .5rem; padding: .75rem; overflow-x: auto; font-size: .8rem; white-space: pre; }



/* live import: tracker */
.job--live { border-color: var(--brand); border-width: 2px; padding: 1rem 1.1rem; }
.live-headline { font-size: 1.1rem; font-weight: 700; margin: .5rem 0 .1rem !important; }
.live-sub { color: var(--muted); font-size: .88rem; }
.tracker { list-style: none; margin: .9rem 0 .2rem; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .35rem; counter-reset: s; }
.tracker li { position: relative; padding-top: .8rem; font-size: .72rem; line-height: 1.2; color: var(--muted); text-align: left; overflow-wrap: normal; }
.tracker li::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 6px; border-radius: 3px; background: var(--track); }
.tracker li[data-s="done"]::before { background: var(--brand); }
.tracker li[data-s="done"] { color: var(--text); }
.tracker li[data-s="active"] { color: var(--text); font-weight: 700; }
.tracker li[data-s="active"]::before { height: 8px; top: -1px; background: var(--track); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand); animation: gc-pulse 1.6s ease-in-out infinite; }
.tracker li[data-s="active"]::after { content: ""; position: absolute; top: -1px; left: 0; width: 55%; height: 8px; border-radius: 4px; background: var(--brand); }
@keyframes gc-pulse { 50% { opacity: .65; } }
@media (max-width: 480px) { .tracker { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: .9rem; } .tracker li { font-size: .78rem; } }

/* needs attention */
.job--attn { border-color: var(--warn-line); background: var(--warn-soft); }
.attn { color: var(--warn); }
.attn-title { font-weight: 700; margin: .5rem 0 .2rem; }
.attn-what { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin: .6rem 0 .2rem; }
.attn ol { margin: 0; padding-left: 1.3rem; }
.job--attn .pill-failed { background: var(--warn-line); color: #231500; }

@media (prefers-reduced-motion: reduce) { .tracker li[data-s="active"]::before { animation: none; } * { scroll-behavior: auto; } }

.card-head a { display: inline-flex; align-items: center; min-height: 2.75rem; }
.menu-panel { border-width: 2px; }
:root[data-theme="dark"] .menu-panel { background: #232d27; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .menu-panel { background: #232d27; } }
[data-device="phone"] .paste-row input { flex: 1 1 100%; }
[data-device="phone"] .paste-row button.secondary-outline { flex: 0 0 auto; }
[data-device="phone"] .paste-row .go { flex: 1 1 0; min-width: 0; }
[data-device="phone"] .paste { padding: 1.1rem .95rem; }
[data-device="phone"] .paste-row { gap: .75rem; }

.pill-attn { background: var(--warn-line); color: #231500; }
.job--live[data-status="queued"] { border-style: dashed; border-width: 1px; border-color: var(--line-strong); }
.tracker li[data-s="done"] .lbl::before { content: "\2713\00a0"; font-weight: 700; color: var(--link); }
.tracker { margin-bottom: .9rem; }
.tracker li { color: var(--muted); }

.fail-hint { font-size: .92rem; margin: .4rem 0 .2rem !important; }
.fail-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.paste-panel { margin-top: .75rem; display: grid; gap: .5rem; }
.paste-panel textarea { min-height: 9rem; }

.fail-hint.reason { font-weight: 600; }
.paste-panel { padding-top: .75rem; border-top: 1px solid var(--line); }
.fail-actions .go { padding-inline: 1.1rem; }
.paste-panel textarea { padding-bottom: 1rem; }
