:root {
  color-scheme: light;
  --canvas: #f5f7fb;
  --surface-1: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text-1: #172033;
  --text-2: #526078;
  --text-3: #7b879b;
  --brand: #2563eb;
  --brand-soft: #e8f0ff;
  --success: #07845a;
  --success-soft: #e6f7f0;
  --warning: #ad6800;
  --warning-soft: #fff5dd;
  --danger: #c93645;
  --danger-soft: #fff0f1;
  --info: #2563eb;
  --info-soft: #e8f0ff;
  --font: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --radius-control: 8px;
  --radius-card: 12px;
  --radius-panel: 16px;
  --control-height: 36px;
  --control-height-touch: 44px;
  --text-caption: 12px;
  --text-body: 14px;
  --text-heading: 18px;
  --shadow-subtle: 0 2px 10px rgb(23 32 51 / 4%);
  --panel-shadow: 0 8px 28px rgb(23 32 51 / 7%);
}

* { box-sizing: border-box; }

html { background: var(--canvas); }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--text-1);
  font: 400 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

button { color: inherit; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-4) max(var(--space-5), calc((100vw - 1600px) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(16px);
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 20px;
  font-weight: 620;
  letter-spacing: -0.3px;
}

h2 {
  font-size: var(--text-heading);
  font-weight: 590;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 590;
  letter-spacing: 0.08em;
}

.page-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: var(--space-5);
}

.button {
  display: inline-flex;
  min-height: var(--control-height);
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 7px var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.button svg, .input-wrap svg, .empty-state svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.button:hover { border-color: var(--line-strong); background: var(--surface-3); }
.button:active { transform: translateY(1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, .table-shell:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.button-secondary { background: var(--surface-1); box-shadow: 0 1px 2px rgb(23 32 51 / 6%); }
.button-ghost { align-self: end; background: transparent; }

.source-strip {
  display: grid;
  grid-template-columns: max-content 1px max-content 1fr;
  align-items: center;
  gap: 20px;
  padding: 20px var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface-1);
  box-shadow: var(--panel-shadow);
}

.source-strip > div:not(.source-divider) {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 2px 10px;
}

.source-strip span, .source-strip small { color: var(--text-2); }
.source-strip strong { font-size: 22px; font-weight: 620; }
.source-strip small { grid-column: 1 / -1; font-size: 12px; }
.source-strip p { justify-self: end; color: var(--text-3); }
.source-divider { width: 1px; height: 36px; background: var(--line); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.metric-card {
  min-height: 132px;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  box-shadow: var(--shadow-subtle);
  text-align: left;
  cursor: default;
  transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.metric-card:hover { border-color: var(--line-strong); }
.metric-card.is-selected { border-color: currentColor; background: var(--surface-2); }
.metric-card strong { display: block; margin: 12px 0 2px; font-size: 28px; line-height: 34px; }
.metric-card small { color: var(--text-2); }
.metric-label { font-size: 12px; font-weight: 590; }

.tone-success { color: var(--success); }
.tone-warning { color: var(--warning); }
.tone-danger { color: var(--danger); }
.tone-info { color: var(--info); }

.workspace {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface-1);
  box-shadow: var(--panel-shadow);
}

.workspace-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px 16px;
}

.result-count { color: var(--text-2); }
.result-count strong { color: var(--text-1); font-size: 18px; }

.filters {
  display: grid;
  grid-template-columns: minmax(260px, 1.6fr) minmax(180px, 0.7fr) auto;
  gap: 12px;
  padding: 16px 24px;
  border-block: 1px solid var(--line);
  background: var(--surface-2);
}

.field { display: grid; gap: 6px; }
.field > span { color: var(--text-2); font-size: 12px; font-weight: 510; }
.input-wrap { position: relative; }
.input-wrap svg {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 16px;
  color: var(--text-3);
  transform: translateY(-50%);
}

input, select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-1);
}

input { padding-left: 34px; }
input::placeholder { color: var(--text-3); }

.active-summary {
  min-height: 42px;
  padding: 11px 24px;
  color: var(--text-2);
  font-size: 12px;
}

.table-shell {
  overflow: auto;
  max-height: calc(100vh - 386px);
  border-top: 1px solid var(--line);
}

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

.company-table { min-width: 920px; }
.company-table th:first-child { min-width: 300px; }
.company-name { max-width: 420px; font-weight: 590; }
.number-cell { font-size: 16px; font-weight: 590; white-space: nowrap; }

.absent-link {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--danger-soft);
  cursor: pointer;
}

.absent-link.tone-success { background: var(--success-soft); }
.absent-link:hover { border-color: currentColor; }
.absent-link strong { font-size: 16px; }
.absent-link span { font-size: 12px; white-space: nowrap; }
.absent-link svg {
  width: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  transition: transform 160ms ease;
}
.is-expanded .absent-link svg { transform: rotate(180deg); }
.absent-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.rate-cell {
  display: grid;
  min-width: 110px;
  gap: 6px;
}

.rate-cell > span {
  overflow: hidden;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
}

.rate-cell i {
  display: block;
  width: var(--rate);
  height: 100%;
  border-radius: inherit;
  background: currentColor;
}

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

th {
  position: sticky;
  z-index: 3;
  top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 590;
  white-space: nowrap;
}

tbody tr { transition: background-color 160ms ease; }
tbody tr:hover { background: var(--surface-2); }

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 510;
  white-space: nowrap;
}

.status-pill.tone-success { background: var(--success-soft); }
.status-pill.tone-warning { background: var(--warning-soft); }
.status-pill.tone-danger { background: var(--danger-soft); }
.status-pill.tone-info { background: var(--info-soft); }
.member-cell { font-weight: 590; white-space: nowrap; }
.company-cell { min-width: 230px; max-width: 340px; color: var(--text-2); }
.nowrap { white-space: nowrap; }
.subtle, .muted { color: var(--text-3); }

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--text-2);
}

.empty-state[hidden] { display: none; }
.empty-state svg { width: 32px; color: var(--text-3); }
.empty-state span { color: var(--text-3); font-size: 12px; }

.detail-row > td {
  padding: 0;
  background: var(--canvas);
}

.inline-detail {
  padding: 16px 20px 20px;
  border-bottom: 1px solid var(--line-strong);
}

.inline-detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.inline-detail-head span { color: var(--text-2); font-size: 12px; }

.absence-stores {
  display: grid;
  gap: 10px;
}

.absence-store {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-1);
}

.absence-store-head {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.absence-store-head b,
.absence-broker > b {
  color: var(--danger);
  font-size: 13px;
}

.absence-rank,
.broker-rank {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  font-weight: 650;
}

.absence-brokers {
  display: grid;
}

.absence-broker {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 10px 12px;
}

.absence-broker + .absence-broker { border-top: 1px solid var(--line); }
.absence-broker > div { display: grid; gap: 3px; }
.absence-broker strong { font-size: 14px; }
.absence-broker small { color: var(--text-2); font-size: 12px; }
.broker-rank { background: var(--surface-3); color: var(--text-2); }
.inline-all-arrived { padding: 16px; color: var(--success); }

@media (max-width: 1000px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-search { grid-column: 1 / -1; }
  .button-ghost { width: 100%; }
  .table-shell { max-height: calc(100vh - 510px); }
}

@media (max-width: 600px) {
  .topbar { position: static; align-items: flex-start; padding: 16px; }
  .topbar h1 { font-size: 17px; }
  .topbar .eyebrow { font-size: 10px; }
  .topbar .button { flex: 0 0 auto; min-width: 44px; min-height: 44px; padding-inline: 12px; }
  .topbar .button svg { margin: 0; }
  .topbar .button { font-size: 0; }
  .page-shell { padding: 12px; }
  .source-strip { grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; }
  .source-divider { display: none; }
  .source-strip p { grid-column: 1 / -1; justify-self: start; }
  .source-strip strong { font-size: 20px; }
  .metric-grid { gap: 8px; }
  .metric-card { min-height: 104px; padding: 12px; }
  .metric-card strong { margin-top: 8px; }
  .workspace-header { align-items: start; padding: 16px; }
  .filters { grid-template-columns: 1fr; padding: 12px 16px; }
  .field-search { grid-column: auto; }
  input, select, .button-ghost { min-height: 44px; }
  .active-summary { padding-inline: 16px; }
  .table-shell { max-height: none; }
  .inline-detail-head { display: grid; }
  .absence-store-head,
  .absence-broker { grid-template-columns: 24px minmax(0, 1fr) auto; }
}

@media (max-width: 720px) {
  .table-shell { overflow: visible; border-top: 0; }
  .company-table,
  .company-table tbody { display: block; min-width: 0; }
  .company-table thead { display: none; }
  .company-table tbody { padding: 0 12px 12px; }
  .company-table tbody > tr:not(.detail-row) {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--line);
    box-shadow: var(--shadow-subtle);
  }
  .company-table tbody > tr:not(.detail-row):hover { background: var(--line); }
  .company-table tbody > tr:not(.detail-row) > td {
    display: grid;
    grid-column: span 2;
    min-width: 0;
    min-height: 62px;
    align-content: center;
    gap: 4px;
    padding: 10px 12px;
    border: 0;
    background: var(--surface-1);
  }
  .company-table tbody > tr:not(.detail-row) > td::before {
    content: attr(data-label);
    color: var(--text-3);
    font-size: 11px;
    font-weight: 590;
  }
  .company-table tbody > tr:not(.detail-row) > td.company-name {
    grid-column: span 6;
    max-width: none;
    min-height: auto;
    padding-block: 13px;
    font-size: 15px;
  }
  .company-table .company-name::before { display: none; }
  .company-table tbody > tr:not(.detail-row) > td.absent-cell {
    grid-column: span 6;
    min-height: auto;
  }
  .company-table tbody > tr:not(.detail-row) > td:nth-child(2),
  .company-table tbody > tr:not(.detail-row) > td:nth-child(3) {
    grid-column: span 3;
  }
  .absent-link {
    width: 100%;
    min-height: var(--control-height-touch);
    justify-content: space-between;
    padding: 9px 12px;
  }
  .absent-link strong { font-size: 18px; }
  .rate-cell { min-width: 0; }
  .detail-row { display: block; margin: -4px 0 12px; }
  .detail-row > td { display: block; }
  .inline-detail { padding: 14px 12px 16px; }
  .absence-store { border-radius: 10px; }
  .absence-store-head,
  .absence-broker { padding: 10px; }
  .absence-broker > b { white-space: nowrap; }
}

@media (max-width: 380px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .company-table tbody { padding-inline: 8px; }
  .company-table tbody > tr:not(.detail-row) > td { padding-inline: 9px; }
}

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