:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2557d6;
  --accent-ink: #ffffff;
  --danger: #c4321f;
  --keep: #1f7a4d;
  --keep-bg: #e6f4ec;
  --warn-bg: #fff6e0;
  --warn-line: #f0c860;
  --info-bg: #eaf0fd;
  --error-bg: #fdecea;
  --diff-bg: #fff1d6;
  --diff-ink: #8a5300;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e7e9ee;
    --muted: #98a1b2;
    --line: #2b3039;
    --accent: #6f95ff;
    --accent-ink: #0d1220;
    --danger: #ff7a66;
    --keep: #6fd39f;
    --keep-bg: #183126;
    --warn-bg: #2e2715;
    --warn-line: #7a6223;
    --info-bg: #18233d;
    --error-bg: #3a1c19;
    --diff-bg: #3a2c12;
    --diff-ink: #ffc46b;
    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", Roboto, sans-serif;
}
a { color: var(--accent); }
code { font-size: .9em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand small { color: var(--muted); font-weight: 500; }
.logo { color: var(--accent); font-size: 20px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.top-right form { margin: 0; }

main { max-width: 1400px; margin: 0 auto; padding: 24px 16px 64px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; margin-bottom: 20px;
}
.card.narrow { max-width: 420px; margin: 60px auto; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 6px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 13px; }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 4px; font-weight: 500; }
input[type=password], input[type=search] {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input[type=search] { flex: 1; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  font: inherit; font-weight: 550; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 14px 0 0; }
legend { font-weight: 600; padding: 0 6px; }
label.radio { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 4px 0; }

.mailboxes {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px;
  max-height: 420px; overflow: auto; margin-top: 10px; padding: 2px;
}
.mb {
  display: flex; gap: 10px; align-items: flex-start; font-weight: 400;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.mb:has(input:checked) { border-color: var(--accent); background: var(--info-bg); }
.mb span { display: grid; min-width: 0; }
.mb strong, .mb small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mb small { color: var(--muted); }
.mb input { margin-top: 4px; }

.alert { border-radius: 8px; padding: 10px 14px; margin: 12px 0; border: 1px solid var(--line); }
.alert.error { background: var(--error-bg); border-color: var(--danger); }
.alert.info { background: var(--info-bg); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.jobs .ellipsis { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jobs .actions { display: flex; gap: 6px; justify-content: flex-end; }
form.inline { display: inline; margin: 0; }

.progress { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 18px 0 14px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats div { background: var(--bg); border-radius: 8px; padding: 10px 12px; display: grid; }
.stats .k { font-size: 12px; color: var(--muted); }
.stats .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.current { color: var(--muted); font-size: 13px; min-height: 1.5em; }

.toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 57px; background: var(--surface); padding: 8px 0; z-index: 4; border-bottom: 1px solid var(--line);
}
.group { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; overflow: hidden; }
.group-head {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--bg); padding: 8px 12px; font-size: 14px;
}
.group-head .subject { font-weight: 600; overflow-wrap: anywhere; }
.diff-note { color: var(--diff-ink); font-weight: 600; }
.items th { font-size: 11px; padding: 5px 8px; white-space: nowrap; }
.items td { font-size: 13px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.items tr:last-child td { border-bottom: 0; }
.items tr.msg { cursor: pointer; }
.items tr.msg:hover td { background: var(--bg); }
.items tr.active td { background: var(--info-bg); }
.items tr.kept td { background: var(--keep-bg); }
.items .keep-cell, .items .chk { width: 1%; text-align: center; cursor: default; }
.items .folder, .items .ellip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.items .folder { color: var(--muted); }
.items .textpv { white-space: normal; min-width: 260px; max-width: 420px; font-size: 12px; color: var(--muted); }
.items .cats { white-space: normal; min-width: 120px; }
.items .date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.items .pv { padding: 2px 8px; font-size: 12px; }
.items tr td.diff { background: var(--diff-bg); color: var(--diff-ink); font-weight: 600; }
.items tr.removed td { opacity: .55; }
.items tr.removed .col-folder, .items tr.removed .col-from { text-decoration: line-through; }

.cols { margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.cols summary { cursor: pointer; font-weight: 600; }
.cols-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 12px; margin: 8px 0; }
.cols-grid label.radio { margin: 2px 0; }

.rule-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.rule-list li {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px;
}
.rule-list li label.radio { margin: 0; }
.rule-list li select { flex: 1 1 160px; width: 100%; min-width: 0; }
.grid2 > * { min-width: 0; }
.rule-list .move { margin-left: auto; display: flex; gap: 4px; }
.rule-list .move .btn { padding: 1px 8px; }
.rule-list li:first-child .up, .rule-list li:last-child .down { visibility: hidden; }
.cat {
  display: inline-block; font-size: 11.5px; padding: 1px 7px; margin: 1px 0; border-radius: 99px;
  background: var(--info-bg); color: var(--text); border: 1px solid var(--line);
}

.stack-sm { display: grid; gap: 8px; align-content: start; }
.stack-sm h2 { margin-bottom: 0; }
.stack-sm .row label.radio { margin: 0; }
select, input[type=text] {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
.bulk { background: var(--bg); border-radius: 8px; padding: 4px 14px 12px; margin: 12px 0; }
.bulk .progress { background: var(--surface); }

.preview {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); z-index: 10;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column; padding: 14px 16px; gap: 8px;
}
.preview[hidden] { display: none; }
.preview-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.preview-head strong { font-size: 16px; overflow-wrap: anywhere; }
.pv-meta { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
.pv-meta dt { color: var(--muted); }
.pv-meta dd { margin: 0; overflow-wrap: anywhere; }
.pv-att { font-size: 13px; margin: 0; }
.preview iframe { flex: 1; width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.tag {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.tag.keep { background: var(--keep-bg); color: var(--keep); border-color: transparent; }
.tag.gone { color: var(--danger); }
.tag.att { margin-left: 6px; font-weight: 500; vertical-align: 1px; }
.badge { font-size: 12.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; }

.empty { text-align: center; padding: 30px; color: var(--muted); font-size: 16px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 18px; }

.table-wrap { overflow-x: auto; }

@media (max-width: 640px) {
  .btn { white-space: normal; text-align: left; }
  .summary th:nth-child(4), .summary td:nth-child(4) { display: none; }
  header.top { padding: 10px 16px; }
  .badge { display: none; }
  .card { padding: 16px; }
  .toolbar { top: 51px; position: static; }
}
