: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); }
@media (max-width: 860px) { .g3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .g2, .g3 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.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; }

/* 「架構」分頁：附加在 style.css 後面即可（只用既有 token）。 */

/* 層級脊線：左側一條線，L1→L2→L3 節點串起來 */
.org { position: relative; padding-left: 40px; }
/* 脊線一段一段畫：每一層的節點連到下一層的節點，最後一層不往下畫 */
.tier:not(:last-child)::before { content: ""; position: absolute; left: -27px; top: 22px; bottom: -30px; width: 2px; background: var(--border); }
.tier { position: relative; margin-bottom: 26px; scroll-margin-top: 12px; }
.tier-node {
  position: absolute; left: -33px; top: 7px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--muted);
}
.tier-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 2px 0 12px; font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.4; }
.tier-lv { color: var(--muted); font-size: 12px; font-weight: 600; }
.tier-sub { color: var(--muted); font-size: 13px; font-weight: 400; }
.tier-group { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; margin: 22px 0 10px; font-size: 14px; font-weight: 600; color: var(--text); }
.tier-group .tier-sub { font-size: 12.5px; }

/* 卡片內文：這一頁用 14px（「找資料」為主，不是看數字） */
.arch-kv { margin: 0; font-size: 14px; grid-template-columns: 4.5em minmax(0, 1fr); gap: 8px 14px; }
.arch-kv dt { color: var(--muted); }
.arch-kv .note { font-size: 12.5px; }
.arch-name { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.arch-link { color: var(--accent); text-decoration: none; }
.arch-link:hover { text-decoration: underline; }
/* 接上指令是要「打」的字，不是連結：用程式碼小框，和 teal 的網址連結分開 */
.arch-cmd { color: var(--text); font-size: 13.5px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.ext { margin-left: 4px; flex: none; opacity: .85; }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

/* owner 卡 */
.owner-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .owner-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1040px) { .owner-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.owner { padding: 16px 16px 6px; scroll-margin-top: 12px; display: flex; flex-direction: column; }
.owner-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.owner-head h4 { margin: 0; font-size: 16px; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.owner-what { margin-top: 2px; font-size: 14px; color: var(--text); }
.owner-purpose { margin: 4px 0 14px; font-size: 13px; color: var(--muted); line-height: 1.55; }
.owner > .arch-kv { padding-top: 12px; border-top: 1px solid var(--border-soft); }
.owner-head .badge { flex: none; font-size: 12px; color: var(--text); border: 1px dashed var(--muted); background: none; }

/* 展開：目錄、Repo、埠號明細（摘要列高 44px） */
.owner-more { margin-top: auto; padding-top: 8px; }
.owner-more summary {
  min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
  color: var(--muted); font-size: 13px; border-top: 1px solid var(--border-soft); margin-top: 6px;
}
.owner-more summary::-webkit-details-marker { display: none; }
.owner-more summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
.owner-more[open] summary::before { transform: rotate(45deg); }
.owner-more[open] { padding-bottom: 12px; }
.port-list { list-style: none; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px dashed var(--border); display: grid; gap: 8px; font-size: 13px; }
.port-list li { display: grid; grid-template-columns: 4.5em minmax(0, 1fr); gap: 14px; }
.port-list .note { display: block; font-size: 12px; }
.port-none { margin-top: 10px; }

/* L1、L2 */
.arch-pres { padding: 16px; max-width: 560px; }
.arch-pm { padding: 16px; }
.pm-kv { margin-top: 10px; }
.pm-duties { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.pm-cols { display: grid; gap: 18px; margin-top: 8px; }
@media (min-width: 900px) { .pm-cols { grid-template-columns: 1.4fr 1fr; gap: 28px; } }
.arch-pm h5 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.arch-ul { margin: 0; padding-left: 1.1em; font-size: 14px; display: grid; gap: 4px; }
.arch-ul li::marker { color: var(--muted-2); }
.svc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.svc-name { display: block; }
.svc-meta { display: block; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.svc-meta .sep { color: var(--muted-2); }
.pm-host { margin: 12px 0 0; }
.pm-host a, .arch-end a { color: var(--text); }

/* 跳轉列：L3 一長串卡片，先給一排名字可以直接跳 */
.jump { display: grid; gap: 12px; margin-bottom: 4px; }
.jump-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
@media (min-width: 560px) { .jump-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.jump-kind { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.jump a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 9px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  background: var(--panel); border: 1px solid var(--border); color: var(--text); font-size: 13px; text-decoration: none;
}
.jump a:hover { border-color: var(--muted-2); }

.arch-rules { margin-top: 4px; }
.arch-rules h3 { color: var(--text); font-size: 14px; }
.arch-end { margin: 18px 0 0; text-align: center; }

@media (prefers-reduced-motion: reduce) { .owner-more summary::before { transition: none; } }

/* 這一頁的小字一律用 --muted：--muted-2 在面板上只有 3.18:1（建議全站一起改，見設計說明） */
#arch-body .note, #arch-body .src, #arch-body .mono.note, .arch-pm > .note .mono, .svc-meta .sep, .arch-ul li::marker { color: var(--muted); }

/* 分頁變成 7 個：窄螢幕縮小左右內距，390 寬剛好一排放得下、不用橫向捲 */
@media (max-width: 420px) { .tabs { gap: 0; } .tabs button { padding: 10px 9px; min-height: 44px; } }

/* 連結的點擊範圍撐到 44px 高，但不改變排版（上下用負 margin 抵銷） */
.arch-link { display: inline-flex; align-items: center; min-height: 44px; margin-block: -14px; }
.arch-kv dd { padding-block: 1px; }
@media (min-width: 1040px) { .jump { display: none; } } /* 寬螢幕卡片一眼看得完，不需要跳轉列 */
/* 寬螢幕：PM 的基本資料和職責左右並排，共用服務與文件在下面橫跨兩欄 */
@media (min-width: 900px) {
  .arch-pm { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); column-gap: 28px; }
  .arch-pm > .owner-head, .arch-pm > .pm-kv { grid-column: 1; }
  .arch-pm > .pm-duties { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; padding-top: 0; border-top: 0; }
  .arch-pm > .pm-more { grid-column: 1 / -1; }
}
