:root {
  --bg: #0a0e14;
  --panel: #111722;
  --panel-2: #0d131c;
  --border: #1e2633;
  --border-soft: #192231;
  --text: #e5e9f0;
  --muted: #8a97a8;
  --muted-2: #5d6879;
  --accent: #34d399;
  --accent-dim: #1f3d33;
  --blue: #3b82f6;
  --red: #fb7185;
  --amber: #fbbf24;
  --green: #34d399;
  --radius: 14px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Noto Sans TC", "PingFang TC", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px 64px; }

/* header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0 18px; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-dim); color: var(--accent);
}
.brand h1 { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: .3px; }
.brand .sub { font-size: 12px; color: var(--muted-2); margin-top: 1px; }
.live { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(52,211,153,.5); animation: pulse 2s infinite; }
.live .dot.stale { background: var(--amber); animation: none; }
.live .dot.down { background: var(--red); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.4);} 70%{ box-shadow: 0 0 0 7px rgba(52,211,153,0);} 100%{ box-shadow:0 0 0 0 rgba(52,211,153,0);} }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tabs button {
  background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 500;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
  font-family: inherit; transition: color .15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: #fff; border-bottom-color: var(--blue); }

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

/* section label */
.section { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .5px; margin: 4px 0 12px; }
.section .hint { letter-spacing: 0; color: var(--muted-2); font-weight: 400; }

/* grid + cards */
.grid { display: grid; gap: 16px; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .g3, .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.card.pad-lg { padding: 20px 22px; }
.card h3 { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 14px; }
.card h3 .ico { color: var(--muted-2); display: inline-flex; }
.card h3 .right { margin-left: auto; font-size: 11px; color: var(--muted-2); font-weight: 400; }

/* gauge card */
.gauge-card { text-align: center; }
.gauge-wrap { position: relative; width: 170px; margin: 2px auto 6px; }
.gauge-val { position: absolute; left: 0; right: 0; top: 54%; transform: translateY(-50%); font-size: 26px; font-weight: 700; }
.gauge-sub { font-size: 12px; color: var(--muted); margin-top: -4px; }
.spark { margin-top: 12px; }
.spark-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted-2); margin-top: 4px; }

/* KPI */
.kpi .label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .num { font-size: 30px; font-weight: 700; margin-top: 8px; letter-spacing: .5px; }
.kpi .num.sm { font-size: 22px; }

/* key-value list */
.kv { display: grid; grid-template-columns: fit-content(42%) 1fr; gap: 9px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.mono { font-family: "SF Mono", "JetBrains Mono", ui-monospace, "Menlo", monospace; font-size: 12.5px; }

/* table */
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tscroll table { min-width: 440px; }
thead th { text-align: left; color: var(--muted-2); font-weight: 500; font-size: 12px; padding: 0 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .note.mono { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.badge { white-space: nowrap; }

/* 手機：表格每一列變成一張小卡（第一欄當標題，其餘「欄名 值」逐行），不橫向捲動 */
@media (max-width: 560px) {
  .tscroll table.stack { min-width: 0; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tbody tr { padding: 10px 4px; border-bottom: 1px solid var(--border-soft); }
  table.stack tbody tr:last-child { border-bottom: none; }
  table.stack tbody td { display: flex; gap: 12px; border: none; padding: 3px 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  table.stack tbody td::before { content: attr(data-label); flex: 0 0 84px; color: var(--muted-2); font-size: 12px; }
  table.stack tbody td:first-child { display: block; font-weight: 600; padding-bottom: 6px; }
  table.stack tbody td:first-child::before, table.stack tbody td.empty::before { display: none; }
  table.stack td .note.mono { max-width: none; white-space: normal; margin-left: 16px; }
}

/* status dot */
.sdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.sdot.ok { background: var(--green); }
.sdot.warn { background: var(--amber); }
.sdot.bad { background: var(--red); }
.sdot.idle { background: var(--muted-2); }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 6px; background: #1b2432; color: var(--muted); }
.badge.ok { background: rgba(52,211,153,.12); color: var(--green); }
.badge.bad { background: rgba(251,113,133,.12); color: var(--red); }
.badge.warn { background: rgba(251,191,36,.12); color: var(--amber); }

.val-ok { color: var(--green); }
.val-bad { color: var(--red); }
.val-warn { color: var(--amber); }

.note { color: var(--muted-2); font-size: 12.5px; }
.src { font-size: 11px; color: var(--muted-2); margin-left: auto; font-weight: 400; text-transform: none; letter-spacing: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* 表單（存取分頁）*/
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .invite-url {
  font-family: inherit; font-size: 15px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--blue); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
button.btn.sm { font-size: 13px; padding: 6px 12px; }
button.btn.danger { background: none; color: var(--red); border-color: rgba(251,113,133,.45); }
.invite-box { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); text-align: center; }
.invite-box img { width: 200px; height: 200px; background: #fff; border-radius: 10px; padding: 8px; }
.invite-url { font-family: "SF Mono", ui-monospace, monospace; font-size: 12px; margin: 14px 0 12px; text-align: left; }
.msg { font-size: 13px; margin-top: 10px; min-height: 18px; }
.mt { margin-top: 22px; }
.mt-s { margin-top: 16px; }
.empty { color: var(--muted-2); font-size: 13px; padding: 20px; text-align: center; }

/* overlay (login / register) */
.overlay { position: fixed; inset: 0; background: rgba(5,8,12,.82); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.overlay.show { display: flex; }
.overlay .box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 380px; width: 100%; text-align: center; }
.overlay h2 { margin: 0 0 8px; font-size: 18px; }
.overlay p { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
button.btn { font-family: inherit; font-size: 14px; font-weight: 600; padding: 10px 18px; border-radius: 9px; border: 1px solid var(--accent); background: var(--accent); color: #05140e; cursor: pointer; }
button.btn.ghost { background: none; color: var(--text); border-color: var(--border); }
button.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }
