:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a5f 0%, transparent 50%),
              radial-gradient(900px 500px at 100% 0%, #163249 0%, transparent 45%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  display: grid;
  gap: 14px;
}

.login-card h1 {
  margin: 0;
  font-size: 1.4rem;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: #082f49;
  font-weight: 600;
  cursor: pointer;
}

button.secondary { background: #334155; color: var(--text); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: #7f1d1d; color: #fecaca; }
button.ok { background: #14532d; color: #bbf7d0; }

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.muted { color: var(--muted); margin: 0; font-size: 0.9rem; }
.error { color: #fecaca; margin: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 6px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.table-wrap { overflow: auto; }

.table-scroll {
  max-height: min(58vh, 560px);
  overflow-y: auto;
  overflow-x: auto;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: 0 1px 0 var(--line);
}

.table-scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 999px;
}

.table-scroll::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th { color: var(--muted); font-weight: 600; background: rgba(15, 23, 42, 0.45); }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge.ok { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.badge.bad { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.badge.warn { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }

.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.8rem;
}

.machine-id {
  white-space: normal;
  word-break: break-all;
  max-width: 280px;
  cursor: pointer;
  color: #7dd3fc;
}

.machine-id:hover {
  text-decoration: underline;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.link-btn {
  background: transparent;
  border: 0;
  padding: 0;
  color: #7dd3fc;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.link-btn:hover {
  text-decoration: underline;
}

.expire-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

button.tiny {
  padding: 4px 8px;
  font-size: 0.78rem;
}

.ops {
  white-space: nowrap;
}

.auth-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 118px;
}

.auth-switch-text {
  display: grid;
  line-height: 1.15;
}

.auth-switch-text strong {
  font-size: 0.92rem;
}

.auth-switch-text span {
  font-size: 0.75rem;
  color: var(--muted);
}

.auth-switch.is-on .auth-switch-text strong { color: #86efac; }
.auth-switch.is-off .auth-switch-text strong { color: #fca5a5; }
.auth-switch.is-expired.is-on .auth-switch-text strong { color: #fcd34d; }

button.switch {
  padding: 0;
  border: 0;
  background: transparent;
  display: inline-flex;
  cursor: pointer;
}

.switch-track {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #475569;
  border: 1px solid #64748b;
  display: inline-flex;
  align-items: center;
  padding: 2px;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.switch-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e2e8f0;
  transform: translateX(0);
  transition: transform 0.18s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.auth-switch.is-on .switch-track {
  background: #15803d;
  border-color: #22c55e;
}

.auth-switch.is-on .switch-thumb {
  transform: translateX(18px);
  background: #f0fdf4;
}

.auth-switch.is-off .switch-track {
  background: #7f1d1d;
  border-color: #ef4444;
}

.auth-switch.is-expired.is-on .switch-track {
  background: #92400e;
  border-color: #f59e0b;
}

button.switch:focus-visible .switch-track {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

button.switch:hover .switch-track {
  filter: brightness(1.08);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  max-width: 420px;
  width: calc(100% - 32px);
}

dialog::backdrop {
  background: rgba(2, 6, 23, 0.65);
}

.dialog-card {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.dialog-card h3 {
  margin: 0;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.form-row label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.form-row select {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.preview strong {
  color: #7dd3fc;
}

dialog {
  max-width: 520px;
}

#detail-view .topbar h1 {
  margin-top: 10px;
}
