:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --card-sunk: #f2f2f4;
  --ink: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #a1a1a6;
  --hair: rgba(0, 0, 0, 0.08);
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff3b30;
  --green-soft: rgba(52, 199, 89, 0.12);
  --orange-soft: rgba(255, 159, 10, 0.14);
  --red-soft: rgba(255, 59, 48, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.06);
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-sunk: #2c2c2e;
    --ink: #f5f5f7;
    --ink-2: #a1a1a6;
    --ink-3: #6e6e73;
    --hair: rgba(255, 255, 255, 0.1);
    --blue: #0a84ff;
    --blue-hover: #409cff;
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --green-soft: rgba(48, 209, 88, 0.16);
    --orange-soft: rgba(255, 159, 10, 0.18);
    --red-soft: rgba(255, 69, 58, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }

/* ── nav ─────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid var(--hair);
}
.nav-inner {
  max-width: 980px; margin: 0 auto; padding: 0 22px;
  height: 52px; display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 600; letter-spacing: -0.01em; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.nav-links { display: flex; gap: 20px; font-size: 13px; color: var(--ink-2); }
.nav-links a { color: inherit; }
.nav-links a:hover { color: var(--ink); }

/* ── layout ──────────────────────────────────────────────── */
.page { max-width: 980px; margin: 0 auto; padding: 44px 22px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
h1 { font-size: 40px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.08; margin: 0; }
.sub { color: var(--ink-2); margin: 8px 0 0; font-size: 17px; letter-spacing: -0.01em; }

/* ── buttons ─────────────────────────────────────────────── */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit;
  background: var(--blue); color: #fff; font-weight: 500; font-size: 15px;
  padding: 11px 20px; border-radius: 980px;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--blue-hover); }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card-sunk); color: var(--ink); }
.btn.secondary:hover { background: color-mix(in srgb, var(--card-sunk) 80%, var(--ink-3)); }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ── cards ───────────────────────────────────────────────── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.hero {
  padding: 34px 34px 30px;
  display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center;
  margin-bottom: 18px;
}
.hero-icon {
  width: 72px; height: 72px; border-radius: 50%;
  display: grid; place-items: center; font-size: 34px; font-weight: 700; color: #fff;
}
.hero-icon.ok { background: var(--green); }
.hero-icon.warn { background: var(--orange); }
.hero-icon.err { background: var(--red); }
.hero-icon.idle { background: var(--ink-3); }
.hero h2 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.hero p { margin: 8px 0 0; color: var(--ink-2); font-size: 16px; max-width: 60ch; }
.hero .meta { margin-top: 12px; font-size: 13px; color: var(--ink-3); }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 760px) { .grid { grid-template-columns: repeat(2, 1fr); } .hero { grid-template-columns: 1fr; } }
.stat { padding: 20px 22px 18px; }
.stat .label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.stat .value {
  font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.05; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat .hint { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.stat .value.green { color: var(--green); }
.stat .value.orange { color: var(--orange); }

/* ── table ───────────────────────────────────────────────── */
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 30px 0 12px; padding: 0 4px;
}
.section-title h3 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.section-title span { font-size: 13px; color: var(--ink-3); }
.table { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 20px; text-align: left; border-bottom: 1px solid var(--hair); }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .03em; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.code { font-weight: 600; letter-spacing: -0.01em; }
td.code small { display: block; font-weight: 400; color: var(--ink-2); font-size: 12.5px; margin-top: 2px; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-block; min-width: 46px; text-align: center;
  padding: 4px 10px; border-radius: 980px; font-weight: 600; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pill.add { background: var(--green-soft); color: var(--green); }
.pill.retire { background: var(--orange-soft); color: var(--orange); }
.pill.zero { background: var(--card-sunk); color: var(--ink-3); font-weight: 500; }
.empty { padding: 40px; text-align: center; color: var(--ink-2); }

/* ── progress steps ─────────────────────────────────────── */
.progress { padding: 26px 30px 22px; margin-bottom: 18px; }
.progress-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.progress-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.progress-head span { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 980px; background: var(--card-sunk); overflow: hidden; margin-bottom: 18px; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 980px; width: 0; transition: width .5s ease; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 760px) { .steps { grid-template-columns: 1fr; } }
.step { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--card-sunk); transition: background .2s ease; }
.step .ico { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; background: var(--ink-3); }
.step .ico .spinner { width: 12px; height: 12px; border-width: 2px; }
.step .txt { min-width: 0; }
.step .lbl { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.step .dtl { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; font-variant-numeric: tabular-nums; min-height: 1.2em; }
.step.active { background: color-mix(in srgb, var(--blue) 10%, var(--card)); }
.step.active .ico { background: var(--blue); }
.step.done .ico { background: var(--green); }
.step.error .ico { background: var(--red); }
.step.pending { opacity: .6; }

.banner {
  padding: 14px 18px; border-radius: 14px; margin-bottom: 18px; font-size: 14px;
  background: var(--red-soft); color: var(--red); font-weight: 500;
}

/* ── actions / sync / modal ─────────────────────────────── */
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn.danger { background: var(--orange); }
.btn.danger:hover { background: #ffb340; }
.spinner.dark { border-color: rgba(0,0,0,.18); border-top-color: var(--ink); }
@media (prefers-color-scheme: dark) { .spinner.dark { border-color: rgba(255,255,255,.2); border-top-color: var(--ink); } }
.env-tag {
  font-size: 10px; font-weight: 700; letter-spacing: .08em; padding: 2px 7px; border-radius: 980px;
  background: var(--card-sunk); color: var(--ink-2); margin-left: 4px;
}
.env-tag.prod { background: var(--orange-soft); color: var(--orange); }
.banner.ok { background: var(--green-soft); color: var(--green); }
.log {
  margin: 16px 0 0; padding: 12px 14px; max-height: 220px; overflow: auto;
  background: var(--card-sunk); border-radius: 12px;
  font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}
.log:empty { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(0,0,0,.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.modal[hidden] { display: none; }
.sheet { width: 100%; max-width: 460px; padding: 30px 30px 26px; text-align: center; }
.sheet-icon { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 14px; display: grid; place-items: center; color: #fff; font-size: 26px; font-weight: 700; }
.sheet-icon.warn { background: var(--orange); }
.sheet-icon.ok { background: var(--green); }
.sheet h2 { margin: 0 0 10px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.sheet p { margin: 0 0 10px; color: var(--ink-2); font-size: 14.5px; }
.sheet p.muted { color: var(--ink-3); font-size: 12.5px; }
.sheet-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.sheet-actions .btn { min-width: 150px; justify-content: center; }
.foot strong { color: var(--ink-2); font-weight: 600; }

/* ── userscript import panel ─────────────────────────────── */
.import-panel {
  margin-top: 16px; padding: 18px 20px; border-radius: 16px;
  background: color-mix(in srgb, var(--blue) 9%, var(--card));
  display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center; justify-content: space-between;
}
.import-panel[hidden] { display: none; }
.import-text { display: flex; flex-direction: column; gap: 3px; }
.import-text strong { font-size: 16px; letter-spacing: -0.01em; }
.import-text span { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.import-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.import-actions .btn { text-decoration: none; }
.import-hint { flex-basis: 100%; margin: 0; font-size: 12.5px; color: var(--ink-3); }

/* ── login ───────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 380px; padding: 40px 36px 34px; text-align: center; }
.login .logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 18px; background: var(--blue); display: grid; place-items: center; color: #fff; font-size: 30px; font-weight: 700; }
.login h1 { font-size: 26px; }
.login p { color: var(--ink-2); margin: 6px 0 24px; font-size: 15px; }
.field {
  width: 100%; font: inherit; font-size: 16px; padding: 13px 16px;
  border-radius: 12px; border: 1px solid var(--hair); background: var(--card-sunk); color: var(--ink);
  outline: none; transition: box-shadow .15s ease, border-color .15s ease;
}
.field:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(0,113,227,.18); }
.login .btn { width: 100%; justify-content: center; margin-top: 12px; padding: 13px; }
.login .error { color: var(--red); font-size: 13px; margin: 10px 0 0; font-weight: 500; }
.foot { text-align: center; color: var(--ink-3); font-size: 12px; margin-top: 30px; }
