:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #ffffff;
  --text: #111111;
  --muted: #666666;
  --border: #ded7ca;
  --accent: #154b8b;
  --accent-soft: #e5eef9;
  --error: #8a1f11;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #f7f4ee 0%, #ece6dc 100%);
  color: var(--text);
}

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

.shell {
  min-height: 100vh;
}

.topbar {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 0;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

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

.status-pill {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  padding-top: 36px;
}

.ghost-link,
.text-link,
.clear-button {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  padding: 10px 12px;
}

.text-link,
.clear-button {
  padding: 8px 12px;
}

.app {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 56px;
}

.hero {
  margin-bottom: 24px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1.05;
}

.lede {
  margin: 10px 0 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 16px;
}

.search-panel,
.result-card,
.notice,
.detail-card,
.detail-placeholder,
.statsbar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.search-panel {
  padding: 18px;
  margin-bottom: 24px;
}

.controls {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #faf8f4;
}

.segment {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
}

.segment.active {
  background: white;
  color: var(--text);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.search-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
}

.search-button {
  border: 0;
  border-radius: 10px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 700;
}

.search-button:disabled {
  opacity: 0.6;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.statsbar {
  margin-bottom: 18px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 16px;
  font-weight: 800;
}

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

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

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

.results h2 {
  margin: 0;
  font-size: 20px;
}

.notice {
  padding: 18px;
  margin-bottom: 12px;
  color: var(--muted);
}

.notice.error {
  color: var(--error);
  border-color: #e2b3aa;
  background: #fff5f3;
}

.notice.warn {
  color: #7a4b00;
  border-color: #e5c68d;
  background: #fff9ec;
}

.notice.loading {
  color: var(--muted);
  background: #fbfbfb;
}

.result-card {
  padding: 18px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.result-card:hover,
.result-card.selected {
  border-color: #b8cbe0;
  box-shadow: 0 8px 24px rgba(21, 75, 139, 0.08);
  transform: translateY(-1px);
}

.result-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.result-title {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

.pill {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.pill-official {
  background: #e4f1e8;
  color: #1f6a3a;
}

.pill-web {
  background: #ece7ff;
  color: #5a3ea6;
}

.meta,
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.meta {
  margin-top: 10px;
}

.meta-top {
  margin-top: 6px;
}

.summary {
  margin: 12px 0;
  line-height: 1.6;
  color: #222;
}

.detail-panel {
  position: sticky;
  top: 20px;
}

.detail-card,
.detail-placeholder {
  padding: 18px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.detail-head h2 {
  margin: 6px 0 0;
  font-size: 22px;
  line-height: 1.2;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.detail-summary {
  margin: 16px 0;
  color: #222;
  line-height: 1.6;
}

.detail-list {
  margin: 0;
  display: grid;
  gap: 12px;
}

.detail-list div {
  display: grid;
  gap: 4px;
}

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.detail-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.detail-links a {
  font-weight: 700;
}

.detail-json {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.ai-summary {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid #d8e2ef;
  background: #f6f9ff;
  border-radius: 12px;
}

.ai-summary p {
  margin: 8px 0 0;
  line-height: 1.6;
  color: #1c2a3a;
}

.ai-summary-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-json pre {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #3a3a3a;
}

.detail-placeholder {
  color: var(--muted);
}

@media (max-width: 720px) {
  h1 {
    font-size: 30px;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .result-top {
    flex-direction: column;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    padding-top: 0;
  }

  .workspace,
  .statsbar {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}
