:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1929;
  --surface-2: #111f32;
  --surface-3: #16263b;
  --line: #263a54;
  --line-soft: #1d2e44;
  --text: #edf5ff;
  --text-2: #afc0d5;
  --muted: #7f95af;
  --blue: #62a9ff;
  --green: #55d9aa;
  --amber: #ffbd55;
  --red: #ff727d;
  --radius: 12px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; }
body { margin: 0; overflow: hidden; color: var(--text); background: var(--bg); }
button, select, input { font: inherit; }
button, select, a {
  min-height: 36px;
  border: 1px solid #314863;
  border-radius: 8px;
  color: #dce9f8;
  background: #101e31;
}
button, a { cursor: pointer; }
button:hover, a:hover { border-color: #4c7098; background: #172a42; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-decoration: none;
}

.screen-shell { height: 100dvh; min-height: 0; overflow: hidden; }
.topbar {
  height: 62px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}
.top-clock {
  grid-column: 2;
  display: grid;
  justify-items: center;
  gap: 2px;
}
.top-clock time { font-size: 1.06rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.top-clock span { color: var(--muted); font-size: .76rem; }
.topbar nav { grid-column: 3; display: flex; justify-content: flex-end; gap: 8px; }
.topbar nav button { padding: 0 14px; }

.dashboard {
  height: calc(100dvh - 62px);
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: var(--traffic-panel-height, 310px) minmax(280px, 1fr);
  gap: 10px;
  padding: 12px;
}

.panel {
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.panel > header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.panel > header h2 { margin: 0; font-size: 1.08rem; }
.panel > header span { color: var(--muted); font-size: .8rem; }
.traffic-panel {
  grid-column: 1 / -1;
  grid-row: 1;
  display: grid;
  grid-template-rows: 50px 70px 42px minmax(0, 1fr);
}
.traffic-panel > header > div { display: flex; align-items: baseline; gap: 10px; }
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--amber);
  font-size: .8rem;
  font-weight: 600;
}
.live-badge::before { width: 7px; height: 7px; content: ""; border-radius: 50%; background: currentColor; }
.live-badge[data-tone="success"] { color: var(--green); }
.live-badge[data-tone="error"] { color: var(--red); }

.traffic-metrics {
  display: grid;
  grid-template-columns: 1fr 1.35fr repeat(4, 1fr);
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.traffic-metrics article {
  min-width: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  padding: 8px 12px;
  text-align: center;
}
.traffic-metrics article + article { border-left: 1px solid var(--line); }
.traffic-metrics span { color: var(--muted); font-size: .78rem; }
.traffic-metrics strong {
  overflow: hidden;
  color: var(--text);
  font-size: 1.38rem;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.traffic-metrics article:nth-child(2) strong { color: var(--blue); }
.traffic-metrics article:nth-child(4) strong { color: var(--green); }

.traffic-toolbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.traffic-toolbar > span { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.type-filters { min-width: 0; display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; }
.type-filters::-webkit-scrollbar { display: none; }
.type-filters button { min-height: 30px; padding: 0 12px; border-color: transparent; background: transparent; white-space: nowrap; }
.type-filters button:hover { border-color: #304964; background: #14243a; }
.type-filters button[aria-selected="true"] { border-color: #3d6da3; color: white; background: #1b3b63; }
.type-filters b { margin-left: 4px; color: inherit; }

.traffic-table-wrap, .task-table-wrap { min-height: 0; overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td {
  height: 42px;
  padding: 5px 8px;
  overflow: hidden;
  border-bottom: 1px solid var(--line-soft);
  text-align: center;
  text-overflow: ellipsis;
}
.traffic-table th, .traffic-table td { height: clamp(42px, 4.45vh, 48px); }
th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: #a9bdd4;
  background: #0d1929;
  font-size: .78rem;
  font-weight: 600;
}
td { color: #d7e4f2; font-size: .84rem; }
tbody tr:hover td { background: #122239; }
.traffic-table th:nth-child(1) { width: 7%; }
.traffic-table th:nth-child(2) { width: 20%; }
.traffic-table th:nth-child(3) { width: 12%; }
.traffic-table th:nth-child(4) { width: 15%; }
.traffic-table th:nth-child(5) { width: 9%; }
.traffic-table th:nth-child(6) { width: 9%; }
.traffic-table th:nth-child(7) { width: 11%; }
.traffic-table th:nth-child(8) { width: 10%; }
.traffic-table th:nth-child(9) { width: 7%; }
.traffic-row[data-active="true"] td { background: #102438; }
.traffic-row[data-active="true"]:hover td { background: #142b43; }
.type-tag {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--text-2);
  background: var(--surface-3);
}
.type-tag[data-type="music"], .type-tag[data-type="audio"] { color: #ffd17c; }
.type-tag[data-type="image"], .type-tag[data-type="video"] { color: #9bc5ff; }
.model-identity strong, .model-identity small, .task-copy strong, .task-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-identity small, .task-copy small { margin-top: 2px; color: var(--muted); }
.concurrency-value { display: block; color: var(--green); font-size: .98rem; font-variant-numeric: tabular-nums; }
.concurrency-track { width: 72px; height: 3px; display: block; margin: 4px auto 0; overflow: hidden; border-radius: 3px; background: #293a50; }
.concurrency-track i { height: 100%; display: block; background: var(--green); }
.traffic-users { overflow: hidden; color: var(--text-2); white-space: nowrap; text-overflow: ellipsis; }
.traffic-users b { color: var(--blue); }
.metric-main { color: var(--text); font-variant-numeric: tabular-nums; }
.metric-sub { display: block; margin-top: 1px; color: var(--muted); font-size: .72rem; }
.traffic-state { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.traffic-state::before { width: 6px; height: 6px; content: ""; border-radius: 50%; background: var(--muted); }
.traffic-state[data-state="calling"] { color: var(--green); }
.traffic-state[data-state="calling"]::before { background: var(--green); }
.traffic-state[data-state="waiting"], .traffic-state[data-state="degraded"] { color: var(--amber); }
.traffic-state[data-state="waiting"]::before, .traffic-state[data-state="degraded"]::before { background: var(--amber); }
.traffic-state[data-state="unhealthy"] { color: var(--red); }
.traffic-state[data-state="unhealthy"]::before { background: var(--red); }

.tasks-panel {
  grid-column: 1 / 9;
  grid-row: 2;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr) 38px;
}
.tasks-header { display: grid !important; grid-template-columns: minmax(160px, 1fr) auto auto; }
.tasks-order { color: var(--muted); font-size: .78rem; }
.tasks-header select { width: 112px; justify-self: end; padding: 0 9px; }
.tasks-table th:nth-child(1) { width: 13%; }
.tasks-table th:nth-child(2) { width: 10%; }
.tasks-table th:nth-child(3) { width: 20%; }
.tasks-table th:nth-child(4) { width: 15%; }
.tasks-table th:nth-child(5) { width: 15%; }
.tasks-table th:nth-child(6) { width: 14%; }
.tasks-table th:nth-child(7) { width: 13%; }
.task-user small { display: block; margin-top: 2px; color: var(--muted); }
.task-status { color: var(--text-2); font-weight: 700; }
.task-status[data-tone="active"] { color: var(--blue); }
.task-status[data-tone="waiting"],
.task-status[data-tone="warning"] { color: var(--amber); }
.task-status[data-tone="success"] { color: var(--green); }
.task-status[data-tone="danger"] { color: var(--red); }
.task-status[data-tone="muted"] { color: var(--muted); }
.task-duration { color: var(--text); font-variant-numeric: tabular-nums; }
.progress { display: flex; align-items: center; justify-content: center; gap: 6px; }
.progress span { width: 50px; height: 4px; overflow: hidden; border-radius: 4px; background: #293a50; }
.progress i { height: 100%; display: block; background: var(--blue); }
.tasks-panel footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 3px 12px;
  border-top: 1px solid var(--line-soft);
}
.tasks-panel footer button { min-height: 28px; padding: 0 10px; }
.tasks-panel footer span { min-width: 86px; color: var(--text-2); text-align: center; }
.tasks-panel footer em { position: absolute; right: 14px; color: var(--muted); font-style: normal; }

.operations-panel {
  grid-column: 9 / -1;
  grid-row: 2;
  display: grid;
  grid-template-rows: 50px auto minmax(0, 1fr);
}
.queue-lanes { border-bottom: 1px solid var(--line-soft); }
.queue-grid {
  display: grid;
  grid-template-columns: minmax(100px, 1.2fr) .85fr .7fr 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  text-align: center;
}
.queue-grid > :first-child { text-align: left; }
.queue-grid-head { min-height: 34px; color: var(--muted); background: var(--surface-2); font-size: .72rem; }
.queue-grid-row { min-height: 50px; border-top: 1px solid var(--line-soft); }
.queue-grid-row strong { color: var(--text-2); font-size: .84rem; }
.queue-grid-row b { color: var(--text); font-size: .96rem; font-variant-numeric: tabular-nums; }
.queue-grid-row[data-pressure="waiting"] b:nth-child(2),
.queue-grid-row[data-pressure="full"] b:nth-child(2),
.queue-grid-row[data-pressure="full"] b:nth-child(4) { color: var(--amber); }
.alerts { min-height: 0; overflow-y: auto; }
.queue-notice { min-height: 48px; display: grid; grid-template-columns: 82px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line-soft); }
.queue-notice span { color: var(--muted); font-size: .76rem; }
.queue-notice strong { overflow: hidden; font-size: .84rem; text-overflow: ellipsis; white-space: nowrap; }
.queue-notice b { color: var(--amber); white-space: nowrap; }
.queue-notice[data-tone="danger"] b { color: var(--red); }
.queue-clear { margin: 0; padding: 18px 12px; color: var(--muted); text-align: center; }

.empty-state { height: 100%; display: grid; place-content: center; gap: 4px; color: var(--text-2); text-align: center; }
.empty-state small { color: var(--muted); }
.panel-loading {
  position: absolute;
  inset: 50px 0 0;
  display: none;
  align-content: start;
  gap: 14px;
  padding: 30px 10%;
  background: var(--surface);
}
.panel-loading i {
  width: 100%;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, #162438 25%, #20344d 50%, #162438 75%);
  background-size: 200% 100%;
  animation: skeleton 1.6s ease-in-out infinite;
}
.panel-loading i:nth-child(2) { width: 82%; }
.panel-loading i:nth-child(3) { width: 92%; }
.panel-loading i:nth-child(4) { width: 68%; }
.panel[data-state="loading"] .panel-loading { display: grid; }
.panel[data-state="loading"] > :not(header):not(.panel-loading) { visibility: hidden; }
@keyframes skeleton { to { background-position: -200% 0; } }

@media (max-width: 1100px) {
  body { overflow: auto; }
  .screen-shell { height: auto; min-height: 100dvh; overflow: visible; }
  .topbar { height: auto; min-height: 62px; grid-template-columns: 1fr auto; gap: 8px; padding-block: 8px; }
  .top-clock { grid-column: 1; justify-self: start; }
  .topbar nav { grid-column: 2; }
  .dashboard { height: auto; min-height: calc(100dvh - 62px); grid-template-columns: 1fr; grid-template-rows: auto; }
  .traffic-panel, .tasks-panel, .operations-panel { grid-column: 1; grid-row: auto; }
  .traffic-panel { min-height: 560px; }
  .tasks-panel { min-height: 460px; }
  .operations-panel { min-height: 360px; }
  .traffic-table { min-width: 1180px; }
  .traffic-metrics { grid-template-columns: repeat(3, 1fr); }
  .traffic-metrics article:nth-child(4) { border-left: 0; }
  .traffic-metrics article:nth-child(n+4) { border-top: 1px solid var(--line); }
  .traffic-panel { grid-template-rows: 50px 132px 42px minmax(0, 1fr); }
}

@media (max-width: 720px) {
  :root { font-size: 13px; }
  .topbar { grid-template-columns: 1fr; }
  .top-clock { grid-column: 1; justify-self: center; }
  .topbar nav { grid-column: 1; justify-content: stretch; }
  .topbar nav > * { flex: 1; padding-inline: 6px; }
  .traffic-panel > header > div { display: block; }
  .traffic-metrics { grid-template-columns: repeat(2, 1fr); }
  .traffic-metrics article:nth-child(3), .traffic-metrics article:nth-child(5) { border-left: 0; }
  .traffic-metrics article:nth-child(n+3) { border-top: 1px solid var(--line); }
  .traffic-panel { min-height: 650px; grid-template-rows: 58px 198px 42px minmax(0, 1fr); }
  .tasks-header { grid-template-columns: 1fr !important; min-height: 120px !important; justify-items: center; }
  .tasks-header select { justify-self: center; }
  .tasks-panel { min-height: 560px; grid-template-rows: 120px minmax(0, 1fr) 38px; }
  .tasks-table { min-width: 1120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
