:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #162033;
  --muted: #697386;
  --line: #d9e0ea;
  --navy: #162033;
  --blue: #2563eb;
  --teal: #0f766e;
  --green: #15803d;
  --amber: #b45309;
  --red: #b91c1c;
  --violet: #6d28d9;
  --shadow: 0 18px 45px rgba(22, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: #111827;
  color: #eef2ff;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  color: #111827;
  font-weight: 800;
}

.brand-name {
  font-size: 15px;
  font-weight: 800;
}

.brand-subtitle,
.footer-copy,
.eyebrow,
.metric-label,
.panel p,
.usage-card span {
  color: var(--muted);
  font-size: 12px;
}

.brand-subtitle,
.footer-copy {
  color: #9ca3af;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  cursor: pointer;
}

.nav-item span {
  width: 20px;
  color: #93c5fd;
  text-align: center;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: #ffffff;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 14px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
}

.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34,197,94,0.16);
}

.footer-title {
  font-size: 13px;
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.topbar-actions,
.panel-header,
.proxy-output {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  padding: 0 14px;
  background: var(--blue);
  color: white;
  font-weight: 800;
}

.secondary-button {
  padding: 0 12px;
  border-color: var(--line);
  background: white;
  color: var(--ink);
  font-weight: 700;
}

.icon-button {
  width: 38px;
  background: white;
  border-color: var(--line);
  color: var(--ink);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

.metric-card {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.metric-card strong {
  font-size: 26px;
}

.metric-trend {
  font-size: 12px;
  font-weight: 800;
}

.good { color: var(--green); }
.neutral { color: var(--amber); }
.bad { color: var(--red); }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
  gap: 14px;
}

.panel {
  padding: 18px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header.compact {
  margin-bottom: 10px;
}

.panel p {
  margin: 5px 0 0;
}

.generator-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
}

.proxy-output {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #eef2ff;
}

.proxy-output code {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: #1e1b4b;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pool-list {
  display: grid;
  gap: 10px;
}

.pool-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pool-item strong,
.node-card strong {
  font-size: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
}

.pill.healthy { background: #dcfce7; color: var(--green); }
.pill.degraded { background: #fef3c7; color: var(--amber); }
.pill.dead { background: #fee2e2; color: var(--red); }

.full-panel {
  min-height: 560px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.node-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.node-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  box-shadow: none;
}

.node-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.traffic-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.usage-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  box-shadow: none;
}

.usage-card strong {
  font-size: 20px;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.settings-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #111827;
  color: white;
  opacity: 0;
  transform: translateY(10px);
  transition: 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 86px minmax(0, 1fr);
  }

  .brand-block {
    justify-content: center;
  }

  .brand-block > div:not(.brand-mark),
  .nav-item:not(.active) {
    overflow: hidden;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
    font-size: 0;
  }

  .nav-item span {
    font-size: 15px;
  }

  .sidebar-footer {
    justify-content: center;
  }

  .sidebar-footer > div:not(.health-dot) {
    display: none;
  }

  .metric-grid,
  .content-grid,
  .traffic-layout,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px;
  }

  .brand-block,
  .sidebar-footer {
    display: none;
  }

  .nav-list {
    display: flex;
    min-width: max-content;
  }

  .nav-item {
    width: auto;
    min-width: 48px;
    padding: 0 12px;
    font-size: 13px;
  }

  .workspace {
    padding: 18px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .content-grid,
  .traffic-layout,
  .settings-grid,
  .node-grid,
  .generator-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }
}
