:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #fbfbf8;
  --ink: #20231f;
  --muted: #62685f;
  --line: #d9ddd2;
  --line-strong: #b9c0b2;
  --accent: #2d6d5a;
  --accent-dark: #194c3d;
  --table-header-bg: #214f42;
  --table-header-bg-strong: #173c31;
  --amber: #a36920;
  --shadow: 0 16px 34px rgba(45, 55, 45, 0.08);
  --table-header-offset: 0px;
  --mono: "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, monospace;
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(45, 109, 90, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(163, 105, 32, 0.08), transparent 38%),
    var(--bg);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 28px clamp(18px, 4vw, 56px) 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.86);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}

.brand h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 4vw, 46px);
  line-height: 1.05;
  font-weight: 720;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
}

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

.action-button,
.icon-button {
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  background: var(--accent-dark);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.action-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.action-button.subtle {
  background: transparent;
  color: var(--accent-dark);
}

main {
  width: min(100%, 1560px);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 40px) 42px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.summary-item {
  min-height: 96px;
  padding: 18px;
  background: var(--panel);
}

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

.summary-item strong {
  font-family: var(--mono);
  font-size: clamp(26px, 3vw, 36px);
  font-weight: 650;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(5, minmax(145px, 1fr));
  gap: 12px;
  margin: 18px 0;
  align-items: end;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 109, 90, 0.16);
}

.insight-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: var(--line);
}

.insight-strip > div {
  background: var(--panel-soft);
  padding: 18px;
}

.insight-strip h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  position: relative;
}

.tooltip {
  position: relative;
  display: inline-flex;
}

.tooltip-trigger {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: #fff;
  color: var(--accent-dark);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 720;
  cursor: help;
}

.tooltip-card {
  position: absolute;
  top: calc(100% + 10px);
  left: -40px;
  width: min(760px, calc(100vw - 48px));
  max-height: min(620px, calc(100dvh - 120px));
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 22px 48px rgba(32, 35, 31, 0.18);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 25;
}

.tooltip:hover .tooltip-card,
.tooltip:focus-within .tooltip-card {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.tooltip-card p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.6;
}

.tooltip-card p:last-child {
  margin: 12px 0 0;
}

.tooltip-card table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 12px;
}

.tooltip-card th,
.tooltip-card td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

.tooltip-card th {
  background: var(--table-header-bg);
  color: #fff;
  font-weight: 720;
}

.tooltip-card td:first-child {
  font-family: var(--mono);
  font-weight: 720;
  white-space: nowrap;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 12px;
}

.breakdown-pill {
  appearance: none;
  min-height: 34px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.breakdown-pill:hover,
.breakdown-pill:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.breakdown-pill:focus-visible {
  outline: 3px solid rgba(45, 109, 90, 0.18);
  outline-offset: 2px;
}

.breakdown-pill:active {
  transform: translateY(1px);
}

.breakdown-pill.active {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  color: #fff;
}

.pill strong {
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 650;
}

.breakdown-pill.active strong {
  color: #fff;
}

.table-section {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.table-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.table-meta p {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
}

table {
  width: 100%;
  min-width: 2100px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: var(--table-header-offset);
  z-index: 12;
  background: var(--table-header-bg);
  color: #fff;
  text-align: left;
  font-size: 13px;
  font-weight: 760;
  border-bottom: 2px solid var(--table-header-bg-strong);
  padding: 13px 10px;
  white-space: nowrap;
  user-select: none;
  box-shadow: 0 8px 18px rgba(32, 35, 31, 0.16);
}

thead th.sortable:hover {
  background: var(--table-header-bg-strong);
}

tbody td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
  max-width: 280px;
  min-width: 92px;
  line-height: 1.45;
}

tbody tr {
  background: #fff;
  transition: background 140ms ease;
}

tbody tr:nth-child(even) {
  background: #fbfcfa;
}

tbody tr:hover,
tbody tr.selected {
  background: #edf5ef;
}

tbody td:first-child,
thead th:first-child {
  position: sticky;
  left: 0;
  background: inherit;
  box-shadow: 1px 0 0 var(--line);
  font-family: var(--mono);
  font-weight: 650;
}

tbody td:first-child {
  z-index: 3;
}

thead th:first-child {
  z-index: 14;
  background: var(--table-header-bg-strong);
  color: #fff;
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.18), 0 8px 18px rgba(32, 35, 31, 0.18);
}

.number-cell {
  font-family: var(--mono);
  text-align: right;
}

.focus-cell {
  color: var(--amber);
  font-weight: 720;
  letter-spacing: 0;
}

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

.detail-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(520px, calc(100vw - 36px));
  max-height: min(720px, calc(100dvh - 36px));
  overflow: auto;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 22px 48px rgba(32, 35, 31, 0.18);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 30;
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 35, 31, 0.16);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 29;
}

.detail-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.detail-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.detail-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-header h2 {
  margin: 4px 0 0;
  font-size: 21px;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  background: var(--accent-dark);
  color: #fff;
  border-color: var(--accent-dark);
}

.quote-panel {
  padding: 14px 18px 0;
}

.quote-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 13px 14px;
}

.quote-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.quote-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.quote-main strong {
  font-family: var(--mono);
  font-size: 24px;
}

.quote-main span {
  font-family: var(--mono);
  font-weight: 720;
}

.quote-card.positive .quote-main span {
  color: #1f7a53;
}

.quote-card.negative .quote-main span {
  color: #b23b3b;
}

.quote-card.neutral .quote-main span {
  color: var(--muted);
}

.quote-meta,
.quote-empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.detail-panel dl {
  margin: 0;
  padding: 8px 18px 18px;
}

.detail-panel dt {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.detail-panel dd {
  margin: 5px 0 0;
  color: var(--ink);
  line-height: 1.55;
  word-break: break-word;
}

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

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

  .search-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .summary-grid,
  .controls,
  .insight-strip {
    grid-template-columns: 1fr;
  }

  .table-meta {
    display: grid;
  }

  .tooltip-card {
    left: -18px;
    width: calc(100vw - 36px);
  }

}
