/* Modern CSS reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
}

html {
  scroll-padding-top: 4.5rem;
}

@view-transition {
  navigation: auto;
}

:root {
  --ease-spring: linear(
    0, 0.006, 0.025 2.8%, 0.101 6.1%, 0.539 18.9%, 0.721 25.3%, 0.849 31.5%,
    0.937 38.1%, 0.968 41.8%, 0.991 45.7%, 1.006 50.1%, 1.015 55%, 1.017 63.9%,
    1.001
  );
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light mode */
:root {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-surface-hover: #f5f5f4;
  --color-text: #1c1917;
  --color-text-secondary: #44403c;
  --color-text-muted: #78716c;
  --color-border: #e7e5e4;
  --color-border-subtle: #f5f5f4;

  --color-accent: #d97706;
  --color-accent-hover: #b45309;
  --color-accent-light: #fef3c7;
  --color-accent-text: #92400e;

  --color-primary: #0d9488;
  --color-primary-hover: #0f766e;
  --color-primary-light: #ccfbf1;
  --color-primary-dark: #115e59;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow: 0 1px 3px rgb(0 0 0 / 0.06), 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);

  --ring-color: rgb(13 148 136 / 0.2);
  --content-width: 90rem;
  --page-padding: 1.5rem;

  --transition-fast: 150ms var(--ease-out-expo);
  --transition-spring: 500ms var(--ease-spring);

  color-scheme: light;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0c0f14;
    --color-surface: #151a23;
    --color-surface-hover: #1e2530;
    --color-text: #e7e5e4;
    --color-text-secondary: #a8a29e;
    --color-text-muted: #78716c;
    --color-border: #292f3a;
    --color-border-subtle: #1e2530;

    --color-accent: #f59e0b;
    --color-accent-hover: #fbbf24;
    --color-accent-light: #292215;
    --color-accent-text: #fcd34d;

    --color-primary: #2dd4bf;
    --color-primary-hover: #5eead4;
    --color-primary-light: #132726;
    --color-primary-dark: #99f6e4;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --color-bg: #0c0f14;
  --color-surface: #151a23;
  --color-surface-hover: #1e2530;
  --color-text: #e7e5e4;
  --color-text-secondary: #a8a29e;
  --color-text-muted: #78716c;
  --color-border: #292f3a;
  --color-border-subtle: #1e2530;

  --color-accent: #f59e0b;
  --color-accent-hover: #fbbf24;
  --color-accent-light: #292215;
  --color-accent-text: #fcd34d;

  --color-primary: #2dd4bf;
  --color-primary-hover: #5eead4;
  --color-primary-light: #132726;
  --color-primary-dark: #99f6e4;

  color-scheme: dark;
}

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

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

/* Header */
header {
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  border-block-end: 1px solid var(--color-border);
  padding-block: 0.875rem;
  padding-inline: var(--page-padding);
  position: sticky;
  inset-block-start: 0;
  z-index: 40;
  backdrop-filter: blur(8px);
}

@supports not (backdrop-filter: blur(8px)) {
  header { background: var(--color-surface); }
}

header > .header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  inline-size: 100%;
  max-inline-size: var(--content-width);
  margin-inline: auto;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.site-nav-link {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0.375rem 0.625rem;
  border-radius: 4px;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.site-nav-link:hover {
  color: var(--color-primary);
  text-decoration: none;
}
.site-nav-link.active {
  color: var(--color-accent);
}

.header-controls { display: flex; align-items: center; gap: 0.5rem; }

/* Theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}
.theme-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--color-accent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.theme-toggle:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.theme-toggle:hover::before { opacity: 0.05; }
.theme-toggle:active { transform: scale(0.97); }
.theme-toggle svg {
  inline-size: 1.125rem;
  block-size: 1.125rem;
  transition: transform var(--transition-spring), opacity var(--transition-fast);
}
.theme-toggle:hover svg { transform: rotate(15deg); }
.theme-toggle span { min-inline-size: 2.5rem; }

.theme-icon-light,
.theme-icon-dark,
.theme-icon-auto {
  display: none;
}
:root:not([data-theme]) .theme-icon-auto,
:root[data-theme="auto"] .theme-icon-auto {
  display: block;
}
:root[data-theme="light"] .theme-icon-light {
  display: block;
  color: var(--color-accent);
}
:root[data-theme="dark"] .theme-icon-dark {
  display: block;
  color: var(--color-accent);
}

/* Page header — base layout set below with sort controls */
.page-header {
  padding: 1.5rem var(--page-padding);
  max-width: var(--content-width);
  margin: 0 auto;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}
.trials-count {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Layout */
.index-layout {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--page-padding) 2rem;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
}
@media (max-width: 768px) {
  .index-layout { grid-template-columns: 1fr; }
}

/* Filters */
.filters-toggle-btn {
  display: none;
  margin: 0 var(--page-padding);
  padding: 0.5rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  color: var(--color-text);
  font-size: 0.875rem;
  cursor: pointer;
}
.filter-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.375rem;
  border-radius: 9999px;
  background: var(--color-primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.375rem;
}
@media (max-width: 768px) {
  .filters-toggle-btn { display: flex; align-items: center; }
  .filters-sidebar {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--color-surface);
    padding: 1rem;
    overflow-y: auto;
  }
  .filters-sidebar[data-class\:open] { display: block; }
  .filters-done-btn { display: block; }
}
.filters-done-btn {
  display: none;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}

.filters-sidebar h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 1rem 0 0.5rem;
}
.filters-sidebar h3:first-child { margin-top: 0; }

.filters-sidebar input[type="search"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.875rem;
}
.filters-sidebar input[type="search"]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--ring-color);
}

.filter-chips { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.filter-chip:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.filter-chip.active {
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 8px rgb(217 119 6 / 0.3);
}
.filter-chip.active .chip-count { color: rgba(255, 255, 255, 0.8); }
.chip-count {
  font-size: 0.65rem;
  color: var(--color-text-muted);
}

.filter-chips-scroll {
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.sponsor-search-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.875rem;
}
.sponsor-search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--ring-color);
}

.checkbox-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  cursor: pointer;
}
.checkbox-filter + .checkbox-filter {
  margin-top: 0.375rem;
}

/* Trials grid */
.trials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.trial-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  overflow: hidden;
  transition: all var(--transition-fast);
}
.trial-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}
.trial-card a {
  display: block;
  padding: 1rem;
  color: inherit;
  text-decoration: none;
}

.trial-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.trial-nctid {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.trial-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.trial-card-sponsor {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

.trial-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.charts-badge { color: var(--color-accent-text); }
.ann-badge { color: var(--color-primary); }

.trial-card-conditions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-lg { font-size: 0.8rem; padding: 0.25rem 0.75rem; }

.badge-phase {
  background: var(--color-accent-light);
  color: var(--color-accent-text);
}
.phase-1 { background: #dbeafe; color: #1e40af; }
.phase-2 { background: #fef3c7; color: #92400e; }
.phase-3 { background: #d1fae5; color: #065f46; }
.phase-4 { background: #ede9fe; color: #5b21b6; }

.badge-status {
  background: var(--color-border-subtle);
  color: var(--color-text-secondary);
}
.status-recruiting { background: #d1fae5; color: #065f46; }
.status-active { background: #dbeafe; color: #1e40af; }
.status-completed { background: #e5e7eb; color: #374151; }
.status-terminated { background: #fee2e2; color: #991b1b; }

.badge-type {
  background: var(--color-border-subtle);
  color: var(--color-text-muted);
}

/* Tags */
.condition-tag, .intervention-tag, .term-tag {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  font-size: 0.7rem;
  background: var(--color-border-subtle);
  color: var(--color-text-secondary);
}
.condition-tag { background: #fef3c7; color: #92400e; }
.intervention-tag { background: #dbeafe; color: #1e40af; }
.condition-tag.more { background: transparent; color: var(--color-text-muted); }

:root[data-theme="dark"] .condition-tag { background: #292215; color: #fcd34d; }
:root[data-theme="dark"] .intervention-tag { background: #1e2530; color: #93c5fd; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .condition-tag { background: #292215; color: #fcd34d; }
  :root:not([data-theme="light"]) .intervention-tag { background: #1e2530; color: #93c5fd; }
}

/* Trial detail */
.trial-detail {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--page-padding) 2rem;
}

.trial-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}
.breadcrumb-sep { color: var(--color-border); }

.trial-detail-layout {
  display: grid;
  grid-template-columns: 1fr;
}

.detail-section {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border-subtle);
}
.detail-section:last-child { border-bottom: none; }
.detail-section h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.trial-header { margin-bottom: 0.5rem; }
.trial-header-badges {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.trial-title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}
.trial-brief-title {
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: 0.5rem;
}
.official-title {
  margin-top: 0.5rem;
}
.official-title summary {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  cursor: pointer;
}
.official-title p {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-top: 0.5rem;
  line-height: 1.5;
}

.trial-ids {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.external-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.icon-external { width: 0.875rem; height: 0.875rem; }

/* Meta grid */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.meta-field dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.125rem;
}
.meta-field dd {
  font-size: 0.9rem;
  font-weight: 500;
}
.sponsor-class {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Terms */
.terms-group { margin-bottom: 1rem; }
.terms-group h3 {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.terms-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

/* Summary cards */
.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
}
.summary-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.flow-arms { display: flex; flex-direction: column; gap: 0.375rem; }
.flow-arm {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}
.arm-name { font-weight: 500; }
.arm-stats { color: var(--color-text-secondary); }

.outcome-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.85rem;
}
.outcome-primary { background: #d1fae5; color: #065f46; }
.outcome-secondary { background: #dbeafe; color: #1e40af; }
.outcome-timeframe { font-size: 0.75rem; color: var(--color-text-muted); }
.more-count { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.5rem; }

/* Charts */
.chart-section { margin-bottom: 1.5rem; }
.chart-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.chart-category-heading {
  grid-column: 1 / -1;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1.25rem 0 0.375rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
}
.chart-category-heading:first-child {
  margin-top: 0;
}
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));
  gap: 0.75rem;
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chart-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.chart-card.chart-expanded {
  grid-column: 1 / -1;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.chart-card.chart-expanded rocket-echarts {
  min-height: 520px;
}

.chart-card-header {
  padding: 0.625rem 0.75rem 0.25rem;
  cursor: pointer;
  transition: background 0.15s;
}

.chart-card-header h3 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.chart-card-header::after {
  content: "click anywhere in this area to expand";
  display: block;
  font-size: 0.625rem;
  color: var(--color-text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

.chart-card:not(.chart-full-width):hover .chart-card-header::after {
  opacity: 1;
}

.chart-card.chart-expanded .chart-card-header::after {
  content: "click anywhere in this area to collapse";
}

.chart-card:not(.chart-full-width):hover .chart-card-header {
  animation: header-pulse 2s ease-in-out infinite;
}

.chart-full-width .chart-card-header {
  cursor: default;
}

.chart-full-width .chart-card-header::after {
  display: none;
}

@keyframes header-pulse {
  0%, 100% { background: color-mix(in srgb, var(--color-primary) 6%, var(--color-surface)); }
  50% { background: color-mix(in srgb, var(--color-primary) 14%, var(--color-surface)); }
}

/* Rocket component base styles */
rocket-echarts {
  display: block;
  width: 100%;
  min-height: 360px;
  transition: min-height 300ms var(--ease-out-expo);
}

rocket-echarts .chart-container {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
}

rocket-globe {
  display: block;
  width: 100%;
  min-height: 500px;
  border-top: 1px solid var(--color-border);
  transition: min-height 300ms var(--ease-out-expo);
}

/* Globe card */
.globe-card {
  margin-bottom: 0.75rem;
}

.globe-card .chart-card-header {
  display: flex;
  align-items: center;
  cursor: pointer;
  justify-content: space-between;
}

.globe-card.chart-expanded rocket-globe {
  min-height: 85vh;
}

.more-charts { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.5rem; }

/* Linked announcements */
.linked-announcements {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.linked-announcement {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
}
.linked-announcement:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

/* Page nav — horizontal on mobile, fixed left on desktop */
.page-nav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  position: sticky;
  top: 3.5rem;
  z-index: 30;
  background: color-mix(in srgb, var(--color-surface) 90%, transparent);
  backdrop-filter: blur(8px);
  border-block-end: 1px solid var(--color-border);
  padding: 0.625rem 0.75rem;
  margin-inline: calc(-1 * var(--page-padding));
  scrollbar-width: none;
}
.page-nav::-webkit-scrollbar { display: none; }

.page-nav-link {
  flex-shrink: 0;
  padding: 0.375rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.page-nav-link:hover {
  color: var(--color-primary);
  background: var(--color-surface-hover);
  text-decoration: none;
}
.page-nav-link.active {
  color: var(--color-accent);
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

@media (min-width: 72rem) {
  .page-nav {
    position: fixed;
    left: var(--page-padding);
    top: 4.5rem;
    width: 10rem;
    flex-direction: column;
    overflow-x: visible;
    overflow-y: auto;
    max-height: calc(100vh - 5.5rem);
    background: transparent;
    backdrop-filter: none;
    border-block-end: none;
    padding: 0;
    margin-inline: 0;
    gap: 0.125rem;
  }
  .page-nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
  }
  .page-nav-link.active {
    border-color: transparent;
    border-inline-start: 2px solid var(--color-accent);
    border-radius: 0 0.375rem 0.375rem 0;
  }
  .trial-detail {
    padding-left: calc(10rem + var(--page-padding) + 1.5rem);
  }
}

/* Loading */
.loading {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}
.empty {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-muted);
  grid-column: 1 / -1;
}

/* Page header */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header-left {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

/* Sort controls */
.sort-controls {
  display: flex;
  gap: 0.25rem;
}
.sort-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.sort-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.sort-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: transparent;
}

/* Clear filters */
.clear-filters-btn {
  display: inline-flex;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-accent);
  background: var(--color-accent-light);
  border: 1px solid var(--color-accent);
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.clear-filters-btn:hover {
  background: var(--color-accent);
  color: white;
}

/* Filter pills */
.filter-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  padding: 0 var(--page-padding);
  max-width: var(--content-width);
  margin: 0 auto 0.75rem;
}
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  background: var(--color-primary-light);
  border: 1px solid color-mix(in srgb, var(--color-primary) 30%, transparent);
  border-radius: 9999px;
}
.pill-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1;
  color: var(--color-primary);
  background: transparent;
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.pill-remove:hover {
  background: var(--color-primary);
  color: white;
}

/* CQRS loading indicator — shown on the clicked element until SSE morph */
.is-loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}
.is-loading::after {
  content: '';
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-left: 0.4em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: middle;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Scroll sentinel */
.scroll-sentinel {
  grid-column: 1 / -1;
  height: 1px;
}

/* Load more (no-JS fallback) */
.load-more-btn {
  grid-column: 1 / -1;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  color: var(--color-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.load-more-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}
