:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6a6a70;
  --border: #e1e1dc;
  --accent: #2c5c8a;
  --accent-hover: #234a70;
  --accent-text: #ffffff;
  --ok-bg: #e5f2ea;
  --ok-text: #1f5e3b;
  --warn-bg: #fbf0d9;
  --warn-text: #7a5300;
  --err-bg: #fbe7e5;
  --err-text: #9c2219;
  --run-bg: #e3edf7;
  --run-text: #234a70;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #1f1f22;
    --text: #e9e9ec;
    --muted: #9d9da5;
    --border: #34343a;
    --accent: #6ea3d6;
    --accent-hover: #8bb6e0;
    --accent-text: #0e1a26;
    --ok-bg: #1b3326;
    --ok-text: #8fd3aa;
    --warn-bg: #3a2f14;
    --warn-text: #e8c36f;
    --err-bg: #3d1e1b;
    --err-text: #f2a39b;
    --run-bg: #1c2b3a;
    --run-text: #a9c8e8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1120px; margin: 0 auto; padding: .6rem 16px;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: .25rem 0; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.account { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.who { color: var(--muted); }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.lang-switch button { border: 0; border-radius: 0; padding: .15rem .5rem; background: transparent; color: var(--muted); font-size: .8rem; }
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.page { max-width: 1120px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.heading h1, .heading h2 { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 420px; margin: 3rem auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sub { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 2rem 0; }

.flash { border-radius: 8px; padding: .6rem .9rem; margin: 0 0 1rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }

button, .button {
  display: inline-block; font: inherit; cursor: pointer; text-decoration: none;
  padding: .45rem .9rem; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
button:hover, .button:hover { border-color: var(--muted); color: var(--text); }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
.danger { color: var(--err-text); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.link.danger { color: var(--err-text); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: .45rem .6rem; width: 100%;
}
input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); }
input[type="file"] { padding: .35rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; }
label .hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
form.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.inline-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.inline-form input { width: auto; flex: 1 1 10rem; }

.job-form fieldset {
  border: 0; border-top: 1px solid var(--border); margin: 0; padding: 1rem 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.25rem;
}
.job-form fieldset:first-of-type { border-top: 0; padding-top: 0; }
.job-form .wide { grid-column: 1 / -1; }
fieldset.names {
  border: 0; border-top: 1px solid var(--border); margin: 0; padding: .9rem 0 0;
  display: flex; flex-direction: column; gap: .6rem;
}
fieldset.names legend { font-weight: 600; padding: 0; float: left; width: 100%; margin-bottom: .2rem; }
fieldset.names p { margin: 0; }
.actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 1rem; }
progress.upload { width: 100%; margin-top: 1rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.row-actions input { width: 11rem; }
.jobs .card { padding: 0; }
.progress-cell { white-space: nowrap; }
.pct { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }

progress { width: 8rem; height: .5rem; vertical-align: middle; accent-color: var(--accent); }
.progress-card progress { width: 100%; height: .6rem; margin: .5rem 0; }
.progress-card .row { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.progress-card .row.small { align-items: center; color: var(--muted); }
.progress-card .row.small progress { flex: 1; margin: 0; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge-queued { background: var(--warn-bg); color: var(--warn-text); }
.badge-running { background: var(--run-bg); color: var(--run-text); }
.badge-done { background: var(--ok-bg); color: var(--ok-text); }
.badge-failed { background: var(--err-bg); color: var(--err-text); }
.badge-cancelled { background: var(--border); color: var(--muted); }

.columns { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.preview { width: 100%; height: 60vh; min-height: 320px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.downloads { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0; }
.facts { display: grid; grid-template-columns: minmax(5rem, 38%) minmax(0, 1fr); gap: .35rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); overflow-wrap: anywhere; hyphens: auto; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .columns { grid-template-columns: minmax(0, 1fr); }
  .job-form fieldset { grid-template-columns: minmax(0, 1fr); }
  .account { margin-left: 0; }
  .card.narrow { margin: 1rem auto; }
}
