:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --fg: #14161a;
  --muted: #6b7280;
  --line: #e4e6eb;
  --accent: #4f46e5;
  --accent-fg: #ffffff;
  --ok: #0f7b3f; --ok-bg: #d9f2e3;
  --warn: #8a5a00; --warn-bg: #fdf0cf;
  --err: #a3212b; --err-bg: #fbdfe1;
  --idle: #4b5563; --idle-bg: #e6e8ec;
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #171a21; --fg: #e8eaee; --muted: #929aa8; --line: #262b34;
    --accent: #7c7ff5; --accent-fg: #0f1115;
    --ok: #6ee7a8; --ok-bg: #123324; --warn: #f7cf74; --warn-bg: #35290d;
    --err: #ff9aa2; --err-bg: #3a1418; --idle: #aab2c0; --idle-bg: #232833;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; min-height: 100vh;
}
.top { order: 1; } main { order: 3; } .tabbar { order: 4; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; letter-spacing: .16em; font-size: 14px; color: var(--accent); }
.version { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.grow { flex: 1; }
.chip {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px;
}

/* ---------- layout ---------- */
main { width: 100%; max-width: 780px; margin: 0 auto; padding: 14px 12px 20px; }
.stack > * + * { margin-top: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.card-head .muted { margin-left: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- form ---------- */
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 9px; margin: 12px 0; font-size: 14px; }
.check input { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1 1 auto; min-height: 44px; padding: 0 16px; font: inherit; font-weight: 600;
  border: 1px solid var(--line); border-radius: 11px; background: var(--card); color: var(--fg); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.sm { flex: none; min-height: 34px; font-size: 13px; padding: 0 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active { transform: scale(.985); }

/* ---------- dropzone ---------- */
.drop {
  display: flex; flex-direction: column; gap: 3px; align-items: center; justify-content: center;
  text-align: center; padding: 22px 14px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 13px;
}
.drop strong { color: var(--fg); font-size: 14px; }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---------- doc rows ---------- */
.list { margin-top: 12px; }
.row {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.row input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.row .name { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.row .subj { margin-top: 5px; font-size: 13px; min-height: 38px; padding: 8px 10px; }
.row .x {
  border: none; background: transparent; color: var(--muted); font-size: 20px;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
}
.row .x:active { background: var(--bg); }

/* ---------- badges & filters ---------- */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px; text-transform: uppercase;
}
.b-queued { background: var(--idle-bg); color: var(--idle); }
.b-pending { background: var(--warn-bg); color: var(--warn); }
.b-success { background: var(--ok-bg); color: var(--ok); }
.b-failure { background: var(--err-bg); color: var(--err); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button {
  font: inherit; font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer;
}
.filters button.on { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

/* ---------- job / contact cards ---------- */
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.item .hd { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.item .who { font-weight: 650; font-size: 14px; overflow-wrap: anywhere; }
.item .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.item .meta { margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.item .err { margin-top: 6px; font-size: 12px; color: var(--err); overflow-wrap: anywhere; }
.item .actions { margin-top: 10px; }
.item .actions .btn { flex: 0 1 auto; min-height: 36px; font-size: 13px; }

/* ---------- bottom nav ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px; border: none; background: none; color: var(--muted);
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
}
.tabbar button.on { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar i {
  position: absolute; top: 6px; left: 50%; margin-left: 8px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}

/* ---------- login ---------- */
body.boot > *, #login[hidden] { display: none; }
#login {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: 20px; background: var(--bg); overflow: auto;
}
#login .card { width: 100%; max-width: 340px; margin: 0; padding: 22px; }
.login-logo {
  font-weight: 800; letter-spacing: .2em; font-size: 20px; color: var(--accent);
  text-align: center; margin-bottom: 20px;
}
.login-version {
  display: block; margin-top: 4px; letter-spacing: .04em; font-size: 11px;
  font-weight: 600; color: var(--muted);
}
.login-err {
  margin: 4px 0 0; font-size: 13px; color: var(--err);
  background: var(--err-bg); border-radius: 9px; padding: 9px 11px;
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px); opacity: 0;
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20; pointer-events: none;
  max-width: min(92vw, 460px); padding: 11px 16px; border-radius: 12px;
  background: #1f2430; color: #fff; font-size: 13px; transition: .2s;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #93202b; }

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  body { padding-bottom: 24px; }
  .tabbar {
    order: 2; position: static; width: calc(100% - 24px); max-width: 780px;
    margin: 12px auto 0; border-radius: 999px;
    border: 1px solid var(--line); overflow: hidden;
  }
  .tabbar button { flex-direction: row; gap: 7px; font-size: 13px; padding: 11px 0; }
  .tabbar i { top: 12px; margin-left: 34px; }
  #toast { bottom: 24px; }
}
