:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e6e8ec;
  --line-soft: #eef0f3;
  --text: #1c2127;
  --muted: #5c6570;
  --subtle: #8a939e;
  --brand: #1f4e79;
  --brand-soft: #e8eef5;
  --ok-bg: #e7f6ed;
  --ok-text: #1b7a3d;
  --off-bg: #f3f4f6;
  --off-text: #6b7280;
  --run-bg: #e8f3ff;
  --run-text: #155a9c;
  --warn-bg: #fff4e5;
  --warn-text: #9a5b00;
  --danger-bg: #fdecee;
  --danger-text: #b42318;
  --switch-on: #1b7a3d;
  --switch-off: #c5cad1;
  --bar: #cfe3d8;
  --bar-fill: #2f9e5f;
  --bar-warn: #d97706;
  --shadow: 0 1px 2px rgba(28, 33, 39, 0.04), 0 8px 24px rgba(28, 33, 39, 0.04);
  --radius: 12px;
  --focus: 0 0 0 3px rgba(31, 78, 121, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Source Han Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

/* ——— Auth pages ——— */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 32px 28px;
}
.auth-card h1 { font-size: 22px; font-weight: 650; letter-spacing: 0.02em; }
.auth-card .lead { margin-top: 6px; color: var(--muted); font-size: 13px; }
.auth-form { margin-top: 22px; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}
.field input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.auth-form .btn { width: 100%; height: 36px; }
.auth-links { margin-top: 16px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 12px; }
.banner {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.banner.error { background: var(--danger-bg); color: var(--danger-text); }
.banner.notice { background: var(--ok-bg); color: var(--ok-text); }

/* ——— Admin ——— */
.app { padding: 28px 32px 36px; }
header.app-hd {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
h1 { font-size: 22px; font-weight: 650; letter-spacing: 0.02em; }
.meta { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 14px; }
.meta form { display: inline; }
h2 { font-size: 14px; font-weight: 650; margin: 0; }

.sec-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.sec-hd .sub { color: var(--muted); font-size: 12px; font-weight: 400; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.valid { background: var(--ok-bg); color: var(--ok-text); }
.badge.soon { background: var(--warn-bg); color: var(--warn-text); }
.badge.expired { background: var(--off-bg); color: var(--off-text); }

.dot {
  width: 8px; height: 8px; border-radius: 50%; background: #c5cad1; flex: 0 0 auto;
}
.dot.ok { background: #2f9e5f; box-shadow: 0 0 0 3px rgba(47, 158, 95, 0.18); }

.metrics { display: flex; gap: 8px; flex-wrap: wrap; }
.metric {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 0;
  text-decoration: none;
}
.metric:hover { text-decoration: none; filter: brightness(0.98); }
.metric b { font-size: 14px; font-weight: 700; }
.metric.plain { background: #f3f4f6; color: var(--muted); }
.metric.warn { background: var(--warn-bg); color: var(--warn-text); }
.metric.on { box-shadow: 0 0 0 1px currentColor; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.search {
  height: 32px;
  width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}
.search::placeholder { color: var(--subtle); }
.search:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg a, .seg span {
  height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 550;
  color: var(--muted);
  border-right: 1px solid var(--line);
  text-decoration: none;
  background: #fff;
}
.seg a:last-child, .seg span:last-child { border-right: 0; }
.seg a.on, .seg span.on { background: var(--brand-soft); color: var(--brand); }
.seg a:hover { text-decoration: none; }

.btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}
.btn:hover { background: #fafbfc; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger-text); border-color: #f0c4c4; }
.linkish { background: none; border: 0; color: var(--brand); padding: 0; font-size: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  white-space: nowrap;
}
thead th .col-sub {
  display: block;
  font-weight: 500;
  letter-spacing: 0;
  margin-top: 2px;
  color: var(--subtle);
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fcfcfd; }
.email { font-weight: 600; color: var(--text); }
.sub { color: var(--subtle); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.owner { font-weight: 550; }
.time { color: var(--muted); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; white-space: nowrap; }
.period .remain { font-size: 12px; margin-top: 2px; }
.remain.ok { color: var(--muted); }
.remain.warn { color: var(--warn-text); font-weight: 600; }
.remain.exp { color: var(--danger-text); font-weight: 600; }

.run { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); white-space: nowrap; }
.run.on { color: var(--run-text); font-weight: 550; }
.run.on .dot { background: #2f9e5f; box-shadow: 0 0 0 3px rgba(47, 158, 95, 0.18); }

.cap { min-width: 168px; }
.cap .nums { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; font-weight: 550; }
.cap .nums span { color: var(--muted); font-weight: 400; }
.bar { margin-top: 6px; height: 6px; background: #eef1f4; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--bar-fill); border-radius: 99px; }
.bar.warn > i { background: var(--bar-warn); }
.bar.off { opacity: .45; }

.actions { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.switch {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); padding: 0; font-size: 12px;
}
.track {
  width: 32px; height: 18px; border-radius: 999px;
  background: var(--switch-off); position: relative; flex: 0 0 auto;
}
.track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.16);
  transition: left 160ms ease-out;
}
.switch.on { color: var(--ok-text); }
.switch.on .track { background: var(--switch-on); }
.switch.on .track::after { left: 16px; }
.switch:focus-visible { outline: none; }
.switch:focus-visible .track { box-shadow: var(--focus); }

.logs { margin-top: 14px; }
.log-list { padding: 6px 6px 8px; }
.log {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
}
.log:hover { background: #fafbfc; }
.log .when { color: var(--subtle); font-variant-numeric: tabular-nums; font-size: 12px; }
.log .what { color: var(--text); }
.log .what b { font-weight: 650; }

.srv .line1 { display: flex; align-items: center; gap: 8px; }
.srv .line2 { margin-top: 3px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.srv.off .line2 { color: var(--subtle); }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ——— Modal / drawer ——— */
.overlay {
  position: fixed; inset: 0;
  background: rgba(28, 33, 39, 0.36);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px 32px;
  z-index: 40;
}
.overlay.open { display: flex; }
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal.wide { max-width: 640px; }
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal header h2 { font-size: 16px; }
.modal .body { padding: 16px; display: grid; gap: 14px; }
.modal .foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line); background: #fafbfc;
}
.modal .close {
  width: 28px; height: 28px; border: 0; background: transparent;
  color: var(--muted); font-size: 18px; border-radius: 8px;
}
.modal .close:hover { background: var(--line-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { color: var(--subtle); font-size: 12px; }
.token-box {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: #f6f7f9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
}
.kv { display: grid; grid-template-columns: 108px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.detail-section h3 { font-size: 13px; font-weight: 650; margin-bottom: 8px; }

@media (max-width: 1366px) {
  .app { padding: 20px 16px 28px; }
  .sec-hd { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .track::after { transition: none; }
}
