:root {
  --bg: #0b0f17;
  --bg-elev: #131a26;
  --bg-elev-2: #1b2330;
  --border: #232c3b;
  --text: #e6edf6;
  --text-dim: #93a1b3;
  --text-muted: #647489;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.15);
  --yellow: #eab308;
  --yellow-soft: rgba(234, 179, 8, 0.15);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.15);
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: linear-gradient(180deg, var(--bg-elev) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; line-height: 1; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: 0.2px; }
.subtitle { margin: 0; font-size: 12px; color: var(--text-muted); }

.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.last-updated {
  font-size: 12px; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.refresh-state { font-size: 12px; color: var(--accent); min-width: 60px; }

.btn {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #232e3f; border-color: #2f3b50; }
.btn:active { transform: translateY(1px); }
.btn-toggle.is-off { opacity: 0.55; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2f74f0; }

/* ---------- Layout ---------- */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

/* ---------- Cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 14px;
}
.card-label { font-size: 13px; color: var(--text-dim); font-weight: 550; }
.card-sub { font-size: 11px; color: var(--text-muted); }
.percent {
  font-size: 38px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -1px;
}
.percent .unit { font-size: 18px; color: var(--text-dim); margin-left: 2px; }
.bar {
  position: relative;
  height: 10px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 14px;
}
.bar-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0%;
  border-radius: 6px;
  background: var(--green);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s;
}
.bar-fill.warn { background: var(--yellow); }
.bar-fill.crit { background: var(--red); }
.card-meta {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 12px; font-size: 12px; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.card-meta b { color: var(--text-dim); font-weight: 600; }
.reset-countdown {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--bg-elev-2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex; justify-content: space-between; align-items: center;
}
.reset-countdown .countdown {
  font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.reset-at {
  margin-top: 0; /*紧贴倒计时行*/
  padding: 6px 12px 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  border-radius: 0 0 8px 8px;
  background: var(--bg-elev-2);
}
.card-error {
  margin-top: 12px; padding: 8px 10px;
  background: var(--red-soft); border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px; font-size: 12px; color: #fca5a5;
  word-break: break-word;
}

/* ---------- Panels / tables ---------- */
.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.range-label { font-size: 11px; color: var(--text-muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 18px; text-align: left; }
th {
  font-weight: 600; color: var(--text-dim);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--bg-elev-2);
}
td { border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }
.empty-row td { text-align: center; color: var(--text-muted); }

/* ---------- Raw details ---------- */
.raw-details {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
}
.raw-details summary { cursor: pointer; color: var(--text-dim); font-size: 13px; }
#raw-output {
  margin: 12px 0 0;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-dim);
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
}

/* ---------- Skeleton ---------- */
.skeleton-card { padding: 22px; }
.skeleton {
  height: 16px; width: 45%;
  background: linear-gradient(90deg, var(--bg-elev-2) 25%, #1f2937 50%, var(--bg-elev-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
.skeleton.short { height: 10px; width: 100%; margin-top: 18px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 8, 13, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
  width: min(380px, 90vw);
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.muted { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.modal-card input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
}
.modal-card input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.error-text { color: #fca5a5; font-size: 12px; margin: 10px 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }

.hidden { display: none !important; }

/* ---------- Banner ---------- */
.banner {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}
.banner strong { font-size: 14px; }
.banner span { font-size: 12px; color: var(--text-muted); }
.banner.danger { background: var(--red-soft); border-color: rgba(239,68,68,0.35); }
.banner.danger strong { color: #fca5a5; }

/* ---------- Dashboard / key groups ---------- */
.dashboard { display: flex; flex-direction: column; gap: 28px; }
.empty-hint {
  padding: 40px 24px; text-align: center;
  color: var(--text-muted); font-size: 14px;
  background: var(--bg-elev); border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-hint b { color: var(--text-dim); }

.key-group {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.group-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.group-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.group-meta { font-size: 12px; color: var(--text-muted); }
.group-error {
  padding: 8px 12px; margin-bottom: 14px;
  background: var(--red-soft); border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px; font-size: 12px; color: #fca5a5;
}
.card-empty {
  padding: 18px; text-align: center; color: var(--text-muted);
  background: var(--bg-elev-2); border-radius: 10px; font-size: 13px;
}
/* card / bar / percent / panels / table styles already exist above. */

/* ---------- Manage modal (wide) ---------- */
.modal-wide { width: min(620px, 92vw); max-height: 86vh; overflow-y: auto; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.modal-head h2 { margin: 0; }
.btn-icon {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.btn-icon:hover { background: var(--bg-elev-2); color: var(--text); }

.add-form {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-top: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-wide { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--text-dim); }
.field input {
  padding: 9px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 9px; color: var(--text);
  font-size: 13px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.form-actions {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px;
}
.divider { height: 1px; background: var(--border); margin: 18px 0; }

.key-list { display: flex; flex-direction: column; gap: 8px; }
.key-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.key-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.key-name { font-weight: 600; font-size: 14px; }
.key-url { font-size: 12px; color: var(--text-dim); }
.key-id { font-size: 11px; color: var(--text-muted); font-family: ui-monospace, monospace; }
.key-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: #fca5a5; }
.btn-danger:hover { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.4); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
  .container { padding: 18px 16px 48px; }
  .percent { font-size: 32px; }
  .brand h1 { font-size: 16px; }
}
