:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --line: #dfe4e8;
  --line-soft: #edf0f2;
  --text: #1d252c;
  --muted: #69757f;
  --green: #147d64;
  --green-soft: #e5f4ef;
  --blue: #2468b4;
  --blue-soft: #eaf2fb;
  --amber: #a76000;
  --amber-soft: #fff3d6;
  --red: #b52d35;
  --red-soft: #fdebed;
  --gray-soft: #eef1f3;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }

.topbar { height: 58px; display: flex; align-items: center; gap: 30px; padding: 0 28px; border-bottom: 1px solid #ccd3d8; background: #1f2b33; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 188px; font-size: 16px; font-weight: 600; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 5px; background: #2ca37f; font-size: 12px; }
.nav-tabs { display: flex; align-self: stretch; }
.nav-link { display: flex; align-items: center; min-width: 92px; justify-content: center; color: #bac4ca; border-bottom: 3px solid transparent; }
.nav-link:hover, .nav-link.active { color: #fff; border-bottom-color: #44bd95; }
.top-meta { display: flex; align-items: center; gap: 12px; margin-left: auto; color: #aeb9bf; font-size: 12px; }
.demo-badge { padding: 4px 7px; border: 1px solid #53636c; border-radius: 4px; color: #dce4e8; }
.admin-identity { display: flex; align-items: baseline; gap: 7px; }
.admin-identity strong { color: #fff; font-weight: 600; }
.admin-identity small { color: #96a5ad; }
.logout-form { margin: 0; }
.logout-form button { padding: 2px 0; border: 0; border-bottom: 1px solid transparent; background: transparent; color: #bac4ca; cursor: pointer; }
.logout-form button:hover { border-bottom-color: #bac4ca; color: #fff; }

.login-page { min-height: 100vh; background: #eef1f3; }
.login-shell { display: grid; min-height: 100vh; padding: 40px; place-items: center; }
.login-panel { width: 420px; max-width: 100%; padding: 38px 40px 40px; border: 1px solid #d8dee2; background: #fff; box-shadow: 0 12px 30px #24323b12; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 34px; }
.login-logo { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 6px; background: #147d64; }
.login-logo img { display: block; width: 38px; height: 38px; object-fit: contain; }
.login-brand span { color: var(--muted); font-size: 12px; }
.login-brand h1 { margin-top: 2px; font-size: 23px; line-height: 1.25; font-weight: 650; }
.login-form { display: grid; gap: 18px; }
.login-form label > span { color: #43515a; font-size: 13px; }
.login-form input { height: 42px; }
.login-submit { width: 100%; height: 42px; margin-top: 4px; }
.login-error { padding: 9px 11px; border: 1px solid #e4a5aa; background: var(--red-soft); color: var(--red); }

.page-shell { width: min(1540px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 40px; }
.page-heading, .detail-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
h1, h2, h3, p { margin: 0; }
.page-heading h1, .detail-heading h1 { font-size: 25px; line-height: 1.25; font-weight: 650; }
.page-heading p, .detail-heading p { margin-top: 5px; color: var(--muted); }
.heading-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #8a969e; box-shadow: 0 0 0 3px #e5e9eb; }
.status-dot.success { background: #22a478; box-shadow: 0 0 0 3px #d9eee7; }
.status-dot.running { background: #2e76b7; box-shadow: 0 0 0 3px #dceaf6; }
.status-dot.failed { background: #ba343c; box-shadow: 0 0 0 3px #f6dde0; }

.filterbar { display: grid; grid-template-columns: 160px 160px 160px minmax(220px, 1fr) auto; gap: 12px; align-items: end; padding: 15px 16px; border: 1px solid var(--line); background: var(--surface); }
label { display: flex; flex-direction: column; gap: 5px; }
label > span { color: var(--muted); font-size: 12px; }
input, select, textarea { width: 100%; border: 1px solid #cbd2d7; border-radius: 5px; background: #fff; color: var(--text); outline: none; }
input, select { height: 36px; padding: 0 10px; }
textarea { padding: 9px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #3a8c76; box-shadow: 0 0 0 2px #dbefe9; }
.primary-btn, .secondary-btn { height: 36px; padding: 0 17px; border: 1px solid transparent; border-radius: 5px; cursor: pointer; }
.primary-btn { background: var(--green); color: #fff; }
.primary-btn:hover { background: #0e6d56; }
.secondary-btn { border-color: #b9c3c9; background: #fff; color: #34414a; }
button:disabled { opacity: .45; cursor: not-allowed; }
.full { width: 100%; }

.metric-strip { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); margin: 16px 0; border: 1px solid var(--line); background: var(--surface); }
.metric { min-width: 0; min-height: 104px; padding: 15px 16px; border-right: 1px solid var(--line-soft); }
.metric:last-child { border-right: 0; }
.metric > span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 4px 0 1px; font-size: 27px; line-height: 1.2; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric small { color: var(--muted); white-space: normal; }
.metric.normal strong { color: var(--green); }
.metric.attention strong { color: var(--amber); }
.metric.unknown strong { color: #66717a; }
.metric.critical strong { color: var(--red); }

.table-section, .panel { border: 1px solid var(--line); background: var(--surface); }
.section-heading, .panel-heading { min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 16px; border-bottom: 1px solid var(--line-soft); }
.section-heading > div, .panel-heading > div { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.section-heading h2, .panel-heading h2 { font-size: 15px; font-weight: 650; }
.section-heading span, .panel-heading span, .row-count { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 1120px; }
.data-table th { height: 42px; padding: 0 12px; background: #f8f9fa; color: #5f6b74; text-align: left; font-size: 12px; font-weight: 600; white-space: nowrap; }
.data-table td { height: 60px; padding: 8px 12px; border-top: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tbody tr:hover { background: #f7faf9; }
.clickable-row { cursor: pointer; }
.data-table td > strong { display: block; font-weight: 600; white-space: nowrap; }
.data-table td > small { display: block; margin-top: 2px; color: var(--muted); white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; font-family: Consolas, "SFMono-Regular", monospace; white-space: nowrap; }
.source-tag, .result-tag { display: inline-flex; align-items: center; min-height: 23px; padding: 2px 7px; border-radius: 4px; font-size: 12px; white-space: nowrap; }
.source-tag { background: var(--gray-soft); color: #44515a; }
.source-plan { background: var(--blue-soft); color: #1e5c9f; }
.source-manual, .source-manual_stop { background: #e8f5f1; color: #176b56; }
.source-key, .source-key_stop { background: #f1ecfa; color: #63489a; }
.result-tag.normal { background: var(--green-soft); color: #12694f; }
.result-tag.attention { background: var(--amber-soft); color: #8c5200; }
.result-tag.unknown { background: var(--gray-soft); color: #53616a; }
.result-tag.critical { background: var(--red-soft); color: #a3212b; }
.empty-state { padding: 34px !important; color: var(--muted); text-align: center; }

.breadcrumb { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; color: var(--muted); font-size: 12px; }
.breadcrumb a { color: var(--blue); }
.detail-heading { align-items: center; }
.detail-heading h1 { margin-top: 7px; }
.detail-result { display: flex; align-items: flex-end; flex-direction: column; gap: 5px; }
.detail-result small { color: var(--muted); font-family: Consolas, monospace; }
.task-content { display: flex; align-items: stretch; margin-bottom: 16px; border: 1px solid var(--line); background: var(--surface); }
.task-content-heading { display: flex; min-width: 170px; padding: 13px 16px; border-right: 1px solid var(--line-soft); flex-direction: column; justify-content: center; }
.task-content-heading h2 { font-size: 15px; font-weight: 650; }
.task-content-heading span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.task-content-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); flex: 1; min-width: 0; }
.task-content-grid > div { min-width: 0; padding: 13px 14px; border-right: 1px solid var(--line-soft); }
.task-content-grid > div:last-child { border-right: 0; }
.task-content-grid span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.task-content-grid strong { display: block; overflow-wrap: anywhere; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-metrics { display: grid; grid-template-columns: repeat(6, 1fr); margin-bottom: 16px; border: 1px solid var(--line); background: var(--surface); }
.detail-metrics > div { min-width: 0; padding: 13px 14px; border-right: 1px solid var(--line-soft); }
.detail-metrics > div:last-child { border-right: 0; }
.detail-metrics span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.detail-metrics strong { display: block; overflow-wrap: anywhere; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.detail-main, .detail-side { display: grid; gap: 16px; min-width: 0; }
.panel { min-width: 0; }
.heartbeat-panel canvas { display: block; width: calc(100% - 32px); height: 240px; margin: 8px 16px 0; }
.legend { display: flex !important; align-items: center !important; gap: 14px !important; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend i { display: inline-block; width: 15px; height: 4px; }
.line-blue { background: #2878c7; }
.block-green { height: 8px !important; background: #79bda9; }
.block-gray { height: 8px !important; background: #d5dade; }
.phase-counts { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 8px; border-top: 1px solid var(--line-soft); }
.phase-counts span { padding: 10px 16px; border-right: 1px solid var(--line-soft); color: var(--muted); text-align: center; font-size: 12px; }
.phase-counts span:last-child { border-right: 0; }
.phase-counts strong { margin-left: 5px; color: var(--text); }
.timeline { padding: 6px 16px 15px; }
.timeline-item { position: relative; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 20px; min-height: 62px; padding: 12px 0 12px 18px; border-bottom: 1px solid var(--line-soft); }
.timeline-item::before { content: ""; position: absolute; left: 0; top: 19px; width: 8px; height: 8px; border-radius: 50%; background: #71808a; }
.timeline-item.type-work::before { background: var(--green); }
.timeline-item.type-cmd::before { background: var(--blue); }
.timeline-item.type-plan::before { background: #7052a3; }
.timeline-item.type-error::before { background: var(--red); }
.timeline-item time { color: var(--muted); font-family: Consolas, monospace; font-size: 12px; }
.timeline-item strong { font-weight: 600; }
.timeline-item p { margin-top: 3px; color: var(--muted); overflow-wrap: anywhere; }
.raw-panel summary { padding: 16px; cursor: pointer; font-weight: 600; }
.raw-panel pre { max-height: 520px; overflow: auto; margin: 0; padding: 16px; border-top: 1px solid var(--line-soft); background: #182129; color: #dce6eb; font: 12px/1.55 Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-panel, .review-panel { padding-bottom: 15px; }
.ai-panel { position: relative; }
.ai-panel > :not(.panel-heading), .review-panel > :not(.panel-heading) { margin-left: 15px; margin-right: 15px; }
.ai-loading { position: absolute; z-index: 3; inset: 61px 0 0; display: grid; place-items: center; margin: 0 !important; background: #ffffffd9; }
.ai-loading[hidden] { display: none; }
.loading-spinner { width: 28px; height: 28px; border: 3px solid #d9e2e6; border-top-color: var(--green); border-radius: 50%; animation: ai-spin .75s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-inline-error { margin-top: 12px; padding: 9px 10px; border: 1px solid #e4a5aa; background: var(--red-soft); color: var(--red); }
.ai-inline-error[hidden] { display: none; }
.ai-empty { display: flex; flex-direction: column; gap: 5px; padding: 24px 0; color: var(--muted); }
.ai-empty strong { color: var(--text); }
.ai-conclusion { display: flex; flex-direction: column; gap: 5px; padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.ai-conclusion span, .ai-conclusion small { color: var(--muted); font-size: 12px; }
.ai-panel h3 { margin: 14px 15px 5px !important; font-size: 13px; }
.evidence-list, .plain-list { margin-top: 5px !important; margin-bottom: 14px !important; padding-left: 18px; }
.evidence-list li, .plain-list li { margin: 6px 0; }
.evidence-list time { display: block; color: var(--muted); font-size: 11px; }
.ai-action-form { margin-top: 14px; }
.ai-history { margin-top: 16px; padding-top: 2px; border-top: 1px solid var(--line-soft); }
.ai-history > h3 { margin-left: 0 !important; }
.ai-message-list { max-height: 320px; overflow-y: auto; }
.ai-message { padding: 9px 0 9px 10px; border-left: 3px solid #cbd4d9; border-bottom: 1px solid var(--line-soft); }
.ai-message.role-user { border-left-color: var(--blue); }
.ai-message.role-assistant { border-left-color: var(--green); }
.ai-message > div { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ai-message time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.ai-message p { margin-top: 4px; color: #46535c; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-discuss-form { display: grid; gap: 9px; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line-soft); }
.review-panel form { display: grid; gap: 12px; padding-top: 14px; }
.flash-stack { position: fixed; z-index: 20; top: 68px; right: 20px; display: grid; gap: 8px; }
.flash { max-width: 420px; padding: 10px 13px; border: 1px solid var(--line); background: #fff; box-shadow: 0 4px 14px #1a242c20; }
.flash.success { border-color: #9bcdbc; }
.flash.error { border-color: #e4a5aa; }

@media (max-width: 1100px) {
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(3) { border-right: 0; }
  .metric:nth-child(-n+3) { border-bottom: 1px solid var(--line-soft); }
  .detail-metrics { grid-template-columns: repeat(3, 1fr); }
  .task-content { flex-direction: column; }
  .task-content-heading { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .task-content-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail-metrics > div:nth-child(3) { border-right: 0; }
  .detail-metrics > div:nth-child(-n+3) { border-bottom: 1px solid var(--line-soft); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .brand { min-width: auto; }
  .brand > span:last-child { display: none; }
  .nav-link { min-width: 78px; }
  .page-shell { width: calc(100% - 24px); padding-top: 16px; }
  .page-heading, .detail-heading { align-items: flex-start; flex-direction: column; }
  .filterbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-field, .filterbar .primary-btn { grid-column: 1 / -1; }
  .metric-strip, .detail-metrics { grid-template-columns: repeat(2, 1fr); }
  .task-content-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(n), .detail-metrics > div:nth-child(n) { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
  .metric:nth-child(2n), .detail-metrics > div:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n+2), .detail-metrics > div:nth-last-child(-n+2) { border-bottom: 0; }
  .detail-side { grid-template-columns: minmax(0, 1fr); }
  .section-heading > div, .panel-heading > div { align-items: flex-start; flex-direction: column; gap: 2px; }
  .legend { display: none !important; }
  .timeline-item { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .admin-identity small { display: none; }
  .login-shell { padding: 24px; }
  .login-panel { padding: 32px 24px; }
}
