:root {
  --ink: #18202c;
  --muted: #657083;
  --line: #d8dee8;
  --panel: #ffffff;
  --wash: #f4f7fb;
  --brand: #145c70;
  --brand-strong: #0b3f4f;
  --accent: #b65f2a;
  --success: #247a48;
  --warning: #a96f00;
  --quiet: #eef3f6;
  --shadow: 0 16px 40px rgba(24, 32, 44, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--wash);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  background: var(--brand);
  color: #ffffff;
  font-weight: 800;
  border-radius: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.05;
}

.brand p,
.results-toolbar p,
.settings-header p,
.source-card p,
.empty-state span {
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 260px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.auth-status span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-status a {
  flex: 0 0 auto;
  color: var(--brand);
  text-decoration: none;
}

.auth-status a:hover {
  text-decoration: underline;
}

.view-switch {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.view-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--brand-strong);
  padding: 0 12px;
  font-weight: 800;
}

.view-button.active {
  background: #ffffff;
  box-shadow: 0 1px 5px rgba(24, 32, 44, 0.12);
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-strong);
  font-weight: 700;
  white-space: nowrap;
}

main {
  padding: 22px clamp(18px, 4vw, 48px) 40px;
}

.auth-gate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-gate h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.auth-gate p {
  color: var(--muted);
}

.auth-locked .app-view {
  display: none;
}

.app-view {
  display: none;
}

.app-view.active {
  display: grid;
  gap: 18px;
}

.search-panel,
.summary-panel,
.filters,
.results-panel,
.source-card,
.settings-header,
.security-note,
.connector-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-panel {
  padding: 18px;
}

.search-form {
  display: grid;
  gap: 10px;
}

.search-form > label {
  color: var(--brand-strong);
  font-weight: 800;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.search-row input,
.filters input[type="date"],
.connector-form input,
.connector-form select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #ffffff;
}

.search-row input:focus,
.filters input:focus,
.connector-form input:focus,
.connector-form select:focus {
  outline: 3px solid rgba(20, 92, 112, 0.18);
  border-color: var(--brand);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  background: var(--brand);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--brand-strong);
}

.secondary-button:hover {
  border-color: var(--brand);
}

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

.source-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.source-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #ffffff;
  font-weight: 900;
}

.hubspot {
  background: #d66130;
}

.sharepoint {
  background: #166b87;
}

.workflowmax {
  background: #49536a;
}

.source-card h2,
.results-toolbar h2,
.filters h2 {
  font-size: 18px;
}

.source-card p {
  margin-top: 4px;
  font-size: 13px;
}

.source-status {
  justify-self: end;
  padding: 6px 8px;
  border-radius: 999px;
  background: #e7f5ed;
  color: var(--success);
  font-size: 12px;
  font-weight: 800;
}

.source-status.searching {
  background: #fff5dd;
  color: var(--warning);
}

.source-status.error {
  background: #ffe8e1;
  color: #9b2d16;
}

.summary-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  overflow: hidden;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-right: 1px solid var(--line);
}

.summary-item:last-child {
  border-right: 0;
}

.summary-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 999px;
  background: #a8b2c0;
}

.summary-item strong,
.summary-item span:last-child {
  display: block;
}

.summary-item strong {
  font-size: 14px;
}

.summary-item span:last-child {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.summary-item.active .summary-dot {
  background: var(--success);
}

.summary-item.active {
  background: #f2fbf6;
}

.summary-item.no-match.active {
  background: #fff8ed;
}

.summary-item.no-match.active .summary-dot {
  background: var(--warning);
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.filters {
  position: sticky;
  top: 14px;
  padding: 16px;
}

.filter-header,
.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 800;
}

fieldset {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
  padding: 16px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

legend {
  padding: 0;
  color: var(--brand-strong);
  font-weight: 800;
}

.filters label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #2b3544;
  font-size: 14px;
}

.filters input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

.filters input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
}

.results-panel {
  min-width: 0;
  padding: 16px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tab {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--brand-strong);
  padding: 0 12px;
  font-weight: 800;
}

.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.results-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.result-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.result-card header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.result-card h3 {
  margin: 0;
  font-size: 18px;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--quiet);
  color: #344055;
  font-size: 12px;
  font-weight: 800;
}

.confidence {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: #eef8f2;
  color: var(--success);
  font-weight: 900;
}

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

.detail {
  display: grid;
  gap: 3px;
}

.detail span:first-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.summary-text {
  color: #344055;
  line-height: 1.45;
}

.source-link {
  justify-self: start;
  color: var(--brand);
  font-weight: 900;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 34px;
  border: 1px dashed #bac4d2;
  border-radius: 8px;
  background: #fbfcfe;
  text-align: center;
}

.settings-view {
  align-content: start;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
}

.settings-header h2 {
  margin: 0;
  font-size: 22px;
}

.security-note {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-left: 4px solid var(--accent);
}

.security-note span,
.settings-message,
.backend-panel p,
.storage-status {
  color: var(--muted);
}

.backend-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.backend-panel h3 {
  margin: 0 0 4px;
}

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

.backend-columns > div {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.storage-status {
  font-size: 12px;
  font-weight: 800;
}

.backend-columns ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
  color: #344055;
  font-size: 13px;
}

.settings-message {
  min-height: 22px;
  font-weight: 800;
}

.settings-message.success {
  color: var(--success);
}

.settings-message.error {
  color: #9b2d16;
}

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

.connector-card {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.connector-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.connector-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connector-title h3 {
  margin: 0;
  font-size: 18px;
}

.connector-status {
  padding: 6px 8px;
  border-radius: 999px;
  background: #ffe8e1;
  color: #9b2d16;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.connector-status.configured {
  background: #e7f5ed;
  color: var(--success);
}

.connector-form {
  display: grid;
  gap: 12px;
}

.connector-form label {
  display: grid;
  gap: 6px;
  color: #2b3544;
  font-size: 14px;
  font-weight: 800;
}

.inline-check {
  display: flex !important;
  align-items: center;
  grid-template-columns: none;
}

.inline-check input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--brand);
}

.secret-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.connector-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 980px) {
  .source-grid,
  .summary-panel,
  .workspace,
  .connector-settings,
  .backend-columns {
    grid-template-columns: 1fr;
  }

  .summary-item {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-item:last-child {
    border-bottom: 0;
  }

  .filters {
    position: static;
  }

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

@media (max-width: 640px) {
  .topbar,
  .header-actions,
  .auth-gate,
  .filter-header,
  .settings-header,
  .results-toolbar,
  .search-row {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .source-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .source-status {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .result-card header,
  .result-details {
    grid-template-columns: 1fr;
  }

  .confidence {
    width: 100%;
    height: 42px;
  }
}
