:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #dfe4ec;
  --border-strong: #c7d0dc;
  --text: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --blue: #1769e0;
  --blue-weak: #eaf2ff;
  --green: #138a4a;
  --green-weak: #e8f7ef;
  --red: #c92a2a;
  --red-weak: #fff0f0;
  --amber: #b76a00;
  --amber-weak: #fff6df;
  --violet: #6d3fc4;
  --violet-weak: #f3efff;
  --slate-weak: #edf1f6;
  --shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-width: 1180px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 330px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.25;
}

.global-controls {
  display: grid;
  grid-template-columns: 168px;
  align-items: end;
  gap: 10px;
}

.control,
.field {
  display: grid;
  gap: 6px;
}

.control span,
.field span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  height: 34px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  white-space: nowrap;
}

.btn:hover {
  border-color: #9eb0c5;
  background: #fbfcff;
}

.btn.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.btn.primary:hover {
  background: #105bc6;
}

.btn.link {
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue);
}

.btn.link.warning {
  color: var(--amber);
}

.btn.link.muted {
  color: var(--muted);
}

.icon-btn {
  width: 34px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.workspace {
  display: grid;
  gap: 14px;
  padding: 16px 24px 28px;
}

.metric,
.table-block,
.filter-grid {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
}

.metric .value {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 750;
  line-height: 1.1;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab {
  min-width: 150px;
  height: 42px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--blue);
  color: var(--blue);
  font-weight: 700;
}

.tab-panel {
  display: none;
  gap: 14px;
}

.tab-panel.active {
  display: grid;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(118px, 1fr));
  gap: 12px;
  align-items: end;
  padding: 14px;
}

.span-2 {
  grid-column: span 2;
}

.range {
  display: grid;
  grid-template-columns: 1fr 20px 1fr;
  gap: 6px;
  align-items: center;
}

.range.compact {
  grid-template-columns: 1fr 112px;
}

.range i {
  color: var(--muted);
  font-style: normal;
  text-align: center;
}

.filter-actions {
  display: flex;
  gap: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(116px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 86px;
  padding: 12px;
}

.value.green {
  color: var(--green);
}

.value.red {
  color: var(--red);
}

.value.amber {
  color: var(--amber);
}

.value.violet {
  color: var(--violet);
}

.table-block {
  overflow: hidden;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 0;
}

.section-title h2 {
  font-size: 15px;
  line-height: 1.35;
}

.table-scroll {
  max-height: 610px;
  margin-top: 12px;
  overflow: auto;
  border-top: 1px solid var(--border);
}

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

.data-table th,
.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #475569;
  font-weight: 650;
}

.data-table tbody tr:hover td {
  background: #fbfdff;
}

.data-table tbody tr.ignored td {
  background: #fafafa;
  color: var(--muted);
}

.ops {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.badge.red {
  background: var(--red-weak);
  color: var(--red);
}

.badge.green {
  background: var(--green-weak);
  color: var(--green);
}

.badge.amber {
  background: var(--amber-weak);
  color: var(--amber);
}

.badge.blue {
  background: var(--blue-weak);
  color: var(--blue);
}

.badge.violet {
  background: var(--violet-weak);
  color: var(--violet);
}

.badge.gray {
  background: var(--slate-weak);
  color: #475569;
}

.empty-state {
  padding: 42px 12px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 80;
  display: none;
  max-width: 520px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 8px;
  background: #172033;
  color: #fff;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.2);
}

.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.38);
}

.drawer {
  position: fixed;
  top: 0;
  right: -760px;
  z-index: 70;
  display: flex;
  width: 760px;
  max-width: 100vw;
  height: 100vh;
  flex-direction: column;
  background: #fff;
  box-shadow: -20px 0 34px rgba(15, 23, 42, 0.22);
  transition: right 0.22s ease;
}

.drawer.show {
  right: 0;
}

.drawer-header,
.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.drawer-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

.drawer-header h2 {
  font-size: 18px;
}

.drawer-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.detail-group {
  margin-bottom: 18px;
}

.detail-title {
  margin-bottom: 10px;
  padding-left: 8px;
  border-left: 3px solid var(--blue);
  font-weight: 750;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 16px;
}

.detail-cell {
  min-width: 0;
}

.detail-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-value {
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.chart-box {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.hour-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
}

.hour-cell {
  display: grid;
  height: 30px;
  place-items: center;
  border: 1px solid #bbefd0;
  border-radius: 6px;
  background: var(--green-weak);
  color: var(--green);
  font-size: 11px;
}

.hour-cell.missing {
  border-color: #ffb5b5;
  background: var(--red-weak);
  color: var(--red);
  font-weight: 750;
}

.line-chart {
  position: relative;
  height: 220px;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  background: linear-gradient(to bottom, transparent 24%, #edf1f6 25%, transparent 26%, transparent 49%, #edf1f6 50%, transparent 51%, transparent 74%, #edf1f6 75%, transparent 76%);
}

.line-chart svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.threshold {
  position: absolute;
  top: 35%;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--red);
}

.threshold-label {
  position: absolute;
  top: calc(35% - 20px);
  right: 4px;
  color: var(--red);
  font-size: 12px;
}

.bar-compare {
  display: grid;
  gap: 12px;
}

.compare-row {
  display: grid;
  grid-template-columns: 130px 1fr 96px;
  gap: 10px;
  align-items: center;
}

.bar-bg {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9eef5;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--blue);
}

.bar-fill.red {
  background: var(--red);
}

.bar-fill.amber {
  background: var(--amber);
}

.chart-note {
  margin-top: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1280px) {
  .app-shell {
    min-width: 0;
  }

  .topbar,
  .global-controls {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .global-controls,
  .filter-grid {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand {
    min-width: 0;
  }

  .global-controls,
  .filter-grid,
  .metric-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .tabs {
    overflow-x: auto;
  }
}
