:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1c2024;
  --muted: #6b7480;
  --accent: #2b6cb0;
  --accent-hover: #23578e;
  --ok: #1f8a4c;
  --warn: #b4690e;
  --err: #c0392b;
  --run: #2b6cb0;
  --idle: #8a93a0;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1d2126;
    --border: #2f353d;
    --text: #e6e9ed;
    --muted: #98a2b0;
    --accent: #5b9bd8;
    --accent-hover: #74aee4;
    --ok: #45b877;
    --warn: #d99b3d;
    --err: #e06a5c;
    --run: #5b9bd8;
    --idle: #6f7885;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0 0 .3em; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
code {
  font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  padding: .1em .35em;
  border-radius: 4px;
}
.muted { color: var(--muted); font-size: .875rem; }
.error { color: var(--err); font-size: .875rem; margin: .4em 0 0; }
.errors { margin: .4em 0 0; padding-left: 1.2em; color: var(--err); font-size: .8125rem; }

/* --- layout ------------------------------------------------------------- */

.view.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 600; cursor: pointer; }
.topbar nav { margin-left: auto; display: flex; gap: .25rem; }

.page { max-width: 1220px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.job-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
fieldset.card { border: 1px solid var(--border); }
legend { font-weight: 600; padding: 0 .4em; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; }
.row > label { flex: 1 1 180px; }
@media (max-width: 780px) { .grid-2 { grid-template-columns: 1fr; } }

/* --- forms -------------------------------------------------------------- */

label { display: block; margin-bottom: .7rem; font-size: .8125rem; color: var(--muted); }
label.checkbox {
  display: flex; align-items: center; gap: .5rem;
  color: var(--text); font-size: .875rem;
}
label.checkbox input { width: auto; margin: 0; }

input, select, textarea {
  width: 100%;
  margin-top: .25rem;
  padding: .5rem .6rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
textarea { font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

button, .ghost {
  font: inherit;
  padding: .5rem .9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .ghost:hover { border-color: var(--accent); color: var(--accent); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
button.danger:hover { background: var(--err); color: #fff; border-color: var(--err); }
button.link { border: none; background: none; padding: .4rem .6rem; color: var(--muted); }
button.link:hover { color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.tiny { padding: .2rem .5rem; font-size: .75rem; }

.actions { display: flex; align-items: center; gap: 1rem; }
.login-card { width: min(360px, 100%); }
.check-result { font-size: .8125rem; margin: .2rem 0 0; }
.check-result.ok { color: var(--ok); }
.check-result.bad { color: var(--err); }
.bulk-status { margin-top: .5rem; }

/* --- progress ----------------------------------------------------------- */

.bar {
  flex: 1;
  height: 8px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  border-radius: 99px;
  overflow: hidden;
  min-width: 80px;
}
.bar.big { height: 12px; }
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--run);
  border-radius: 99px;
  transition: width .4s ease;
}
.bar-fill.done { background: var(--ok); }
.bar-fill.error { background: var(--err); }
.bar-fill.cancelled { background: var(--idle); }

.summary-bar { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.summary-bar strong { min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.stats { display: flex; flex-wrap: wrap; gap: 1.25rem; font-size: .8125rem; color: var(--muted); }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; }

/* --- table -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: .55rem .7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress-col { width: 210px; }
.cell-progress { display: flex; align-items: center; gap: .5rem; }
.cell-progress span { font-size: .75rem; color: var(--muted); min-width: 3em; text-align: right; font-variant-numeric: tabular-nums; }
.mailbox-user { font-weight: 500; }
.mailbox-target { font-size: .75rem; color: var(--muted); }
.folder-cell { font-size: .8125rem; color: var(--muted); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-error { color: var(--err); font-size: .75rem; max-width: 320px; white-space: normal; }

.status {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 99px;
  white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.pending, .status.queued { color: var(--idle); background: color-mix(in srgb, var(--idle) 15%, transparent); }
.status.running { color: var(--run); background: color-mix(in srgb, var(--run) 15%, transparent); }
.status.done { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.status.error { color: var(--err); background: color-mix(in srgb, var(--err) 15%, transparent); }
.status.cancelled { color: var(--idle); background: color-mix(in srgb, var(--idle) 15%, transparent); }
.status.running::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* --- job list ----------------------------------------------------------- */

.job-card { display: flex; align-items: center; gap: 1rem; cursor: pointer; }
.job-card:hover { border-color: var(--accent); }
.job-card .job-main { flex: 1; min-width: 0; }
.job-card h3 { margin: 0; font-size: 1rem; }
.job-card .job-meta { font-size: .8125rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* --- modal -------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, .55);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  z-index: 20;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: min(1000px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-box .spacer { flex: 1; }
.modal-box pre {
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.verify-list { list-style: none; margin: .5rem 0 0; padding: 0; font-size: .8125rem; }
.verify-list li { padding: .3rem 0; border-bottom: 1px solid var(--border); }
.verify-list li:last-child { border-bottom: none; }
.verify-ok { color: var(--ok); }
.verify-bad { color: var(--err); }
[hidden] { display: none !important; }
