:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #dc2626;
  --shadow: 0 16px 42px rgba(24, 39, 75, 0.10);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf3fb;
}

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

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

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

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand.compact {
  color: var(--ink);
  margin-bottom: 4px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.plan-box small,
.plan-box span {
  color: #cbd5e1;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  text-align: left;
  padding: 12px 14px;
  color: #dbeafe;
  background: transparent;
  cursor: pointer;
}

.nav-button.active,
.nav-button:hover {
  color: #fff;
  background: rgba(37, 99, 235, 0.45);
}

.plan-box {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

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

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

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button,
.quick-action {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 42px;
}

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

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

.button.secondary,
.quick-action {
  color: var(--ink);
  background: #e8eef8;
}

.quick-action.danger {
  color: #fff;
  background: var(--red);
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  background: #ecfdf3;
  border: 1px solid #bbf7d0;
  margin-bottom: 18px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

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

.metric {
  padding: 18px;
}

.metric span,
.metric small,
.muted {
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 34px;
  line-height: 1;
  margin: 10px 0;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  gap: 18px;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.panel {
  padding: 18px;
}

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

.quick-grid,
.rule-list,
.command-list,
.health-grid,
.stack-list {
  display: grid;
  gap: 10px;
}

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

.event-list {
  display: grid;
  gap: 10px;
  max-height: 380px;
  overflow: auto;
}

.event-item,
.child-card,
.rule-card,
.health-item,
.router-card,
.token-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.event-item strong,
.event-item span,
.child-card strong,
.child-card span,
.router-card strong,
.router-card span,
.router-card small {
  display: block;
}

.event-item span,
.child-card span,
.device-row small,
.router-card span,
.router-card small {
  color: var(--muted);
  font-size: 13px;
}

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

.router-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.router-card code,
.token-box code {
  display: block;
  max-width: 100%;
  overflow: auto;
  white-space: nowrap;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef2ff;
  color: #1e3a8a;
}

.token-box {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.install-script {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #172033;
  background: #f8fafc;
  white-space: pre;
  overflow: auto;
}

.form {
  display: grid;
  gap: 12px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.form input,
.device-row input,
.device-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
}

.device-table {
  display: grid;
  gap: 10px;
}

.device-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.9fr 0.9fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.check {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.check input {
  width: auto;
}

.rule-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.switch {
  position: relative;
  width: 50px;
  height: 28px;
}

.switch input {
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

.switch input:checked + span {
  background: var(--blue);
}

.switch input:checked + span::after {
  transform: translateX(22px);
}

.command-list code {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef2ff;
  color: #1e3a8a;
}

.health-item.good {
  border-color: #86efac;
}

.health-item.warn {
  border-color: #fcd34d;
}

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

  .sidebar {
    position: static;
  }

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

  .metric-grid,
  .split,
  .section-grid,
  .device-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .main,
  .sidebar {
    padding: 18px;
  }

  .nav,
  .quick-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }
}
