:root {
    --bg: #ffffff;
    --side: #f4f4f6;
    --hover: #eaeaee;
    --line: #dedee3;
    --text: #1d1d22;
    --muted: #6b6b76;
    --top: #24242c;
    --top-text: #e9e9ef;
    --accent: #1f5f8b;
    --accent-soft: #e2edf5;
    --up: #2f8a4e;
    --up-soft: #e1f2e7;
    --warn: #b47a00;
    --warn-soft: #fbf0d4;
    --down: #c0392b;
    --down-soft: #f9e1de;
    --none: #9a9aa3;
    --none-soft: #ececef;
    --code: #f3f3f6;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #18181c;
        --side: #1f1f25;
        --hover: #2a2a31;
        --line: #33333b;
        --text: #e8e8ee;
        --muted: #a0a0ab;
        --top: #101014;
        --accent: #7cb4dc;
        --accent-soft: #1c3142;
        --up: #6cc58a;
        --up-soft: #1d3326;
        --warn: #e4b74e;
        --warn-soft: #3a2f15;
        --down: #ef8a7f;
        --down-soft: #3e221f;
        --none-soft: #2b2b31;
        --code: #24242b;
        color-scheme: dark;
    }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
#view { flex: 1; min-height: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }
code { background: var(--code); padding: 0 4px; border-radius: 3px; }
h2 { font-size: 1.35rem; margin: 0; }
h4 { font-size: 0.95rem; margin: 1.4rem 0 0.4rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.pad { padding: 1rem; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.break { word-break: break-word; }
.strong { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.row.end { justify-content: flex-end; margin-top: 0.75rem; }
.glyph { display: inline-block; min-width: 1em; text-align: center; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 1.25rem; padding: 0 1rem; height: 48px; background: var(--top); color: var(--top-text); }
.topbar nav { display: flex; gap: 0.25rem; overflow-x: auto; }
.topbar nav a { color: var(--top-text); opacity: 0.75; padding: 0.35rem 0.7rem; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { opacity: 1; text-decoration: none; background: rgba(255, 255, 255, 0.08); }
.topbar nav a.active { opacity: 1; background: rgba(255, 255, 255, 0.14); }
.topbar .btn.ghost { color: var(--top-text); }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: inherit; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 11px; }
.brand.big { font-size: 1.3rem; margin-bottom: 1rem; color: var(--text); }

/* buttons and fields */
.btn { font: inherit; display: inline-flex; align-items: center; gap: 0.25rem; cursor: pointer; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 0.3rem 0.7rem; border-radius: 6px; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.link { border: none; background: none; color: var(--accent); }
.btn.small { padding: 0.15rem 0.5rem; font-size: 0.85em; }
.btn.block { width: 100%; justify-content: center; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 0.3rem 0.5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.error { color: var(--down); min-height: 1.2em; margin: 0.4rem 0 0; }
.warn { background: var(--warn-soft); color: var(--warn); padding: 0.5rem 0.75rem; border-radius: 6px; }

/* status */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--none); flex-shrink: 0; }
.dot.s-up { background: var(--up); }
.dot.s-warning { background: var(--warn); }
.dot.s-down { background: var(--down); }
.pill, .badge { display: inline-block; min-width: 1.4em; text-align: center; padding: 0 0.45rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; line-height: 1.5; background: var(--none-soft); color: var(--muted); }
.s-up.pill, .s-up.badge { background: var(--up-soft); color: var(--up); }
.s-warning.pill, .s-warning.badge { background: var(--warn-soft); color: var(--warn); }
.s-down.pill, .s-down.badge { background: var(--down-soft); color: var(--down); }
.status { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.1rem 0.7rem; border-radius: 999px; font-weight: 600; background: var(--none-soft); }
.status.s-up { background: var(--up-soft); color: var(--up); }
.status.s-warning { background: var(--warn-soft); color: var(--warn); }
.status.s-down { background: var(--down-soft); color: var(--down); }

/* two-pane layout */
.console { display: flex; height: 100%; }
.sidebar { width: 290px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); }
.sidebar-search { padding: 0.6rem; border-bottom: 1px solid var(--line); }
.sidebar-search input { width: 100%; }
.tree { flex: 1; overflow: auto; padding: 0.25rem 0 1rem; }
.tree-client { display: flex; align-items: center; gap: 0.35rem; width: 100%; font: inherit; font-weight: 700; color: var(--text); background: none; border: none; padding: 0.45rem 0.75rem; cursor: pointer; text-align: left; }
.tree-client:hover { background: var(--hover); }
.tree-stage { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.07em; color: var(--muted); padding: 0.5rem 1rem 0.15rem 1.8rem; }
.tree-env { display: flex; align-items: flex-start; gap: 0.55rem; padding: 0.3rem 0.75rem 0.3rem 1.8rem; color: var(--text); border-left: 3px solid transparent; }
.tree-env:hover { background: var(--hover); text-decoration: none; }
.tree-env.active { background: var(--accent-soft); border-left-color: var(--accent); }
.tree-env .dot, .tree-env .glyph { margin-top: 0.4rem; }
.tree-env-text { display: flex; flex-direction: column; min-width: 0; }
.tree-env-name { font-weight: 500; }
.tree-env.active .tree-env-name { font-weight: 700; }
.tree-env-issue { font-size: 0.8em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail { flex: 1; min-width: 0; overflow: auto; }
.detail-head { padding: 1rem 1.5rem 0; border-bottom: 1px solid var(--line); }
.detail-head .facts { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 0.35rem; }
.issues { margin-top: 0.6rem; padding: 0.35rem 0.7rem; border-radius: 6px; font-size: 0.9em; }
.issues.s-warning { background: var(--warn-soft); color: var(--warn); }
.issues.s-down { background: var(--down-soft); color: var(--down); }
.tabs { display: flex; gap: 0.25rem; margin-top: 0.9rem; overflow-x: auto; }
.tabs a { padding: 0.5rem 0.9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.detail-body { padding: 1.2rem 1.5rem 2rem; }

/* history */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; align-items: flex-start; gap: 0.8rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.ev-icon { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--none-soft); color: var(--muted); flex-shrink: 0; }
.ev-icon.sev-warning { background: var(--warn-soft); color: var(--warn); }
.ev-icon.sev-critical { background: var(--down-soft); color: var(--down); }
.ev-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; font-weight: 600; }

/* monitor */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.7rem; margin-bottom: 0.8rem; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.8rem; }
.card-label { font-size: 0.75rem; color: var(--muted); }
.card-value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card-value.danger { color: var(--down); }
.chart { display: block; width: 100%; height: 160px; border-bottom: 1px solid var(--line); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-area { fill: var(--accent); opacity: 0.1; }
.chart-threshold { stroke: var(--down); stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.chart-bar { fill: var(--accent); opacity: 0.8; }
.chart-bar.flagged { fill: var(--down); }
.chart-label { fill: var(--muted); font-size: 11px; }
.chart-axis { display: flex; justify-content: space-between; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--line); }
th { background: var(--side); font-weight: 600; white-space: nowrap; font-size: 0.85em; }
tbody tr:last-child td { border-bottom: none; }
.kv th { width: 180px; color: var(--muted); font-weight: 500; background: none; }
.log-msg { white-space: pre-wrap; word-break: break-word; display: block; }
.grid td { vertical-align: middle; padding: 0.3rem 0.4rem; }
.grid input[type=text], .grid input[type=number], .grid select { width: 100%; min-width: 9rem; }
.grid tr.dirty td { background: var(--warn-soft); }
.grid .sticky { position: sticky; left: 0; background: var(--bg); z-index: 1; white-space: nowrap; }
.grid th.sticky { background: var(--side); }
.grid tr.dirty .sticky { background: var(--warn-soft); }
.grid .btn + .btn { margin-left: 0.25rem; }
ul.plain { padding-left: 1.2rem; }

/* pages, forms, dialogs */
.page { padding: 1.2rem 1.5rem 2rem; height: 100%; overflow: auto; }
.env-form fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 0.9rem; padding: 0.6rem 0.9rem 0.8rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.6rem 1rem; }
.env-form legend { font-weight: 600; padding: 0 0.3rem; }
.env-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85em; color: var(--muted); }
.env-form label.check { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--text); font-size: 1em; }
.env-form input:disabled { opacity: 0.6; }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: var(--bg); color: var(--text); border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 2rem); display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); }
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem; overflow: auto; }
.copy-box { display: flex; flex-direction: column; gap: 0.4rem; align-items: flex-end; }
.copy-box textarea { width: 100%; resize: vertical; background: var(--code); }
pre.hint { white-space: pre-wrap; background: var(--code); padding: 0.6rem 0.8rem; border-radius: 6px; font-size: 0.85em; }
.toast { position: fixed; right: 1rem; bottom: 1rem; padding: 0.6rem 1rem; border-radius: 8px; background: var(--top); color: var(--top-text); z-index: 60; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); }
.toast.err { background: var(--down); color: #fff; }
.login-wrap { display: grid; place-items: center; height: 100%; padding: 1rem; background: var(--side); }
.login { width: min(380px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 1.6rem; display: flex; flex-direction: column; gap: 0.6rem; }
.login label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--muted); font-size: 0.9em; }

@media (max-width: 760px) {
    .console { flex-direction: column; height: auto; }
    .sidebar { width: auto; max-height: 45vh; border-right: none; border-bottom: 1px solid var(--line); }
    .detail { overflow: visible; }
    .topbar { gap: 0.6rem; }
    .detail-head, .detail-body, .page { padding-left: 1rem; padding-right: 1rem; }
}

/* sidebar: search + board toggle */
.sidebar-search.with-action { display: flex; gap: 0.4rem; align-items: center; }
.sidebar-search.with-action input { flex: 1; min-width: 0; }
.icon-btn { padding: 0.3rem 0.55rem; font-size: 1.05rem; line-height: 1; }

/* board */
.board { height: 100%; overflow: auto; padding: 1rem 1.5rem 2rem; }
.board-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-bottom: 1rem; position: sticky; top: -1rem; padding: 0.6rem 0; background: var(--bg); z-index: 2; }
.board-bar input { width: 220px; }
.board-counts { display: inline-flex; gap: 0.3rem; }
.chips { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.chip { font: inherit; border: none; background: none; color: var(--muted); padding: 0.25rem 0.8rem; cursor: pointer; }
.chip.active { background: var(--accent); color: #fff; }
.bgroup { margin-bottom: 1.4rem; }
.bgroup h3 { font-size: 1rem; margin: 0 0 0.6rem; }
.bgroup-counts { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.bgroup-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.8rem; }
.bcard { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.75rem 0.85rem 0.65rem; border: 1px solid var(--line); border-left: 4px solid var(--none); border-radius: 10px; background: var(--bg); color: var(--text); transition: border-color 0.6s, box-shadow 0.2s, transform 0.2s; }
.bcard:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.bcard.s-up { border-left-color: var(--up); }
.bcard.s-warning { border-left-color: var(--warn); }
.bcard.s-down { border-left-color: var(--down); background: linear-gradient(0deg, var(--down-soft), var(--bg) 70%); }
.bcard-head { display: flex; align-items: center; gap: 0.45rem; }
.bcard-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard-stage { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; }
.bcard-status { margin-left: auto; font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.bcard.s-up .bcard-status { color: var(--up); }
.bcard.s-warning .bcard-status { color: var(--warn); }
.bcard.s-down .bcard-status { color: var(--down); }
.bcard-sub { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard-issue { font-size: 0.8rem; color: var(--warn); min-height: 1.2em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bcard.s-down .bcard-issue { color: var(--down); }
.bcard-issue.calm { color: var(--up); }
.meters { display: flex; flex-direction: column; gap: 0.25rem; }
.meter { display: grid; grid-template-columns: 3.2rem 1fr 2.6rem; align-items: center; gap: 0.4rem; font-size: 0.75rem; }
.meter-label { color: var(--muted); }
.meter-value { text-align: right; font-variant-numeric: tabular-nums; }
.meter-track { height: 6px; border-radius: 3px; background: var(--none-soft); overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width 1.2s cubic-bezier(.2, .8, .2, 1), background-color 0.6s; }
.meter-fill.warm { background: var(--warn); }
.meter-fill.hot { background: var(--down); }
.bcard-spark .spark { display: block; width: 100%; height: 40px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.spark-line.slow { stroke: var(--down); }
.spark-area { fill: var(--accent); opacity: 0.08; }
.spark-base { stroke: var(--line); stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.spark-dot { fill: var(--accent); transform-box: fill-box; transform-origin: center; animation: dot-pulse 2s ease-in-out infinite; }
.spark-dot.slow { fill: var(--down); }
.bcard-foot { display: flex; gap: 0.6rem; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bcard-age.stale { color: var(--down); font-weight: 600; }
.bcard-extra { margin-left: auto; color: var(--warn); }

/* the status light breathes: faster when worse */
.dot.pulse { box-shadow: 0 0 0 0 currentColor; }
.dot.pulse.s-up { color: color-mix(in srgb, var(--up) 55%, transparent); animation: breathe 3.2s ease-out infinite; }
.dot.pulse.s-warning { color: color-mix(in srgb, var(--warn) 60%, transparent); animation: breathe 1.8s ease-out infinite; }
.dot.pulse.s-down { color: color-mix(in srgb, var(--down) 65%, transparent); animation: breathe 0.9s ease-out infinite; }
@keyframes breathe { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes dot-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.7); opacity: 0.55; } }
/* a new report: the card beats once */
.bcard.beat { animation: beat 0.9s ease-out; }
@keyframes beat { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }

@media (prefers-reduced-motion: reduce) {
    .dot.pulse, .spark-dot, .bcard.beat { animation: none; }
    .meter-fill, .bcard { transition: none; }
}
@media (max-width: 760px) {
    .board { padding: 0.8rem 1rem 1.5rem; }
    .board-bar input { width: 100%; }
}
