* { box-sizing: border-box; }

:root {
  --bg: #f5f7fb;
  --paper: #ffffff;
  --line: #dbe2ee;
  --text: #142033;
  --muted: #617087;
  --head: #edf4ff;
  --head-2: #f3f6fb;
  --blue: #1d4ed8;
  --green: #047857;
  --amber: #a16207;
  --red: #b91c1c;
}

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

body { padding: 28px 36px 44px; }

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: 0;
}

#subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

nav {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: #e9eef7;
  border: 1px solid var(--line);
  border-radius: 8px;
}

nav a {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
}

nav a.active {
  background: var(--paper);
  color: var(--blue);
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.daily-layout {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.date-sidebar {
  position: sticky;
  top: 18px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.side-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.date-list {
  display: grid;
  gap: 8px;
}

.date-option {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #f3f6fb;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.date-option span {
  font-size: 14px;
  font-weight: 800;
}

.date-option small {
  color: var(--muted);
  font-size: 12px;
}

.date-option.active {
  background: #eaf2ff;
  border-color: #b9cef8;
  color: var(--blue);
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: #e9eef7;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab {
  height: 34px;
  min-width: 64px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.tab.active {
  background: var(--paper);
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi {
  min-height: 72px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.kpi strong {
  font-size: 28px;
  line-height: 1;
}

.date-block {
  margin-bottom: 26px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
}

.date-title {
  padding: 12px 16px;
  background: var(--head);
  color: var(--blue);
  font-size: 22px;
  font-weight: 800;
  border-radius: 8px 8px 0 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 12px 14px;
  vertical-align: top;
  line-height: 1.55;
  font-size: 14px;
}

th:last-child, td:last-child { border-right: 0; }

th {
  background: var(--head-2);
  text-align: left;
  font-size: 15px;
}

.col-cat { width: 120px; }
.col-issue { width: 40%; }
.col-source { width: 190px; }
.col-gh { width: 320px; }

.cat {
  font-weight: 800;
  font-size: 16px;
}

.numbered-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 6px;
  min-height: 100%;
}

.num {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.55;
}

.source-group + .source-group,
.mini-gap {
  margin-top: 10px;
}

.category-cell {
  background: #fbfdff;
}

.meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.problem-link {
  display: inline;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-weight: 800;
  line-height: 1.55;
  text-align: left;
  cursor: pointer;
}

.problem-link:hover {
  text-decoration: underline;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #edf2f7;
  color: var(--muted);
}

.badge.good { background: #dff8ee; color: var(--green); }
.badge.warn { background: #fff4cf; color: var(--amber); }
.badge.bad { background: #fee2e2; color: var(--red); }

.issue-compact {
  position: relative;
  display: grid;
  grid-template-columns: auto auto auto auto 22px;
  justify-content: start;
  align-items: center;
  column-gap: 9px;
  min-height: 28px;
}

.issue-num {
  font-weight: 800;
  white-space: nowrap;
}

.issue-time {
  min-width: 0;
  max-width: 76px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #42526a;
}

.issue-engineer {
  min-width: 0;
  max-width: 56px;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 8px;
  border: 1px solid var(--tag-border);
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-fg);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.issue-detail {
  position: relative;
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #cbd7ea;
  border-radius: 50%;
  background: #f8fbff;
  color: #58708f;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  cursor: default;
  user-select: none;
}

.issue-detail:hover,
.issue-detail:focus {
  border-color: #8fb1ec;
  color: var(--blue);
  outline: 0;
}

.issue-tip {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  display: none;
  width: min(360px, calc(100vw - 52px));
  padding: 10px 12px;
  border: 1px solid #cbd7ea;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
  color: var(--text);
  text-align: left;
}

.issue-tip::before {
  content: "";
  position: absolute;
  right: 8px;
  top: -6px;
  width: 10px;
  height: 10px;
  transform: rotate(45deg);
  border-left: 1px solid #cbd7ea;
  border-top: 1px solid #cbd7ea;
  background: #ffffff;
}

.issue-detail:hover .issue-tip,
.issue-detail:focus .issue-tip {
  display: block;
}

.issue-tip-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  line-height: 1.5;
}

.issue-tip-row + .issue-tip-row {
  border-top: 1px solid #edf2f7;
}

.issue-tip-row span {
  color: var(--muted);
  font-weight: 700;
}

.issue-tip-row strong {
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.empty {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 40px;
  text-align: center;
}

.empty h2 { margin: 0 0 8px; }
.empty p { margin: 0; color: var(--muted); }

.message-popover[hidden] {
  display: none;
}

.message-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}

.popover-backdrop {
  display: none;
}

.popover-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  width: min(620px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 28px));
  display: flex;
  flex-direction: column;
  overflow: visible;
  background: #f2f5f8;
  border: 1px solid rgba(148, 163, 184, 0.65);
  border-radius: 8px;
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.22);
  pointer-events: auto;
}

.popover-panel::before {
  content: "";
  position: absolute;
  top: clamp(18px, var(--arrow-top, 36px), calc(100% - 18px));
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-left: 1px solid rgba(148, 163, 184, 0.65);
  border-bottom: 1px solid rgba(148, 163, 184, 0.65);
  transform: translateY(-50%) rotate(45deg);
}

.popover-panel[data-side="left"]::before {
  left: -7px;
}

.popover-panel[data-side="right"]::before {
  right: -7px;
  transform: translateY(-50%) rotate(225deg);
}

.popover-panel[data-side="none"]::before {
  display: none;
}

.popover-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.popover-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.popover-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.close-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.chat-stream {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 18px 18px 22px;
}

.chat-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.chat-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.chat-separator::before,
.chat-separator::after {
  content: "";
  height: 1px;
  flex: 1;
  background: #d9e2ee;
}

.chat-row:last-child {
  margin-bottom: 0;
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #d8e2f0;
  color: #324155;
  font-weight: 800;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.bubble-wrap {
  min-width: 0;
}

.chat-meta {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
}

.chat-bubble {
  position: relative;
  display: inline-block;
  max-width: min(520px, 100%);
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #dde5ef;
  border-radius: 6px;
  color: var(--text);
  line-height: 1.65;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.chat-bubble::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 12px;
  width: 10px;
  height: 10px;
  background: #ffffff;
  border-left: 1px solid #dde5ef;
  border-bottom: 1px solid #dde5ef;
  transform: rotate(45deg);
}

.chat-row.target .chat-meta {
  color: var(--blue);
  font-weight: 700;
}

.chat-row.target .chat-bubble {
  background: #eaf2ff;
  border-color: #b9cef8;
}

.chat-row.target .chat-bubble::before {
  background: #eaf2ff;
  border-color: #b9cef8;
}

.chat-row.target.flash .chat-bubble {
  animation: targetBubbleFade 3.2s ease-out forwards;
}

.chat-row.target.flash .chat-bubble::before {
  animation: targetBubbleArrowFade 3.2s ease-out forwards;
}

@keyframes targetBubbleFade {
  0% {
    background: #fff1a8;
    border-color: #f59e0b;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.22), 0 6px 18px rgba(245, 158, 11, 0.18);
  }
  45% {
    background: #fff7c7;
    border-color: #fbbf24;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.12), 0 3px 10px rgba(245, 158, 11, 0.12);
  }
  100% {
    background: #eaf2ff;
    border-color: #b9cef8;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  }
}

@keyframes targetBubbleArrowFade {
  0% {
    background: #fff1a8;
    border-color: #f59e0b;
  }
  45% {
    background: #fff7c7;
    border-color: #fbbf24;
  }
  100% {
    background: #eaf2ff;
    border-color: #b9cef8;
  }
}

@media (max-width: 1100px) {
  body { padding: 18px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .daily-layout { grid-template-columns: 1fr; }
  .date-sidebar { position: static; }
  .date-list { grid-template-columns: repeat(auto-fit, minmax(138px, 1fr)); }
  .toolbar { flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  table { min-width: 1180px; }
  .date-block { overflow-x: auto; }
}
