:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --panel: #fffdfa;
  --ink: #202124;
  --muted: #72706b;
  --line: #e3ded3;
  --green: #28735b;
  --blue: #315f9b;
  --red: #aa4b45;
  --gold: #9a6b22;
  --sidebar: #242622;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 17px;
  letter-spacing: 0;
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 0;
  padding: 24px 18px;
  overflow: auto;
  background: var(--sidebar);
  color: #f8f4eb;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #d4b36b;
  color: #25231e;
  font-weight: 800;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 2px;
  color: rgba(248, 244, 235, 0.7);
  font-size: 14px;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(248, 244, 235, 0.72);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.muted-label {
  color: rgba(248, 244, 235, 0.56);
  font-size: 14px;
}

.source-name {
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.5;
}

.sync-chip {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(248, 244, 235, 0.82);
  font-size: 14px;
  line-height: 1.4;
}

.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  min-width: 0;
  padding: 28px;
  overflow: hidden;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.2;
}

.topbar p {
  max-width: 720px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
}

.primary-button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: #202124;
  color: white;
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}

.secondary-button {
  align-self: end;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}

.secondary-button:hover {
  border-color: #c9c1b3;
  background: #f8f6f1;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-actions span {
  color: var(--muted);
  font-size: 15px;
  white-space: nowrap;
}

.primary-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  align-content: start;
  flex: 1 1 auto;
  gap: 18px;
  min-height: 0;
  overflow: auto;
}

#diagnosis-view.view.active {
  align-content: stretch;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  min-height: 120px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card span {
  color: var(--muted);
  font-size: 15px;
}

.metric-card strong {
  display: block;
  margin-top: 18px;
  font-size: 31px;
  line-height: 1;
}

.accent-green strong {
  color: var(--green);
}

.accent-blue strong {
  color: var(--blue);
}

.accent-red strong {
  color: var(--red);
}

.content-band {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: 22px;
}

.section-heading span {
  color: var(--muted);
  font-size: 15px;
}

.store-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.store-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.store-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.store-card h3 {
  margin: 0;
  font-size: 19px;
}

.badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef3ef;
  color: var(--green);
  font-size: 14px;
  white-space: nowrap;
}

.store-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-width: 0;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.stat strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 19px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eee8dc;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  color: var(--muted);
  font-size: 15px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pagination-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-controls select {
  min-width: 86px;
}

.diagnosis-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

.diagnosis-layout > .content-band {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.diagnosis-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.diagnosis-item {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.diagnosis-item:hover,
.diagnosis-item.active {
  border-color: #bcb39f;
  background: #faf7ef;
}

.diagnosis-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.diagnosis-item span,
.diagnosis-item small {
  color: var(--muted);
  line-height: 1.45;
}

.diagnosis-item strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 14px;
}

.status-warning {
  background: #fff3df;
  color: var(--gold);
}

.status-blocked {
  background: #fbe8e6;
  color: var(--red);
}

.status-normal {
  background: #eaf3ed;
  color: var(--green);
}

.status-unknown {
  background: #f1eee7;
  color: var(--muted);
}

.report-preview {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  padding-right: 6px;
  overflow: auto;
  font-size: 16px;
  line-height: 1.6;
}

.report-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border: 1px solid #e7dcc6;
  border-radius: 8px;
  background: #fffaf0;
}

.report-title h3 {
  margin: 0;
  font-size: 26px;
  line-height: 1.25;
}

.report-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 700;
}

.report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
}

.report-meta span {
  padding: 6px 10px;
  border-radius: 8px;
  background: #f7f3eb;
}

.report-meta-primary {
  margin-top: -4px;
}

.report-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-section-lead {
  border-color: #e7dcc6;
  background: #fffdf8;
}

.report-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee7db;
}

.report-section-title::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 999px;
  background: var(--gold);
}

.report-section h4 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

.report-section p {
  color: var(--muted);
  line-height: 1.75;
}

.report-hint {
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff8e8;
  color: var(--gold);
  font-size: 14px;
  line-height: 1.5;
}

.report-metric-list {
  display: grid;
  gap: 12px;
}

.report-metric {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.report-metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.report-metric-head span {
  color: var(--muted);
  font-size: 14px;
}

.report-data-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.report-data-grid div {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: #f8f6f1;
}

.report-data-grid span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.report-data-grid strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.report-action-list div,
.report-empty {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8f6f1;
  color: var(--muted);
}

.report-info-list {
  display: grid;
  gap: 12px;
}

.report-info-item {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.report-info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.report-info-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-info-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
}

.report-info-item p {
  margin: 0;
  color: var(--muted);
}

.report-chip-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.report-chip {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: #f8f6f1;
}

.report-chip strong,
.report-chip span,
.report-chip small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-chip span,
.report-chip small {
  color: var(--muted);
  font-size: 14px;
}

.report-meta.compact {
  gap: 8px;
}

.report-meta.compact span {
  padding: 4px 8px;
  font-size: 14px;
}

.action-plan-item {
  border-color: #e7dcc6;
  background: #fffdf8;
}

.ai-report-box {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid #e7dcc6;
  border-radius: 8px;
  background: #fffdf8;
}

.ai-report-group {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #eee7db;
}

.ai-report-group ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.ai-report-text {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #f8f6f1;
  color: var(--ink);
  font: inherit;
  white-space: pre-wrap;
}

.metric-detail-group {
  display: grid;
  gap: 10px;
}

.metric-detail-title {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

.metric-detail-table {
  display: grid;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric-detail-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.1fr) minmax(110px, 1fr) minmax(110px, 1fr) minmax(110px, 1fr) minmax(86px, 0.8fr) minmax(72px, 0.7fr);
  gap: 10px;
  min-width: 760px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.metric-detail-row:last-child {
  border-bottom: 0;
}

.metric-detail-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-detail-head {
  background: #f8f6f1;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.secondary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

td {
  font-size: 17px;
}

.filter-row {
  display: flex;
  align-items: end;
  gap: 12px;
}

.filter-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 15px;
}

select,
input {
  min-width: 180px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #202124;
  color: white;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
}

@media (max-width: 1100px) {
  .metric-grid,
  .store-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px;
  }

  .brand-block,
  .sidebar-footer {
    display: none;
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    min-height: 38px;
    padding: 0 8px;
    text-align: center;
    font-size: 15px;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    align-items: stretch;
    justify-content: space-between;
  }

  h1 {
    font-size: 28px;
  }

  .metric-grid,
  .report-data-grid,
  .store-grid {
    grid-template-columns: 1fr;
  }

  .filter-row {
    display: grid;
  }

  .pagination-bar,
  .pagination-controls,
  .diagnosis-layout {
    display: grid;
    justify-items: stretch;
  }

  .diagnosis-layout {
    grid-template-columns: 1fr;
  }

  select,
  input {
    width: 100%;
  }
}
