:root {
  --paper: #f6f5f1;
  --surface: #ffffff;
  --ink: #1d1f1c;
  --muted: #6b6f68;
  --line: #e3e2dc;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe8;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --bad: #a3352b;
  --bad-soft: #f8e3e0;
  --info: #31597a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151714;
    --surface: #1e211d;
    --ink: #ecece6;
    --muted: #9da197;
    --line: #2f332d;
    --accent: #5fae84;
    --accent-ink: #0f1a13;
    --accent-soft: #22352a;
    --warn: #e0a64a;
    --warn-soft: #3a2f1c;
    --bad: #e3786c;
    --bad-soft: #3b2220;
    --info: #8db6d8;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.loading { text-align: center; color: var(--muted); margin-top: 30vh; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* Layout */
.screen { max-width: 560px; margin: 0 auto; padding: 28px 20px 120px; }
.screen.wide { max-width: 980px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 18px; }
.brand img { width: 28px; height: 28px; }
h1 { font-size: 28px; line-height: 1.2; margin: 18px 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 24px 0 8px; }
p.lead { font-size: 17px; color: var(--muted); margin: 0 0 20px; }

/* Controls */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 11px 16px; font-weight: 560; cursor: pointer; min-height: 44px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { width: 100%; font-size: 18px; padding: 16px 18px; min-height: 58px; border-radius: 14px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0 4px; font-weight: 600; }
.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px;
}
.field input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0; }
.check input { width: 20px; height: 20px; margin-top: 2px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

/* Cards and badges */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.plain { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.light { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: inline-block; flex: none; }
.light.ok { background: #3c9a63; }
.light.needs_auth, .light.connecting { background: #d39a2c; }
.light.error { background: var(--bad); }
.light.tools_only { background: var(--info); }

/* Onboarding */
.steps { display: flex; gap: 6px; margin: 22px 0 4px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps i.on { background: var(--accent); }
.stepname { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.recovery { font-size: 20px; line-height: 1.7; letter-spacing: 0.04em; word-spacing: 0.3em; text-align: center; padding: 18px; user-select: all; }
.choices { display: grid; gap: 10px; }
.choice { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; }
.choice.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.choice b { display: block; }
.choice small { color: var(--muted); display: block; font-weight: 400; font-size: 14px; }
.verify { display: flex; gap: 12px; align-items: flex-start; }
.verify .icon { font-size: 22px; line-height: 1; }
.catalog { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .catalog { grid-template-columns: 1fr 1fr; } }
.conn { display: flex; flex-direction: column; gap: 6px; }
.conn header { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.conn p { margin: 0; color: var(--muted); font-size: 14px; }
.conn footer { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.progress { list-style: none; padding: 0; margin: 18px 0; }
.progress li { display: flex; gap: 12px; align-items: center; padding: 10px 0; color: var(--muted); }
.progress li.on { color: var(--ink); font-weight: 600; }
.progress li.done { color: var(--ink); }
.progress li .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 13px; }
.progress li.on .dot { border-color: var(--accent); border-top-color: transparent; animation: spin 1s linear infinite; }
.progress li.done .dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Queue */
.topbar { display: flex; align-items: center; gap: 8px; padding: 14px 16px; max-width: 980px; margin: 0 auto; }
@media (max-width: 460px) {
  .topbar .brand span.name { display: none; }
  .topbar .count { font-size: 13px; white-space: nowrap; }
  .seg button { padding: 8px 10px; }
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; color: var(--muted); font-weight: 600; min-height: 38px; }
.seg button.on { background: var(--ink); color: var(--paper); }
.iconbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; width: 40px; height: 40px; cursor: pointer; display: grid; place-items: center; }
.count { font-size: 14px; color: var(--muted); font-weight: 600; }
.one { max-width: 600px; margin: 8px auto 0; padding: 0 20px 140px; }
.one .from { color: var(--muted); font-size: 15px; }
.one h1 { font-size: 26px; margin: 6px 0 8px; }
.one .why { font-size: 17px; margin: 0 0 18px; }
.draft textarea { width: 100%; min-height: 160px; field-sizing: content; border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface); font-size: 16px; line-height: 1.5; resize: vertical; }
.draft .to { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
details.orig { margin-top: 14px; color: var(--muted); }
details.orig summary { cursor: pointer; font-weight: 600; }
details.orig pre { white-space: pre-wrap; font: inherit; font-size: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.actions { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 22%); }
.actions .inner { max-width: 600px; margin: 0 auto; display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.actions .inner .big, .actions .inner .wide { grid-column: 1 / -1; }
.stack > .card + .choices, .card + .stack { margin-top: 14px; }
.empty { text-align: center; margin-top: 18vh; }
.empty .big-check { font-size: 56px; }
.list { max-width: 980px; margin: 0 auto; padding: 0 20px 80px; display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .list { grid-template-columns: 380px 1fr; align-items: start; } }
.rows { display: flex; flex-direction: column; gap: 8px; }
.rowitem { display: flex; gap: 12px; text-align: left; width: 100%; padding: 12px 14px; align-items: flex-start; }
.rowitem.sel { border-color: var(--accent); }
.rowitem .t { font-weight: 620; }
.rowitem .w { color: var(--muted); font-size: 14px; }
.rowitem .meta { font-size: 12.5px; color: var(--muted); }
.detail { position: sticky; top: 12px; }
.detail .actions-inline { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* Sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 10; }
.sheet { position: fixed; right: 0; top: 0; bottom: 0; width: min(520px, 100%); background: var(--paper); z-index: 11; overflow: auto; padding: 20px; border-left: 1px solid var(--line); }
.sheet section { margin-bottom: 24px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
table.plain td { padding: 8px 4px; border-bottom: 1px solid var(--line); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: 12px; display: flex; gap: 10px; align-items: center; z-index: 20; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.toast button.link { color: var(--accent-soft); }
.toast[hidden] { display: none; }

body.plain { display: grid; place-items: center; min-height: 100vh; }
.plain-card { max-width: 480px; padding: 24px; }

pre.card { overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.conn input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; }
.light.needs_bridge { background: #d39a2c; }
.bridge header.row, .bridge footer.row { display: flex; align-items: center; gap: 10px; }
.bridge footer.row { margin-top: 12px; }
.bridge-steps { margin: 12px 0; }
.bridge-steps li { align-items: flex-start; }
pre.cmd { margin: 0; font-size: 13px; white-space: pre-wrap; word-break: break-all; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px; user-select: all; }
