:root {
  color-scheme: dark;
  --bg: #06101d;
  --surface: #0b1928;
  --surface-2: #102338;
  --line: #20374d;
  --text: #eef7ff;
  --muted: #91a8ba;
  --cyan: #47d7ff;
  --cyan-soft: rgba(71, 215, 255, 0.12);
  --green: #58e6a9;
  --amber: #ffcc66;
  --red: #ff707f;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 75% -10%, rgba(34, 139, 180, 0.24), transparent 34rem),
    linear-gradient(180deg, #071421 0, var(--bg) 32rem);
  font-size: 16px;
  line-height: 1.5;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
a { color: inherit; }

.topbar {
  min-height: 72px;
  padding: 12px clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(145, 168, 186, 0.16);
  background: rgba(6, 16, 29, 0.78);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; letter-spacing: .08em; }
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: .7rem; letter-spacing: .18em; }
.brand-mark {
  width: 52px; height: 52px; display: grid; place-items: center;
  border: 1px solid rgba(71, 215, 255, .5); border-radius: 15px;
  color: var(--cyan); font-weight: 800; font-size: 1.35rem;
  background: linear-gradient(145deg, rgba(71, 215, 255, .16), rgba(71, 215, 255, .03));
  box-shadow: inset 0 0 22px rgba(71, 215, 255, .08);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; font-size: 1.05rem; }
.top-actions, .dialog-actions, .key-actions { display: flex; align-items: center; gap: 8px; }

.page-shell { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 40px 0 72px; }
.status-hero {
  display: flex; justify-content: space-between; align-items: end; gap: 24px;
  padding: clamp(24px, 5vw, 48px); min-height: 230px;
  border: 1px solid var(--line); border-radius: 24px;
  background:
    linear-gradient(115deg, rgba(71, 215, 255, .1), transparent 52%),
    repeating-linear-gradient(90deg, transparent 0 63px, rgba(255,255,255,.018) 64px),
    var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.eyebrow { margin: 0 0 10px; color: var(--cyan); font-size: .75rem; font-weight: 750; letter-spacing: .18em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2.1rem, 7vw, 4.6rem); line-height: .98; letter-spacing: -.055em; }
h2 { margin-bottom: 0; font-size: clamp(1.35rem, 3vw, 1.8rem); letter-spacing: -.035em; }
.hero-meta, .muted { color: var(--muted); }
.hero-meta { margin: 0; font-size: 1rem; }
.route-badge { padding: 10px 14px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.route-badge.loading { color: var(--muted); background: rgba(145,168,186,.1); }
.route-badge.good { color: var(--green); background: rgba(88,230,169,.11); border: 1px solid rgba(88,230,169,.3); }
.route-badge.warning { color: var(--amber); background: rgba(255,204,102,.1); border: 1px solid rgba(255,204,102,.3); }

.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 14px 0; }
.metric-card, .panel { border: 1px solid var(--line); background: rgba(11, 25, 40, .92); box-shadow: 0 16px 44px rgba(0,0,0,.16); }
.metric-card { min-height: 142px; padding: 22px; border-radius: 18px; display: flex; flex-direction: column; justify-content: end; }
.metric-card.accent { background: linear-gradient(145deg, rgba(71,215,255,.14), rgba(11,25,40,.94)); }
.metric-card strong { display: block; margin: 7px 0 2px; font-size: 1.55rem; letter-spacing: -.03em; }
.metric-card small, .metric-label { color: var(--muted); }
.metric-label { font-size: .82rem; text-transform: uppercase; letter-spacing: .12em; }

.panel { margin-top: 14px; border-radius: 20px; padding: clamp(20px, 4vw, 30px); }
.panel.compact { margin-top: 0; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.button {
  min-height: 42px; border: 1px solid transparent; border-radius: 11px; padding: 9px 15px;
  color: var(--text); background: transparent; cursor: pointer; font-weight: 700;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible { outline: 3px solid rgba(71,215,255,.32); outline-offset: 2px; }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.primary { color: #031018; background: var(--cyan); }
.button.ghost { border-color: var(--line); background: rgba(255,255,255,.025); }
.button.danger { color: #200208; background: var(--red); }
.button.danger-ghost { color: var(--red); border-color: rgba(255,112,127,.25); }
.small-button { min-height: 36px; padding: 6px 10px; font-size: .85rem; }

.key-list { display: grid; gap: 10px; }
.key-row {
  display: grid; grid-template-columns: minmax(220px, 1fr) 160px auto; align-items: center; gap: 18px;
  padding: 16px; border: 1px solid rgba(145,168,186,.14); border-radius: 15px; background: rgba(255,255,255,.018);
}
.key-identity { display: flex; align-items: center; gap: 13px; min-width: 0; }
.key-avatar { flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--cyan); background: var(--cyan-soft); font-weight: 800; }
.key-identity strong, .key-identity small, .key-usage strong, .key-usage small { display: block; }
.key-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-identity small, .key-usage small { color: var(--muted); }
.key-usage { text-align: right; }
.loading-state, .empty-state { padding: 26px; text-align: center; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.detail-list { margin: 0; }
.detail-list > div { display: grid; grid-template-columns: minmax(130px, .8fr) 1.2fr; gap: 16px; padding: 12px 0; border-top: 1px solid rgba(145,168,186,.12); }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.banner { margin: 14px 0; padding: 14px 16px; border-radius: 12px; }
.banner.error, .form-error { color: #ffb5bd; background: rgba(255,112,127,.09); border: 1px solid rgba(255,112,127,.26); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; padding: 13px 16px; color: #031018; background: var(--green); border-radius: 12px; box-shadow: var(--shadow); font-weight: 750; }

.dialog { width: min(500px, calc(100% - 28px)); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 25px; background: #0b1928; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,5,10,.72); backdrop-filter: blur(5px); }
.form-stack { display: grid; gap: 17px; }
.form-stack label { display: grid; gap: 7px; color: #cfe0eb; font-weight: 650; }
.form-stack label small { color: var(--muted); font-weight: 400; }
input { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; color: var(--text); background: #071421; }
.dialog-actions { justify-content: flex-end; }
.danger-text { color: var(--red); }

.login-page { display: grid; place-items: center; padding: 20px; }
.login-shell { width: min(430px, 100%); }
.login-card { padding: clamp(26px, 7vw, 42px); border: 1px solid var(--line); border-radius: 24px; background: rgba(11,25,40,.95); box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 26px; }
.login-card h1 { font-size: 2.45rem; }
.login-foot { margin: 24px 0 0; color: var(--muted); text-align: center; font-size: .82rem; }

@media (max-width: 900px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .key-row { grid-template-columns: 1fr auto; }
  .key-usage { grid-column: 1; text-align: left; padding-left: 53px; }
  .key-actions { grid-column: 2; grid-row: 1 / span 2; flex-direction: column; align-items: stretch; }
}

@media (max-width: 650px) {
  .topbar { padding: 10px 16px; }
  .brand small { display: none; }
  .top-actions .button { min-height: 40px; padding: 7px 10px; font-size: .85rem; }
  .page-shell { width: min(100% - 24px, 1180px); padding-top: 18px; }
  .status-hero { min-height: 210px; align-items: flex-start; flex-direction: column; justify-content: space-between; border-radius: 19px; }
  .status-hero h1 { font-size: clamp(2rem, 11vw, 3rem); overflow-wrap: anywhere; }
  .metrics-grid, .detail-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 118px; }
  .panel-heading { align-items: flex-start; }
  .key-row { grid-template-columns: 1fr; gap: 12px; }
  .key-usage { grid-column: auto; padding-left: 53px; }
  .key-actions { grid-column: auto; grid-row: auto; flex-direction: row; flex-wrap: wrap; padding-left: 53px; }
  .detail-list > div { grid-template-columns: 1fr; gap: 3px; }
  .detail-list dd { text-align: left; }
  .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
