:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --ok: #16a34a;
  --err: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e293b;
    --primary: #3b82f6;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.site-select { width: auto; max-width: 42vw; padding: 5px 8px; font-size: 14px; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.conn b { font-weight: 500; }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.conn.on i { background: var(--ok); }
.conn.off i { background: var(--err); }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.field { display: block; margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { resize: vertical; min-height: 140px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--err); }
.btn.small { padding: 5px 10px; font-size: 14px; }
.btn.block { width: 100%; padding: 14px; font-size: 17px; }
.btn:disabled { opacity: .55; cursor: default; }

.link { background: none; border: 0; color: var(--primary); font: inherit; padding: 0; cursor: pointer; text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--border); border-radius: 10px; padding: 3px; margin-bottom: 12px;
}
.seg { border: 0; background: transparent; font: inherit; color: var(--text); padding: 8px; border-radius: 8px; cursor: pointer; }
.seg.active { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.dropzone {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 160px; border: 2px dashed var(--border); border-radius: 12px; cursor: pointer;
}
.dropzone.drag { border-color: var(--primary); }
.dropzone > div { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px; }
.drop-icon { font-size: 36px; }
#preview { max-width: 100%; max-height: 220px; border-radius: 8px; margin-bottom: 6px; }
#fileName { word-break: break-all; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer;
}
.stepper input { width: 56px; text-align: center; padding: 8px 4px; }

.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.progress div { height: 100%; width: 0; background: var(--primary); transition: width .15s; }

.actions { display: flex; gap: 10px; margin-bottom: 12px; }
.actions .btn { flex: 1; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px;
}
#discoverList > li { background: var(--bg); }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-title { font-weight: 600; word-break: break-word; }
.item-sub { font-size: 13px; color: var(--muted); word-break: break-all; }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 99px; background: var(--border); color: var(--muted); white-space: nowrap; }
.badge.default { background: var(--primary); color: var(--primary-text); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.err { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.badge.run { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.check input { width: auto; }
.check.field { display: flex; font-size: 15px; color: var(--text); }
.banner a { color: var(--primary); }

.empty { text-align: center; padding: 30px 10px; }

.banner {
  margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--primary) 12%, var(--card)); font-size: 14px;
}
.banner.warn { background: color-mix(in srgb, var(--warn) 16%, var(--card)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
}
.tabbar button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--primary); font-weight: 600; }
.tabbar button.active span { filter: none; opacity: 1; }

dialog {
  width: min(520px, calc(100% - 24px)); max-height: calc(100% - 24px);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); padding: 18px;
}
dialog::backdrop { background: rgba(2, 6, 23, .5); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }

.test-result { font-size: 14px; padding: 8px 10px; border-radius: 8px; background: var(--bg); white-space: pre-line; }
.test-result.ok { color: var(--ok); }
.test-result.err { color: var(--err); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: #0f172a; color: #fff; font-size: 14px; transition: .2s; z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

.job-overlay {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, .55);
}
.job-overlay[hidden] { display: none; }
.job-box { background: var(--card); border-radius: var(--radius); padding: 24px 28px; text-align: center; min-width: 220px; }
.job-box p { margin: 12px 0 0; font-weight: 600; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
