/* ─── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-card: #1e2130;
  --bg-card-hover: #252840;
  --border: #2e3149;
  --border-strong: #3d4160;
  --text: #e8eaf0;
  --text-muted: #8890b0;
  --text-subtle: #5a6080;
  --accent: #6c8fff;
  --accent-hover: #8aa3ff;
  --accent-dim: rgba(108, 143, 255, 0.12);
  --red: #ff5f6d;
  --red-dim: rgba(255, 95, 109, 0.12);
  --orange: #ff9f43;
  --orange-dim: rgba(255, 159, 67, 0.12);
  --green: #26d97f;
  --green-dim: rgba(38, 217, 127, 0.12);
  --yellow: #ffd32a;
  --yellow-dim: rgba(255, 211, 42, 0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.85em; background: var(--border); padding: 0.1em 0.4em; border-radius: 3px; }

/* ─── Header ─────────────────────────────────────────────── */
.site-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-icon { width: 28px; height: 28px; color: var(--accent); flex-shrink: 0; }
.brand h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.tagline { font-size: 0.75rem; color: var(--text-muted); margin-top: -1px; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  position: relative;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--bg-card); color: var(--text); border-color: var(--border-strong); }
.btn-icon svg { width: 18px; height: 18px; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
  position: absolute;
  top: 4px; right: 4px;
  border: 1.5px solid var(--bg-surface);
}
.status-dot.ok { background: var(--green); }
.status-dot.error { background: var(--red); }
.status-dot.loading { background: var(--yellow); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ─── Status Panel ───────────────────────────────────────── */
.status-panel {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 0;
}
.status-panel.open { max-height: 700px; opacity: 1; }

.status-panel-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
}
.status-panel h2 { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.75rem; }

.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.source-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.source-card-name { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.source-card-meta { font-size: 0.72rem; color: var(--text-muted); }

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15em 0.5em;
  border-radius: 3px;
  vertical-align: middle;
}
.badge-ok { background: var(--green-dim); color: var(--green); }
.badge-stale { background: var(--yellow-dim); color: var(--yellow); }
.badge-error { background: var(--red-dim); color: var(--red); }
.badge-pending { background: var(--border); color: var(--text-muted); }
.badge-loading { background: var(--yellow-dim); color: var(--yellow); animation: pulse 1.2s ease-in-out infinite; }
.badge-disabled { background: var(--border); color: var(--text-subtle); }

.status-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
.status-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.scheduler-info { font-size: 0.75rem; color: var(--text-subtle); }
.refresh-cooldown { font-size: 0.75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.loading-placeholder { font-size: 0.8rem; color: var(--text-muted); padding: 0.5rem 0; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #0f1117;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }

/* ─── Main Content ───────────────────────────────────────── */
.main-content {
  flex: 1;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1.5rem;
}

/* ─── Search Section ─────────────────────────────────────── */
.search-section { margin-bottom: 2.5rem; }

.search-form {}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.25rem 0.25rem 0.25rem 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
}
.search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.search-icon { width: 18px; height: 18px; color: var(--text-subtle); flex-shrink: 0; margin-right: 0.5rem; }

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 1rem;
  color: var(--text);
  font-family: var(--font);
  padding: 0.5rem 0;
}
.search-input::placeholder { color: var(--text-subtle); }

.search-btn {
  flex-shrink: 0;
  border-radius: calc(var(--radius) - 3px);
  padding: 0.6rem 1.4rem;
  position: relative;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(15, 17, 23, 0.3);
  border-top-color: #0f1117;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.is-searching .spinner { display: inline-block; }
.is-searching .btn-text { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-subtle);
  line-height: 1.5;
}
.disclaimer svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 2px; }

/* ─── Results ────────────────────────────────────────────── */
.results-summary {
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.results-summary strong { color: var(--text); font-size: 1rem; }
.results-summary .hit-count { color: var(--red); font-weight: 700; }
.results-summary .no-hit-count { color: var(--green); font-weight: 700; }

.results-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Source Result Card */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.result-card.has-hits { border-color: var(--red); box-shadow: 0 0 0 1px var(--red-dim); }
.result-card.no-hits { opacity: 0.65; }

.result-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.125rem;
  cursor: pointer;
  user-select: none;
  gap: 0.75rem;
}
.result-card-header:hover { background: var(--bg-card-hover); }

.result-card-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
}
.result-card-title h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hit-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--red-dim);
  color: var(--red);
  flex-shrink: 0;
}
.hit-badge.zero { background: var(--green-dim); color: var(--green); }

.chevron {
  width: 16px; height: 16px;
  color: var(--text-subtle);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.result-card.expanded .chevron { transform: rotate(180deg); }

.result-card-status {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.result-card-body {
  display: none;
  border-top: 1px solid var(--border);
}
.result-card.expanded .result-card-body { display: block; }

.result-error {
  padding: 0.875rem 1.125rem;
  font-size: 0.8rem;
  color: var(--orange);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.result-error svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 2px; }

.no-hits-msg {
  padding: 0.875rem 1.125rem;
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.unavailable-note {
  font-size: 0.75rem;
  color: var(--text-subtle);
  padding: 0.5rem 0.25rem;
  text-align: center;
}

/* ─── Hit Accordion List ─────────────────────────────────── */
.hits-list {
  display: flex;
  flex-direction: column;
}

.hit-item {
  border-top: 1px solid var(--border);
}
.hit-item:first-child { border-top: none; }

/* Collapsed header */
.hit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.125rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}
.hit-header:hover { background: var(--bg-card-hover); }

.hit-header-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}
.hit-header-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hit-header-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Expanded body */
.hit-body {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 1rem 1.125rem;
}
.hit-item.expanded .hit-body { display: block; }
.hit-item.expanded .chevron { transform: rotate(180deg); }

/* Detail grid inside body */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.detail-section { min-width: 0; }
.detail-section--full { grid-column: 1 / -1; }

.detail-heading {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-subtle);
  margin-bottom: 0.4rem;
}

.detail-list {
  list-style: none;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.detail-list li { word-break: break-word; }
.detail-key { color: var(--text-subtle); }
.detail-empty { color: var(--text-subtle); font-style: italic; }

.detail-remarks {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.65;
  word-break: break-word;
}

/* Shared small components */
.matched-name { font-weight: 600; font-size: 0.9rem; }
.match-highlight { background: var(--yellow-dim); color: var(--yellow); border-radius: 2px; padding: 0 1px; }

.type-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15em 0.5em;
  border-radius: 3px;
  white-space: nowrap;
}
.type-individual { background: var(--accent-dim); color: var(--accent); }
.type-entity { background: var(--orange-dim); color: var(--orange); }
.type-vessel, .type-aircraft { background: var(--border); color: var(--text-muted); }

.programs-list { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.program-tag {
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  border-radius: 3px;
  padding: 0.1em 0.45em;
  white-space: nowrap;
}

.score-bar { display: flex; align-items: center; gap: 0.4rem; }
.score-fill {
  height: 4px; border-radius: 2px; width: 0;
  background: var(--accent);
  flex-shrink: 0;
  max-width: 52px;
}
.score-val { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* ─── Error Banner ───────────────────────────────────────── */
[hidden] {
  display: none !important;
}

.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.875rem 1.125rem;
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}
.error-banner svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* ─── Footer ─────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-subtle);
  line-height: 1.8;
}
.footer-note { color: var(--text-subtle); opacity: 0.7; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .main-content { padding: 1.25rem 1rem; }
  .header-inner { padding: 0.75rem 1rem; }
  .search-input { font-size: 0.9rem; }
  table.hits-table th:nth-child(n+4),
  table.hits-table td:nth-child(n+4) { display: none; }
}
