/* ===== MB 盤前檢查 UI ===== */
:root {
  --bg: #0f1419;
  --bg-card: #1a2029;
  --bg-card-hover: #212a36;
  --border: #2d3748;
  --text: #e6edf3;
  --text-muted: #8b98a9;
  --primary: #4a9eff;
  --telegram: #2aabee;

  --status-ok: #2ea043;
  --status-info: #4a9eff;
  --status-warn: #d29922;
  --status-alert: #f85149;
  --status-error: #6e7681;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
               "Microsoft JhengHei", Roboto, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Topbar ---- */
.topbar {
  background: #161b22;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 600; }
.subtitle { margin: 0; font-size: 12px; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.date-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--bg-card-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #3a8ae0; }
.btn-telegram { background: var(--telegram); border-color: var(--telegram); color: #fff; }
.btn-telegram:hover { background: #1f97d4; }
.btn-ghost { background: transparent; border-color: transparent; padding: 6px 10px; font-size: 16px; }

/* ---- Summary bar ---- */
.container { max-width: 860px; margin: 0 auto; padding: 24px; }
.summary-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.pill {
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
}
.pill-blue { background: rgba(74,158,255,.15); border-color: var(--primary); color: #8ec5ff; }
.pill-red { background: rgba(248,81,73,.15); border-color: var(--status-alert); color: #ff9b96; }
.pill-gray { background: var(--bg-card); color: var(--text-muted); }
.pill:empty { display: none; }  /* Telegram 已設定時提示為空 → 隱藏空 pill */

/* ---- Card grid ---- */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  transition: opacity .2s, border-color .2s;
}
.card.disabled { opacity: .45; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.card-title-wrap { display: flex; align-items: center; gap: 10px; }
.status-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--status-error);
  flex-shrink: 0;
  border: 2px solid transparent;
}
.card[data-status="ok"]    .status-dot { background: var(--status-ok); }
.card[data-status="info"]  .status-dot { background: var(--status-info); }
.card[data-status="warn"]  .status-dot { background: var(--status-warn); }
.card[data-status="alert"] .status-dot { background: var(--status-alert); box-shadow: 0 0 8px var(--status-alert); }
.card[data-status="error"] .status-dot { background: var(--status-error); }

.card-title { margin: 0; font-size: 16px; font-weight: 600; }
.card-desc { margin: 0 0 10px; font-size: 12px; color: var(--text-muted); }
.card-controls { display: flex; align-items: center; gap: 6px; }

.card-summary {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  min-height: 36px;
}
.card-details {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.card-details li {
  padding: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.card-details li:empty { height: 8px; }

/* ---- 重點高亮 ---- */
.hl-num {
  color: var(--text);
  font-weight: 700;
}
.hl-bull { color: var(--status-ok); font-weight: 700; }
.hl-bear { color: var(--status-alert); font-weight: 700; }
.hl-key  { color: var(--status-warn); font-weight: 700; }

.card-details li.d-head {
  color: var(--text-muted);
  font-weight: 600;
  opacity: .8;
}
.card-details li.d-note {
  font-style: italic;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 2px;
  padding-left: 22px;
}
.card-details li.d-alert {
  color: var(--status-warn);
  font-weight: 600;
  background: rgba(210, 153, 34, .1);
  border-left: 3px solid var(--status-warn);
  padding-left: 8px;
  border-radius: 4px;
}
.card-summary .hl-num,
.card-summary .hl-bull,
.card-summary .hl-bear,
.card-summary .hl-key { font-weight: 700; }

/* ---- 圖表（C/D） ---- */
.card-chart {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.card-chart canvas {
  max-height: 180px;
  width: 100% !important;
}
.card-chart .chart-source {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}
.card-chart[hidden] { display: none; }
.card-chart .chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 8px;
}
.card-chart .chart-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.card-chart .chart-legend .legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* ---- 經濟數據表格（需求 B）---- */
.card-details .ec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 4px;
}
.card-details .ec-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.card-details .ec-table td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}
.card-details .ec-table th:nth-child(n+5),
.card-details .ec-table td:nth-child(n+5) { text-align: right; white-space: nowrap; }
.card-details .ec-table .ec-imp { color: var(--status-warn); letter-spacing: 1px; white-space: nowrap; }
.card-details .ec-date { text-align: center; font-weight: 600; color: var(--text); padding: 6px 0; }
.card-details .ec-demo { color: var(--status-warn); font-size: 12px; margin-bottom: 4px; }
.card-details .ec-remind {
  margin-top: 8px;
  color: var(--status-warn);
  background: rgba(210, 153, 34, .1);
  border-left: 3px solid var(--status-warn);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---- Telegram 設定 modal（需求 B）---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.modal-box h3 { margin: 0 0 16px; font-size: 16px; }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--primary); }
.tab-panel[hidden] { display: none; }
.modal-field { display: block; margin-bottom: 14px; }
.modal-field span {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.modal-field input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
}
.modal-field input:focus { outline: none; border-color: var(--primary); }
.modal-hint { font-size: 12px; color: var(--text-muted); line-height: 1.6; margin: 4px 0 10px; }
.modal-status { font-size: 13px; color: var(--text-muted); min-height: 18px; margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-adv { margin-bottom: 12px; }
.modal-adv summary { font-size: 12px; color: var(--text-muted); cursor: pointer; }
.modal-adv .adv-row { display: flex; gap: 10px; margin-top: 8px; }
.modal-adv .adv-row label { flex: 1; font-size: 12px; color: var(--text-muted); }
.modal-adv .adv-row input {
  width: 100%; box-sizing: border-box; margin-top: 4px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; color: var(--text); font-size: 13px;
}
.em-recip { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }
.em-recip-head { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.em-list { list-style: none; padding: 0; margin: 0 0 8px; }
.em-item { display: flex; gap: 8px; margin-bottom: 6px; }
.em-item .em-edit {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text); font-size: 13px;
}
.em-item .em-del {
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; padding: 0 10px; font-size: 13px;
}
.em-add { display: flex; gap: 8px; }
.em-add input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text); font-size: 13px;
}
.sched-note { font-size: 11px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }

/* ---- Toggle switch ---- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #3a4250; border-radius: 24px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 18px; width: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ---- States ---- */
.skeleton {
  display: inline-block;
  color: var(--text-muted);
  font-weight: 400;
}
.card.loading .card-summary,
.card.loading .card-details { opacity: .5; }

/* ---- 警示項目 highlight（B） ---- */
/* warn 黃警：摘要加粗放大、邊框帶黃光 */
.card[data-status="warn"] {
  border-color: var(--status-warn);
  box-shadow: 0 0 0 1px var(--status-warn), 0 4px 16px rgba(210,153,34,.18);
}
.card[data-status="warn"] .card-summary {
  color: #ffcf5c;
  font-size: 16px;
  font-weight: 700;
}
.card[data-status="warn"] .card-details {
  color: #e6edf3;
  font-weight: 500;
}
/* alert 紅警：最強 highlight、邊框紅光閃爍 */
.card[data-status="alert"] {
  border-color: var(--status-alert);
  box-shadow: 0 0 0 1px var(--status-alert), 0 4px 18px rgba(248,81,73,.25);
}
.card[data-status="alert"] .card-summary {
  color: #ff6b63;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .3px;
}
.card[data-status="alert"] .card-details {
  color: #ffd6d4;
  font-weight: 600;
}
.card[data-status="alert"] .card-title {
  color: #ff9b96;
}
/* 警示內容中含 ⚠️ / 🔴 的行特別標示 */
.card[data-status="warn"] .card-details li,
.card[data-status="alert"] .card-details li {
  line-height: 1.7;
}

/* ---- Footer ---- */
.footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  text-align: center;
}
.muted { color: var(--text-muted); font-size: 12px; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #161b22;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 100;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: var(--status-ok); }
#toast.error { border-color: var(--status-alert); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .card-grid { grid-template-columns: 1fr; }
  .topbar-actions .btn { font-size: 13px; padding: 7px 12px; }
}
