:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #161d28;
  --panel-3: #1b2431;
  --border: #223041;
  --border-soft: #1a2432;
  --text: #e6edf3;
  --muted: #8b98a5;
  --muted-2: #627082;
  --accent: #5b8cff;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --purple: #a78bfa;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* ==================== Sidebar ==================== */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 16px;
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(91, 140, 255, 0.12), transparent 60%),
    linear-gradient(180deg, #0d131b, #0a0e13);
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #071018;
  background: linear-gradient(135deg, #7aa2ff, #22c55e);
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.35);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; letter-spacing: 0.2px; }
.brand-text span { font-size: 10.5px; color: var(--muted); letter-spacing: 0.6px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(91, 140, 255, 0.18), rgba(91, 140, 255, 0.04));
  border-color: rgba(91, 140, 255, 0.35);
  color: #dbe7ff;
}
.nav-item .ico { width: 20px; text-align: center; font-size: 15px; }
.nav-item .count {
  margin-left: auto;
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border-soft);
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}
.health-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
  box-shadow: 0 0 0 3px rgba(139, 152, 165, 0.12);
}
.health-badge.ok { color: #b9f6ce; }
.health-badge.ok::before { background: var(--accent-2); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.health-badge.bad { color: #ffc9c9; }
.health-badge.bad::before { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18); }

.version { font-size: 10.5px; color: var(--muted-2); font-family: var(--mono); }

/* ==================== Main ==================== */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 15, 20, 0.82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title h1 { margin: 0; font-size: 20px; letter-spacing: -0.2px; }
.topbar-title p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content {
  padding: 24px 28px 48px;
  overflow-y: auto;
  flex: 1;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

/* ==================== Buttons ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-3); border-color: #2c3c50; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, #5b8cff, #6f6bff);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.28);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.35); color: #ffb4b4; }
.btn.danger:hover { background: rgba(239, 68, 68, 0.2); }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; }

/* ==================== Cards / layout ==================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  position: relative;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background:
    radial-gradient(120% 100% at 100% 0%, rgba(91, 140, 255, 0.10), transparent 55%),
    var(--panel);
  overflow: hidden;
}
.stat-card .stat-label { font-size: 11.5px; color: var(--muted); letter-spacing: 0.3px; text-transform: uppercase; }
.stat-card .stat-value { font-size: 28px; font-weight: 750; margin-top: 4px; letter-spacing: -0.5px; }
.stat-card .stat-value small { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-card .stat-foot { margin-top: 4px; font-size: 11.5px; color: var(--muted-2); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); gap: 16px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.card {
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: var(--panel);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent);
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 650; }
.card-head .sub { font-size: 11.5px; color: var(--muted); }
.card-body { padding: 14px 16px; }
.card-body.tight { padding: 6px 10px; }
.card-body.flush { padding: 0; }

.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ==================== Tables ==================== */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted-2);
  font-weight: 650;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.015);
  white-space: nowrap;
}
.table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: rgba(91, 140, 255, 0.055); }
.table tbody tr.clickable { cursor: pointer; }
.table td .primary-text { font-weight: 600; }
.table td .sub-text { font-size: 11.5px; color: var(--muted); }

/* ==================== Badges / pills ==================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.badge.ok { color: #7cf0a4; background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.28); }
.badge.run { color: #9dc0ff; background: rgba(91, 140, 255, 0.14); border-color: rgba(91, 140, 255, 0.32); }
.badge.fail { color: #ff9b9b; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.3); }
.badge.warn { color: #ffd08a; background: rgba(245, 158, 11, 0.13); border-color: rgba(245, 158, 11, 0.32); }
.badge.muted { color: var(--muted); background: rgba(139, 152, 165, 0.1); border-color: rgba(139, 152, 165, 0.22); }
.badge.purple { color: #d4c2ff; background: rgba(167, 139, 250, 0.13); border-color: rgba(167, 139, 250, 0.3); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  font-size: 11.5px;
  color: var(--muted);
}
.pill b { color: var(--text); font-weight: 600; }

/* ==================== Forms ==================== */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: 0.2px; }
.field .hint { font-size: 11px; color: var(--muted-2); }

input, select, textarea {
  width: 100%;
  background: #0e141c;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(91, 140, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.14);
}
textarea { resize: vertical; min-height: 92px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
label.check input { width: auto; }

/* ==================== Modal ==================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 9, 0.68);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fade 0.12s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 640px;
  max-width: 100%;
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, #141b25, #10161e);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: pop 0.14s ease;
}
@keyframes pop { from { transform: translateY(6px) scale(0.99); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; }

/* ==================== Toast ==================== */

.toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  min-width: 240px;
  max-width: 380px;
  padding: 11px 14px;
  border-radius: 10px;
  background: #17202b;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: pop 0.14s ease;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.4); }
.toast.err { border-color: rgba(239, 68, 68, 0.45); }

/* ==================== Detail views ==================== */

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.detail-head h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.3px; }
.detail-head .sub { color: var(--muted); font-size: 12.5px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.meta-item {
  padding: 12px 14px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
}
.meta-item .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted-2); }
.meta-item .v { margin-top: 4px; font-size: 14px; font-weight: 600; word-break: break-all; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: 0.8; }

/* ==================== Event log ==================== */

.event-log {
  max-height: 520px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  background: #0a0e13;
  border-top: 1px solid var(--border-soft);
}
.event-row { display: flex; gap: 10px; padding: 6px 14px; border-bottom: 1px solid rgba(34, 48, 65, 0.35); }
.event-row:last-child { border-bottom: none; }
.event-seq { color: var(--muted-2); min-width: 42px; text-align: right; }
.event-type { min-width: 130px; font-weight: 650; color: #9dc0ff; }
.event-type.ok { color: #7cf0a4; }
.event-type.fail { color: #ff9b9b; }
.event-type.warn { color: #ffd08a; }
.event-body { color: var(--muted); word-break: break-all; flex: 1; }

/* ==================== Role / provider cards ==================== */

.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.role-card {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.role-card .role-top { display: flex; align-items: center; gap: 9px; }
.role-card .role-avatar {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(91,140,255,0.25), rgba(34,197,94,0.18));
  font-size: 15px;
}
.role-card .role-name { font-weight: 650; }
.role-card .role-cat { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.role-card .role-desc { font-size: 12px; color: var(--muted); min-height: 32px; }
.role-card .role-model { font-family: var(--mono); font-size: 11px; color: #9dc0ff; }

.provider-card { padding: 16px; border-radius: 12px; border: 1px solid var(--border-soft); background: var(--panel); }
.provider-card .p-top { display: flex; align-items: center; justify-content: space-between; }
.provider-card .p-name { font-weight: 700; font-size: 15px; }
.provider-card .p-url { margin-top: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); word-break: break-all; }
.provider-card .p-model { margin-top: 8px; font-size: 12px; }

/* ==================== Misc ==================== */

.section-title { display: flex; align-items: center; gap: 10px; margin: 24px 0 12px; }
.section-title h2 { margin: 0; font-size: 16px; }
.section-title .line { flex: 1; height: 1px; background: var(--border-soft); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border-soft); font-size: 12.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; word-break: break-all; }

.code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: #0a0e13;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  padding: 10px 12px;
  color: #b9c7d6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; gap: 14px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border-soft); padding: 12px 14px; }
  .brand { padding: 0; flex-shrink: 0; }
  .brand-text span { display: none; }
  .nav { flex-direction: row; gap: 4px; overflow-x: auto; }
  .nav-item { white-space: nowrap; padding: 8px 10px; }
  .sidebar-foot { display: none; }
  .main { height: auto; min-height: 100vh; }
  .topbar { padding: 14px 16px; }
  .content { padding: 16px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
