:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #202326;
  --muted: #687078;
  --line: #d8dee1;
  --teal: #0f8b8d;
  --teal-dark: #0b5f61;
  --amber: #c77700;
  --red: #b3413a;
  --green: #277a4b;
  --ink: #17201f;
  --shadow: 0 18px 42px rgba(20, 31, 34, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 139, 141, 0.08), transparent 310px),
    var(--bg);
  color: var(--text);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

a {
  color: inherit;
}

.topbar,
main {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
}

.brand-mark svg,
.icon-button svg,
.search-box svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 1.22rem + 1vw, 2.25rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.25rem, 1.05rem + 0.7vw, 1.75rem);
  line-height: 1.18;
  letter-spacing: 0;
}

h3 {
  font-size: 1.04rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow,
.label,
label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 720;
  text-decoration: none;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.icon-button {
  padding: 0 12px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button:hover,
.action-button:hover {
  border-color: var(--teal);
  background: #f8fbfb;
}

.icon-button:active,
.action-button:active {
  transform: translateY(1px);
}

.action-button:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

main {
  padding-bottom: 48px;
}

.intro-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: stretch;
}

.control-panel,
.progress-panel,
.site-card,
.external-search,
.knowledge-band {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 20px;
  padding: 20px;
}

.search-row {
  display: grid;
  gap: 8px;
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.14);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
}

.api-preview {
  display: grid;
  gap: 9px;
  padding: 11px 12px;
  border: 1px solid rgba(15, 139, 141, 0.22);
  border-radius: 8px;
  background: rgba(15, 139, 141, 0.07);
}

.api-preview[hidden] {
  display: none;
}

.api-preview p {
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
  margin: 0;
}

.api-preview-details {
  display: grid;
  grid-template-columns: minmax(96px, max-content) minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
}

.api-preview-details dt {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 820;
}

.api-preview-details dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.api-preview code {
  display: block;
  padding: 8px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  white-space: normal;
}

.api-preview span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.filter-block {
  display: grid;
  gap: 10px;
}

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

.segmented button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 750;
}

.segmented button.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  letter-spacing: 0;
  text-transform: none;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
  flex: 0 0 auto;
}

.progress-panel {
  display: grid;
  grid-template-columns: 132px 1fr;
  align-items: center;
  gap: 14px;
  padding: 18px;
  overflow: hidden;
}

.radar {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #14201f;
}

.radar svg {
  width: 100%;
  height: 100%;
  fill: none;
}

.radar circle,
.radar path {
  stroke: rgba(255, 255, 255, 0.22);
  stroke-width: 1.4;
}

.radar .radar-sweep {
  fill: rgba(15, 139, 141, 0.38);
  stroke: rgba(16, 201, 188, 0.7);
}

.radar .dot {
  stroke: none;
}

.dot-a {
  fill: #ffd166;
}

.dot-b {
  fill: #36c7b7;
}

.dot-c {
  fill: #ee6c5a;
}

.progress-copy {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.progress-number {
  font-size: 2rem;
  line-height: 1;
  font-weight: 850;
}

.progress-copy p:last-child {
  color: var(--muted);
  line-height: 1.45;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 34px 0 14px;
}

.external-search {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 18px;
}

.external-search-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.external-search-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.external-search-hint {
  max-width: 680px;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.external-search-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  line-height: 1.45;
}

.external-search.has-query .external-search-empty {
  display: none;
}

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

.external-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(188px, auto);
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.external-result h3 {
  overflow-wrap: anywhere;
}

.external-result p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.external-result .action-button {
  min-width: 0;
}

.external-result-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.live-results {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  line-height: 1.4;
}

.live-results.loading {
  color: var(--teal-dark);
  font-weight: 760;
}

.live-results.setup,
.live-results.error {
  border-color: rgba(199, 119, 0, 0.35);
  background: rgba(199, 119, 0, 0.08);
  color: #6f4700;
}

.live-results.error {
  border-color: rgba(179, 65, 58, 0.32);
  background: rgba(179, 65, 58, 0.08);
  color: var(--red);
}

.live-results .action-button {
  width: fit-content;
  min-width: 138px;
}

.live-results-summary {
  color: var(--text);
  font-weight: 790;
}

.live-results-query,
.live-results-help {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.live-results-query {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

.live-result-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
}

.live-result-list li {
  padding-left: 2px;
}

.live-result-list a {
  display: inline-block;
  color: var(--teal-dark);
  font-weight: 780;
  overflow-wrap: anywhere;
}

.live-result-list span {
  display: block;
  margin-top: 2px;
  color: var(--green);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.live-result-list p {
  margin-top: 4px;
  font-size: 0.88rem;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.site-list {
  display: grid;
  gap: 12px;
}

.site-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  padding: 18px;
}

.card-main {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.category {
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 3px;
}

.summary,
.note,
.sources,
.knowledge-grid p {
  color: var(--muted);
  line-height: 1.5;
}

.risk-pill {
  flex: 0 0 auto;
  min-width: 88px;
  padding: 6px 9px;
  border-radius: 999px;
  background: #eef3f1;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 820;
  text-align: center;
}

.risk-pill.high {
  background: rgba(179, 65, 58, 0.12);
  color: var(--red);
}

.risk-pill.medium {
  background: rgba(199, 119, 0, 0.15);
  color: #8a5200;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #3b4147;
  font-size: 0.84rem;
  font-weight: 680;
}

.note {
  padding: 11px 12px;
  border-left: 3px solid var(--teal);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}

.card-side {
  display: grid;
  align-content: start;
  gap: 12px;
}

.card-side label {
  display: grid;
  gap: 6px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.action-button {
  width: 100%;
  padding: 0 12px;
  text-align: center;
}

.action-button.primary {
  border-color: var(--teal-dark);
  background: var(--teal);
  color: #fff;
}

.action-button.primary:hover {
  background: var(--teal-dark);
}

details {
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 780;
}

.sources {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-left: 18px;
  font-size: 0.88rem;
}

.knowledge-band {
  margin-top: 28px;
  padding: 20px;
  box-shadow: none;
}

.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.knowledge-grid article {
  padding-top: 13px;
  border-top: 3px solid var(--line);
}

.knowledge-grid h3 {
  margin-bottom: 6px;
}

.empty {
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.manual-browser-modal[hidden] {
  display: none;
}

.manual-browser-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
}

.manual-browser-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 31, 0.58);
  backdrop-filter: blur(5px);
}

.manual-browser-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(1120px, calc(100vw - 28px));
  height: min(820px, calc(100vh - 28px));
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.manual-browser-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.manual-browser-top .icon-button {
  min-height: 40px;
  padding: 0 12px;
}

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

.browser-dots {
  display: flex;
  gap: 6px;
  padding: 0 2px;
}

.browser-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d56a5e;
}

.browser-dots span:nth-child(2) {
  background: #d8a63a;
}

.browser-dots span:nth-child(3) {
  background: #4f9d69;
}

.manual-browser-bar input {
  min-width: 0;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.manual-browser-frame-shell {
  min-height: 260px;
  background: #fff;
}

.manual-browser-frame-shell iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.manual-browser-note {
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

@media (max-width: 900px) {
  .intro-grid,
  .site-card,
  .external-results,
  .knowledge-grid {
    grid-template-columns: 1fr;
  }

  .progress-panel {
    grid-template-columns: 118px 1fr;
  }

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

@media (max-width: 640px) {
  .topbar,
  main {
    width: min(100vw - 20px, 1180px);
  }

  .topbar,
  .section-head,
  .external-search-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .sort-control,
  .external-search-actions {
    justify-content: stretch;
  }

  .icon-button,
  .sort-control select,
  .external-search-actions .action-button {
    width: 100%;
  }

  .external-result {
    grid-template-columns: 1fr;
  }

  .external-result-actions {
    grid-template-columns: 1fr;
  }

  .filter-grid,
  .api-preview-details,
  .progress-panel {
    grid-template-columns: 1fr;
  }

  .radar {
    width: 132px;
  }

  .card-title-row {
    flex-direction: column;
  }

  .risk-pill {
    min-width: 0;
  }

  .manual-browser-dialog {
    width: calc(100vw - 20px);
    height: calc(100vh - 20px);
  }

  .manual-browser-top,
  .manual-browser-bar {
    align-items: stretch;
  }

  .manual-browser-top {
    flex-direction: column;
  }

  .manual-browser-bar {
    grid-template-columns: 1fr;
  }

  .browser-dots {
    display: none;
  }

  .manual-browser-bar .action-button {
    width: 100%;
  }
}
