:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-soft: #fbfcfe;
  --surface-muted: #f4f6fa;
  --border: #e4e9f2;
  --border-strong: #d6dfed;
  --text: #101827;
  --text-muted: #6b7284;
  --nav: #181b21;
  --blue: #1f56c7;
  --blue-strong: #133e95;
  --blue-soft: #edf4ff;
  --orange: #ff7a00;
  --orange-soft: #fff1e3;
  --green: #029c52;
  --red: #d83a2f;
  --shadow-lg: 0 18px 40px rgba(16, 24, 39, 0.08);
  --shadow-sm: 0 8px 20px rgba(16, 24, 39, 0.05);
  --radius-xl: 18px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --content-width: 1200px;
  --font-sans: "Inter", "PingFang SC", "PingFang HK", "Helvetica Neue",
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: linear-gradient(180deg, #f7f9fc 0%, #f8f9fb 100%);
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
}

.topbar {
  background: var(--nav);
  border-bottom: 1px solid rgba(119, 140, 181, 0.25);
}

.topbar__inner {
  width: min(calc(100% - 48px), 1520px);
  height: 60px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 180px 1fr auto;
  align-items: center;
  gap: 28px;
}

.brand {
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.topnav {
  display: flex;
  gap: 28px;
  align-items: center;
  overflow: hidden;
}

.topnav a {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}

.topnav a.is-active {
  color: #fff;
  font-weight: 600;
}

.topbar__actions {
  display: flex;
  gap: 10px;
}

.hero__stats {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.page {
  width: min(calc(100% - 40px), var(--content-width));
  margin: 0 auto;
  padding: 26px 0 48px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.hero h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1.1;
}

.hero p {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

.found-count {
  margin-top: 18px;
  color: var(--blue-strong);
  font-weight: 700;
  font-size: 14px;
}

.template-module__insert-note {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 18px;
  border-radius: 12px;
  border: 1px dashed #c9d7ef;
  background: linear-gradient(180deg, #f6faff 0%, #f2f7ff 100%);
}

.insert-note__tag {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: #dceafe;
  color: var(--blue-strong);
  font-size: 12px;
  font-weight: 700;
}

.insert-note__text {
  font-size: 13px;
  color: #496182;
}

.template-module,
.filters-module,
.results-module,
.annotation-card {
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
}

.template-module {
  padding: 20px 24px 18px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-lg);
  background:
    linear-gradient(180deg, #ffffff 0%, #fbfcff 100%),
    linear-gradient(90deg, rgba(31, 86, 199, 0.06) 0%, rgba(31, 86, 199, 0) 100%);
}

.module-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 24px;
  align-items: start;
  margin-bottom: 16px;
}

.module-head__main {
  min-width: 0;
}

.module-head__aside {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.module-side-note {
  max-width: 240px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: right;
}

.module-kicker {
  color: var(--blue-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.module-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.module-description {
  color: var(--text-muted);
  font-size: 13px;
  max-width: 680px;
}

.template-rail-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 22px;
  align-items: center;
}

.template-rail-nav {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.template-rail {
  display: flex;
  gap: 10px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.template-rail::-webkit-scrollbar {
  display: none;
}

.rail-nav-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--blue-strong);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.rail-nav-btn:hover {
  border-color: #bfd1ee;
  background: #f8fbff;
}

.rail-nav-btn:disabled {
  cursor: default;
  color: #bdc7d8;
  border-color: #e7ecf4;
  background: #f8fafc;
}

.template-pill {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.18s ease;
}

.template-pill:hover {
  border-color: #abc4f5;
  box-shadow: var(--shadow-sm);
}

.template-pill.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow:
    0 0 0 3px rgba(31, 86, 199, 0.09),
    inset 0 -2px 0 rgba(31, 86, 199, 0.2);
}

.template-pill__title {
  font-size: 14px;
  white-space: nowrap;
}

.template-pill.is-active .template-pill__title {
  color: var(--blue-strong);
  font-weight: 700;
}

.template-pill__meta {
  color: var(--green);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.pill-market {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid #cfdbef;
  background: #f7faff;
  color: var(--blue-strong);
  font-size: 10px;
  font-weight: 700;
}

.pill-info {
  color: #b0b9c8;
  font-size: 12px;
}

.rail-progress {
  margin-top: 12px;
  height: 6px;
  width: min(68%, 820px);
  border-radius: 999px;
  background: #e9eef6;
}

.rail-progress__fill {
  width: 18%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff7a00 0%, #ffa24d 100%);
  transition: width 0.22s ease;
}

.filters-module {
  padding: 16px 24px 18px;
  margin-bottom: 18px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(16, 24, 39, 0.02);
}

.section-caption {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.filters-module__head {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}

.filters-module__left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.filters-title {
  font-weight: 700;
  font-size: 18px;
}

.applied-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  font-size: 14px;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  color: var(--blue-strong);
  background: var(--blue-soft);
  border: 1px solid #b7cff7;
  font-weight: 700;
  font-size: 12px;
}

.text-link {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--blue-strong);
  font-weight: 600;
  cursor: pointer;
}

.filters-module__search {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: #9ba5b5;
  font-size: 14px;
}

.search-icon {
  order: 2;
  font-size: 16px;
}

.filters-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.filter-tab {
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-tab.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue-strong);
  font-weight: 700;
}

.results-module {
  padding: 20px 24px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
}

.applied-template-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-bottom: 14px;
}

.applied-template-bar__label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.applied-template-bar__name {
  color: var(--blue-strong);
  font-size: 15px;
  font-weight: 700;
}

.results-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
}

.results-label {
  color: var(--blue-strong);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.results-summary h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.results-summary p {
  margin: 0;
  color: var(--text-muted);
  max-width: 620px;
  font-size: 14px;
}

.results-actions {
  display: flex;
  gap: 10px;
}

.template-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  margin-bottom: 16px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 12px;
}

.tag-chip.is-key {
  border-color: #ffc58e;
  background: var(--orange-soft);
  color: #c06205;
  font-weight: 600;
}

.tag-chip.is-selected-template {
  border-color: #bfd1ee;
  background: #edf4ff;
  color: var(--blue-strong);
  font-weight: 700;
}

.table-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-head,
.table-row {
  display: grid;
  grid-template-columns: 100px 1.5fr 110px 110px 120px;
  gap: 0;
  align-items: center;
}

.table-head {
  min-height: 46px;
  padding: 0 16px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.table-row {
  min-height: 58px;
  padding: 0 16px;
  border-top: 1px solid #eef2f7;
  font-size: 13px;
}

.table-row:nth-child(odd) {
  background: #fff;
}

.table-row:nth-child(even) {
  background: #fcfdff;
}

.is-positive {
  color: var(--green);
  font-weight: 700;
}

.is-negative {
  color: var(--red);
  font-weight: 700;
}

.annotation-panel {
  display: grid;
  grid-template-columns: 1fr;
}

.annotation-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px dashed #d5dfef;
  background: #fbfdff;
  color: var(--text-muted);
  font-size: 12px;
}

.annotation-strip__label {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--blue-strong);
  font-weight: 700;
}

.template-hover-card {
  position: fixed;
  z-index: 45;
  width: 310px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: #fff;
  box-shadow: 0 20px 50px rgba(16, 24, 39, 0.16);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
}

.template-hover-card.is-visible {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
}

.hover-card__title-row {
  margin-bottom: 10px;
}

.hover-card__title {
  font-size: 15px;
  font-weight: 700;
}

.hover-card__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.hover-card__desc {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.hover-card__apply {
  display: block;
  margin-left: auto;
}

.hover-card__apply.is-applied {
  color: var(--green);
  cursor: default;
}

.btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.18s ease;
}

.btn--sm {
  height: 36px;
}

.btn--ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.btn--ghost:hover {
  border-color: #b8c7de;
}

.btn--primary {
  background: var(--blue-strong);
  color: #fff;
}

.btn--primary:hover {
  background: #0f347d;
}

.btn--icon .arrow {
  font-size: 18px;
  line-height: 1;
  color: var(--blue-strong);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 23, 38, 0.3);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 40;
}

.modal-backdrop--compact {
  z-index: 55;
}

.dialog-card {
  width: min(520px, calc(100vw - 40px));
  border-radius: 18px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 28px 60px rgba(16, 24, 39, 0.14);
  padding: 28px 28px 24px;
}

.dialog-card__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.dialog-card__header h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.dialog-card__header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
}

.dialog-card__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.dialog-card__actions--stack {
  flex-direction: column;
}

.dialog-card__actions--stack .btn {
  width: 100%;
}

.field-block {
  display: grid;
  gap: 8px;
}

.field-block__label {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.field-block__input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font: inherit;
}

.field-block__input:focus {
  outline: none;
  border-color: #9cb7ea;
  box-shadow: 0 0 0 3px rgba(31, 86, 199, 0.08);
}

.modal-close {
  border: 0;
  background: transparent;
  color: #b0b8c5;
  font-size: 38px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 8px;
}

.modal-close:hover {
  background: #f3f5f9;
  color: #7f8aa0;
}

.apply-link {
  border: 0;
  background: transparent;
  color: var(--blue-strong);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.apply-link.is-applied {
  color: var(--green);
  cursor: default;
}

.apply-link:disabled {
  opacity: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  min-width: 168px;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(16, 24, 39, 0.9);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  box-shadow: 0 18px 40px rgba(16, 24, 39, 0.18);
  z-index: 70;
}

@media (max-width: 1024px) {
  .topbar__inner {
    width: calc(100% - 32px);
    grid-template-columns: 1fr auto;
  }

  .topnav {
    display: none;
  }

  .page {
    width: calc(100% - 24px);
    padding-top: 18px;
  }

  .module-head,
  .filters-module__head,
  .results-head,
  .template-rail-wrap {
    grid-template-columns: 1fr;
  }

  .module-head__aside {
    justify-items: start;
  }

  .module-side-note {
    text-align: left;
  }

  .template-rail-nav {
    grid-template-columns: 1fr;
  }

  .rail-nav-btn {
    display: none;
  }

  .table-head,
  .table-row {
    grid-template-columns: repeat(5, minmax(90px, 1fr));
    overflow-x: auto;
  }

  .dialog-card {
    padding: 24px 20px 20px;
  }
}

@media (max-width: 640px) {
  .hero {
    flex-direction: column;
  }

  .hero h1 {
    font-size: 30px;
  }

  .template-module,
  .filters-module,
  .results-module {
    padding-left: 16px;
    padding-right: 16px;
  }

  .filters-module__left {
    flex-wrap: wrap;
  }

  .annotation-strip {
    align-items: flex-start;
    min-height: auto;
    padding: 10px 12px;
  }

  .modal {
    padding: 20px 16px 18px;
  }

  .modal__header h3 {
    font-size: 28px;
  }
}
