/* ── Variables ─────────────────────────────────────── */
:root {
  --bg:           #f5f7fa;
  --card:         #ffffff;
  --border:       #e2e8f0;
  --primary:      #1a4f72;
  --primary-dark: #14405e;
  --accent:       #2e86ab;
  --text:         #1a202c;
  --muted:        #718096;
  --note:         #4a5568;
  --radius:       6px;
  --shadow:       0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

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

/* ── Layout ────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
main.container { padding-top: 1.25rem; padding-bottom: 2.5rem; }

/* ── Header ────────────────────────────────────────── */
.app-header { background: var(--primary); color: #fff; padding: 1.1rem 0; }
.app-header h1 { font-size: 1.2rem; font-weight: 600; letter-spacing: -0.01em; }
.app-header .subtitle { font-size: 0.8rem; opacity: 0.7; margin-top: 0.2rem; }
.app-header .header-source { font-size: 0.72rem; opacity: 0.55; margin-top: 0.25rem; }
.app-header .header-source a { color: #fff; text-decoration: underline; opacity: 0.85; }

.demo-badge {
  background: rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 9999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.66rem;
  font-weight: 500;
  margin-left: 0.6rem;
  vertical-align: middle;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ── Card ──────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 1rem;
}
.card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.3rem;
}

/* ── Search section ────────────────────────────────── */
.search-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.search-field { flex: 1; }

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.field-group { display: flex; flex-direction: column; gap: 0.25rem; }

.field-group label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field-group input[type="text"],
.field-group select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.42rem 0.65rem;
  font-size: 0.875rem;
  color: var(--text);
  background: #fff;
  min-width: 145px;
}

.field-group input[type="text"]:focus,
.field-group select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.filter-note {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Buttons ───────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.48rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-detail {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 0.22rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-detail:hover { background: var(--accent); color: #fff; }

.btn-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.65rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
}
.btn-close:hover { background: #f0f4f8; }

.demo-note {
  font-size: 0.68rem;
  color: var(--muted);
  font-style: italic;
}

.source-demo-notice {
  display: inline-block;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.38rem 0.85rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.btn-source {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.38rem 1rem;
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-source:hover { background: var(--primary); color: #fff; text-decoration: none; }


/* ── Traceability card ─────────────────────────────── */
.section-trace { border-left: 3px solid var(--accent); }

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

.trace-item { display: flex; flex-direction: column; gap: 0.15rem; }

.trace-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.trace-value {
  font-size: 0.83rem;
  color: var(--text);
  font-weight: 500;
}

.trace-ncts {
  font-size: 0.8rem;
  color: var(--note);
  margin-bottom: 0.75rem;
}

.trace-source-search {
  margin-bottom: 0.75rem;
}
.trace-ncts a { font-size: 0.8rem; }

.trace-nct-summary { color: var(--note); }

.btn-nct-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  margin-left: 0.3rem;
  text-decoration: underline;
}
.btn-nct-toggle:hover { color: var(--primary); }

.btn-enf-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  margin-bottom: 0.35rem;
  text-decoration: underline;
  display: block;
}
.btn-enf-toggle:hover { color: var(--primary); }

.trace-nct-links { margin-top: 0.4rem; }

.preview-banner {
  background: #fffbeb;
  border: 1px solid #f6e05e;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: #744210;
}

/* ── Charts ────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.chart-card-wide {
  grid-column: 1 / -1;
}

.chart-card-wide .chart-wrap {
  height: 220px;
}

.chart-card { padding: 1rem 1.25rem; }

.chart-note {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.chart-wrap {
  position: relative;
  height: 180px;
}

.chart-click-hint {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.35rem;
  font-style: italic;
}

/* ── Per-chart view toggle ──────────────────────────── */
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.3rem;
}

.chart-card-header h3 { margin-bottom: 0; }

.btn-chart-view {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 0.13rem 0.5rem;
  font-size: 0.67rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-chart-view:hover { border-color: var(--accent); color: var(--accent); }

/* ── Results table ─────────────────────────────────── */
.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.btn-export {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 0.22rem 0.65rem;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-export:hover { background: var(--accent); color: #fff; }

.export-note {
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.5rem;
}

.results-count {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: normal;
}

/* ── Filter chip row ───────────────────────────────── */
.filter-chip-row {
  background: #ebf8ff;
  border: 1px solid #bee3f8;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.chip-row-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.chip-row-label {
  font-size: 0.78rem;
  color: #2c5282;
  font-weight: 600;
  white-space: nowrap;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: #2c5282;
  color: #fff;
  border-radius: 9999px;
  padding: 0.18rem 0.45rem 0.18rem 0.65rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.chip-remove {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0 0.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.chip-remove:hover { color: #fff; }

.chip-clear-all {
  background: transparent;
  border: 1px solid #4a6fa5;
  color: #2c5282;
  border-radius: var(--radius);
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip-clear-all:hover { background: #2c5282; color: #fff; }

.chip-row-meta {
  font-size: 0.76rem;
  color: #2c5282;
}

.chip-meta-empty { color: #c53030; font-weight: 600; }
.chip-meta-note  { color: #4a6fa5; }

.table-wrap { overflow-x: auto; }

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.results-table th {
  text-align: left;
  padding: 0.45rem 0.65rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-weight: 600;
}

.results-table td {
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.results-table tbody tr:hover { background: #f7fafc; }
.results-table tbody tr:last-child td { border-bottom: none; }

.title-cell { max-width: 260px; }
.title-text { display: block; line-height: 1.4; }

/* ── Badges ────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-recruiting            { background: #c6f6d5; color: #22543d; }
.badge-active-not-recruiting { background: #feebc8; color: #744210; }
.badge-not-yet-recruiting    { background: #bee3f8; color: #2c5282; }
.badge-enrolling-by-invitation { background: #e9d8fd; color: #44337a; }
.badge-completed             { background: #e2e8f0; color: #4a5568; }
.badge-terminated            { background: #fed7d7; color: #742a2a; }
.badge-withdrawn             { background: #fed7d7; color: #742a2a; }
.badge-suspended             { background: #fefcbf; color: #744210; }
.badge-default               { background: #e2e8f0; color: #4a5568; }

/* ── Descriptor tags ───────────────────────────────── */
.tag {
  display: inline-block;
  background: #ebf8ff;
  color: #2b6cb0;
  border: 1px solid #bee3f8;
  border-radius: 9999px;
  padding: 0.08rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 600;
  margin-top: 0.25rem;
  margin-right: 0.2rem;
  cursor: default;
}

/* ── Study detail panel ────────────────────────────── */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  margin: 0;
}

.detail-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 0.85rem;
}

.detail-actions { margin-bottom: 1rem; }

.detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
  padding: 0.85rem;
  background: #f7fafc;
  border-radius: var(--radius);
  margin-bottom: 1.1rem;
}

.detail-meta-item { display: flex; flex-direction: column; gap: 0.15rem; }

.detail-meta-item .label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.detail-meta-item .value {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.detail-section { margin-bottom: 1rem; }

.detail-section h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.4rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border);
}

.detail-section p,
.detail-section li {
  font-size: 0.83rem;
  color: var(--text);
  line-height: 1.5;
}

.detail-section ul {
  padding-left: 1.1rem;
  margin: 0;
}

.detail-section li { margin-bottom: 0.25rem; }

.trace-detail-section { margin-top: 0.5rem; }

.tag-trace {
  font-size: 0.7rem;
  color: var(--muted);
  font-style: italic;
  margin-left: 0.3rem;
}

/* ── Limitations ───────────────────────────────────── */
.section-limitations p {
  font-size: 0.83rem;
  color: var(--note);
  margin-bottom: 0.6rem;
  line-height: 1.6;
}
.limitations-framing {
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  font-style: italic;
  color: var(--muted) !important;
}

/* ── About ─────────────────────────────────────────── */
.section-about p {
  font-size: 0.83rem;
  color: var(--note);
  margin-bottom: 0.6rem;
  line-height: 1.6;
}
.section-about a { color: var(--primary); }

/* ── Filter status tag (inline label note in filter controls) ── */
.filter-status-tag {
  font-size: 0.65em;
  font-weight: 400;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

/* ── Disabled filter controls ──────────────────────── */
.field-group select:disabled {
  background: #f7fafc;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.75;
}

/* ── Filter enforcement section (traceability card) ── */
.enf-section {
  margin-bottom: 0.75rem;
}

.enf-section-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.enf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.22rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.enf-row:last-child { border-bottom: none; }

.enf-label { color: var(--note); }

.enf-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 9999px;
  font-size: 0.67rem;
  font-weight: 600;
  white-space: nowrap;
}

.enf-api      { background: #c6f6d5; color: #22543d; }
.enf-local    { background: #fefcbf; color: #744210; }
.enf-disabled { background: #e2e8f0; color: #4a5568; }
.enf-na       { background: #f7fafc; color: #a0aec0; }

/* ── Start-year range control ──────────────────────── */
.start-year-range {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.start-year-range-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.start-year-range-sep {
  font-size: 0.85rem;
  color: var(--muted);
  padding-bottom: 0.45rem;
  line-height: 1;
}

.start-year-range-error {
  font-size: 0.75rem;
  color: #c53030;
  margin-top: 0.2rem;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 1100px) {
  .charts-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .charts-grid  { grid-template-columns: 1fr; }
  .search-row   { flex-direction: column; align-items: stretch; }
  .filters-row  { flex-direction: column; }
  .field-group input[type="text"],
  .field-group select { min-width: 100%; }
  .btn-primary  { width: 100%; text-align: center; }
}
