/* 宜睿中台 監控儀表板
   亮色單一主題（營運牆面用，刻意不做深色模式以避免灰黑觀感）。
   品牌紅只用在「外框」（頂端色帶、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;
}

* { 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);
}

/* ── 頁首 ── */
.dash-header {
    position: relative;      /* LOGO 絕對定位的基準 */
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 22px;
}

/* LOGO 置中且脫離版面流：兩側內容變寬變窄都不會推動它 */
.brand-logo {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    height: 52px;            /* 原始 SVG 為 200×46，維持原比例、略放大 */
    width: auto;
    max-width: 300px;
    object-fit: contain;
}

/* 有 LOGO 時環境徽章平常隱藏（LOGO 本身已標示環境），窄螢幕才接手 */
.env-chip-fallback { display: none; }

/* 窄螢幕時置中的 LOGO 會壓到標題／徽章：隱藏 LOGO、改由環境徽章識別 */
@media (max-width: 960px) {
    .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(--muted);
    font-size: 12px;
    margin-left: 6px;
}

.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); }

/* 副標可點擊展開異常代碼清單（按鈕外觀還原成文字，虛線底標示可點） */
.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(--muted);
}

/* ── 圖表卡 ── */
.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; }
.axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.value-label { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.hit { fill: transparent; }

/* ── 明細表 ── */
.card-table { padding-bottom: 18px; }

.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-secondary); }

.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: 12px;
    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; }
