:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-muted: #eef2f0;
  --border: #d8dfdc;
  --text: #202724;
  --muted: #68736e;
  --accent: #176b55;
  --accent-hover: #105442;
  --accent-soft: #e3f1eb;
  --blue: #2855a6;
  --blue-soft: #e8eef9;
  --red: #a33c42;
  --red-soft: #f8e9ea;
  --yellow: #765c0a;
  --yellow-soft: #f8f1d7;
  --shadow: 0 8px 24px rgba(31, 42, 37, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 26px;
}

h2 {
  margin-bottom: 14px;
  font-size: 17px;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 7px;
}

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

.brand small {
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.trial-counter {
  padding: 5px 8px;
  border: 1px solid #8fb9aa;
  border-radius: 5px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 750;
}

.page {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 40px) 50px;
}

.page-heading,
.section-heading,
.contact-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.page-heading {
  margin-bottom: 22px;
}

.page-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}

.button:hover {
  border-color: #aab6b1;
  text-decoration: none;
}

.button-primary {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.button-primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.button-secondary {
  color: var(--accent);
  border-color: #8fb9aa;
}

.button-quiet {
  min-height: 34px;
  color: var(--muted);
  border-color: transparent;
  background: transparent;
}

.button-small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.button-wide {
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-tile {
  display: flex;
  min-height: 72px;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface);
}

.stat-tile:hover,
.stat-tile.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  text-decoration: none;
}

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

.stat-tile strong {
  font-size: 21px;
}

.filters-form {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.filter-primary {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) repeat(5, minmax(130px, 1fr));
  align-items: end;
  gap: 10px;
  padding: 14px;
}

.filters-form label,
.stack-form label {
  display: grid;
  gap: 5px;
}

.filters-form label > span,
.stack-form label > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.filters-form input,
.filters-form select,
.stack-form input,
.stack-form select,
.stack-form textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  outline: none;
  background: var(--surface);
}

.filters-form input:focus,
.filters-form select:focus,
.stack-form input:focus,
.stack-form select:focus,
.stack-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-main-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 24px;
  padding: 16px 14px 18px;
  border-top: 1px solid var(--border);
}

.filter-help {
  position: relative;
  grid-column: 1 / -1;
  width: fit-content;
}

.filter-help summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  list-style-position: outside;
}

.filter-help-popover {
  position: absolute;
  z-index: 10;
  top: calc(100% + 8px);
  left: 0;
  width: min(440px, calc(100vw - 64px));
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.filter-help-popover p {
  margin-bottom: 8px;
}

.filter-help-popover p:last-child {
  margin-bottom: 0;
}

.filter-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.filter-group-wide,
.advanced-fields,
.username-choice {
  grid-column: 1 / -1;
}

.filter-group legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.choice-grid-wide {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.filters-form .choice {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
}

.filters-form .choice:has(input:checked) {
  border-color: #80ac9b;
  color: var(--accent);
  background: var(--accent-soft);
}

.filters-form .choice input {
  width: 15px;
  min-height: auto;
  flex: 0 0 auto;
  margin: 0;
}

.filters-form .choice span {
  color: inherit;
  font-size: 12px;
  font-weight: 600;
}

.advanced-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

.username-choice {
  width: fit-content;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 11px 14px;
  border-top: 1px solid var(--border);
}

.result-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 2px 9px;
  color: var(--muted);
  font-size: 12px;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--border);
  background: var(--surface);
}

.contacts-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  table-layout: fixed;
}

.contacts-table th {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
}

.contacts-table td {
  padding: 12px;
  border-bottom: 1px solid #e7ebe9;
  vertical-align: top;
}

.contacts-table tbody tr:hover {
  background: #fafcfb;
}

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

.contacts-table th:nth-child(1) {
  width: 18%;
}

.contacts-table th:nth-child(2) {
  width: 15%;
}

.contacts-table th:nth-child(3) {
  width: 30%;
}

.contacts-table th:nth-child(4) {
  width: 14%;
}

.contacts-table th:nth-child(5) {
  width: 11%;
}

.contacts-table th:nth-child(6) {
  width: 12%;
}

.contact-name,
.telegram-link,
.keywords,
.chat-titles,
.muted,
.signal-label {
  display: block;
}

.contact-name {
  overflow: hidden;
  margin-bottom: 3px;
  color: var(--text);
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.telegram-link {
  overflow: hidden;
  text-overflow: ellipsis;
}

.reveal-form {
  margin-top: 7px;
}

.reveal-error {
  display: block;
  max-width: 230px;
  margin-top: 6px;
  color: var(--red);
  font-size: 11px;
  line-height: 1.3;
}

.reveal-form button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button-reveal {
  color: var(--accent);
  border-color: #8fb9aa;
}

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

.inline-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.inline-flags span,
.signal-label {
  width: fit-content;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 10px;
}

.category-badge {
  display: inline-flex;
  padding: 4px 7px;
  border-radius: 4px;
  color: #46504b;
  background: var(--surface-muted);
  font-size: 11px;
  font-weight: 750;
}

.category-badge.category-1 {
  color: var(--blue);
  background: var(--blue-soft);
}

.category-badge.category-2 {
  color: var(--accent);
  background: var(--accent-soft);
}

.category-badge.category-4 {
  color: var(--yellow);
  background: var(--yellow-soft);
}

.keywords,
.chat-titles {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.profile-cell p {
  display: -webkit-box;
  overflow: hidden;
  margin-bottom: 7px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.workspace-status {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 4px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 700;
}

.workspace-status.status-not_relevant {
  color: var(--red);
  background: var(--red-soft);
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 18px;
}

.pagination a {
  display: grid;
  min-width: 36px;
  min-height: 36px;
  place-items: center;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
}

.pagination a:hover,
.pagination a.active {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
  text-decoration: none;
}

.empty-state {
  padding: 35px !important;
  color: var(--muted);
  text-align: center;
}

.breadcrumb {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 12px;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  align-items: start;
  gap: 24px;
}

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

.contact-header {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.contact-identifiers {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.contact-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

.contact-facts > div {
  min-width: 0;
  padding: 18px 18px 18px 0;
  border-bottom: 1px solid var(--border);
}

.contact-facts > div:nth-child(even) {
  padding-left: 18px;
  border-left: 1px solid var(--border);
}

.contact-facts dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.contact-facts dd {
  overflow-wrap: anywhere;
  margin: 0;
}

.source-section {
  margin-top: 26px;
}

.section-heading span {
  color: var(--muted);
}

.source-list {
  border-top: 1px solid var(--border);
}

.source-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.source-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.source-row time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.workspace-panel {
  position: sticky;
  top: 88px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stack-form {
  display: grid;
  gap: 14px;
}

.workspace-panel > .button {
  margin-top: 10px;
}

.panel-note {
  margin-top: 12px;
}

.flash-stack {
  position: fixed;
  z-index: 50;
  top: 76px;
  right: 24px;
}

.flash {
  padding: 11px 14px;
  border: 1px solid #92b9aa;
  border-radius: 6px;
  color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--surface-muted);
}

.login-panel {
  width: min(390px, 100%);
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.narrow-page {
  width: min(680px, 100%);
}

.settings-panel {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.settings-panel > p {
  color: var(--muted);
}

.purchase-panel {
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.purchase-panel h1 {
  margin-top: 10px;
}

.beta-badge {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--yellow);
  background: var(--yellow-soft);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.purchase-lead {
  max-width: 600px;
  color: var(--muted);
  font-size: 16px;
}

.purchase-steps {
  display: grid;
  gap: 9px;
  margin: 24px 0;
  padding-left: 22px;
}

.purchase-cta {
  min-height: 44px;
}

.purchase-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.login-brand {
  margin-bottom: 34px;
}

.login-panel h1 {
  margin-bottom: 20px;
}

.auth-description,
.auth-switch {
  color: var(--muted);
}

.auth-description {
  margin-bottom: 20px;
}

.auth-switch {
  margin: 18px 0 0;
  text-align: center;
}

.auth-switch-compact {
  margin-top: 12px;
  font-size: 13px;
}

input[autocomplete="one-time-code"] {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.form-error {
  padding: 9px 11px;
  border-radius: 5px;
  color: var(--red);
  background: var(--red-soft);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 1380px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .filter-primary {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .search-field {
    grid-column: span 2;
  }

  .choice-grid-wide {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    min-height: 58px;
    gap: 8px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .user-name,
  .brand small {
    display: none;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-actions .button {
    min-height: 32px;
    padding: 6px 8px;
    font-size: 11px;
  }

  .trial-counter {
    display: none;
  }

  .purchase-button {
    padding-right: 9px !important;
    padding-left: 9px !important;
  }

  .page {
    padding-top: 18px;
  }

  .page-heading,
  .contact-header {
    align-items: stretch;
    flex-direction: column;
  }

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

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

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

  .filter-main-content {
    grid-template-columns: 1fr;
  }

  .filter-group-wide,
  .advanced-fields,
  .username-choice,
  .filter-help {
    grid-column: auto;
  }

  .filter-help-popover {
    position: fixed;
    top: 82px;
    right: 16px;
    left: 16px;
    width: auto;
  }

  .choice-grid,
  .choice-grid-wide,
  .advanced-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .detail-layout {
    grid-template-columns: 1fr;
  }

  .workspace-panel {
    position: static;
    order: -1;
  }

  .contact-facts {
    grid-template-columns: 1fr;
  }

  .contact-facts > div:nth-child(even) {
    padding-left: 0;
    border-left: 0;
  }
}

@media (max-width: 480px) {
  .brand small {
    display: none;
  }

  .stats-grid,
  .filter-primary,
  .choice-grid,
  .choice-grid-wide,
  .advanced-fields {
    grid-template-columns: 1fr;
  }

  .search-field {
    grid-column: auto;
  }
}
