:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --ink: #1c1f24;
  --mute: #6d737b;
  --line: #e3e5e9;
  --accent: #c24b32;
  --accent-ink: #ffffff;
  --ok: #2f6f4e;
  --ok-bg: #e7f3ec;
  --warn: #8a5a16;
  --warn-bg: #f8efd8;
  --bad: #a33b35;
  --bad-bg: #f8e8e6;
  --radius: 8px;
  --header: 52px;
  --z-header: 20;
  --z-drawer: 40;
  --z-toast: 50;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

.hidden, [hidden] { display: none !important; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  z-index: 70;
  background: var(--ink);
  color: #fff;
  padding: 8px 12px;
  text-decoration: none;
  border-radius: 6px;
}

.skip:focus { top: 12px; }

.mute { color: var(--mute); }
.small { font-size: 12px; }
.mono {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.num { font-variant-numeric: tabular-nums; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  transition: background 160ms var(--ease), transform 140ms var(--ease);
}

.btn:hover { background: #eceef1; }
.btn:active { transform: scale(0.98); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover { background: #ad3f29; }

.btn.text {
  border: 0;
  background: transparent;
  color: var(--mute);
  min-height: 32px;
  padding: 0 6px;
}

.btn.text:hover { color: var(--ink); background: transparent; }

.btn.warn { color: var(--bad); border-color: transparent; background: var(--bad-bg); }
.btn.warn:hover { background: #f3d8d5; }

.btn:disabled { opacity: 0.45; cursor: wait; }

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field span {
  color: var(--mute);
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

textarea { min-height: 88px; resize: vertical; }

.flash { margin: 12px 0 0; color: var(--bad); }

.brand-lockup, .brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.gate {
  display: grid;
  align-items: center;
  min-height: 100dvh;
}

.gate-form {
  width: min(22rem, calc(100% - 40px));
  margin: 0 auto;
  padding: 8vh 0;
}

.gate h1 {
  margin: 20px 0 8px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.lede {
  margin: 0 0 24px;
  color: var(--mute);
}

.gate .btn.primary { width: 100%; min-height: 40px; }

.gate-note {
  margin: 28px 0 0;
  color: var(--mute);
  font-size: 13px;
}

.shell { min-height: 100dvh; }

.top {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  height: var(--header);
  padding: 0 24px;
  background: rgb(242 243 245 / 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

nav { display: flex; gap: 2px; }

.nav {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--mute);
}

.nav:hover { color: var(--ink); background: rgb(0 0 0 / 0.04); }

.nav.on {
  color: var(--accent);
  background: rgb(194 75 50 / 0.08);
}

.top-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage {
  width: min(960px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.page h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.kicker {
  max-width: 52ch;
  margin: 0 0 22px;
  color: var(--mute);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0 0 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric { padding: 16px 0 18px; }
.metric + .metric { padding-left: 20px; }

.metric b {
  display: block;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric.bad b { color: var(--bad); }

.metric span {
  display: block;
  margin-top: 6px;
  color: var(--mute);
  font-size: 13px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin: 8px 0 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.panel { margin: 0 0 24px; padding: 4px 0; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.form-grid .wide { grid-column: 1 / -1; }

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 6px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checks input {
  width: 16px;
  min-height: 16px;
  padding: 0;
  accent-color: var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 12px 10px 12px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--mute);
  font-size: 12px;
  font-weight: 500;
}

tr.clickable { cursor: pointer; }
tr.clickable:hover td { color: var(--ink); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
}

.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.partial { background: var(--warn-bg); color: var(--warn); }
.badge.failed { background: var(--bad-bg); color: var(--bad); }

.filters { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 18px; align-items: center; }

.source-select {
  height: 30px;
  margin-left: 8px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.cell-select {
  height: 28px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--mute);
  font-size: 13px;
}

.tag {
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 18px;
  vertical-align: 1px;
  background: rgb(194 75 50 / 0.08);
  color: var(--accent);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.drawer-actions { margin-top: 16px; }

.detail-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 0 0 14px;
  font-size: 13px;
}

.detail-meta dt { color: var(--mute); }
.detail-meta dd { margin: 0; word-break: break-all; }

.filter {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--mute);
}

.filter.on { color: var(--accent); background: rgb(194 75 50 / 0.08); }

.token-box {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

.token-lines { display: grid; gap: 8px; }

.copy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.copy-row code {
  flex: 1;
  min-width: 0;
  word-break: break-all;
  white-space: pre-wrap;
}

.copy-row .btn { flex: none; }

.url-copy { cursor: copy; }

.detail-body-row { display: flex; align-items: flex-start; gap: 8px; }
.detail-body-row .detail-body { flex: 1; }
  white-space: pre-wrap;
}

.empty { padding: 28px 0; color: var(--mute); }

.empty strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-weight: 600;
}

.skel { display: grid; gap: 12px; padding-top: 8px; }

.skel i {
  display: block;
  height: 14px;
  background: #e6e8ec;
  border-radius: 4px;
}

.skel i:nth-child(1) { width: 24%; height: 28px; }
.skel i:nth-child(2) { width: 48%; }
.skel i:nth-child(3) { width: 100%; height: 72px; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--z-toast);
  max-width: 26rem;
  padding: 10px 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
}

.scrim {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgb(28 31 36 / 0.28);
}

.drawer, .confirm {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(400px, 100%);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 20px 22px 28px;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.drawer-body { overflow: auto; font-size: 14px; line-height: 1.6; }

.detail h3 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
}

.detail-body {
  margin: 0 0 16px;
  color: var(--mute);
  white-space: pre-wrap;
}

.deliveries {
  margin: 0;
  padding: 0;
  list-style: none;
}

.deliveries li {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  color: var(--mute);
  font-family: var(--mono);
  font-size: 12px;
}

.confirm-panel {
  position: absolute;
  left: 50%;
  top: 44%;
  width: min(340px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 20px 16px;
}

.confirm-panel p { margin: 0 0 16px; }

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 840px) {
  .top {
    grid-template-columns: 1fr auto;
    height: auto;
    padding: 10px 16px 8px;
    gap: 8px;
  }
  nav { grid-column: 1 / -1; }
  .top-end .mono { display: none; }
  .stage { width: calc(100% - 32px); padding-top: 20px; }
  .metrics, .form-grid { grid-template-columns: 1fr 1fr; }
  .metric + .metric { padding-left: 16px; }
  th:nth-child(4), td:nth-child(4) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
