/* ====================================================================
   DSB - KPI 儀表板樣式
   ==================================================================== */

.dsb-page {
  min-height: calc(100vh - var(--app-toolbar-height));
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
  padding: 16px;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

.dsb-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 4px;
}
.dsb-page-title {
  font-size: 22px;
  font-weight: 600;
  color: #f8fafc;
  letter-spacing: 1px;
}
.dsb-page-meta {
  font-size: 13px;
  color: #94a3b8;
}
.dsb-page-meta .dsb-status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 6px;
  animation: dsb-pulse 1.6s ease-in-out infinite;
}

@keyframes dsb-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== 期間 / 粒度 工具列 ===== */
.dsb-range-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #334155;
  border-radius: 8px;
}
.dsb-range-bar label { color: #94a3b8; font-size: 13px; margin: 0; }
.dsb-range-sep { color: #475569; }
.dsb-range-quick { display: inline-flex; gap: 6px; }
.dsb-chip {
  border: 1px solid #475569;
  background: transparent;
  color: #cbd5e1;
  font-size: 13px;
  padding: 3px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
}
.dsb-chip:hover { border-color: #64748b; color: #f1f5f9; }
.dsb-chip.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

/* ===== 燈號 ===== */
.dsb-light-G { color: #22c55e; }
.dsb-light-Y { color: #facc15; }
.dsb-light-R { color: #ef4444; }
.dsb-light-bg-G { background: rgba(34, 197, 94, 0.15); border: 1px solid rgba(34, 197, 94, 0.35); }
.dsb-light-bg-Y { background: rgba(250, 204, 21, 0.15); border: 1px solid rgba(250, 204, 21, 0.35); }
.dsb-light-bg-R { background: rgba(239, 68, 68, 0.18); border: 1px solid rgba(239, 68, 68, 0.45); }
.dsb-light-bg-N { background: rgba(148, 163, 184, 0.12); border: 1px solid rgba(148, 163, 184, 0.3); }

.dsb-card.dsb-light-R {
  animation: dsb-red-breath 2.4s ease-in-out infinite;
}
@keyframes dsb-red-breath {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
  50% { box-shadow: 0 0 24px 2px rgba(239, 68, 68, 0.55); }
}

/* ===== 總覽牆 ===== */
.dsb-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.dsb-overview-card {
  background: #1e293b;
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.15s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}
.dsb-overview-card:hover {
  transform: translateY(-2px);
  color: inherit;
}
.dsb-overview-card .dsb-cat {
  font-size: 11px;
  color: #94a3b8;
  letter-spacing: 0.5px;
}
.dsb-overview-card .dsb-name {
  font-size: 15px;
  font-weight: 600;
  color: #f1f5f9;
  margin: 4px 0 10px;
}
.dsb-overview-card .dsb-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.dsb-overview-card .dsb-unit {
  font-size: 14px;
  color: #94a3b8;
  margin-left: 4px;
}
.dsb-overview-card .dsb-time {
  font-size: 11px;
  color: #64748b;
  margin-top: 6px;
}
.dsb-overview-empty {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}

/* ===== 部門儀表板 (Grid) ===== */
.dsb-board-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 90px;
  gap: 14px;
}
.dsb-card {
  background: #1e293b;
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.dsb-card:hover {
  transform: translateY(-2px);
}
.dsb-card .dsb-card-title {
  font-size: 13px;
  color: #cbd5e1;
  margin: 0 0 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dsb-card .dsb-card-title .dsb-card-light {
  font-size: 16px;
}
.dsb-card .dsb-card-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
}
.dsb-card .dsb-card-value .dsb-unit { font-size: 14px; color: #94a3b8; margin-left: 4px; }
/* 趨勢折線卡：較小的數值 + 較大的折線圖 */
.dsb-card .dsb-card-value.dsb-card-value-sm { font-size: 18px; }
.dsb-card .dsb-card-spark {
  flex: 1;
  min-height: 30px;
}
.dsb-card .dsb-card-line {
  flex: 1;
  min-height: 90px;
}
.dsb-card .dsb-card-gauge {
  flex: 1;
  min-height: 100px;
}
.dsb-card .dsb-card-footer {
  font-size: 11px;
  color: #64748b;
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
}

/* ===== 未確認告警面板 ===== */
.dsb-alert-panel {
  background: #1e293b;
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 16px;
}
.dsb-alert-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.dsb-alert-panel-header h5 {
  margin: 0; font-size: 15px; color: #f1f5f9;
}
.dsb-alert-list {
  max-height: 260px;
  overflow-y: auto;
}
.dsb-alert-item {
  display: grid;
  grid-template-columns: 110px 1fr 80px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px 6px;
  border-bottom: 1px solid #334155;
  font-size: 13px;
}
.dsb-alert-item:last-child { border-bottom: none; }
.dsb-alert-time { color: #94a3b8; font-family: monospace; }
.dsb-alert-name { color: #f1f5f9; font-weight: 500; }
.dsb-alert-trans { color: #cbd5e1; text-align: center; }
.dsb-alert-value { color: #fbbf24; font-weight: 600; }
.dsb-alert-actions button {
  background: #334155;
  color: #e2e8f0;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
.dsb-alert-actions button:hover { background: #475569; }

/* ===== 下鑽頁 ===== */
.dsb-drilldown {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
.dsb-drilldown-chart {
  background: #1e293b;
  border-radius: 12px;
  padding: 14px;
  min-height: 420px;
}
.dsb-drilldown-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dsb-info-card {
  background: #1e293b;
  border-radius: 12px;
  padding: 14px 16px;
}
.dsb-info-card h6 {
  font-size: 13px; color: #94a3b8; margin: 0 0 8px;
  text-transform: uppercase; letter-spacing: 1px;
}
.dsb-info-card table { width: 100%; font-size: 13px; }
.dsb-info-card table td { padding: 4px 0; color: #e2e8f0; }
.dsb-info-card table td:first-child { color: #94a3b8; width: 90px; }

/* ===== KPI 邏輯說明 Modal ===== */
.dsb-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  backdrop-filter: blur(2px);
}
.dsb-modal {
  background: #1e293b;
  color: #e2e8f0;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dsb-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}
.dsb-modal-title { font-size: 18px; font-weight: 600; color: #f8fafc; }
.dsb-modal-sub { font-size: 12px; color: #94a3b8; margin-top: 4px; letter-spacing: 0.4px; }
.dsb-modal-close {
  background: transparent;
  color: #94a3b8;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
}
.dsb-modal-close:hover { color: #f1f5f9; }
.dsb-modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
}

.dsb-info-section {
  background: rgba(15, 23, 42, 0.4);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.dsb-info-section:last-child { margin-bottom: 0; }
.dsb-info-label {
  font-size: 12px;
  color: #94a3b8;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.dsb-info-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.dsb-info-col { text-align: left; }
.dsb-info-value { font-size: 20px; font-weight: 700; }
.dsb-info-formula {
  font-size: 16px;
  font-weight: 600;
  color: #93c5fd;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  padding: 4px 0;
}
.dsb-logic-body {
  font-size: 13px;
  line-height: 1.7;
  color: #e2e8f0;
}
.dsb-logic-h {
  color: #fbbf24;
  font-weight: 600;
  margin-top: 8px;
  margin-bottom: 2px;
}
.dsb-logic-h:first-child { margin-top: 0; }
.dsb-info-tbl {
  width: 100%;
  font-size: 13px;
}
.dsb-info-tbl td {
  padding: 4px 6px;
  border-bottom: 1px solid #334155;
}
.dsb-info-tbl tr:last-child td { border-bottom: none; }
.dsb-info-sql {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  margin-top: 8px;
  max-height: 280px;
  white-space: pre;
}
.dsb-info-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.dsb-info-error code {
  color: #fecaca;
  font-size: 12px;
}
.dsb-info-actions {
  background: transparent;
  text-align: right;
  padding: 4px 0;
}
.dsb-info-link {
  color: #60a5fa;
  text-decoration: none;
  font-size: 13px;
}
.dsb-info-link:hover { color: #93c5fd; }

/* ===== 卡片 ℹ️ 按鈕 ===== */
.dsb-info-btn {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  line-height: 20px;
  padding: 0;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.dsb-info-btn:hover {
  background: rgba(96, 165, 250, 0.4);
  color: #f1f5f9;
}

/* ===== Toolbar KPI 儀表板按鈕 ===== */
.kpi-overview-btn {
  position: relative;
}
.kpi-red-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
  animation: dsb-badge-pulse 1.8s ease-in-out infinite;
}
@keyframes dsb-badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
