:root {
  --surface: #f7f9fb;
  --surface-lowest: #ffffff;
  --surface-low: #f2f4f6;
  --surface-high: #e6e8ea;
  --surface-highest: #e0e3e5;
  --ink: #191c1e;
  --ink-soft: #45464d;
  --muted: #76777d;
  --black: #000000;
  --white: #ffffff;
  --sidebar-width: 256px;
  --topbar-height: 72px;
  --content-max: 1280px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { min-width: 320px; background: var(--surface-lowest); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface-lowest);
  color: var(--ink);
  font-family: "Hanken Grotesk", "Avenir Next", "PingFang SC", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.dialog-open { overflow: hidden; }

button,
a { font: inherit; }

button { color: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 3px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--surface-highest);
  background: rgb(247 249 251 / 94%);
  backdrop-filter: blur(18px);
}

.topbar-inner {
  display: flex;
  align-items: stretch;
  width: 100%;
  max-width: calc(var(--content-max) + var(--sidebar-width));
  height: 100%;
  margin: 0 auto;
  padding: 0 32px;
}

.brand {
  align-self: center;
  color: var(--black);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  text-decoration: none;
  white-space: nowrap;
}

.primary-nav {
  display: flex;
  align-items: stretch;
  gap: 34px;
  height: 100%;
  margin-left: 72px;
}

.nav-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 1px 0 0;
  transition: color 160ms ease;
}

.nav-tab::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--black);
  content: "";
  opacity: 0;
  transform: scaleX(.35);
  transition: opacity 160ms ease, transform 160ms ease;
}

.nav-tab:hover,
.nav-tab.is-active { color: var(--black); }

.nav-tab.is-active { font-weight: 700; }

.nav-tab.is-active::after { opacity: 1; transform: scaleX(1); }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  max-width: calc(var(--content-max) + var(--sidebar-width));
  min-height: calc(100vh - var(--topbar-height));
  margin: 0 auto;
}

.sidebar {
  min-height: calc(100vh - var(--topbar-height));
  padding: 34px 28px 48px;
  background: var(--surface-low);
}

.sidebar-header { margin-bottom: 38px; }

.library-sidebar-header { margin-bottom: 20px; }

.sidebar-summary {
  margin-bottom: 30px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--surface-highest);
}

.sidebar-header h2 {
  margin: 6px 0 0;
  color: var(--black);
  font-size: 24px;
  line-height: 32px;
  letter-spacing: -.02em;
}

.section-kicker,
.filter-title,
.listing-head,
.metric-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .085em;
  line-height: 16px;
  text-transform: uppercase;
}

.section-kicker { margin: 0 0 5px; }

.filter-group + .filter-group {
  margin-top: 36px;
  padding-top: 30px;
  border-top: 1px solid var(--surface-highest);
}

.filter-title {
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  color: var(--ink-soft);
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 36px;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 14px;
  line-height: 20px;
}

.filter-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1px solid #9b9ca1;
  border-radius: 2px;
  accent-color: var(--black);
  cursor: pointer;
}

.filter-option:hover { color: var(--black); }

.amount-range {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.amount-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
}

.amount-input {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 34px;
  padding-left: 9px;
  border: 1px solid var(--surface-highest);
  border-radius: 4px;
  background: var(--white);
  color: var(--muted);
}

.amount-input:focus-within {
  border-color: var(--black);
  box-shadow: 0 0 0 1px var(--black);
}

.amount-input input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 7px 0 3px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--black);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.amount-input input::-webkit-inner-spin-button { margin: 0; }

.amount-input:has(input[aria-invalid="true"]) {
  border-color: #a83b32;
  box-shadow: 0 0 0 1px #a83b32;
}

.document-nav { display: grid; gap: 6px; }

.document-nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
}

.document-nav button::after { content: "→"; opacity: 0; transform: translateX(-5px); transition: 160ms ease; }
.document-nav button:hover { color: var(--black); background: var(--surface-high); }
.document-nav button.is-active { color: var(--black); background: var(--surface-high); font-weight: 700; }
.document-nav button.is-active::after { opacity: 1; transform: translateX(0); }

.main-content {
  min-width: 0;
  padding: 44px 40px 80px;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 40px;
}

.content-header h1,
.document-empty h1 {
  margin: 0;
  color: var(--black);
  font-size: 32px;
  font-weight: 650;
  letter-spacing: -.025em;
  line-height: 40px;
}

.content-intro {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 24px;
}

.content-tools {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.search-control {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  width: 200px;
  max-width: 100%;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--surface-highest);
  border-radius: 5px;
  background: var(--white);
  color: var(--muted);
}

.search-control:focus-within {
  border-color: var(--black);
  box-shadow: 0 0 0 1px var(--black);
}

.search-icon {
  flex: 0 0 auto;
  color: var(--black);
  font-size: 19px;
  line-height: 1;
}

.search-control input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 0 0 7px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}

.search-control input::placeholder { color: var(--muted); }

.sort-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
}

.sort-control select {
  width: 100%;
  height: 36px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--surface-highest);
  border-radius: 4px;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

.sort-control select:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 2px;
}

.listing-count {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
}

.filter-trigger {
  display: none;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--surface-highest);
  border-radius: 4px;
  background: var(--white);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.listing-head,
.listing-row {
  display: grid;
  grid-template-columns: minmax(264px, 2.58fr) 1.1fr 1.1fr .8fr 264px;
  column-gap: 24px;
  align-items: center;
}

.listing-head {
  position: sticky;
  z-index: 20;
  top: var(--topbar-height);
  padding: 13px 20px;
  border-bottom: 1px solid var(--surface-highest);
  background: var(--surface-lowest);
}

.listing-body { min-height: 200px; }

.listing-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-top: 32px;
}

.pagination-button {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--surface-highest);
  border-radius: 4px;
  background: var(--white);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.pagination-button:hover:not(:disabled) { border-color: var(--black); color: var(--black); }
.pagination-button[aria-current="page"] { border-color: var(--black); background: var(--black); color: var(--white); font-weight: 700; }
.pagination-button:disabled { color: var(--surface-highest); cursor: not-allowed; }
.pagination-ellipsis { width: 24px; color: var(--muted); text-align: center; }

.listing-row {
  position: relative;
  min-height: 82px;
  margin-top: 4px;
  padding: 21px 20px;
  border-radius: 8px;
  animation: row-in 360ms both;
  transition: background-color 180ms ease, transform 180ms ease;
}

.listing-row:hover { background: var(--surface-low); transform: translateX(2px); }

@keyframes row-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.project-cell { display: flex; align-items: center; gap: 15px; min-width: 0; }

.project-logo {
  position: relative;
  display: grid;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--surface-highest);
  border-radius: 7px;
  background: var(--surface-high);
  color: #505f76;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}

.project-logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--white); }
.project-logo.is-broken img { display: none; }
.project-copy { min-width: 0; }
.project-name { overflow: hidden; color: var(--black); font-size: 16px; font-weight: 700; line-height: 22px; text-overflow: ellipsis; white-space: nowrap; }

.project-value-proposition {
  grid-column: 1 / -1;
  overflow: hidden;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-label { display: none; margin-bottom: 4px; font-size: 10px; }
.metric-value { color: var(--black); font-size: 16px; font-variant-numeric: tabular-nums; font-weight: 600; line-height: 22px; }
.metric-value.is-missing { color: var(--muted); font-size: 13px; font-weight: 500; }

.listing-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.listing-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--black);
  border-radius: 4px;
  background: var(--white);
  color: var(--black);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 160ms ease, color 160ms ease;
}

.listing-action::after { content: "↗"; font-size: 13px; }
.listing-action:hover { background: var(--black); color: var(--white); }
.snapshot-button:disabled { border-color: var(--surface-highest); color: var(--muted); cursor: not-allowed; }
.snapshot-button:disabled::after { display: none; }
.snapshot-button:disabled:hover { background: var(--white); color: var(--muted); }

.empty-state,
.error-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  border-bottom: 1px solid var(--surface-highest);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.error-state { color: #93000a; }

.loading-state { display: grid; gap: 8px; padding-top: 12px; }
.loading-line { height: 76px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-low) 20%, var(--surface) 50%, var(--surface-low) 80%); background-size: 240% 100%; animation: loading 1.4s infinite linear; }
@keyframes loading { to { background-position: -240% 0; } }

.document-empty {
  display: flex;
  min-height: calc(100vh - 200px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.document-mark { width: 50px; height: 64px; margin-bottom: 24px; border: 1px solid var(--surface-highest); border-radius: 4px; background: linear-gradient(135deg, transparent 12px, var(--surface-low) 0) top right / 17px 17px no-repeat, var(--surface); }
.document-empty p:last-child { margin: 12px 0 0; color: var(--muted); }

.drawer-backdrop { display: none; }

.snapshot-dialog {
  width: min(1120px, calc(100vw - 48px));
  max-width: none;
  height: min(860px, calc(100vh - 48px));
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 28px 80px rgb(19 27 46 / 22%);
}

.snapshot-dialog::backdrop { background: rgb(25 28 30 / 48%); backdrop-filter: blur(4px); }
.snapshot-panel { display: grid; grid-template-rows: 76px 1fr; height: 100%; }
.snapshot-header { display: flex; align-items: center; justify-content: space-between; padding: 0 24px 0 28px; border-bottom: 1px solid var(--surface-highest); }
.snapshot-header h2 { max-width: min(70vw, 800px); margin: 0; overflow: hidden; color: var(--black); font-size: 20px; text-overflow: ellipsis; white-space: nowrap; }
.dialog-close { display: grid; width: 38px; height: 38px; padding: 0 0 3px; place-items: center; border: 0; border-radius: 50%; background: var(--surface-low); cursor: pointer; font-size: 25px; line-height: 1; transition: background-color 160ms ease; }
.dialog-close:hover { background: var(--surface-high); }
#snapshot-frame { width: 100%; height: 100%; border: 0; background: var(--surface-high); }

@media (max-width: 1100px) {
  .listing-head { display: none; }
  .listing-row { grid-template-columns: 1fr 1fr; gap: 18px 24px; margin: 0; padding: 23px 0; border-bottom: 1px solid var(--surface-highest); border-radius: 0; }
  .listing-row:hover { background: transparent; transform: none; }
  .project-cell, .listing-actions { grid-column: 1 / -1; }
  .metric-label { display: block; }
  .listing-actions { margin-top: 2px; }
  .listing-action { min-height: 40px; padding: 0 8px; font-size: 11px; }
  .project-value-proposition {
    display: -webkit-box;
    margin-top: 0;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

@media (max-width: 900px) {
  .project-value-proposition { order: 1; }
  .listing-actions { order: 2; }
  .topbar-inner { padding: 0 20px; }
  .brand { font-size: 21px; }
  .primary-nav { gap: 24px; margin-left: auto; }
  .nav-tab { font-size: 14px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 50; top: var(--topbar-height); bottom: 0; left: 0; width: min(84vw, 320px); min-height: 0; overflow-y: auto; box-shadow: 18px 0 45px rgb(19 27 46 / 12%); transform: translateX(-105%); transition: transform 220ms ease; }
  .sidebar.is-open { transform: translateX(0); }
  .drawer-backdrop { position: fixed; z-index: 45; inset: var(--topbar-height) 0 0 min(84vw, 320px); width: auto; height: auto; border: 0; background: rgb(25 28 30 / 32%); }
  .drawer-backdrop.is-visible { display: block; }
  .main-content { padding: 30px 20px 60px; }
  .content-header { align-items: flex-start; flex-wrap: wrap; margin-bottom: 28px; }
  .content-header h1 { font-size: 28px; line-height: 36px; }
  .content-intro { max-width: 420px; }
  .content-tools { flex-direction: column; align-items: flex-end; gap: 10px; }
  .filter-trigger { display: inline-flex; }
  .snapshot-dialog { width: calc(100vw - 20px); height: calc(100vh - 20px); }
  .snapshot-header { padding: 0 14px 0 18px; }
}

@media (max-width: 600px) {
  .listing-pagination { gap: 2px; }
  .pagination-button { min-width: 28px; height: 30px; padding: 0 4px; font-size: 12px; }
  .pagination-ellipsis { width: 12px; }
}

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