:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #14181f; --muted: #6b7480;
  --line: #e2e6ec; --accent: #2f6fed; --accent-ink: #ffffff;
  --ok: #1a7f45; --warn: #9a6700; --err: #c0362c;
  --ok-bg: #e6f4ec; --warn-bg: #fdf3d8; --err-bg: #fbeae8;
  --radius: 10px;
}
/* Dark values are declared under both scopes: the media query covers the OS
   setting, the [data-theme] scope covers an explicit choice and must win both
   ways. Declaring only one of them lets parts of the page disagree. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12151a; --panel: #1a1f26; --ink: #e6e9ee; --muted: #98a1ae;
    --line: #2a313b; --accent: #5b8dfa; --accent-ink: #0d1117;
    --ok: #58c98a; --warn: #e3b341; --err: #f2837a;
    --ok-bg: #16281f; --warn-bg: #2b2417; --err-bg: #2d1c1a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12151a; --panel: #1a1f26; --ink: #e6e9ee; --muted: #98a1ae;
  --line: #2a313b; --accent: #5b8dfa; --accent-ink: #0d1117;
  --ok: #58c98a; --warn: #e3b341; --err: #f2837a;
  --ok-bg: #16281f; --warn-bg: #2b2417; --err-bg: #2d1c1a;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
       background: var(--bg); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 1rem; display: flex; gap: .75rem; align-items: baseline; }
h3 { font-size: .95rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); font-weight: 400; font-size: .875rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; color: var(--ink); }
.topbar nav { display: flex; gap: 1.25rem; align-items: center; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.25rem;
}

form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.span2 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .875rem; font-weight: 500; }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
input, select {
  font: inherit; padding: .5rem .6rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
input[type=checkbox] { width: auto; padding: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; cursor: pointer; padding: .5rem .9rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger:hover { border-color: var(--err); color: var(--err); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
form.inline { display: inline-flex; gap: .5rem; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.kv td:first-child { color: var(--muted); width: 14rem; }
.counts { display: flex; gap: .6rem; }

.badge {
  display: inline-block; padding: .1rem .55rem; border-radius: 99px;
  font-size: .78rem; font-weight: 600; border: 1px solid var(--line); background: var(--bg);
}
.badge.completed, .badge.uploaded { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.running, .badge.pending, .badge.downloaded, .badge.parsed { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.failed, .badge.error, .badge.completed_with_errors { background: var(--err-bg); color: var(--err); border-color: transparent; }

.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.error { background: var(--err-bg); color: var(--err); }

.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
            flex-wrap: wrap; margin-bottom: 1.25rem; }
.job-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.counters { display: flex; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }

.log {
  background: #0d1117; color: #d8dee9; border-radius: 8px; padding: .9rem;
  max-height: 26rem; overflow: auto; font-size: .82rem; line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin: 0;
  white-space: pre-wrap; word-break: break-word;
}
.log .lvl-error { color: #ff8f85; }
.log .lvl-warn { color: #ffd479; }
.log .ts { color: #6b7480; }

.accounts { list-style: none; padding: 0; margin: .5rem 0 0; }
.accounts li { display: flex; justify-content: space-between; align-items: center;
               gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }

.login-card {
  max-width: 22rem; margin: 6vh auto 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.75rem;
}
.login-card form { display: flex; flex-direction: column; gap: .9rem; margin-top: 1.25rem; }

@media (max-width: 640px) {
  form.grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}

/* --- Resource meters ------------------------------------------------------
   Form: a meter, per "a single ratio against a limit". Color job: status.
   Three states only -- the four-state ramp puts warning and serious 13.6 apart
   in normal-vision ΔE, below the 15 floor; three steps measure 24+.
   The fill carries severity and the unfilled track is a lighter step of the
   same ramp, so state reads across the whole bar. Values and labels wear text
   tokens, never the state color. */
.system .meter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1.1rem 1.5rem;
}
.meter { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.meter-label { font-size: .8rem; font-weight: 600; color: var(--ink); }
/* Proportional figures: tabular-nums is for columns, not standalone values. */
.meter-value { font-size: 1.35rem; font-weight: 600; color: var(--ink); line-height: 1; }

.meter-track {
  position: relative; height: 8px; border-radius: 4px; overflow: hidden;
  background: var(--meter-track, #e2e6ec);
}
.meter-fill {
  height: 100%;
  /* Square at the baseline, 4px rounded at the data-end. */
  border-radius: 0 4px 4px 0;
  background: var(--meter-fill, #2a78d6);
  min-width: 2px;
  transition: width .4s ease, background-color .3s ease;
}
.meter-foot {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: .5rem; font-size: .78rem; color: var(--muted); min-width: 0;
}
.meter-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter-state {
  display: inline-flex; align-items: center; gap: .3rem;
  white-space: nowrap; color: var(--muted); text-transform: capitalize;
}
.meter-state .dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--meter-fill, var(--muted));
}
.meter-state .dot.state-stale { background: var(--muted); }

/* Status steps, fixed. Track is a lighter step of the fill's own ramp. */
.state-normal   { --meter-fill: #2a78d6; --meter-track: #d7e5f7; }
.state-warning  { --meter-fill: #fab219; --meter-track: #fbeac4; }
.state-critical { --meter-fill: #d03b3b; --meter-track: #f4d8d8; }
.state-unknown  { --meter-fill: #898781; --meter-track: #e2e6ec; }

/* Dark mode is selected, not flipped: warning clears 9.49:1 on a dark surface,
   so the same fill reads far better here than it can on white. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .state-normal   { --meter-fill: #3987e5; --meter-track: #1d3352; }
  :root:not([data-theme="light"]) .state-warning  { --meter-fill: #fab219; --meter-track: #4a3a14; }
  :root:not([data-theme="light"]) .state-critical { --meter-fill: #d03b3b; --meter-track: #4a2020; }
  :root:not([data-theme="light"]) .state-unknown  { --meter-fill: #898781; --meter-track: #2a313b; }
}
:root[data-theme="dark"] .state-normal   { --meter-fill: #3987e5; --meter-track: #1d3352; }
:root[data-theme="dark"] .state-warning  { --meter-fill: #fab219; --meter-track: #4a3a14; }
:root[data-theme="dark"] .state-critical { --meter-fill: #d03b3b; --meter-track: #4a2020; }
:root[data-theme="dark"] .state-unknown  { --meter-fill: #898781; --meter-track: #2a313b; }

.system.compact { padding: 1rem 1.25rem; }
.system.compact .meter-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem 1.25rem; }
.system.compact .meter-value { font-size: 1.05rem; }

@media (prefers-reduced-motion: reduce) {
  .meter-fill { transition: none; }
}

textarea {
  font: inherit; padding: .5rem .6rem; border-radius: 8px; resize: vertical;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
table.folders td:nth-child(4), table.folders td:nth-child(5) { font-variant-numeric: tabular-nums; }

/* --- Job progress and finish estimate ------------------------------------ */
.progress-card { display: flex; flex-direction: column; gap: .8rem; }
.progress-head {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem;
}
.progress-label {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin-bottom: .2rem;
}
.progress-value { font-size: 1.35rem; font-weight: 600; color: var(--ink); line-height: 1.15; }
.progress-value .muted { font-size: .9rem; font-weight: 400; }
.progress-track {
  height: 8px; border-radius: 4px; overflow: hidden; background: var(--meter-track, #d7e5f7);
}
.progress-fill {
  height: 100%; border-radius: 0 4px 4px 0; min-width: 2px;
  background: var(--meter-fill, #2a78d6); transition: width .5s ease;
}
@media (prefers-reduced-motion: reduce) { .progress-fill { transition: none; } }
