:root {
  color-scheme: light;
  --bg: #f5f7f5;
  --ink: #17201d;
  --muted: #66716d;
  --line: #d9dfdb;
  --panel: #ffffff;
  --panel-2: #f9fbfa;
  --accent: #097969;
  --accent-2: #b45f06;
  --danger: #b42318;
  --warn: #a15c07;
  --good: #1d7f42;
  --shadow: 0 12px 32px rgba(20, 34, 30, 0.08);
}

* {
  box-sizing: border-box;
}

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

button {
  min-width: 88px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 680;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease;
}

button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.scheduler-toggle {
  min-width: 118px;
}

button.scheduler-toggle.on {
  border-color: rgba(29, 127, 66, 0.32);
  background: rgba(29, 127, 66, 0.08);
  color: var(--good);
}

button.scheduler-toggle.off {
  border-color: rgba(161, 92, 7, 0.3);
  background: rgba(161, 92, 7, 0.08);
  color: var(--warn);
}

.topbar {
  min-height: 96px;
  padding: 24px clamp(18px, 4vw, 44px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

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

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 34px) 42px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
  gap: 18px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.usage-panel,
.prediction-panel,
.analysis-panel {
  grid-column: 1 / -1;
}

.usage-panel {
  padding: 0;
}

.usage-panel summary {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  list-style: none;
  padding: 16px 20px;
}

.usage-panel summary::-webkit-details-marker {
  display: none;
}

.usage-panel summary h2 {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.usage-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.usage-panel[open] summary .badge {
  color: var(--accent);
  border-color: rgba(9, 121, 105, 0.28);
  background: rgba(9, 121, 105, 0.07);
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  padding: 18px 20px 20px;
}

.usage-grid section {
  min-width: 0;
}

.usage-grid h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.usage-grid p,
.usage-grid li {
  color: var(--ink);
  line-height: 1.66;
}

.usage-grid p {
  margin: 0 0 10px;
}

.usage-grid ul {
  margin: 0;
  padding-left: 18px;
}

.usage-grid li {
  margin-bottom: 6px;
}

.risk-panel,
.agent-panel {
  grid-column: span 6;
}

.report-panel {
  grid-column: span 7;
}

.log-panel {
  grid-column: span 5;
}

.history-panel {
  grid-column: 1 / -1;
}

.prediction-panel h3,
.prediction-panel .lead,
.analysis-panel .lead {
  max-width: 1120px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.panel h2 {
  font-size: 16px;
  color: var(--muted);
  font-weight: 760;
}

.panel h3 {
  font-size: 23px;
  line-height: 1.2;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
  white-space: nowrap;
}

.badge.good {
  color: var(--good);
  border-color: rgba(29, 127, 66, 0.28);
  background: rgba(29, 127, 66, 0.07);
}

.badge.warn {
  color: var(--warn);
  border-color: rgba(161, 92, 7, 0.28);
  background: rgba(161, 92, 7, 0.08);
}

.badge.danger {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.28);
  background: rgba(180, 35, 24, 0.08);
}

.lead {
  margin: 0;
  color: var(--ink);
  line-height: 1.68;
}

.muted {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.62;
}

.tag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.tag {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--panel-2);
  color: var(--ink);
  line-height: 1.42;
  font-size: 14px;
}

.progress-wrap {
  margin: 16px 0;
}

.progress-line {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e7ece8;
  overflow: hidden;
}

.progress-line span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #57a773);
  transition: width 0.24s ease;
}

#progressText {
  min-height: 24px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.rows {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.severity {
  justify-self: end;
  font-weight: 780;
}

.sector-block {
  border-bottom: 1px solid var(--line);
}

.sector-block summary {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  list-style: none;
  padding: 11px 0;
}

.sector-block summary::-webkit-details-marker {
  display: none;
}

.sector-block summary span {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.sector-block summary strong {
  font-size: 16px;
}

.sector-block summary small {
  color: var(--muted);
  font-weight: 720;
}

.sector-body {
  padding: 0 0 18px;
}

.sector-body p {
  margin: 0 0 10px;
  line-height: 1.62;
}

.sector-baseline {
  color: var(--muted);
}

.sector-sub {
  margin-top: 14px;
}

.sector-sub h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0;
}

.news-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 0;
}

.news-details summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  padding: 9px 12px;
}

.news-details summary::-webkit-details-marker {
  display: none;
}

.news-details summary h4 {
  margin: 0;
}

.news-details summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.sector-sub ul {
  margin: 0;
  padding-left: 18px;
}

.news-details .article-list {
  padding: 0 14px 12px 30px;
}

.sector-sub li {
  margin-bottom: 8px;
  line-height: 1.48;
}

.indicator-list li,
.article-list li,
.source-list li {
  padding-right: 4px;
}

.indicator-list strong,
.article-list a,
.source-list span {
  color: var(--ink);
  font-weight: 720;
}

.indicator-list span,
.article-list span,
.source-list small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.indicator-list em {
  display: inline-block;
  margin-top: 2px;
  color: var(--accent);
  font-style: normal;
  font-size: 13px;
}

.article-list a {
  overflow-wrap: anywhere;
  text-decoration: none;
}

.article-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.source-failed,
.source-failed small {
  color: var(--danger);
}

.metric-row,
.expectation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.expectation-grid {
  grid-template-columns: 0.7fr 0.65fr minmax(0, 1.65fr);
}

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

.metric-row strong,
.expectation-grid strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.2;
}

.event-log {
  margin: 0;
  padding-left: 20px;
  max-height: 270px;
  overflow: auto;
}

.event-log li {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.45;
}

.event-log strong {
  color: var(--ink);
}

.history-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.history-head-actions button,
.history-more {
  min-width: 76px;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.history-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px 12px;
}

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

.history-stats strong {
  display: block;
  font-size: 22px;
  line-height: 1.15;
}

.history-timeline {
  position: relative;
  display: grid;
  gap: 12px;
}

.history-timeline::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 9px;
  width: 2px;
  background: var(--line);
}

.history-item {
  position: relative;
  padding-left: 26px;
}

.history-item summary {
  min-height: 70px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 12px 14px;
}

.history-item summary::-webkit-details-marker,
.history-sector summary::-webkit-details-marker {
  display: none;
}

.history-dot {
  position: absolute;
  left: 4px;
  top: 29px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid var(--panel);
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  z-index: 1;
}

.history-execution .history-dot {
  background: var(--accent-2);
  box-shadow: 0 0 0 1px var(--accent-2);
}

.history-summary {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.history-summary time,
.history-summary small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.history-summary strong {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.36;
}

.history-body {
  margin: 8px 0 6px;
  padding: 16px 16px 18px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: #fff;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 0;
}

.history-metrics.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.history-metrics div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-2);
}

.history-metrics strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

.history-sub {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.history-sub h4 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.history-sectors {
  display: grid;
  gap: 8px;
}

.history-sector {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 0 12px 12px;
}

.history-sector summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  padding: 6px 0;
}

.history-sector summary strong,
.history-sector summary span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-sector summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.history-sector p {
  margin: 8px 0 0;
  line-height: 1.62;
}

.history-mini-list {
  margin-top: 12px;
}

.history-mini-list h5,
.history-mini-list summary h5 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.history-mini-list ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.history-mini-list li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.history-mini-list strong,
.history-mini-list a {
  color: var(--ink);
  font-weight: 720;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.history-mini-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.history-mini-list span {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.history-more {
  margin-top: 16px;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .prediction-panel,
  .analysis-panel,
  .risk-panel,
  .agent-panel,
  .report-panel,
  .log-panel,
  .usage-panel,
  .history-panel {
    grid-column: 1;
  }

  .history-metrics,
  .history-metrics.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .top-actions button {
    width: 100%;
  }

  .tag-grid,
  .metric-row,
  .expectation-grid,
  .history-stats,
  .usage-grid,
  .history-metrics,
  .history-metrics.compact {
    grid-template-columns: 1fr;
  }

  .history-item summary {
    grid-template-columns: 1fr;
  }

  .history-sector summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .severity {
    justify-self: start;
  }

  .sector-block summary {
    grid-template-columns: 1fr;
  }
}
