/* homevm-watch — 「平常安靜，出事大聲」。顏色只用在狀態；設計系統見 ui-design.md */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e2e5ea;
  --text: #161a21; --text-2: #4b5563; --muted: #5f6673; --accent: #2f5bd3;
  --ok: #15803d; --warn: #a16207; --fail: #c62828; --off: #5f6673;
  --ok-bg: #e8f5ec; --warn-bg: #fdf5e1; --fail-bg: #fdecec; --off-bg: #eef0f3;
  --log-bg: #0b0e13; --log-text: #d5dae1; --log-dim: #7d8590; --log-err: #ff7b72; --log-warn: #e3b341;
  --led-off: #c9ced6;
  --shadow: 0 1px 2px rgb(0 0 0 / .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, Consolas, "Noto Sans Mono CJK TC", monospace;
  --r-card: 12px; --r-ctl: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --surface: #161b22; --surface-2: #1d232c; --border: #2a313b;
    --text: #e6e9ee; --text-2: #b3bac5; --muted: #8b949e; --accent: #7aa2ff;
    --ok: #4ade80; --warn: #facc15; --fail: #f87171; --off: #8b949e;
    --ok-bg: rgb(74 222 128 / .14); --warn-bg: rgb(250 204 21 / .14);
    --fail-bg: rgb(248 113 113 / .16); --off-bg: rgb(139 148 158 / .16);
    --led-off: #3a424d; --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.mono { font-family: var(--mono); font-size: .92em; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.meta, .muted { color: var(--muted); font-size: 13px; }
.meta-warn { color: var(--warn); } .meta-fail { color: var(--fail); font-weight: 600; } .meta-ok { color: var(--ok); }
.empty { color: var(--muted); font-size: 14px; margin: 8px 0; list-style: none; }

/* ── 頂欄 ── */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  padding: 0 16px; min-height: 52px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border); backdrop-filter: saturate(1.4) blur(8px);
}
.brand { display: inline-flex; align-items: center; gap: 8px; margin-right: 12px; color: var(--text); font-weight: 700; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand-led { width: 8px; height: 8px; border-radius: 2px; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.nav { display: flex; flex: 1; gap: 2px; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; color: var(--text-2); border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.logout { margin: 0; }

/* ── 版面 ── */
.page { max-width: 1180px; margin: 0 auto; padding: 16px; }
.page-title { font-size: 20px; margin: 4px 0 16px; }
.back { display: inline-flex; min-height: 44px; align-items: center; font-size: 14px; }
.overview-grid { display: grid; gap: 16px; }
.col-main, .col-side { display: grid; gap: 16px; align-content: start; min-width: 0; }
@media (min-width: 960px) { .overview-grid { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); } }

/* ── 卡片 ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.overview-grid .card, .page > .card:not(.login) { margin: 0; }
.page > .card + .card, .page > div + .logview, .page > .panel + .card, .page > div > .panel + .card { margin-top: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; }
.card-head .card-title { margin: 0; }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.card-link { font-size: 13px; }

/* ── 招牌：LED 面板 ── */
.panel {
  display: grid; gap: 12px; margin-bottom: 16px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: var(--r-card);
}
.panel-warn { border-left-color: var(--warn); }
.panel-fail { border-left-color: var(--fail); background: linear-gradient(90deg, var(--fail-bg), var(--surface) 70%); }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.panel-verdict { margin: 0; font-size: 22px; font-weight: 700; color: var(--ok); }
.panel-warn .panel-verdict { color: var(--warn); }
.panel-fail .panel-verdict { color: var(--fail); }
.panel-meta { margin: 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
/* 每格可點區域 24×24（WCAG 2.2 目標尺寸），燈本身 22×14 */
.leds { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.led { display: grid; place-items: center; width: 26px; height: 24px; border-radius: 4px; --led: var(--led-off); }
.led::before { content: ""; width: 22px; height: 14px; border-radius: 3px; background: var(--led); box-shadow: inset 0 -2px 0 rgb(0 0 0 / .15); }
.led:hover::before { filter: brightness(1.15); }
.led-ok { --led: var(--ok); }
.led-warn { --led: var(--warn); }
.led-fail { --led: var(--fail); }
.led-warn::before, .led-fail::before { box-shadow: 0 0 0 3px color-mix(in srgb, var(--led) 30%, transparent); }

/* ── 告警 ── */
.card-alert { border-color: color-mix(in srgb, var(--fail) 40%, var(--border)); background: var(--fail-bg); margin-bottom: 16px; }
.card-alert .card-title { color: var(--fail); }
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alert-list li { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; padding-left: 10px; border-left: 3px solid var(--warn); }
.alert-list li.sev-critical { border-left-color: var(--fail); }
.alert-title { font-weight: 600; }
.detail-alerts { margin: 12px 0; }

/* ── 指標 ── */
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; }
@media (min-width: 640px) { .metrics { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.metric { display: grid; gap: 2px; align-content: start; padding: 12px; background: var(--surface-2); border-radius: var(--r-ctl); min-width: 0; }
.metric dt { font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.metric dd { margin: 0; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.metric dd small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.metric .meta { font-size: 12px; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 26px; margin-top: 4px; fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.bar { display: block; height: 4px; margin-top: 6px; border-radius: 2px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.bar-warn > span { background: var(--warn); } .bar-fail > span { background: var(--fail); }

/* ── 狀態 pill ── */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--ok); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill-ok { padding-left: 0; padding-right: 0; font-weight: 500; }
.pill-warn { color: var(--warn); background: var(--warn-bg); }
.pill-fail { color: var(--fail); background: var(--fail-bg); }
.pill-off, .pill-unknown { color: var(--off); background: var(--off-bg); }
.pill-lg { font-size: 14px; padding: 3px 12px; }
.pill-ok.pill-lg { padding: 3px 0; }

/* ── 服務列 ── */
.group-title { display: flex; align-items: center; gap: 8px; margin: 16px 0 4px; font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.card-title + .group-title { margin-top: 0; }
.count { font-variant-numeric: tabular-nums; padding: 0 6px; border-radius: 999px; background: var(--surface-2); letter-spacing: 0; }
.svc-list, .ext-list, .event-list { list-style: none; margin: 0; padding: 0; }
.svc + .svc { border-top: 1px solid var(--border); }
.svc a {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 12px;
  min-height: 44px; padding: 8px 10px; margin: 0 -10px; color: var(--text); border-left: 3px solid transparent; border-radius: 6px;
}
.svc a:hover { background: var(--surface-2); text-decoration: none; }
.svc-name { font-weight: 500; overflow-wrap: anywhere; }
.svc-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0 12px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.svc-meta:empty { display: none; }
.status-warn > a { border-left-color: var(--warn); background: var(--warn-bg); }
.status-fail > a { border-left-color: var(--fail); background: var(--fail-bg); }
.status-fail .svc-name { font-weight: 700; }
@media (min-width: 640px) {
  .svc a { grid-template-columns: minmax(0, 1fr) auto auto; }
  .svc-meta { grid-column: auto; grid-row: 1; grid-column-start: 2; justify-content: flex-end; }
}

/* ── 外部檢查 ── */
.ext { padding: 10px 0; }
.ext + .ext { border-top: 1px solid var(--border); }
.ext-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.ext-name { font-weight: 500; overflow-wrap: anywhere; }
.ext-meta { display: flex; flex-wrap: wrap; gap: 0 12px; margin-top: 2px; color: var(--muted); font-size: 12px; }
.ext-meta .mono { overflow-wrap: anywhere; }
.ext-error { margin-top: 4px; color: var(--fail); font-size: 12px; overflow-wrap: anywhere; }

/* ── 事件 ── */
.event-list li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding: 6px 0; font-size: 14px; }
.event-list li + li { border-top: 1px solid var(--border); }
.event-list time { color: var(--muted); font-size: 12px; padding-top: 2px; }
.event-list .sev-critical span { color: var(--fail); }

/* ── 服務詳細 ── */
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.detail-title { font-size: 22px; overflow-wrap: anywhere; }
.svc-detail.status-fail { border-left: 4px solid var(--fail); }
.svc-detail.status-warn { border-left: 4px solid var(--warn); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 0; }
@media (min-width: 640px) { .facts { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.fact-wide { grid-column: 1 / -1; }

/* ── log 檢視器 ── */
.logview { margin-top: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.log-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; border-bottom: 1px solid var(--border); }
@media (min-width: 760px) { .log-controls { display: flex; flex-wrap: wrap; align-items: end; } }
.log-services { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; border: 0; min-width: 0; width: 100%; }
.log-services legend { font-size: 12px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; cursor: pointer; }
.chip:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chip input { margin: 0; accent-color: var(--accent); }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
.field-grow { grid-column: 1 / -1; }
@media (min-width: 760px) { .field-grow { flex: 1; min-width: 180px; } }
.field input, .field select {
  width: 100%; min-height: 40px; padding: 0 10px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctl);
}
@media (min-width: 760px) { .field input, .field select { font-size: 14px; } }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.log-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.log-status { font-size: 12px; color: var(--muted); }
.log-status::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--off); vertical-align: 1px; }
.log-lines {
  height: 62vh; min-height: 280px; overflow: auto; padding: 8px 0; background: var(--log-bg); color: var(--log-text);
  font: 12.5px/1.45 var(--mono); overscroll-behavior: contain;
}
.log-lines:empty::before { content: "這段時間沒有符合條件的 log。新的 log 會即時出現在這裡。"; display: block; padding: 16px 12px; color: var(--log-dim); font-family: var(--font); font-size: 13px; }
.log-line { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding: 1px 12px 1px 10px; border-left: 2px solid transparent; }
.log-line time, .log-line .unit { color: var(--log-dim); white-space: nowrap; }
.log-line .unit { display: none; }
.log-line .msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line:hover { background: rgb(255 255 255 / .04); }
.log-line.p0, .log-line.p1, .log-line.p2, .log-line.p3 { border-left-color: var(--log-err); color: var(--log-err); }
.log-line.p4 { color: var(--log-warn); }
@media (min-width: 760px) {
  .log-line { grid-template-columns: auto minmax(0, 14ch) minmax(0, 1fr); }
  .log-line .unit { display: block; overflow: hidden; text-overflow: ellipsis; }
}

.log-status[data-state="live"]::before { background: var(--ok); }
.log-status[data-state="error"]::before { background: var(--fail); }

/* ── 按鈕 ── */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; font: inherit; font-weight: 600; border-radius: var(--r-ctl); border: 1px solid transparent; cursor: pointer; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0e1116; } }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

/* ── 表格 ── */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }

/* ── 登入 ── */
.login { max-width: 380px; margin: 12vh auto 0; padding: 28px 24px; }
.login-brand { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-family: var(--mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.login-title { font-size: 22px; margin-bottom: 20px; }
.stack { display: grid; gap: 14px; }
.stack .btn { margin-top: 6px; }
.form-error { margin: 0 0 14px; padding: 10px 12px; border-radius: var(--r-ctl); background: var(--fail-bg); color: var(--fail); font-size: 14px; font-weight: 500; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
