/* UTK API 監控儀表板（版面沿 WowPrime 儀表板）
   亮色單一主題（營運牆面用，刻意不做深色模式以避免灰黑觀感）。
   品牌紅只用在「外框」（頂端色帶、LOGO、正式區徽章）；圖表內的紅一律保留給異常，
   資料系列維持藍色，避免品牌色與警示色在圖上互相干擾。
   圖表標記色沿用 dataviz 驗證過的步階：系列藍 #2a78d6、critical #d03b3b（已跑 validate_palette.js 通過）。 */

.viz-root {
    --page: #f8f4f0;                          /* 暖象牙白頁面底（配合品牌紅的暖色系） */
    --surface-1: #ffffff;                     /* 卡片表面 */
    --text-primary: #2b2724;                  /* 深暖褐灰（避免純黑） */
    --text-secondary: #5c554f;
    --muted: #8b837c;
    --grid: #ece5de;
    --baseline: #d6ccc2;
    --border: rgba(43, 39, 36, 0.10);
    --shadow-card: 0 1px 2px rgba(43, 39, 36, 0.05), 0 12px 32px -20px rgba(43, 39, 36, 0.28);
    --series-1: #2a78d6;                      /* 系列藍：筆數／回應時間 */
    --status-good: #006300;
    --status-good-bg: #e8f4e9;
    --status-good-border: #bfdec2;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;               /* 異常 */
    --status-critical-bg: #fdeceb;
    --status-critical-border: #f5c5c0;
    --brand-deep: #8f1d2c;                    /* 品牌紅漸層（頁面頂端色帶） */
    --brand-mid: #c8102e;
    --brand-fresh: #e4573f;
    /* 平均回應色階（>=3s 橘紅、>=5s 深紅；文字用深色版保對比，圖形可用 --status-serious） */
    --dur-warn-text: #b45416;                 /* 對白底 4.98:1 */
    --dur-crit: #9d1f1f;                      /* 對白底 7.93:1；刻意深於 --status-critical 以拉開層級 */
    --compare: #6b645e;                       /* 比對日參考線（中性灰，不與系列色/警示色打架） */
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, "Microsoft JhengHei", sans-serif;
}

.viz-root {
    min-height: 100vh;
    color: var(--text-primary);
    padding: 24px clamp(16px, 4vw, 44px) 44px;
    /* 頂端品牌色帶 + 兩側柔光暈染，讓底色有溫度而不灰 */
    border-top: 4px solid transparent;
    border-image: linear-gradient(90deg, var(--brand-deep), var(--brand-mid), var(--brand-fresh)) 1;
    background:
        radial-gradient(1100px 420px at 12% -8%, rgba(200, 16, 46, 0.07), transparent 60%),
        radial-gradient(900px 380px at 88% -10%, rgba(228, 130, 60, 0.07), transparent 55%),
        var(--page);
}

/* ── 頁首 ──
   Grid 三欄：左標題／中 LOGO／右狀態列。LOGO 在版面流內（不再絕對定位），
   瀏覽器會繞著它排版，任何寬度都不會重疊；左右欄過寬時各自內部換行。 */
.dash-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 14px 18px;
    margin-bottom: 22px;
}

/* 沒有 LOGO 的頁面（小時趨勢、行程健康）中欄留空，明確固定左右欄位置 */
.dash-header .brand-text { grid-column: 1; min-width: 0; }
.dash-header .dash-status { grid-column: 3; justify-self: end; justify-content: flex-end; }

.brand-logo {
    grid-column: 2;
    justify-self: center;
    height: 52px;            /* 原始 SVG 為 200×46，維持原比例、略放大 */
    width: auto;
    max-width: 300px;
    object-fit: contain;
}

/* 有 LOGO 時環境徽章平常隱藏（LOGO 本身已標示環境），窄螢幕才接手 */
.env-chip-fallback { display: none; }

/* 窄螢幕：退回單欄堆疊並隱藏 LOGO（空間留給資訊），環境識別交回徽章 */
@media (max-width: 720px) {
    .dash-header { display: flex; flex-wrap: wrap; }
    .brand-logo { display: none; }
    .env-chip-fallback { display: inline-block; }
}

.title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.dash-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.02em;
    margin: 0;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 4px 0 0;
}

/* 環境徽章：一眼區分測試／正式 */
.env-chip {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    padding: 3px 12px;
    border-radius: 999px;
    white-space: nowrap;
}

.env-test {
    color: #0f5cad;
    background: #e3effd;
    border: 1px solid #b7d5f7;
}

.env-prod {
    color: #a02121;
    background: #fde9e7;
    border: 1px solid #f5c1bc;
}

.dash-status {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 14px;
    box-shadow: 0 1px 2px rgba(23, 43, 77, 0.05);
}

.badge .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 7px;
    background: var(--muted);
}

.badge .dot-ok { background: var(--status-good); }
.badge .dot-stale { background: var(--status-serious); }
.badge .dot-error { background: var(--status-critical); }

/* 中台連線徽章的整體染色（狀態不只靠一顆點） */
.badge.is-ok {
    color: var(--status-good);
    background: var(--status-good-bg);
    border-color: var(--status-good-border);
}

.badge.is-bad {
    color: var(--status-critical);
    background: var(--status-critical-bg);
    border-color: var(--status-critical-border);
}

.countdown {
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* ── 指標卡 ── */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.tile {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: var(--shadow-card);
}

.tile-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
}

.tile-sub {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 12px;
    margin-left: 6px;
}

/* 統計卡副值（最慢 X ms／佔比 X%）：比主數字小一級的可讀資訊列 */
.tile-subvalue {
    margin-top: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.tile-subvalue.is-critical { color: var(--status-critical); }

.tile-value {
    font-size: 44px;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.tile-value.is-critical { color: var(--status-critical); }

/* ── 慢回應速度軸（三級：觀察／注意／異常，獨立於回應碼異常） ── */
.speed-tiers {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.speed-tier {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    border-radius: 10px;
    background: #faf6f1;
    border: 1px solid var(--border);
    min-width: 0;
}

.speed-tier-label { font-size: 12px; font-weight: 700; }

.speed-tier-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.speed-observe { color: #8a6d00; }                 /* 觀察：琥珀 */
.speed-attention { color: var(--dur-warn-text); }  /* 注意：橘 */
.speed-critical { color: var(--status-critical); } /* 異常：紅 */
.speed-tier-value.is-critical { color: var(--status-critical); }

/* 副標可點擊展開異常代碼清單（按鈕外觀還原成文字，虛線底標示可點） */
.tile-sub-toggle {
    font: inherit;
    font-weight: 400;
    color: var(--muted);
    font-size: 12px;
    margin-left: 6px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.tile-sub-toggle:hover { color: var(--text-secondary); }

.anomaly-codes {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--grid);
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 2;
}

.code-chip {
    display: inline-block;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--status-critical);
    background: var(--status-critical-bg);
    border: 1px solid var(--status-critical-border);
    border-radius: 6px;
    padding: 1px 8px;
    margin: 0 4px 2px 0;
}

.card-note {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── 圖表卡 ── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 20px 12px;
    box-shadow: var(--shadow-card);
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.card-head h2 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
}

.legend {
    display: flex;
    gap: 14px;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.swatch-normal { background: var(--series-1); }
.swatch-anomaly { background: var(--status-critical); }

.chart svg { width: 100%; height: auto; display: block; }

/* SVG 標記（顏色集中在此） */
.bar-normal { fill: var(--series-1); }
.bar-anomaly { fill: var(--status-critical); }
.line-path { stroke: var(--series-1); fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--baseline); stroke-width: 1; }
/* 可讀性規則（2026-07-19）：13px 以下的字不用淡灰 --muted（對白底對比僅 3.4:1，低於小字建議 4.5:1） */
.axis-label { fill: var(--text-secondary); font-size: 12px; font-variant-numeric: tabular-nums; }
.value-label { fill: var(--text-secondary); font-size: 12px; font-variant-numeric: tabular-nums; }
.hit { fill: transparent; }

/* ── 明細表 ── */
.card-table { padding-bottom: 18px; }

/* 窄螢幕表格自身橫捲，頁面不橫捲 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .detail-table { min-width: 480px; }

.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.detail-table th,
.detail-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--grid);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.detail-table th:first-child,
.detail-table td:first-child { text-align: left; }

.detail-table th {
    color: var(--text-secondary);
    font-weight: 700;
    background: #f8f2ec;
    border-bottom: 1px solid var(--baseline);
}

/* 資料是主角：內文用主色、字級升一級（表頭維持深灰粗體做層次） */
.detail-table td { color: var(--text-primary); font-size: 14px; }

.detail-table tbody tr:hover td { background: #faf6f1; }

.detail-table td.is-critical { color: var(--status-critical); font-weight: 600; }

/* ── Tooltip ── */
.tooltip {
    position: fixed;
    z-index: 10;
    pointer-events: none;
    background: var(--surface-1);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(23, 43, 77, 0.18);
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.6;
    font-variant-numeric: tabular-nums;
}

.tooltip .tt-title { font-weight: 700; }
.tooltip .tt-muted { color: var(--muted); }

/* ── 行程健康（/pidhealth） ── */
.nav-link { text-decoration: none; color: var(--text-secondary); }
.nav-link:hover { color: var(--text-primary); }

/* 主機狀態徽章（存活/預期不符時整體染紅） */
.badge.badge-bad {
    color: var(--status-critical);
    background: var(--status-critical-bg);
    border-color: var(--status-critical-border);
}

/* 主機卡片：頂端色條綠＝健康、紅＝有集區掛掉 */
.machine-card { border-top: 3px solid var(--status-good); }
.machine-card.is-degraded { border-top-color: var(--status-critical); }
.machine-card .card-head { margin-bottom: 10px; }

.ph-empty {
    background: var(--surface-1);
    border: 1px dashed var(--baseline);
    border-radius: 14px;
    padding: 28px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

/* 指標說明：單機時填補下方空白，讓內部檢視者不必回來問各欄意義 */
.ph-legend { margin-top: 4px; }
.ph-legend .card-head { margin-bottom: 8px; }
.ph-legend h2 { font-size: 14px; }
.ph-legend ul { margin: 0; padding-left: 18px; }
.ph-legend li { color: var(--text-secondary); font-size: 13px; line-height: 1.75; }
.ph-legend li + li { margin-top: 4px; }
.ph-legend strong { color: var(--text-primary); font-weight: 700; }

/* ── 篩選下拉（日期／比對日；即時監控與小時趨勢頁共用） ── */
.filter-select {
    font: inherit;
    font-size: 13px;
    color: var(--text-primary, inherit);
    background: transparent;
    border: 1px solid var(--border, rgba(127, 127, 127, 0.35));
    border-radius: 999px;
    padding: 4px 12px;
    cursor: pointer;
}
.filter-select:hover { border-color: var(--text-secondary, rgba(127, 127, 127, 0.7)); }
.filter-select option { color: initial; background: initial; }

/* ── FunctionId 多選下拉（function-picker.js） ── */
.function-picker { position: relative; display: inline-block; }

.fp-button {
    font: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 260px;
}
.fp-button > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-button:hover { border-color: var(--text-secondary); }
.fp-button.is-filtered {
    color: #0f5cad;
    background: #e3effd;
    border-color: #b7d5f7;
    font-weight: 600;
}
.fp-caret { font-size: 9px; color: var(--muted); }

.fp-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    min-width: 250px;
    max-width: 340px;
    max-height: 360px;
    overflow-y: auto;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(43, 39, 36, 0.20);
    padding: 8px;
    text-align: left;
}

.fp-section-title { font-size: 11px; color: var(--muted); padding: 6px 8px 4px; }

.fp-recent { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 8px 6px; }

.fp-recent-chip {
    font: inherit;
    font-size: 12px;
    color: var(--text-secondary);
    background: #faf6f1;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    cursor: pointer;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fp-recent-chip:hover { border-color: var(--text-secondary); color: var(--text-primary); }

.fp-divider { border-top: 1px dashed var(--grid); margin: 6px 0; }

.fp-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    width: 100%;
    background: none;
    border: none;
    font-family: inherit;
    text-align: left;
}
.fp-option:hover { background: #faf6f1; }
.fp-option input { accent-color: var(--series-1); margin: 0; }
.fp-all { font-weight: 600; color: var(--text-secondary); }
.fp-all.is-active { color: var(--series-1); }
.fp-empty { font-size: 12px; color: var(--muted); padding: 6px 8px; }

/* ── segmented control（圖卡檢視模式／熱力圖指標切換） ── */
.segmented {
    display: inline-flex;
    background: #f1eae3;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}

.seg-btn {
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 999px;
    padding: 3px 12px;
    cursor: pointer;
    white-space: nowrap;
}
.seg-btn:hover { color: var(--text-primary); }
.seg-btn.is-active {
    background: var(--surface-1);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(43, 39, 36, 0.12);
}

/* ── 平均回應色階（>=3s 橘紅、>=5s 深紅） ── */
.dur-warn { color: var(--dur-warn-text); font-weight: 600; }
.dur-crit { color: var(--dur-crit); font-weight: 700; }
.detail-table td.dur-warn { color: var(--dur-warn-text); font-weight: 600; }
.detail-table td.dur-crit { color: var(--dur-crit); font-weight: 700; }
/* SVG 文字用 fill、圖形標記點整顆換色（線維持系列藍，異常點一眼可辨） */
.marker.dur-warn { fill: var(--status-serious); }
.marker.dur-crit { fill: var(--dur-crit); }
.value-label.dur-warn { fill: var(--dur-warn-text); }
.value-label.dur-crit { fill: var(--dur-crit); }

/* ── 圖例（動態渲染版：位於 card-head 下方一行） ── */
.card > .legend { margin: 0 0 8px; flex-wrap: wrap; row-gap: 4px; min-height: 14px; }

.swatch-line {
    display: inline-block;
    width: 16px;
    height: 0;
    border-top: 2px solid var(--compare);
}
.swatch-line.dashed { border-top-style: dashed; }

/* 比對日參考線（SVG） */
.line-compare {
    stroke: var(--compare);
    fill: none;
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
}
.line-compare.dashed { stroke-dasharray: 5 4; }

/* tooltip 內的分類色圓點 */
.tt-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: baseline;
}

/* ── 明細表展開列（FunctionId 分解） ── */
tr.expandable { cursor: pointer; }

.detail-table tr.breakdown-row td {
    background: #faf6f1;
    text-align: left;
    padding: 8px 12px 10px 24px;
}

.breakdown-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    font-size: 12px;
    color: var(--text-secondary);
}

.breakdown-item { display: inline-flex; align-items: center; gap: 6px; }
.breakdown-item .is-critical { color: var(--status-critical); font-weight: 600; }

/* ── 多日熱力圖（小時趨勢頁） ── */
.heatmap { overflow-x: auto; padding: 4px 0 2px; }

.hm-grid {
    display: grid;
    gap: 3px;
    align-items: center;
    min-width: 620px;
}

.hm-rowlabel {
    font-size: 12px;
    color: var(--text-primary);   /* 原淡灰難讀；日期是查找的入口，用近黑 */
    padding-right: 8px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* 今天：藍色＋粗體，一眼定位 */
.hm-rowlabel.is-today { color: #0f5cad; font-weight: 700; }

.hm-collabel {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.hm-cell {
    height: 18px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(43, 39, 36, 0.06);
    background: #ffffff;
}
.hm-cell:hover { outline: 2px solid var(--text-secondary); outline-offset: -1px; }
.hm-cell.is-zero { background: #ffffff; }
.hm-cell.is-empty { background: #f3efe9; cursor: default; }
.hm-cell.is-empty:hover { outline: none; }

#hm-heatmap-card .legend { margin-top: 8px; }

/* ── 重點觀察（視窗內/當日 異常＋回應偏慢 前 5 名） ── */
.rank-list {
    list-style: none;
    counter-reset: rank;
    margin: 0;
    padding: 0;
}

.rank-list li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 2px;
    border-bottom: 1px solid var(--grid);
    font-size: 14px;
}
.rank-list li:last-child { border-bottom: none; }

.rank-list li:not(.rank-empty)::before {
    counter-increment: rank;
    content: counter(rank);
    flex: none;
    width: 20px;
    font-weight: 700;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.rank-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.rank-stat {
    flex: none;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.rank-stat.is-critical { color: var(--status-critical); }

.rank-empty { color: var(--text-secondary); font-size: 13px; }

/* ── ReturnCode 分佈 chips（異常明細面板頂部） ── */
.code-dist {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}
.code-dist[hidden] { display: none; }
.code-dist-note { font-size: 12px; color: var(--text-secondary); margin-left: 4px; }

/* ── RWD：窄螢幕補強（720px 沿既有頁首斷點；480px 再縮一級） ── */
@media (max-width: 720px) {
    .viz-root { padding: 16px 12px 32px; }
    .tile { padding: 14px 16px; }
    .tile-value { font-size: 36px; }
    .speed-tier-value { font-size: 22px; }
    .speed-tiers { gap: 6px; }
    .card { padding: 14px 14px 10px; }
    .cards { grid-template-columns: 1fr; } /* 圖卡改單欄吃滿寬，軸標籤才不會縮到難讀 */
    .detail-table td { font-size: 13px; }
    .detail-table th, .detail-table td { padding: 8px 9px; }
}

@media (max-width: 480px) {
    .tile-value { font-size: 30px; }
    .speed-tier { padding: 5px 7px; }
    .speed-tier-value { font-size: 19px; }
    .dash-header h1 { font-size: 20px; }
    .rank-list li { font-size: 13px; }
}
