:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --ink: #17211d;
  --muted: #68736e;
  --line: #dce3df;
  --line-strong: #c7d1cc;
  --sidebar: #17251f;
  --sidebar-muted: #9eafa7;
  --accent: #16765f;
  --accent-strong: #0f5f4b;
  --accent-soft: #dcefe8;
  --blue: #397d98;
  --blue-soft: #e2eef2;
  --amber: #b87922;
  --amber-soft: #f5ead8;
  --red: #be514d;
  --red-soft: #f6e2e0;
  --green: #258268;
  --shadow: 0 1px 2px rgba(20, 36, 29, 0.05);
  --radius: 6px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  min-width: 320px;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(22, 118, 95, 0.35);
  outline-offset: 2px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  background: var(--sidebar);
  color: #f4f8f6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 24px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: #2b8a6f;
  color: white;
  font-weight: 700;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 15px;
  font-weight: 600;
}

.brand span {
  margin-top: 3px;
  color: var(--sidebar-muted);
  font-size: 10px;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #bdcbc5;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.nav-item.is-active {
  background: #e6f2ed;
  color: #163b30;
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  flex: 0 0 18px;
  color: inherit;
  font-size: 17px;
  text-align: center;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 14px 8px 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-foot strong,
.sidebar-foot span {
  display: block;
}

.sidebar-foot strong {
  font-size: 12px;
  font-weight: 500;
}

.sidebar-foot span {
  margin-top: 2px;
  color: var(--sidebar-muted);
  font-size: 11px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #5dd7a9;
  box-shadow: 0 0 0 4px rgba(93, 215, 169, 0.12);
}

.main-area {
  min-width: 0;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 15px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.topbar h1,
.dialog-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.top-actions,
.toolbar,
.toolbar-group,
.section-actions,
.tab-strip,
.legend-row {
  display: flex;
  align-items: center;
}

.top-actions {
  gap: 12px;
}

.sync-state {
  padding-right: 12px;
  border-right: 1px solid var(--line);
  text-align: right;
}

.sync-state span,
.sync-state strong {
  display: block;
}

.sync-state span {
  color: var(--muted);
  font-size: 10px;
}

.sync-state strong {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 600;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
}

.icon-button:hover {
  background: var(--surface-soft);
}

.view-root {
  width: min(100%, 1580px);
  margin: 0 auto;
  padding: 22px 28px 40px;
}

.loading-state {
  min-height: 420px;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
}

.loading-state p {
  margin: 14px 0 0;
}

.loading-bar {
  width: 160px;
  height: 4px;
  position: relative;
  overflow: hidden;
  border-radius: 3px;
  background: var(--line);
}

.loading-bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 48px;
  background: var(--accent);
  animation: loading 1.2s ease-in-out infinite;
}

@keyframes loading {
  0% { transform: translateX(-50px); }
  100% { transform: translateX(170px); }
}

.toolbar {
  min-height: 48px;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.toolbar-group,
.section-actions,
.tab-strip,
.legend-row {
  gap: 8px;
  flex-wrap: wrap;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-inline label,
.control-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

select,
.search-input {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

select {
  min-width: 118px;
  padding: 0 30px 0 10px;
}

.search-input {
  width: min(280px, 100%);
  padding: 0 11px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #edf2ef;
}

.segmented button,
.tab-button,
.text-button,
.page-button {
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}

.segmented button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.tab-button {
  min-height: 34px;
  padding: 0 10px;
}

.tab-button.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.text-button {
  min-height: 32px;
  padding: 0 8px;
  color: var(--accent-strong);
}

.text-button:hover {
  background: var(--accent-soft);
}

.context-note {
  color: var(--muted);
  font-size: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.kpi-card {
  min-width: 0;
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-head,
.kpi-foot,
.section-head,
.signal-head,
.company-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  margin-top: 9px;
  font-size: 25px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}

.kpi-foot {
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.trend-up { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--muted); }

.micro-line {
  width: 72px;
  height: 24px;
  flex: 0 0 72px;
}

.section-band {
  padding: 22px 0;
  border-top: 1px solid var(--line);
}

.section-band:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.section-head {
  margin-bottom: 16px;
}

.section-head h2,
.section-head h3,
.company-detail-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.section-head p,
.company-detail-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.overview-grid,
.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.8fr);
  gap: 28px;
  align-items: start;
}

.equal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  align-items: start;
}

.chart-wrap {
  width: 100%;
  min-height: 280px;
  position: relative;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.chart-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: rgba(22, 118, 95, 0.08);
}

.chart-point {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-point.is-selected {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 3;
}

.chart-value-label {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 600;
}

.insight-list,
.signal-list,
.mover-list,
.quality-list {
  display: grid;
  gap: 0;
}

.insight-item,
.signal-item,
.mover-item,
.quality-item {
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.insight-item:first-child,
.signal-item:first-child,
.mover-item:first-child {
  padding-top: 0;
}

.insight-item:last-child,
.signal-item:last-child,
.mover-item:last-child,
.quality-item:last-child {
  border-bottom: 0;
}

.insight-number {
  display: inline-grid;
  width: 22px;
  height: 22px;
  place-items: center;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 650;
}

.insight-item strong,
.signal-item strong,
.mover-item strong {
  font-weight: 600;
}

.insight-item p,
.signal-item p,
.mover-item p,
.quality-item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.signal-head {
  align-items: flex-start;
}

.signal-date,
.rank-badge,
.status-tag,
.category-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
}

.signal-date,
.category-tag {
  background: var(--surface-soft);
  color: var(--muted);
}

.status-tag.is-good {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-tag.is-risk {
  background: var(--red-soft);
  color: #8c3532;
}

.status-tag.is-watch {
  background: var(--amber-soft);
  color: #7c521b;
}

.status-tag.is-neutral {
  background: var(--blue-soft);
  color: #2b6075;
}

.rank-badge {
  justify-content: center;
  min-width: 24px;
  padding: 0 5px;
  background: var(--surface-soft);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(180px, 2.8fr) 86px;
  gap: 12px;
  align-items: center;
}

.bar-label {
  min-width: 0;
}

.bar-label strong,
.bar-label span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-label strong {
  font-size: 12px;
  font-weight: 600;
}

.bar-label span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.bar-track,
.delta-track {
  height: 8px;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  background: #e8eeeb;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-fill.is-blue { background: var(--blue); }
.bar-fill.is-amber { background: var(--amber); }
.bar-fill.is-red { background: var(--red); }

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.stacked-bar {
  width: 100%;
  height: 18px;
  display: flex;
  overflow: hidden;
  border-radius: 4px;
  background: var(--line);
}

.stack-segment {
  height: 100%;
  min-width: 2px;
}

.stack-segment:nth-child(6n + 1) { background: var(--accent); }
.stack-segment:nth-child(6n + 2) { background: var(--blue); }
.stack-segment:nth-child(6n + 3) { background: var(--amber); }
.stack-segment:nth-child(6n + 4) { background: #7f6e9a; }
.stack-segment:nth-child(6n + 5) { background: #4f8a7b; }
.stack-segment:nth-child(6n) { background: #9b685d; }

.legend-row {
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
}

.legend-item:nth-child(6n + 2) .legend-swatch { background: var(--blue); }
.legend-item:nth-child(6n + 3) .legend-swatch { background: var(--amber); }
.legend-item:nth-child(6n + 4) .legend-swatch { background: #7f6e9a; }
.legend-item:nth-child(6n + 5) .legend-swatch { background: #4f8a7b; }
.legend-item:nth-child(6n) .legend-swatch { background: #9b685d; }

.table-shell {
  width: 100%;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  height: 43px;
  padding: 8px 10px;
  border-bottom: 1px solid #e8edea;
  text-align: left;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9f8;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.data-table tbody tr:hover {
  background: #f4f8f6;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table .numeric {
  text-align: right;
}

.data-table .name-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table .appid-cell {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
}

.sortable {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.sortable.is-active {
  color: var(--ink);
}

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

.page-actions {
  display: flex;
  gap: 5px;
}

.page-button {
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

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

.compare-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 24px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.compare-metric {
  padding: 16px;
  border-right: 1px solid var(--line);
}

.compare-metric:last-child {
  border-right: 0;
}

.compare-metric span,
.compare-metric strong,
.compare-metric small {
  display: block;
}

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

.compare-metric strong {
  margin-top: 7px;
  font-size: 18px;
  font-weight: 650;
}

.compare-metric small {
  margin-top: 5px;
  font-size: 11px;
}

.delta-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(180px, 3fr) 84px;
  gap: 12px;
  align-items: center;
  min-height: 34px;
}

.delta-track {
  height: 10px;
  overflow: visible;
  background: transparent;
}

.delta-track::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--line-strong);
}

.delta-fill {
  height: 8px;
  position: absolute;
  top: 1px;
  border-radius: 3px;
}

.delta-fill.is-positive {
  left: 50%;
  background: var(--green);
}

.delta-fill.is-negative {
  right: 50%;
  background: var(--red);
}

.delta-value {
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.company-detail {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 2px solid var(--ink);
}

.company-detail-head {
  margin-bottom: 14px;
}

.empty-state,
.error-state {
  min-height: 220px;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

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

.scope-dialog {
  width: min(620px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 16px 60px rgba(18, 34, 28, 0.18);
}

.scope-dialog::backdrop {
  background: rgba(15, 27, 22, 0.42);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.scope-content {
  padding: 6px 20px 20px;
}

.scope-row {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

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

.scope-row dt {
  color: var(--muted);
  font-size: 12px;
}

.scope-row dd {
  margin: 0;
  line-height: 1.6;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 13px;
  border-radius: 6px;
  background: var(--sidebar);
  color: white;
  box-shadow: 0 8px 32px rgba(18, 34, 28, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.weight-medium { font-weight: 600; }
.align-right { text-align: right; }

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

  .overview-grid,
  .split-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .compare-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .compare-metric:nth-child(3) {
    border-right: 0;
  }

  .compare-metric:nth-child(n + 4) {
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 900px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 12px 14px;
  }

  .brand {
    padding: 0 2px 12px;
  }

  .nav-list {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
    min-height: 38px;
  }

  .sidebar-foot {
    display: none;
  }

  .topbar {
    min-height: 68px;
    padding: 12px 18px;
  }

  .view-root {
    padding: 18px 18px 34px;
  }
}

@media (max-width: 700px) {
  .topbar h1 {
    font-size: 18px;
  }

  .sync-state {
    display: none;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-group {
    width: 100%;
  }

  .field-inline {
    min-width: 0;
    flex: 1 1 140px;
  }

  .field-inline select {
    min-width: 0;
    width: 100%;
  }

  .kpi-grid,
  .equal-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .chart-wrap {
    min-height: 0;
  }

  .compare-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compare-metric,
  .compare-metric:nth-child(3) {
    border-right: 1px solid var(--line);
    border-top: 1px solid var(--line);
  }

  .compare-metric:nth-child(odd) {
    border-left: 0;
  }

  .compare-metric:nth-child(even) {
    border-right: 0;
  }

  .compare-metric:first-child,
  .compare-metric:nth-child(2) {
    border-top: 0;
  }

  .bar-row,
  .delta-row {
    grid-template-columns: minmax(95px, 1fr) minmax(110px, 2fr) 68px;
    gap: 8px;
  }

  .scope-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 460px) {
  .brand-mark,
  .brand span,
  .nav-icon {
    display: none;
  }

  .brand {
    padding-bottom: 9px;
  }

  .nav-item {
    padding: 0 10px;
    font-size: 12px;
  }

  .topbar {
    padding: 11px 14px;
  }

  .view-root {
    padding: 14px 14px 28px;
  }

  .kpi-grid {
    gap: 8px;
  }

  .kpi-card {
    padding: 14px;
  }

  .kpi-value {
    font-size: 22px;
  }

  .compare-summary {
    grid-template-columns: minmax(0, 1fr);
  }

  .compare-metric,
  .compare-metric:nth-child(3),
  .compare-metric:nth-child(even) {
    border-right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
