:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --text: #17202a;
  --muted: #687385;
  --line: #d8dee8;
  --line-strong: #c8d0dc;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #0f8a5f;
  --red: #c24135;
  --amber: #a86512;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

code {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.86rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1rem;
  line-height: 1.25;
}

h2 {
  font-size: 1.45rem;
  line-height: 1.2;
}

h3 {
  font-size: 1rem;
  line-height: 1.25;
}

p,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-row,
.sidebar-brand,
.page-top,
.panel-head,
.toolbar,
.action-row,
.button-group,
.group-head,
.form-actions {
  display: flex;
  align-items: center;
}

.brand-row {
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1f6feb;
  color: #fff;
  font-weight: 800;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--sidebar);
  color: #fff;
  border-right: 1px solid #0b1220;
}

.sidebar-brand {
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand p {
  margin-top: 4px;
  color: #aab4c3;
  font-size: 0.82rem;
}

.sidebar-nav {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 16px 12px;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: #c8d1df;
  text-decoration: none;
  font-weight: 700;
}

.nav-link:hover {
  background: var(--sidebar-soft);
  color: #fff;
}

.nav-link.active {
  background: #eff6ff;
  color: #174ea6;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.app-main {
  min-width: 0;
  padding: 24px;
}

.page-top {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-top p {
  margin-top: 6px;
}

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

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.panel-head,
.group-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-head p,
.group-head p {
  margin-top: 4px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
}

.metric strong {
  font-size: 1.4rem;
}

.metric code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-form,
.event-list,
.group-stack {
  display: grid;
  gap: 12px;
}

.form-grid,
.bulk-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}

.compact-grid {
  grid-template-columns: minmax(220px, 360px) auto;
  justify-content: start;
}

.bulk-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.inline-check {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  padding-top: 25px;
}

.inline-check input {
  width: auto;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 220px;
  padding: 12px;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--blue);
}

.primary-button,
.ghost-button,
.danger-button {
  position: relative;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
  white-space: nowrap;
}

.primary-button:active,
.ghost-button:active,
.danger-button:active {
  transform: translateY(1px);
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.ghost-button {
  background: #fff;
  color: var(--text);
  border-color: var(--line-strong);
}

.ghost-button:hover {
  border-color: #aeb8c7;
  background: #f8fafc;
}

.danger-button {
  background: #fff;
  color: var(--red);
  border-color: #efc4bf;
}

.danger-button:hover {
  background: #fff5f3;
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
}

.is-loading::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.full-width {
  width: 100%;
}

.link-button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.toolbar,
.action-row,
.button-group,
.group-actions,
.form-actions {
  gap: 8px;
  flex-wrap: wrap;
}

.action-row,
.form-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.toast {
  position: fixed;
  top: 18px;
  right: 22px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #eaf7f0;
  color: var(--green);
  border: 1px solid #bfe7d3;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
}

.toast.error {
  background: #fff1f0;
  color: var(--red);
  border-color: #f2c5bf;
}

.toast.info {
  background: #eef5ff;
  color: #174ea6;
  border-color: #c9dcff;
}

.alert {
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.alert-error {
  background: #fff1f0;
  color: var(--red);
  border: 1px solid #f2c5bf;
}

.notice {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid #c9dcff;
  border-radius: 7px;
  background: #eef5ff;
  color: #174ea6;
  font-size: 0.92rem;
  line-height: 1.6;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

.proxy-table {
  min-width: 1420px;
}

.cert-table {
  min-width: 1180px;
}

.cert-upload-grid {
  margin-top: 14px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f4f8;
  color: #394555;
  font-size: 0.84rem;
  font-weight: 800;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: #fbfcfe;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.check-cell {
  width: 46px;
}

.link-cell {
  width: 34%;
}

.link-cell code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upstream {
  font-weight: 700;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  background: #edf1f6;
  color: #566274;
}

.status-ok,
.status-running {
  background: #e5f7ee;
  color: var(--green);
}

.status-failed,
.status-expired,
.status-invalid,
.status-missing {
  background: #fff1f0;
  color: var(--red);
}

.status-stopped,
.status-unknown,
.status-degraded,
.status-none {
  background: #edf1f6;
  color: #566274;
}

.status-new,
.status-tls {
  background: #fff7e5;
  color: var(--amber);
}

.status-reality,
.status-valid {
  background: #e5f7ee;
  color: var(--green);
}

.protocol-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 6px;
  background: #e8eefb;
  color: #24499a;
  font-size: 0.8rem;
  font-weight: 800;
}

.empty-row td,
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 34px;
}

.event-item {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-soft);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .sidebar-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-footer {
    display: none;
  }

  .metric-grid,
  .form-grid,
  .bulk-panel,
  .compact-grid {
    grid-template-columns: 1fr;
  }

  .app-main {
    padding: 16px;
  }

  .page-top,
  .panel-head,
  .group-head {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .sidebar-nav {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .action-row,
  .button-group,
  .group-actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .ghost-button,
  .danger-button,
  .link-button {
    width: 100%;
    justify-content: center;
  }
}
