:root {
  --msd-bg: #f5f7fb;
  --msd-card-bg: #ffffff;
  --msd-text: #1f2937;
  --msd-muted: #64748b;
  --msd-border: #dbe4ef;
  --msd-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --msd-shadow-md: 0 8px 22px rgba(15, 23, 42, 0.1);
  --msd-primary: #6366f1;
  --msd-primary-dark: #4f46e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', sans-serif;
  background: var(--msd-bg);
  color: var(--msd-text);
}

.page-container {
  min-height: 100vh;
  padding: 16px;
  max-width: 1800px;
  margin: 0 auto;
}

/* ====== Header ====== */
.page-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  border-radius: 12px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: var(--msd-shadow-md);
}

.page-header h1 {
  margin: 0;
  color: #ffffff;
  font-size: 24px;
  letter-spacing: 0.2px;
}

.header-desc {
  margin: 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

/* ====== Section Card ====== */
.section-card {
  background: var(--msd-card-bg);
  border-radius: 12px;
  box-shadow: var(--msd-shadow);
  margin-bottom: 16px;
}

.section-inner {
  padding: 16px 20px;
}

.section-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
}

/* ====== Filter Bar ====== */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.filter-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-field label {
  font-size: 13px;
  color: #475569;
  white-space: nowrap;
}

.filter-field input[type='date'] {
  border: 1px solid var(--msd-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  background: #ffffff;
  color: #1f2937;
}

/* ====== Buttons ====== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--msd-primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--msd-primary-dark);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-sm {
  border: 1px solid var(--msd-border);
  border-radius: 6px;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}

.btn-sm:hover:not(:disabled) {
  background: #f1f5f9;
}

/* ====== MultiSelect ====== */
.multi-select {
  position: relative;
  min-width: 200px;
}

.multi-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--msd-border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: #1f2937;
  background: #ffffff;
  cursor: pointer;
}

.multi-select-trigger:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.multi-select-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-select-arrow {
  flex-shrink: 0;
  font-size: 10px;
  color: #94a3b8;
}

.multi-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #ffffff;
  border: 1px solid var(--msd-border);
  border-radius: 8px;
  box-shadow: var(--msd-shadow-md);
  z-index: 100;
  max-height: 300px;
  display: flex;
  flex-direction: column;
}

.multi-select-options {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.multi-select-option:hover {
  background: #f1f5f9;
}

.multi-select-option input[type='checkbox'] {
  pointer-events: none;
}

.multi-select-actions {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--msd-border);
  background: #f8fafc;
  border-radius: 0 0 8px 8px;
}

/* ====== Error / Warning Banners ====== */
.error-banner {
  padding: 12px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #dc2626;
  font-size: 14px;
  margin-bottom: 16px;
}

.warning-banner {
  padding: 12px 16px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: #b45309;
  font-size: 14px;
  margin-bottom: 16px;
}

/* ====== KPI Cards ====== */
.kpi-section {
  margin-bottom: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.kpi-card {
  background: var(--msd-card-bg);
  border-radius: 10px;
  box-shadow: var(--msd-shadow);
  padding: 16px;
  border-top: 3px solid #6366f1;
}

.kpi-label {
  font-size: 12px;
  color: var(--msd-muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.kpi-value.kpi-text {
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
}

.kpi-unit {
  font-size: 12px;
  font-weight: 400;
  color: var(--msd-muted);
}

/* ====== Charts ====== */
.charts-section {
  margin-bottom: 16px;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.charts-row-full {
  grid-template-columns: 1fr;
}

.chart-card {
  background: var(--msd-card-bg);
  border-radius: 10px;
  box-shadow: var(--msd-shadow);
  padding: 16px;
}

.chart-card-full {
  grid-column: 1 / -1;
}

.chart-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--msd-text);
}

.chart-canvas {
  width: 100%;
  height: 320px;
}

.chart-canvas-wide {
  height: 280px;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--msd-muted);
  font-size: 14px;
}

/* ====== Detail Table ====== */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-count {
  font-size: 13px;
  color: var(--msd-muted);
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--msd-border);
  border-radius: 8px;
}

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

.detail-table th {
  background: #f1f5f9;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: #475569;
  white-space: nowrap;
  border-bottom: 2px solid var(--msd-border);
  position: sticky;
  top: 0;
}

.detail-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.detail-table th.sortable:hover {
  background: #e2e8f0;
}

.detail-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

.detail-table td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.empty-row {
  text-align: center;
  padding: 32px;
  color: var(--msd-muted);
}

/* ====== Pagination ====== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--msd-border);
}

.pagination button {
  padding: 8px 16px;
  border: 1px solid var(--msd-border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--msd-primary);
  color: var(--msd-primary);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination .page-info {
  font-size: 13px;
  color: var(--msd-muted);
}

/* ====== Empty State ====== */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--msd-muted);
  font-size: 15px;
}

/* ====== Trace Skeleton ====== */
.trace-skeleton-section {
  margin-bottom: 16px;
}

.trace-skeleton-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.trace-skeleton-card {
  min-height: 100px;
  border-radius: 10px;
  background: #e5eaf2;
  box-shadow: var(--msd-shadow);
}

.trace-skeleton-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.trace-skeleton-chart {
  min-height: 300px;
  border-radius: 10px;
  background: #e5eaf2;
  box-shadow: var(--msd-shadow);
}

.trace-skeleton-trend {
  grid-column: 1 / -1;
}

.trace-skeleton-pulse {
  animation: trace-skeleton-pulse 1.2s ease-in-out infinite;
}

.trace-fade-enter-active,
.trace-fade-leave-active {
  transition: opacity 0.3s ease-in;
}

.trace-fade-enter-from,
.trace-fade-leave-to {
  opacity: 0;
}

@keyframes trace-skeleton-pulse {
  0% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.5;
  }
}

@media (max-width: 1200px) {
  .trace-skeleton-chart-grid {
    grid-template-columns: 1fr;
  }
}
