:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --line: #d8e1ea;
  --text: #17202a;
  --muted: #667085;
  --teal: #0f766e;
  --teal-2: #115e59;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c2410c;
  --green: #15803d;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
  font-size: 14px;
}
a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--teal-2); }

button, .btn {
  background: var(--teal);
  color: #fff;
  border: 0;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
button:hover, .btn:hover { background: var(--teal-2); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}
button.ghost:hover { border-color: var(--teal); color: var(--teal); background: #f8fbfc; }
button.danger { background: var(--red); }
button.danger:hover { background: #9a3412; }

input, select, textarea {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 8px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  min-height: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  min-width: max-content;
}
.brand .logo {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  letter-spacing: 0;
}
.brand .title { font-size: 16px; }
.env-badge {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}
.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}
.nav a {
  padding: 7px 11px;
  border-radius: 6px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active {
  background: rgba(15, 118, 110, 0.1);
  color: var(--teal);
  font-weight: 800;
}
.user {
  font-size: 12px;
  color: var(--muted);
  padding: 5px 10px;
  background: var(--surface-2);
  border-radius: 999px;
  min-width: max-content;
}

main {
  padding: 22px;
  max-width: 1500px;
  margin: 0 auto;
}
.footer {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 16px;
  justify-content: center;
}
.loading {
  text-align: center;
  padding: 60px;
  color: var(--muted);
}
.error-banner {
  background: rgba(194, 65, 12, 0.08);
  border: 1px solid rgba(194, 65, 12, 0.35);
  padding: 12px;
  border-radius: 8px;
  color: var(--red);
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.page-head h1 {
  margin: 0;
  font-size: 22px;
}
.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.card .label {
  font-size: 12px;
  color: var(--muted);
}
.card .value {
  font-size: 26px;
  font-weight: 900;
  margin-top: 4px;
}
.card .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.card.warn .value { color: var(--amber); }
.card.good .value { color: var(--green); }
.card.err .value { color: var(--red); }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}
.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar .grow { flex: 1; }
.toolbar input, .toolbar select { min-width: 150px; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.section .table-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: top;
}
th {
  background: #fbfcfe;
  font-weight: 800;
  color: var(--muted);
  font-size: 12px;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fbfc; }
td code {
  font-family: ui-monospace, "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--blue);
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.badge.ok { background: rgba(21, 128, 61, 0.1); color: var(--green); }
.badge.off { background: rgba(102, 112, 133, 0.12); color: var(--muted); }
.badge.err { background: rgba(194, 65, 12, 0.1); color: var(--red); }
.badge.warn { background: rgba(183, 121, 31, 0.12); color: var(--amber); }
.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.actions button { padding: 5px 9px; font-size: 12px; }
.empty {
  padding: 34px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
}

.login-prompt {
  max-width: 560px;
  margin: 60px auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-prompt h2 {
  margin: 0 0 12px;
  color: var(--teal);
  font-size: 20px;
}
.login-prompt p { color: var(--text); line-height: 1.6; margin: 8px 0; }
.login-prompt ol {
  margin: 16px 0 20px;
  padding-left: 22px;
  color: var(--text);
  line-height: 1.7;
}
.login-prompt kbd {
  display: inline-block;
  padding: 1px 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.login-prompt button {
  background: var(--teal);
  color: white;
  border: 0;
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.login-prompt button:hover { background: var(--teal-2); }
.login-prompt .hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
}

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 18px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  min-width: 430px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}
.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
}
.modal .field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}
.modal .field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}
.modal .actions-row, .actions-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.modal pre {
  white-space: pre-wrap;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  max-height: 50vh;
  overflow: auto;
}

.test-result {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.test-result.ok { border-left: 3px solid var(--green); }
.test-result.err { border-left: 3px solid var(--red); }

@media (max-width: 900px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 10px; }
  main { padding: 14px; }
  .split { grid-template-columns: 1fr; }
  .page-head { align-items: stretch; flex-direction: column; }
  .modal { min-width: 0; width: 100%; }
}
