/* ==========================================================================
   Eligara Sites – Main Stylesheet
   ========================================================================== */

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

/* ---------- Design Tokens ---------- */
:root {
  color-scheme: light;
  accent-color: var(--sage-dark);

  /* ── Typography ─────────────────────────────────────────────────── */
  --font-display: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --font-body:    'Instrument Sans', ui-sans-serif, system-ui, sans-serif;
  --font-mono:    ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* ── Palette: cream paper, sage, moss teal ─────────────────────── */
  --paper:        #ece8e0;
  --paper-raised: #f7f4ed;
  --ink:          #28342c;
  --sage:         #c8ccb8;
  --sage-deep:    #b7c4a6;
  --sage-dark:    #4f6b4a;
  --clay:         #3a7460;
  --clay-dark:    #2c5a4a;
  --clay-light:   #4f8a72;

  /* ── Brand (primary actions) ────────────────────────────────────── */
  /* Muted moss teal — calm, hopeful CTAs for a clinical audience.
     White-on-brand is ~5.4:1. Brand-on-paper uses --brand-dark. */
  --brand:       #3a7460;
  --brand-dark:  #2c5a4a;
  --brand-light: #4f8a72;
  --brand-tint:  #e4f0ea;

  /* ── Eligara.ai palette (mapped onto the instrument family) ─────── */
  --eligara-navy:  #1f241c;
  --eligara-slate: #c8ccb8;
  --eligara-teal:  #4f6b4a;

  /* ── Text ────────────────────────────────────────────────────────── */
  /* ink/paper 10.6:1, muted #5c6358/paper 5.1:1. text-subtle is
     placeholder/decorative only. */
  --text-primary:   #28342c;
  --text-secondary: #3d4338;
  --text-muted:     #5c6358;
  --text-subtle:    #8a9184;
  --text:           var(--text-primary);

  /* ── Surfaces ────────────────────────────────────────────────────── */
  --surface:       #ece8e0;
  --surface-card:  #f7f4ed;
  --surface-admin: #f3f0e8;

  /* ── Warm stone scale (replaces cool gray) ──────────────────────── */
  --gray-50:  #f7f4ed;
  --gray-100: #ede9e0;
  --gray-200: #e2ded5;
  --gray-300: #c3bfb4;
  --gray-400: #a9aca5;
  --gray-500: #818682;
  --gray-600: #5c6358;
  --gray-700: #3d4338;
  --gray-800: #28342c;
  --gray-900: #1a1e19;

  /* ── Borders ─────────────────────────────────────────────────────── */
  --border:        #ddd8cc;
  --border-subtle: #e8e4d8;
  --border-brand:  #b7c4a6;

  /* ── Semantic colours ───────────────────────────────────────────── */
  --success:        #3e6b42;
  --success-bg:     #e7efe0;
  --success-border: #b7c4a6;
  --error:          #9b2c2c;
  --error-bg:       #f8eaea;
  --info:           #3f5e4a;
  --info-bg:        #e7efe0;
  --info-border:    #b7c4a6;

  /* ── Shadows (shadcn-quiet, warm) ───────────────────────────────── */
  --shadow-sm:    0 1px 2px rgba(40, 52, 44, 0.06);
  --shadow-md:    0 8px 24px rgba(40, 52, 44, 0.08);
  --shadow-lg:    0 16px 40px rgba(40, 52, 44, 0.12);
  --shadow-brand: 0 8px 28px rgba(58, 116, 96, 0.16);

  /* ── Radius ──────────────────────────────────────────────────────── */
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-full: 999px;
  --radius:      12px;

  /* ── Transitions ─────────────────────────────────────────────────── */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;

  /* ── Warning / Amber ───────────────────────────────────────────── */
  --warning:               #b45309;
  --warning-bg:            #f6edd8;
  --warning-bg-subtle:     #f0e4c4;
  --warning-border:        #e0c48a;
  --warning-border-subtle: #ead9a8;
  --warning-text:          #78350f;
  --warning-text-dark:     #92400e;

  /* ── Extended error colours ─────────────────────────────────────── */
  --error-mid:    #b8483c;
  --error-dark:   #8f342c;
  --error-darker: #6f2822;
  --error-border: #e3b2ab;

  /* ── Extended success colours ───────────────────────────────────── */
  --success-light:         #6b8f62;
  --success-mid:           #4f6b4a;
  --success-dark:          #3e6b42;
  --success-darker:        #2f5134;
  --success-text:          #2f5134;
  --success-text-dark:     #243d28;
  --success-bg-hover:      #dce6d4;
  --success-border-hover:  #8fa57c;
  --success-border-active: #4f6b4a;

  /* ── Extended info / link colours ──────────────────────────────── */
  --info-dark:         #2f5134;
  --info-darker:       #243d28;
  --info-text:         #3f5e4a;
  --info-text-dark:    #28342c;
  --info-bg-subtle:    #eef1e6;
  --info-border-hover: #8fa57c;

  /* ── Surface subtle ─────────────────────────────────────────────── */
  --surface-subtle: #e8e4d8;

  /* ── Sage surfaces (legacy *-teal names) ────────────────────────── */
  --surface-teal:       #e7efe0;
  --surface-teal-light: #eef1e6;
  --border-teal:        #c8ccb8;

  /* ── Gradient palette (login / error page backgrounds) ──────────── */
  --gradient-teal:       #ece8e0;
  --gradient-cyan:       #e7efe0;
  --gradient-aqua:       #e8e4d8;
  --gradient-mint:       #f7f4ed;

  /* ── Dark chassis (admin / on-dark) ─────────────────────────────── */
  --bg-dark:        #1f241c;
  --bg-dark-navy:   #282e26;
  --bg-dark-hover:  #2c332b;
  --bg-dot:         rgba(40, 52, 44, 0.05);
  --bg-light:       var(--surface);

  /* ── On-dark text / icons ───────────────────────────────────────── */
  --brand-on-dark:      #c8ccb8;
  --text-on-dark-muted: #c3bfb4;

  /* ── White ──────────────────────────────────────────────────────── */
  --white: #ffffff;

  /* ── Accent (selected / admin active) ───────────────────────────── */
  --accent:      #4f6b4a;
  --accent-dark: #3e6b42;
  --accent-bg:   rgba(79, 107, 74, 0.14);

  /* ── Cart / secondary brand (tinted fill, brand text) ──────────── */
  --orange:              #3a7460;
  --orange-bg:           #e4f0ea;
  --orange-bg-hover:     #d3e6dc;
  --orange-border:       #b4d1c4;
  --orange-border-hover: #4f8a72;

  /* ── Role badge ─────────────────────────────────────────────────── */
  --role-bg: #e7efe0;

  /* ── Google sign-in button ──────────────────────────────────────── */
  --google-border:         #dadce0;
  --google-text:           #3c4043;
  --google-bg-hover:       #f8f9fa;
  --google-bg-active:      #f1f3f4;
  --google-border-hover:   #c4c7ca;
  --google-dark-text:      #202124;
  --google-secondary-text: #5f6368;
  --google-blue:           #1a73e8;
  --google-surface-border: #e8eaed;

  /* ── Tonal state overlays ───────────────────────────────────────── */
  --tonal-secondary:       rgba(40, 52, 44, 0.06);
  --tonal-secondary-press: rgba(40, 52, 44, 0.10);

  /* ── Shadow & ring extensions ───────────────────────────────────── */
  --shadow-brand-sm:    0 6px 20px rgba(58, 116, 96, 0.10);
  --shadow-brand-hover: 0 4px 14px rgba(58, 116, 96, 0.22);
  --shadow-brand-card:  0 8px 28px rgba(40, 52, 44, 0.08), 0 1px 3px rgba(40, 52, 44, 0.04);
  --shadow-success:     0 4px 12px rgba(62, 107, 66, 0.22);
  --shadow-success-sm:  0 2px 8px rgba(79, 107, 74, 0.22);
  --shadow-indigo:      0 4px 12px rgba(79, 107, 74, 0.22);
  --shadow-google:      0 1px 6px rgba(60, 64, 67, 0.18);
  --ring-brand:         0 0 0 3px rgba(58, 116, 96, 0.22);
  --ring-info:          0 0 0 2px rgba(79, 107, 74, 0.28);
  --ring-info-glow:     0 0 0 2px rgba(183, 196, 166, 0.55);
  --ring-success-glow:  0 0 0 2px rgba(62, 107, 66, 0.22);

  /* ── shadcn-style aliases ───────────────────────────────────────── */
  --background:          var(--surface);
  --foreground:          var(--text-primary);
  --card:                var(--surface-card);
  --card-foreground:     var(--text-primary);
  --popover:             var(--paper-raised);
  --popover-foreground:  var(--text-primary);
  --primary:             var(--brand);
  --primary-foreground:  var(--white);
  --secondary:           var(--sage);
  --secondary-foreground: var(--text-primary);
  --muted:               var(--gray-100);
  --muted-foreground:    var(--text-muted);
  --destructive:         var(--error);
  --input:               var(--border);
  --ring:                var(--sage-dark);

  /* ── Legacy aliases (backward-compat) ───────────────────────────── */
  --color-brand:      var(--brand);
  --color-brand-dark: var(--brand-dark);
  --color-text:       var(--text-primary);
  --color-text-muted: var(--text-muted);
  --color-surface:    var(--surface);
}

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background-color: var(--surface);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  line-height: 1.5;
  letter-spacing: -0.011em;
}

::selection {
  background: var(--sage);
  color: var(--text-primary);
}

a {
  text-decoration: none;
  color: inherit;
}

/* Native form controls — keep OS pickers, style the closed state */
button,
input,
select,
textarea {
  font: inherit;
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="number"],
input[type="url"],
input[type="password"],
input[type="tel"],
textarea,
select {
  background-color: var(--surface-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.8rem;
  min-height: 40px;
  box-shadow: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

select {
  padding-right: 2rem;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-subtle);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--sage-dark);
  box-shadow: var(--ring-info);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--sage-dark);
  width: 1.05rem;
  height: 1.05rem;
  cursor: pointer;
}

input[type="range"] {
  accent-color: var(--brand);
}

/* shadcn-like button primitives; page styles may refine these */
.btn,
.btn-primary,
.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--brand);
  color: var(--white);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-decoration: none;
  box-shadow: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
}

.btn:hover,
.btn-primary:hover,
.btn-sm:hover {
  background: var(--brand-dark);
}

.btn:disabled,
.btn-primary:disabled,
.btn-sm:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 32px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  box-shadow: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--sage);
  border-color: color-mix(in srgb, var(--sage-dark) 28%, var(--sage));
  box-shadow: none;
}

/* ---------- Page Backgrounds ---------- */

.page-home {
  background: var(--surface);
}

.page-search,
.page-advanced-search,
.page-cases {
  background-color: var(--surface);
}

/* ---------- Hero (Home) ---------- */

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem;
  text-align: center;
}

.brand-img {
  max-width: min(480px, 80vw);
  height: auto;
  margin-bottom: 1rem;
  border-radius: 12px;
  mix-blend-mode: multiply;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 2.5rem;
  max-width: 720px;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

/* ---------- Search Bar ---------- */

.search-bar {
  display: flex;
  align-items: stretch;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  max-width: 720px;
  width: 100%;
  overflow: hidden;
}

.search-field {
  flex: 1;
  padding: 1rem 1.6rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.search-field + .search-field {
  border-left: 1px solid var(--border);
}

.search-field label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.search-field input {
  border: none;
  outline: none;
  box-shadow: none;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: transparent;
  width: 100%;
  font-family: inherit;
  min-height: 0;
  padding: 0;
  border-radius: 0;
}

.search-field input:focus {
  outline: none;
  border: none;
  box-shadow: none;
}

.search-field input::placeholder {
  color: var(--text-subtle);
}

.search-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.6rem;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--white);
  background: var(--brand);
  border-radius: var(--radius-md);
  margin: 6px;
  white-space: nowrap;
  transition: background var(--transition-base);
}

.search-btn:hover {
  background: var(--brand-dark);
  opacity: 1;
}

.search-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Search bar – compact variant (topbar on search page) */

.search-bar--compact {
  box-shadow: var(--shadow-sm);
  max-width: 700px;
}

.search-bar--compact .search-field {
  padding: 0.8rem 1.4rem;
}

.search-bar--compact .search-field label {
  font-size: 0.65rem;
}

.search-bar--compact .search-field input {
  font-size: 0.88rem;
  color: var(--text-primary);
}

.search-bar--compact .search-field input::placeholder {
  color: var(--gray-400);
}

.search-bar--compact .search-btn {
  gap: 0.4rem;
  padding: 0 1.6rem;
  font-size: 0.9rem;
  margin: 5px;
}

.search-bar--compact .search-btn svg {
  width: 16px;
  height: 16px;
}

/* ---------- Role Boxes (Home) ---------- */

.role-boxes {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.role-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.4rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform var(--transition-base), box-shadow var(--transition-base), background var(--transition-base), border-color var(--transition-base);
}

.role-box:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  background: var(--sage);
  border-color: color-mix(in srgb, var(--sage-dark) 30%, var(--sage));
}

.role-box svg {
  width: 22px;
  height: 22px;
  color: var(--sage-dark);
  flex-shrink: 0;
}

/* ---------- Stats (Home) ---------- */

.stats {
  display: flex;
  gap: 2.5rem;
  margin-top: 3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat svg {
  width: 22px;
  height: 22px;
  color: var(--sage-dark);
  flex-shrink: 0;
}

/* ---------- Top Bar (Search) ---------- */

.topbar {
  background: var(--sage);
  padding: 1.5rem 2rem 2rem;
  border-bottom: 1px solid color-mix(in srgb, var(--sage-dark) 18%, var(--sage));
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.topbar .back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.topbar .back:hover {
  opacity: 0.8;
}

.topbar-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* ---------- Workflow Progress Indicator ---------- */

/* Sign in CTA for home page */
.page-home .signin-cta {
  position: absolute;
  top: 62px;
  right: 20px;
  z-index: 1000;
  animation: cta-bounce 1s ease-in-out 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.signin-cta-arrow {
  color: var(--brand);
  font-size: 2rem;
  animation: arrow-pulse 1s ease-in-out infinite;
  margin-bottom: 4px;
  margin-right: 15px;
}

.signin-cta-content {
  background: var(--brand);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-size: 1.125rem;
  font-weight: 700;
  box-shadow: var(--shadow-brand-hover);
  white-space: nowrap;
  text-align: center;
  letter-spacing: 0.01em;
}

@keyframes cta-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@keyframes arrow-pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

@media (max-width: 640px) {
  .page-home .signin-cta {
    top: 52px;
    right: 60px;
  }
  
  .signin-cta-content {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
  }
  
  .signin-cta-arrow {
    font-size: 1.5rem;
  }
}

/* ---------- Workflow Progress Indicator ---------- */

.workflow-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-top: 1.25rem;
  padding: 0;
  height: 50px;
}

.workflow-step {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  padding: 0 2rem 0 2.5rem;
  background: color-mix(in srgb, var(--text-primary) 10%, transparent);
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.25s ease;
  clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 50%, calc(100% - 20px) 100%, 0 100%, 20px 50%);
  margin-left: -20px;
  min-width: 180px;
  text-align: center;
}

.workflow-step:first-child {
  clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 50%, calc(100% - 20px) 100%, 0 100%);
  margin-left: 0;
  padding-left: 2rem;
}

.workflow-step:last-child {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 20px 50%);
  padding-right: 2rem;
}

.workflow-step.active {
  background: var(--surface-card);
  color: var(--text-primary);
  font-weight: 600;
  z-index: 2;
  box-shadow: var(--shadow-sm);
}

.workflow-step.completed {
  background: color-mix(in srgb, var(--sage-dark) 28%, var(--sage));
  color: var(--text-primary);
  font-weight: 500;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .workflow-step {
    font-size: 0.8125rem;
    padding: 0 1.5rem 0 2rem;
    min-width: 140px;
    height: 44px;
  }
  
  .workflow-indicator {
    height: 44px;
  }
  
  .workflow-step:first-child {
    padding-left: 1.5rem;
  }
  
  .workflow-step:last-child {
    padding-right: 1.5rem;
  }
}

@media (max-width: 640px) {
  .workflow-step {
    font-size: 0.75rem;
    padding: 0 1.25rem 0 1.75rem;
    min-width: 110px;
    height: 40px;
  }
  
  .workflow-indicator {
    height: 40px;
  }
  
  .workflow-step:first-child {
    padding-left: 1.25rem;
  }
  
  .workflow-step:last-child {
    padding-right: 1.25rem;
  }
}

@media (max-width: 480px) {
  .workflow-step {
    font-size: 0.6875rem;
    padding: 0 1rem 0 1.5rem;
    min-width: 90px;
    height: 36px;
  }
  
  .workflow-indicator {
    height: 36px;
  }
  
  .workflow-step:first-child {
    padding-left: 1rem;
  }
  
  .workflow-step:last-child {
    padding-right: 1rem;
  }
}

/* ---------- Results (Search) ---------- */

.results {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.results-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.results-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.results-header .count {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------- Trial Cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.2rem;
}

.trial-card {
  --card-title-size: 16px;
  --card-title-lh: 1.35;
  --card-title-lines: 4;
  --card-summary-size: 0.82rem;
  --card-summary-lh: 1.5;
  --card-summary-lines: 6;
  --card-reason-size: 0.78rem;
  --card-reason-lh: 1.45;
  --card-reason-lines: 3;
  --card-reason-count: 3;
  --card-reason-gap: 0.35rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
  height: 100%;
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.trial-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: color-mix(in srgb, var(--sage-dark) 25%, var(--border));
}

@keyframes shimmer {
  0% {
    background-position: -400px 0;
  }

  100% {
    background-position: 400px 0;
  }
}

.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 999px;
}

.trial-card--skeleton {
  min-height: 26rem;
  pointer-events: none;
}

.trial-card--skeleton .card-title-wrap {
  height: calc(var(--card-title-size) * var(--card-title-lh) * var(--card-title-lines));
}

.trial-card--skeleton .card-summary,
.trial-card--skeleton .match-rationale {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.trial-card--skeleton .card-meta {
  align-items: center;
}

.trial-card--skeleton .meta-item {
  flex: 1 1 10rem;
}

.trial-card--skeleton .meta-item--sponsor {
  flex-basis: 100%;
}

.skeleton-badge {
  height: 1.5rem;
  width: 5.25rem;
}

.skeleton-title {
  height: 1rem;
  width: 82%;
}

.skeleton-title + .skeleton-title {
  width: 64%;
}

.skeleton-nct {
  height: 0.875rem;
  width: 6.5rem;
  border-radius: 4px;
}

.skeleton-phase-indicator {
  height: 1.2rem;
  width: 7.25rem;
  border-radius: 4px;
  margin-left: auto;
}

.skeleton-match-score {
  height: 1.2rem;
  width: 4.75rem;
  border-radius: var(--radius-full);
}

.skeleton-line {
  height: 0.85rem;
  width: 100%;
  border-radius: 4px;
}

.skeleton-line--long {
  width: 96%;
}

.skeleton-line--mid {
  width: 88%;
}

.skeleton-line--short {
  width: 72%;
}

.skeleton-meta {
  height: 0.85rem;
  width: 100%;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: var(--gray-200);
  }
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.65rem;
  min-width: 0;
}

.phase-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  margin-left: auto;
  pointer-events: none;
  user-select: none;
  cursor: default;
}

.phase-indicator__label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1;
}

.phase-indicator__boxes {
  display: flex;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
}

.phase-box {
  width: 1.2rem;
  height: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  color: var(--text-subtle);
  background: var(--gray-50);
  border: none;
  border-right: 1px solid var(--gray-300);
  border-radius: 0;
}

.phase-box:last-child {
  border-right: none;
}

.phase-box--active {
  color: #fff;
  background: var(--brand);
}

.card-badges {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}

/* Non-recruiting trial status: yellow = paused / not yet open, red = closed. */
.badge-status--warning {
  font-weight: 700;
  border-color: var(--warning-border);
}

.badge-status--closed {
  font-weight: 700;
  border-color: var(--error-border);
}

.badge-study-type {
  background: var(--sage);
  color: var(--text-primary);
}

.nct {
  font-size: 0.75rem;
  color: var(--info);
  font-weight: 500;
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

.nct::after,
.nct-id::after {
  content: '\2197'; /* ↗ north-east arrow */
  font-size: 0.85em;
  margin-left: 0.25em;
  vertical-align: super;
  font-family: inherit;
  opacity: 0.85;
}

.card-title-wrap {
  height: calc(var(--card-title-size) * var(--card-title-lh) * var(--card-title-lines));
  flex: 0 0 auto;
  min-width: 0;
  overflow: hidden;
}

.card-title {
  font-size: var(--card-title-size);
  font-weight: 200;
  line-height: var(--card-title-lh);
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
  overflow-wrap: break-word;
}

.card-summary {
  font-size: var(--card-summary-size);
  color: var(--text-primary);
  line-height: var(--card-summary-lh);
  height: calc(var(--card-summary-size) * var(--card-summary-lh) * var(--card-summary-lines));
  flex: 0 0 auto;
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--card-summary-lines);
  line-clamp: var(--card-summary-lines);
  overflow: hidden;
  overflow-wrap: break-word;
}

.match-rationale {
  flex: 0 0 auto;
  min-width: 0;
  overflow: hidden;
  margin-top: 0.75rem;
  height: calc(
    (var(--card-reason-size) * var(--card-reason-lh) * var(--card-reason-lines) * var(--card-reason-count)) +
      (var(--card-reason-gap) * (var(--card-reason-count) - 1))
  );
}

.match-score-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--brand-tint);
  color: var(--brand-dark);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.2;
}

.match-reasons {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--card-reason-size);
  line-height: var(--card-reason-lh);
  color: var(--text-primary);
}

.match-reasons li {
  position: relative;
  padding-left: 0.9em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  overflow-wrap: break-word;
}

.match-reasons li::before {
  content: "•";
  position: absolute;
  left: 0;
  top: 0;
}

.match-reasons li + li {
  margin-top: var(--card-reason-gap);
}

.trials-empty {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Hide leftover condition pills from older cached trial-card.js */
.card-tags {
  display: none;
}

.card-meta-block {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.5rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-top: 0.5rem;
  border-top: 1px solid var(--surface-teal-light);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.meta-item--sponsor {
  flex-basis: 100%;
}

.card-link {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand);
}

.card-link:hover {
  text-decoration: underline;
}

/* Location link inside trial cards */
.tl-card-link {
  color: inherit;
  text-decoration: none;
}
.tl-card-link:hover {
  color: var(--brand);
  text-decoration: underline;
}

/* ---------- Empty State ---------- */

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-subtle);
}

.empty h3 {
  font-size: 1.2rem;
  margin: 1rem 0 0.5rem;
  color: var(--text-secondary);
}

.empty p {
  font-size: 0.95rem;
}

/* ---------- Error Pages ---------- */

.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
  background: var(--surface);
}

.error-page h1 {
  font-family: var(--font-display);
  font-size: 4rem;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  letter-spacing: -0.03em;
}

.error-page p {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.error-page a {
  color: var(--brand-dark);
  font-weight: 600;
}

.error-page a:hover {
  text-decoration: underline;
}

/* ---------- Advanced Search ---------- */

.adv-search-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

.adv-search-content h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.adv-search-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.adv-search-main {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
  margin-bottom: 3rem;
}

.patient-info-section,
.checklist-section {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: none;
  padding: 2rem;
}

.checklist-section {
  align-self: start;
}

.patient-info-section {
  display: flex;
  flex-direction: column;
}

#ai-rewrite-container {
  display: none;
  flex-direction: column;
  min-height: 0;
  margin-top: 1.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

#ai-rewrite-container.is-visible {
  display: flex;
}

.ai-rewrite-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0.25rem 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: inherit;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ai-rewrite-header:hover .ai-rewrite-title {
  color: var(--text-primary);
}

.ai-rewrite-header:hover .ai-rewrite-chevron {
  color: var(--text-secondary);
}

.ai-rewrite-header:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.ai-rewrite-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.ai-rewrite-chevron {
  color: var(--text-subtle);
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.ai-rewrite-chevron.collapsed {
  transform: rotate(-90deg);
}

.ai-rewrite-body {
  overflow: hidden;
  max-height: 2000px;
  opacity: 1;
  margin-top: 0.75rem;
  transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
}

.ai-rewrite-body.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

#ai-rewrite-text {
  min-height: calc(160px + 20 * 1.5em);
  line-height: 1.5;
  resize: none;
  background-color: var(--gray-50);
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  .ai-rewrite-chevron,
  .ai-rewrite-body {
    transition: none;
  }
}

.patient-info-section label {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.patient-textarea {
  width: 100%;
  min-height: 280px;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--paper-raised);
  resize: vertical;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.patient-textarea:focus {
  outline: none;
  border-color: var(--brand);
}

.example-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.example-hint-label {
  font-weight: 500;
}

.example-hint-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  color: var(--color-brand);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.example-hint-btn:hover {
  color: var(--color-brand-dark);
}

.btn-analyze {
  margin-top: 1rem;
  width: 100%;
  padding: 0.9rem;
  background: var(--brand);
  color: var(--white);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-base);
}

.btn-analyze:hover {
  background: var(--brand-dark);
}

.btn-analyze:disabled,
.btn-analyze.processing {
  background: var(--gray-400);
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-analyze.processing {
  background: var(--warning);
  cursor: wait;
  opacity: 1;
}

.restricted-case-panel {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2, #f8f9fb);
}

.restricted-case-switch {
  margin-bottom: 0.35rem !important;
}

.restricted-case-hint {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.restricted-trials-picker {
  margin-top: 0.75rem;
}

.restricted-trials-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.restricted-trials-picker-header label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.restricted-trials-actions {
  display: flex;
  gap: 0.75rem;
}

.restricted-trials-actions .btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--brand);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.restricted-trials-actions .btn-link:hover {
  color: var(--brand-dark);
}

#restricted-trials-select {
  width: 100%;
  min-height: 8.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 0.8125rem;
  line-height: 1.35;
}

#restricted-trials-select:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

/* Button spinner */
.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 0.5rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid var(--white);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

.auto-analyze-status {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--info);
}

.status-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--info-border);
  border-top: 2px solid var(--info);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.checklist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.checklist-chevron {
  display: block;
  color: var(--text-subtle);
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.checklist-chevron.collapsed {
  transform: rotate(-90deg);
}

.checklist-body {
  overflow: hidden;
  margin-top: 1.5rem;
  max-height: 2000px;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}

.checklist-body.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

.checklist-section h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0;
}

/* Checklist table */
.checklist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  table-layout: auto;
}

.checklist-row {
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

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

.checklist-row-status {
  width: 28px;
  padding: 0.6rem 0.25rem 0.6rem 0;
  text-align: center;
  vertical-align: middle;
}

.checklist-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.25s, box-shadow 0.25s;
  flex-shrink: 0;
}

.checklist-row--satisfied .checklist-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-bg);
}

.checklist-row-label {
  padding: 0.6rem 0.75rem 0.6rem 0;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  vertical-align: top;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
}

.checklist-row-value {
  padding: 0.6rem 0;
  color: var(--text-secondary);
  font-weight: 400;
  vertical-align: top;
  line-height: 1.5;
  word-break: break-word;
}

.checklist-row--satisfied {
  background: color-mix(in srgb, var(--success-bg) 60%, transparent);
}

.checklist-row--satisfied .checklist-row-label {
  color: var(--success-text-dark);
}

.checklist-row--satisfied .checklist-row-value {
  color: var(--text-primary);
  font-weight: 500;
}

.checklist-status {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--surface-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

.checklist-status.searching {
  background: var(--info-bg);
  color: var(--info);
}

.checklist-status.success {
  background: var(--success-bg);
  color: var(--success-text-dark);
}

.checklist-status.error {
  background: var(--error-bg);
  color: var(--error);
}

.checklist-copy-row {
  justify-content: center;
  margin-top: 0.75rem;
}

.checklist-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.checklist-copy-btn:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.checklist-copy-btn--copied {
  color: var(--success-text-dark);
  border-color: var(--success);
  background: var(--success-bg);
}

.trials-section {
  margin-top: 3rem;
}

.trials-section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}

.match-debug-section {
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface-admin);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.match-debug-section[hidden] {
  display: none;
}

.trials-section .match-debug-section h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 0.35rem;
}

.match-debug-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.match-debug-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.match-debug-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
}

.match-debug-btn:hover,
.match-debug-btn:focus-visible {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.match-debug-link {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.match-debug-link:hover,
.match-debug-link:focus-visible {
  color: var(--text-primary);
}

.match-debug-llm {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.match-debug-section a[hidden],
.match-debug-btn[hidden] {
  display: none;
}

.loading-indicator {
  text-align: center;
  padding: 3rem;
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  border: 4px solid var(--surface-subtle);
  border-top: 4px solid var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-indicator p {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* ---------- Matching funnel ---------- */

.match-funnel {
  position: relative;
  margin: 0 0 2rem;
  padding: 1.5rem 1.5rem 1.25rem;
  /* Keep the funnel clear of the sticky .user-bar after scrollIntoView. */
  scroll-margin-top: 4.5rem;
  background:
    radial-gradient(900px 280px at 8% -20%, rgba(78, 185, 185, 0.16), transparent 55%),
    radial-gradient(700px 240px at 100% 0%, rgba(30, 58, 95, 0.08), transparent 50%),
    var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.match-funnel[hidden] {
  display: none !important;
}

.match-funnel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.match-funnel-eyebrow {
  margin: 0 0 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand-dark);
}

.match-funnel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--eligara-navy);
  line-height: 1.2;
}

.match-funnel-elapsed {
  flex-shrink: 0;
  text-align: right;
  min-width: 4.5rem;
}

.match-funnel-elapsed-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.match-funnel-elapsed-value {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--eligara-navy);
  letter-spacing: -0.03em;
}

.match-funnel-stage {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
}

.match-funnel-svg {
  width: 100%;
  height: auto;
  display: block;
}

.match-funnel-svg .funnel-count {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  fill: #f7fbfb;
  letter-spacing: -0.03em;
}

.match-funnel-svg .funnel-label {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  fill: #d7eef0;
}

.match-funnel-svg .funnel-band {
  transform-origin: 320px 50%;
  transition: opacity 0.45s ease, filter 0.45s ease;
}

.match-funnel-svg .funnel-band.is-pending {
  opacity: 0.38;
  filter: saturate(0.45);
}

.match-funnel-svg .funnel-band.is-active {
  opacity: 1;
}

.match-funnel-svg .funnel-band.is-done {
  opacity: 1;
}

.match-funnel-svg .funnel-band.is-active polygon {
  animation: funnel-shimmer 2.4s ease-in-out infinite;
}

@keyframes funnel-shimmer {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.14); }
}

.match-funnel-particles {
  pointer-events: none;
  position: absolute;
  inset: 6% 18% 8%;
  overflow: hidden;
}

.match-funnel-particles span {
  position: absolute;
  top: -8px;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 8px rgba(78, 185, 185, 0.65);
  opacity: 0;
  animation: funnel-fall 3.6s linear infinite;
}

.match-funnel-particles span:nth-child(1) { left: 18%; animation-delay: 0s; }
.match-funnel-particles span:nth-child(2) { left: 36%; animation-delay: 0.7s; }
.match-funnel-particles span:nth-child(3) { left: 50%; animation-delay: 1.4s; }
.match-funnel-particles span:nth-child(4) { left: 64%; animation-delay: 0.35s; }
.match-funnel-particles span:nth-child(5) { left: 78%; animation-delay: 2.1s; }
.match-funnel-particles span:nth-child(6) { left: 42%; animation-delay: 2.8s; }

@keyframes funnel-fall {
  0% {
    transform: translate(-50%, 0) scale(0.7);
    opacity: 0;
  }
  12% { opacity: 0.9; }
  100% {
    transform: translate(-50%, 340px) scale(0.35);
    opacity: 0;
  }
}

.match-funnel-detail {
  margin: 0.85rem 0 0.25rem;
  text-align: center;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
}

.match-funnel-hint {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
  .match-funnel-svg .funnel-band.is-active polygon,
  .match-funnel-particles span {
    animation: none;
  }

  .match-funnel-particles {
    display: none;
  }
}

@media (max-width: 600px) {
  .match-funnel {
    padding: 1.15rem 0.9rem 1rem;
    margin-bottom: 1.25rem;
  }

  .match-funnel-title {
    font-size: 1.2rem;
  }

  .match-funnel-elapsed-value {
    font-size: 1.15rem;
  }

  .match-funnel-svg .funnel-count {
    font-size: 20px;
  }

  .match-funnel-svg .funnel-label {
    font-size: 10px;
  }

  .match-funnel-svg .funnel-band[data-stage="5"] .funnel-label,
  .match-funnel-svg .funnel-band[data-stage="6"] .funnel-label {
    font-size: 9px;
  }
}

.adv-search-placeholder {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--text-subtle);
}

.adv-search-placeholder svg {
  width: 48px;
  height: 48px;
  color: var(--border-brand);
  margin-bottom: 1rem;
}

.adv-search-placeholder h3 {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.adv-search-placeholder p {
  font-size: 0.95rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .adv-search-main {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .checklist-body {
    margin-top: 0;
  }

  .checklist-body:not(.collapsed) {
    margin-top: 1.25rem;
  }
}

@media (max-width: 600px) {
  /* ── Advanced Search ── */
  .adv-search-content {
    padding: 1.5rem 1rem;
  }

  .adv-search-content h1 {
    font-size: 1.4rem;
  }

  .adv-search-main {
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .patient-info-section,
  .checklist-section {
    padding: 1.25rem;
  }

  .patient-textarea {
    min-height: 200px;
    font-size: 0.9rem;
  }

  /* ── Hero ── */
  .hero {
    padding: 2.5rem 1.25rem 1.5rem;
    justify-content: flex-start;
    gap: 0;
  }

  .brand-img {
    max-width: min(320px, 75vw);
    margin-bottom: 0.75rem;
  }

  .hero h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
  }

  /* ── Search bar ── */
  .search-bar {
    flex-direction: column;
    border-radius: 20px;
  }

  .search-bar--compact {
    border-radius: 16px;
  }

  .search-field {
    padding: 0.85rem 1.2rem;
  }

  .search-field + .search-field {
    border-left: none;
    border-top: 1px solid var(--border-teal);
  }

  .search-btn {
    border-radius: var(--radius-md);
    margin: 8px;
    padding: 0.9rem;
    justify-content: center;
  }

  /* ── Role boxes ── */
  .role-boxes {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
  }

  .role-box {
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    gap: 0.4rem;
    border-radius: 10px;
  }

  .role-box svg {
    width: 18px;
    height: 18px;
  }

  /* ── Stats ── */
  .stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem 1.5rem;
    margin-top: 1.75rem;
    text-align: left;
  }

  .stat {
    font-size: 0.85rem;
  }

  /* ── Grid ── */
  .grid {
    grid-template-columns: 1fr;
  }

  /* ── Navbar ── */
  .user-bar {
    padding: 0 0.75rem;
    height: 48px;
  }

  .nav-links {
    gap: 0;
  }

  .nav-link {
    font-size: 0.8125rem;
    padding: 0.35rem 0.5rem;
  }

  /* ── Feedback popup ── */
  .feedback-popup {
    left: 12px;
    right: 12px;
    width: auto;
  }
}

/* ---------- Impersonation Banner ---------- */
.impersonation-banner {
  background: var(--warning-bg-subtle);
  border-bottom: 2px solid var(--warning-border);
  padding: 0.75rem max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
  text-align: center;
  font-size: 0.875rem;
  color: var(--warning-text);
}

.impersonation-banner strong {
  font-weight: 600;
}

/* ---------- User Bar & Navigation ---------- */
.user-bar {
  background: color-mix(in srgb, var(--paper-raised) 88%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left));
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.user-bar.user-bar-dev {
  background: var(--warning-bg);
  border-bottom-color: var(--warning-border);
}

.user-bar.user-bar-dev .nav-link {
  color: var(--warning-text-dark);
}

.user-bar.user-bar-dev .nav-link:hover {
  background: rgba(252, 211, 77, 0.25);
  color: var(--warning-text-dark);
}

.user-bar.user-bar-dev .nav-link.active {
  background: rgba(252, 211, 77, 0.35);
  color: var(--warning-text-dark);
  font-weight: 700;
}

.nav-links {
  display: flex;
  gap: 0.125rem;
  align-items: center;
}

.nav-link {
  color: var(--text-secondary);
  font-weight: 550;
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  letter-spacing: -0.01em;
  background: transparent;
  border: none;
}

.nav-link:hover {
  background: var(--sage);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--sage);
  color: var(--text-primary);
  font-weight: 650;
}

/* --- Nav Dropdown --- */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border: none;
  cursor: pointer;
  background: transparent;
}

.nav-dropdown-chevron {
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.nav-dropdown.open .nav-dropdown-chevron {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--popover);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  padding: 0.375rem;
  z-index: 200;
  flex-direction: column;
  gap: 0.125rem;
}

.nav-dropdown.open .nav-dropdown-menu {
  display: flex;
}

.nav-dropdown-item {
  display: block;
  color: var(--text-secondary);
  font-weight: 550;
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.45rem 0.875rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.nav-dropdown-item:hover {
  background: var(--sage);
  color: var(--text-primary);
}

.nav-dropdown-item.active {
  background: var(--sage);
  color: var(--text-primary);
  font-weight: 650;
}

.logo-link {
  display: flex;
  align-items: center;
  line-height: 0;
}

.nav-logo {
  height: 32px;
  width: auto;
  display: block;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-name {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------- Case Management Buttons ---------- */
.case-management-bar {
  margin-bottom: 2rem;
  padding: 1rem 1.25rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.case-name-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.case-name-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  max-width: 500px;
}

.case-name-label {
  font-weight: 600;
  white-space: nowrap;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.case-name-input {
  flex: 1;
  min-width: 200px;
  padding: 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.9375rem;
  box-sizing: border-box;
}

.case-name-feedback {
  font-size: 0.8125rem;
  margin-top: 0.5rem;
  display: none;
}

.case-management-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.case-actions-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-shrink: 0;
}

.case-name-wrapper {
  flex: 1;
  min-width: 0;
}

.case-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Mobile responsive */
@media (max-width: 640px) {
  .case-name-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  
  .case-name-input-group {
    max-width: 100%;
  }
  
  .case-name-input {
    min-width: 0;
  }
  
  #save-name-btn {
    width: 100%;
  }
}

.case-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0 1rem;
  min-height: 44px; /* Apple HIG minimum touch target */
  border: none;
  border-radius: 10px; /* iOS rounded-rect */
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.00625em;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
  touch-action: manipulation; /* removes 300ms iOS tap delay */
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  text-decoration: none;
}

.btn-icon {
  font-size: 1.1em;
  line-height: 1;
}

.btn-text {
  line-height: 1;
}

.case-btn--load {
  background: var(--brand);
  color: var(--white);
  box-shadow: none;
}

.case-btn--load:hover {
  background: var(--brand-dark);
  box-shadow: none;
}

.case-btn--load:active {
  background: var(--clay-dark);
  box-shadow: none;
}

.case-btn--save {
  background: var(--success);
  color: var(--white);
  box-shadow: none;
}

.case-btn--save:hover {
  background: var(--success-dark);
  box-shadow: none;
}

.case-btn--save:active {
  background: var(--success-darker);
  box-shadow: none;
}

.case-btn--danger {
  background: var(--error);
  color: var(--white);
  box-shadow: none;
}

.case-btn--danger:hover {
  background: var(--error-dark);
  box-shadow: none;
}

.case-btn--danger:active {
  background: var(--error-darker);
  box-shadow: none;
}

/* Outlined – secondary action */
.case-btn--secondary {
  background: transparent;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  box-shadow: none;
}

.case-btn--secondary:hover {
  background: var(--tonal-secondary);
  border-color: var(--gray-400);
}

.case-btn--secondary:active {
  background: var(--tonal-secondary-press);
}

/* Cart link button in trials header */
.case-btn--cart {
  background: var(--orange-bg);
  color: var(--orange);
  border: 1px solid var(--orange-border);
  box-shadow: none;
  text-decoration: none;
}

.case-btn--cart:hover {
  background: var(--orange-bg-hover);
  border-color: var(--orange-border-hover);
}

.case-btn--results {
  background: var(--sage);
  color: var(--text-primary);
  border: 1px solid color-mix(in srgb, var(--sage-dark) 22%, var(--sage));
  box-shadow: none;
  text-decoration: none;
}
.case-btn--results:hover {
  background: var(--sage-deep);
  border-color: var(--sage-dark);
  color: var(--text-primary);
}

/* Disabled state */
.case-btn--disabled,
.case-btn--results.case-btn--disabled {
  background: var(--gray-100) !important;
  color: var(--text-subtle) !important;
  border-color: var(--border) !important;
  cursor: not-allowed;
  box-shadow: none !important;
}

.case-btn--disabled:hover,
.case-btn--results.case-btn--disabled:hover {
  background: var(--gray-100) !important;
  color: var(--text-subtle) !important;
  border-color: var(--border) !important;
}

/* Per-trial cart toggle button */
.cart-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: var(--surface-card);
  color: var(--text-primary);
  cursor: pointer;
  line-height: 0;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.cart-toggle-btn:hover {
  background: var(--info-bg-subtle);
  border-color: var(--info-border-hover);
  box-shadow: var(--ring-info-glow);
}

.cart-toggle-btn.cart-btn--active {
  background: var(--success-bg);
  border-color: var(--success-border-active);
  box-shadow: var(--ring-success-glow);
}

.cart-toggle-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Per-trial favourite bookmark toggle */
.favourite-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: var(--surface-card);
  color: var(--text-primary);
  cursor: pointer;
  line-height: 0;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.favourite-toggle-btn .favourite-icon--solid {
  display: none;
}

.favourite-toggle-btn:hover {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #b45309;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.favourite-toggle-btn.favourite-btn--active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #b45309;
}

.favourite-toggle-btn.favourite-btn--active .favourite-icon--outline {
  display: none;
}

.favourite-toggle-btn.favourite-btn--active .favourite-icon--solid {
  display: block;
}

.favourite-toggle-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card-bottom {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.cart-notes-inline {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.notes-input {
  flex: 1;
  font-size: 0.875rem;
  border: 1px solid var(--gray-300);
  border-radius: 0.375rem;
  padding: 0.375rem 0.625rem;
  outline: none;
  transition: border-color var(--transition-fast);
  min-width: 0;
}

.notes-input:focus {
  border-color: var(--info);
  box-shadow: var(--ring-info);
}

.notes-save-indicator {
  font-size: 0.75rem;
  white-space: nowrap;
  min-width: 3.5rem;
}

/* Manually curated human-indicator badge */
/* When visible, occupy its own row under the cart button */
.card-bottom > .manually-curated-badge {
  flex-basis: 100%;
  margin-top: 0.1rem;
}

.manually-curated-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: #0f766e;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 9999px;
  padding: 0.2rem 0.6rem;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
}

/* Keep the node in the DOM for JS toggles, but do not reserve a blank row */
.manually-curated-badge--hidden {
  display: none;
}

/* Readonly notes display */
.card-notes-readonly {
  font-size: 0.8125rem;
  color: var(--gray-600);
  background: var(--gray-50);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.375rem 0.625rem;
}
.card-notes-label {
  font-weight: 600;
  color: var(--gray-700);
}

.cart-icon {
  width: 26px;
  height: 26px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  pointer-events: none;
}

.loaded-case-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--info-text-dark);
}

.loaded-case-badge strong {
  font-weight: 600;
  color: var(--info-text);
}

/* ---------- Load Case Dropdown ---------- */
.load-case-dropdown {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  margin-bottom: 2rem;
  max-height: 400px;
  overflow-y: auto;
}

.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.dropdown-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.75rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-base);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.close-btn:hover {
  background: var(--gray-100);
  color: var(--gray-800);
}

.case-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 90%;
  max-height: min(90vh, calc(100dvh - 2rem));
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.modal-body {
  padding: 1.5rem;
}

.modal-body label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
}

.modal-footer .btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-base);
  background: var(--brand);
  color: var(--white);
  box-shadow: none;
}

.modal-footer .btn:hover {
  transform: none;
  background: var(--brand-dark);
  box-shadow: none;
}

.modal-footer .btn:active {
  transform: translateY(0);
}


/* ==========================================================================
   Admin Section
   ========================================================================== */

/* Admin Layout */
.admin-page {
  background: var(--surface-admin);
  min-height: 100vh;
}

.admin-layout {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 260px;
  background: var(--bg-dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: calc(100vh - 52px);
  left: 0;
  top: 52px;
}

.admin-sidebar-header {
  padding: 2rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-sidebar-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--white);
  margin: 0;
}

.admin-nav {
  flex: 1;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
}

.admin-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.5rem;
  color: var(--eligara-slate);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all var(--transition-base);
  border-left: 3px solid transparent;
}

.admin-nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--white);
}

.admin-nav-link.active {
  background: color-mix(in srgb, var(--sage) 18%, transparent);
  color: var(--white);
  border-left-color: var(--sage);
}

.admin-nav-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.admin-nav-divider {
  margin: 0.5rem 1.5rem;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-main {
  flex: 1;
  margin-left: 260px;
  padding: 2rem;
  margin-top: 60px; /* Account for user-bar */
}

@media (max-width: 900px) {
  .admin-layout {
    flex-direction: column;
  }

  .admin-sidebar {
    position: relative;
    width: 100%;
    height: auto;
    top: 0;
  }

  .admin-sidebar-header {
    padding: 1rem 1.25rem;
  }

  .admin-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0.35rem 0.5rem 0.6rem;
    -webkit-overflow-scrolling: touch;
  }

  .admin-nav-link {
    flex: 0 0 auto;
    border-left: 0;
    border-bottom: 3px solid transparent;
    padding: 0.7rem 0.9rem;
    white-space: nowrap;
  }

  .admin-nav-link.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  .admin-nav-divider {
    display: none;
  }

  .admin-main {
    margin-left: 0;
    padding: 1.25rem 1rem 2rem;
  }
}

/* Admin Dashboard */
.admin-dashboard h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 2rem;
}

.admin-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.admin-card {
  background: var(--surface-card);
  border-radius: var(--radius-md);
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all var(--transition-base);
  cursor: pointer;
  display: block;
}

.admin-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.admin-card-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.admin-card-disabled:hover {
  transform: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.admin-card-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.admin-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-900);
  margin: 0 0 0.5rem 0;
}

.admin-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

/* Admin LLM settings */
.llm-settings {
  max-width: 44rem;
}

.llm-settings-header {
  margin-bottom: 1.5rem;
}

.llm-settings-kicker {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand-dark);
}

.llm-settings-header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.llm-settings-lede {
  margin: 0;
  max-width: 38rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.llm-settings-alert {
  margin-bottom: 1.25rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.45;
}

.llm-settings-alert--error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-dark);
}

.llm-settings-alert--success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-darker);
}

.llm-settings-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.llm-settings-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  background: var(--eligara-navy);
  color: var(--white);
}

.llm-settings-current-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-on-dark);
  white-space: nowrap;
}

.llm-settings-current-value {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--white);
  text-align: right;
  word-break: break-word;
}

.llm-settings-groups {
  display: flex;
  flex-direction: column;
}

.llm-settings-group {
  padding: 1.15rem 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}

.llm-settings-group:first-of-type {
  border-top: 0;
}

.llm-settings-group-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.llm-settings-group-title svg {
  color: var(--brand-dark);
  flex-shrink: 0;
}

.llm-settings-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.llm-option {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: 52px;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--gray-50);
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    background var(--transition-fast),
    box-shadow var(--transition-fast);
}

.llm-option:hover {
  border-color: var(--border-brand);
  background: var(--white);
}

.llm-option:has(input:focus-visible) {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

.llm-option:has(input:checked),
.llm-option.is-selected {
  border-color: var(--brand);
  background: var(--surface-teal-light);
  box-shadow: 0 0 0 3px rgba(78, 185, 185, 0.18);
}

.llm-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

.llm-option-mark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--gray-300);
  border-radius: 50%;
  background: var(--white);
  position: relative;
  flex-shrink: 0;
}

.llm-option:has(input:checked) .llm-option-mark,
.llm-option.is-selected .llm-option-mark {
  border-color: var(--brand);
}

.llm-option:has(input:checked) .llm-option-mark::after,
.llm-option.is-selected .llm-option-mark::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--brand);
}

.llm-option-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.llm-option-engine {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.llm-option-meta {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.llm-option-badge {
  flex-shrink: 0;
  padding: 0.18rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: var(--eligara-navy);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.llm-settings-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.15rem;
}

.llm-settings-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  background: var(--eligara-navy);
  color: var(--white);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.llm-settings-save:hover {
  background: var(--bg-dark-navy);
}

.llm-settings-save:active {
  transform: translateY(1px);
}

@media (max-width: 640px) {
  .llm-settings-current {
    flex-direction: column;
    align-items: flex-start;
  }

  .llm-settings-current-value {
    text-align: left;
  }

  .llm-option {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .llm-option-badge {
    grid-column: 2;
    justify-self: start;
  }

  .llm-settings-actions {
    justify-content: stretch;
  }

  .llm-settings-save {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .llm-option,
  .llm-settings-save {
    transition: none;
  }
}

/* Shared admin settings (SSO + LLM) */
.admin-page-head {
  margin-bottom: 1.5rem;
}

.admin-page-head--split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.admin-page-kicker {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand-dark);
}

.admin-page-head h1 {
  margin: 0 0 0.5rem;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.admin-page-lede {
  margin: 0;
  max-width: 40rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.admin-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
}

.admin-back:hover {
  color: var(--text-primary);
}

.admin-panel {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.admin-alert {
  margin-bottom: 1.25rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.45;
}

.admin-alert--error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-dark);
}

.admin-alert--success {
  background: var(--success-bg, #e8f5e9);
  border: 1px solid var(--success-border, #a5d6a7);
  color: var(--success-dark, #1b5e20);
}

.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.admin-btn--primary {
  background: var(--eligara-navy);
  color: var(--white);
}

.admin-btn--primary:hover {
  background: var(--bg-dark-navy);
}

.admin-btn--secondary {
  background: var(--white);
  color: var(--text-secondary);
  border-color: var(--border);
}

.admin-btn--secondary:hover {
  background: var(--gray-50);
}

.admin-btn--danger {
  background: var(--error-bg);
  color: var(--error-dark);
  border-color: var(--error-border);
}

.admin-btn--danger:hover {
  background: #fecaca;
}

.admin-btn--sm {
  min-height: 36px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.admin-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.admin-field {
  margin-bottom: 1.1rem;
}

.admin-field:last-child {
  margin-bottom: 0;
}

.admin-field > label,
.admin-field-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.admin-field input[type="text"],
.admin-field input[type="url"],
.admin-field input[type="email"],
.admin-field input[type="password"],
.admin-field input[type="number"],
.admin-field select,
.admin-field textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  font: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  box-sizing: border-box;
}

.admin-field textarea {
  min-height: 8rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  resize: vertical;
}

.admin-field input:focus,
.admin-field select:focus,
.admin-field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(78, 185, 185, 0.18);
}

.admin-hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.admin-hint code {
  background: var(--gray-100);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.78rem;
}

.req {
  color: var(--error-mid);
}

.admin-switch {
  display: flex !important;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.35rem !important;
}

.admin-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.admin-switch-ui {
  width: 40px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--gray-300);
  position: relative;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.admin-switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--white);
  transition: transform var(--transition-fast);
}

.admin-switch input:checked + .admin-switch-ui {
  background: var(--brand);
}

.admin-switch input:checked + .admin-switch-ui::after {
  transform: translateX(16px);
}

.admin-switch input:focus-visible + .admin-switch-ui {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

/* SSO list */
.sso-table-wrap {
  overflow-x: auto;
}

.sso-table {
  width: 100%;
  border-collapse: collapse;
}

.sso-table th {
  text-align: left;
  padding: 0.85rem 1.1rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--gray-50);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sso-table td {
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.88rem;
  color: var(--gray-700);
  vertical-align: middle;
}

.sso-table tbody tr:last-child td {
  border-bottom: none;
}

.sso-table tbody tr:hover {
  background: var(--gray-50);
}

.sso-table-name {
  font-weight: 600;
  color: var(--text-primary);
}

.sso-table-entity {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sso-slug {
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.sso-status {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sso-status--on {
  background: var(--success-bg);
  color: var(--success-darker);
}

.sso-status--off {
  background: var(--error-bg);
  color: var(--error-dark);
}

.sso-credits {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.sso-credit-edit {
  min-height: 32px;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.sso-credit-edit:hover {
  background: var(--gray-50);
}

.sso-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sso-actions form {
  display: inline;
}

.sso-endpoints {
  margin-top: 1.25rem;
  padding: 1.15rem 1.25rem;
  background: var(--eligara-navy);
  color: var(--white);
  border-radius: var(--radius-lg);
}

.sso-endpoints h2 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.sso-endpoints p {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--eligara-slate);
}

.sso-endpoints ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.55rem;
}

.sso-endpoints li {
  display: grid;
  gap: 0.2rem;
}

.sso-endpoints li span {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-on-dark);
}

.sso-endpoints code {
  font-size: 0.8rem;
  color: var(--white);
  word-break: break-all;
}

.sso-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.sso-empty svg {
  color: var(--brand-dark);
  margin-bottom: 0.75rem;
}

.sso-empty h2 {
  margin: 0 0 0.4rem;
  color: var(--text-primary);
}

.sso-empty p {
  margin: 0 0 1.1rem;
}

.sso-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 39, 0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.sso-modal-backdrop.is-open {
  display: flex;
}

.sso-modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
}

.sso-modal h3 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
}

.sso-modal p {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.sso-modal label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.sso-modal input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: inherit;
  margin-bottom: 1rem;
  box-sizing: border-box;
}

.sso-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* SSO IdP form */
.sso-form-page {
  max-width: 46rem;
}

.sso-form-section {
  padding: 1.25rem 1.35rem 1.35rem;
  margin-bottom: 1.15rem;
}

.sso-form-section h2 {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.sso-form-section h2 span {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}

.sso-llm-intro {
  margin: -0.35rem 0 1rem;
}

.sso-llm-options {
  gap: 0.45rem;
}

.sso-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.25rem;
  margin-bottom: 2rem;
}

.sso-sp-card {
  margin-bottom: 1.25rem;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}

.sso-sp-card-bar {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 1.2rem;
  background: var(--eligara-navy);
  color: var(--white);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sso-sp-card-bar span:last-child {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--brand-on-dark);
}

.sso-sp-grid {
  display: grid;
  gap: 0.85rem;
  padding: 1.15rem 1.2rem 1.25rem;
}

.sso-sp-item label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.sso-copy-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sso-copy-row code {
  flex: 1;
  background: var(--surface-teal-light);
  border: 1px solid var(--border-teal);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  word-break: break-all;
}

.sso-copy-btn {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0.3rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: var(--eligara-navy);
  color: var(--white);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.sso-copy-btn:hover {
  background: var(--bg-dark-navy);
}

@media (max-width: 640px) {
  .admin-page-head--split {
    flex-direction: column;
  }

  .admin-page-head--split .admin-btn {
    width: 100%;
  }

  .sso-form-actions {
    flex-direction: column-reverse;
  }

  .sso-form-actions .admin-btn {
    width: 100%;
  }

  .sso-copy-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Admin Users Page */
.admin-users h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 2rem;
}

.users-table-container {
  background: var(--surface-card);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
}

.users-table thead {
  background: var(--gray-50);
  border-bottom: 1px solid var(--border);
}

.users-table th {
  text-align: left;
  padding: 1rem 1.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.users-table td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  color: var(--gray-700);
}

.users-table tbody tr:last-child td {
  border-bottom: none;
}

.users-table tbody tr:hover {
  background: var(--gray-50);
}

.user-roles {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.role-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--role-bg);
  color: var(--info-darker);
}

.role-badge-none {
  background: var(--gray-100);
  color: var(--text-muted);
}

.text-muted {
  color: var(--text-subtle);
  font-size: 0.85rem;
}

.btn-secondary {
  background: var(--surface-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-secondary:hover {
  background: var(--sage);
  box-shadow: none;
}

/* ============================================================
   Profile Dropdown Menu
   ============================================================ */

.profile-trigger {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  user-select: none;
  transition: background var(--transition-fast);
}

.profile-trigger:hover {
  background: var(--gray-100);
}

/* Avatar */
.profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar-initials {
  color: var(--white);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
}

/* Large avatar in dropdown header */
.profile-avatar-lg {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-avatar-lg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar-lg .profile-avatar-initials {
  font-size: 1.125rem;
}

.profile-trigger-name {
  font-size: 0.875rem;
  color: var(--gray-700);
  font-weight: 500;
}

.profile-chevron {
  color: var(--text-subtle);
  transition: transform var(--transition-base);
  display: flex;
  align-items: center;
}

.profile-trigger.profile-open .profile-chevron {
  transform: rotate(180deg);
}

/* Dropdown panel */
.profile-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 200;
  overflow: hidden;
}

.profile-trigger.profile-open .profile-dropdown-menu {
  display: block;
}

/* Header: avatar + name + email */
.profile-menu-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.profile-menu-header-text {
  min-width: 0;
}

.profile-menu-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-menu-email {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-menu-auth-method {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.25rem;
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}

/* Credits row */
.profile-menu-credits {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--info-darker);
  font-weight: 500;
}

.profile-menu-credits-icon {
  font-size: 1rem;
  line-height: 1;
}

/* Divider */
.profile-menu-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0.25rem 0;
}

/* Menu items */
.profile-menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  color: var(--gray-700);
  font-size: 0.875rem;
  text-decoration: none;
  transition: background var(--transition-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.profile-menu-item:hover {
  background: var(--gray-50);
  color: var(--gray-900);
}

.profile-menu-item--danger {
  color: var(--error);
}

.profile-menu-item--danger:hover {
  background: var(--error-bg);
  color: var(--error-dark);
}

.profile-menu-version {
  padding: 0.35rem 1rem 0.5rem;
  font-size: 0.7rem;
  color: var(--text-subtle);
  user-select: text;
}

/* ==========================================================================
   Mobile Improvements (Apple HIG)
   ========================================================================== */

/* Focus indicators for keyboard / switch control users */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* Badge font-size floor on small screens */
@media (max-width: 640px) {
  .badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.7rem;
  }

  .nct {
    font-size: 0.8125rem;
  }

  .phase-indicator__label {
    font-size: 0.6rem;
  }

  .phase-box {
    width: 1.15rem;
    height: 1.15rem;
  }

  .card-header {
    flex-wrap: wrap;
  }

  .card-meta {
    gap: 0.5rem;
    font-size: 0.7rem;
  }

  .modal-content {
    width: calc(100% - 2rem);
    border-radius: var(--radius-md);
  }

  .empty-state__icon {
    width: clamp(3rem, 20vw, 4rem);
    height: clamp(3rem, 20vw, 4rem);
  }
}

/* ============================================================
   Admin Feedback Page
   ============================================================ */

.admin-feedback h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.25rem;
}

.admin-feedback-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.feedback-table-container {
  background: var(--surface-card);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow-x: auto;
}

.feedback-table th,
.feedback-table td {
  vertical-align: top;
}

.feedback-td-date {
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 130px;
}

.feedback-td-user {
  min-width: 160px;
}

.feedback-user-email {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--gray-800);
}

.feedback-user-id {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.feedback-td-url {
  max-width: 220px;
}

.feedback-url-link {
  font-size: 0.8rem;
  color: var(--accent);
  word-break: break-all;
}

.feedback-url-link:hover {
  text-decoration: underline;
}

.feedback-td-session {
  max-width: 120px;
}

.feedback-session-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-all;
}

.feedback-td-message {
  min-width: 260px;
}

.feedback-message-text {
  font-size: 0.875rem;
  color: var(--gray-700);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 6rem;
  overflow-y: auto;
}

.feedback-th-actions,
.feedback-td-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}

.admin-feedback .btn-delete-icon {
  background: none;
  border: none;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-subtle);
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.admin-feedback .btn-delete-icon:hover {
  color: var(--error);
  background: var(--error-bg);
}

.admin-feedback .btn-delete-icon:active {
  background: var(--orange-bg-hover);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  justify-content: center;
}

.pagination-btn {
  padding: 0.5rem 1rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--gray-700);
  transition: background var(--transition-fast);
}

.pagination-btn:hover {
  background: var(--gray-100);
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.admin-empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.admin-empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* ============================================================
   Feedback / Bug Report Widget
   ============================================================ */

.feedback-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.feedback-btn:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.feedback-popup {
  position: fixed;
  top: 56px;
  right: 12px;
  width: 340px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.feedback-popup[hidden] {
  display: none;
}

.feedback-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.feedback-popup-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-800);
}

.feedback-popup-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.feedback-popup-close:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.feedback-textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--gray-800);
  line-height: 1.5;
  outline: none;
  transition: border-color var(--transition-fast);
}

.feedback-textarea:focus {
  border-color: var(--brand);
  box-shadow: var(--ring-brand);
}

.feedback-popup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.feedback-status {
  font-size: 0.8125rem;
  flex: 1;
  min-width: 0;
}

.feedback-status--success {
  color: var(--success);
}

.feedback-status--error {
  color: var(--error-mid);
}

/* ==========================================================================
   Login Page
   ========================================================================== */

.page-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--surface);
}

.login-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 3rem 2.5rem 2.5rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-brand {
  font-size: 2.4rem;
  font-weight: 400;
  letter-spacing: -0.03em;
  text-transform: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  margin-bottom: 0.35rem;
}

.login-tagline {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 2.25rem;
  font-weight: 400;
}

/* Google sign-in — follows Google brand guidelines */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1.25rem;
  border: 1.5px solid var(--google-border);
  border-radius: 10px;
  background: var(--surface-card);
  color: var(--google-text);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  letter-spacing: 0.01em;
}

.btn-google:hover {
  background: var(--google-bg-hover);
  box-shadow: var(--shadow-google);
  border-color: var(--google-border-hover);
}

.btn-google:active {
  background: var(--google-bg-active);
}

.btn-google svg {
  flex-shrink: 0;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.75rem 0;
  color: var(--text-subtle);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.sso-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sso-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.sso-input::placeholder {
  color: var(--text-subtle);
}

.sso-input:focus {
  border-color: var(--brand);
  box-shadow: var(--ring-brand);
}

.btn-sso {
  width: 100%;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
  letter-spacing: 0.01em;
}

.btn-sso:hover {
  opacity: 1;
  background: var(--brand-dark);
  box-shadow: none;
}

.btn-sso:active {
  opacity: 0.85;
}

.sso-hint {
  font-size: 0.78125rem;
  color: var(--text-subtle);
  margin-top: 0.25rem;
}

.login-alert {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border-subtle);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  text-align: left;
  font-size: 0.875rem;
  color: var(--warning-text-dark);
  line-height: 1.5;
}

.login-alert strong {
  display: block;
  margin-bottom: 0.35rem;
}

.login-alert code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.85em;
}

.login-alert a {
  color: var(--brand);
  text-decoration: underline;
}

.login-footer {
  margin-top: 2rem;
  font-size: 0.78125rem;
  color: var(--text-subtle);
  line-height: 1.6;
}

/* ==========================================================================
   Toast / Snackbar
   ========================================================================== */

#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  pointer-events: none;
  max-width: min(22rem, calc(100vw - 2rem));
}

@media (max-width: 600px) {
  #toast-container {
    right: 50%;
    transform: translateX(50%);
    bottom: 1rem;
    width: calc(100vw - 2rem);
    max-width: none;
  }
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.22s ease, transform 0.22s ease;
  border: 1px solid transparent;
  max-width: 100%;
  word-break: break-word;
}

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

.toast--hiding {
  opacity: 0;
  transform: translateY(0.5rem);
}

.toast--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-darker);
}

.toast--error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error);
}

.toast--info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info-darker);
}

.toast-message {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  color: inherit;
  opacity: 0.55;
  flex-shrink: 0;
}

.toast-close:hover {
  opacity: 1;
}

/* ==========================================================================
   Confirm Dialog  –  Material Design 3
   ========================================================================== */

.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-width: min(23rem, calc(100vw - 3rem));
  max-height: calc(100vh - 3rem);
  width: 100%;
  font-family: var(--font-body);
  background: var(--surface-card);
  /* Explicit centering - inset centers the dialog in the viewport */
  inset: 0;
  margin: auto;
  /* Prevent layout shift */
  position: fixed;
  /* M3 entrance animation */
  animation: confirm-dialog-in 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes confirm-dialog-in {
  from { 
    opacity: 0; 
    transform: scale(0.92);
  }
  to { 
    opacity: 1; 
    transform: scale(1);
  }
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(2px);
  animation: confirm-scrim-in 0.25s ease;
}

@keyframes confirm-scrim-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.confirm-dialog-inner {
  padding: 1.5rem 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* M3 dialog icon */
.confirm-dialog-icon {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: 1rem;
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: center;
}

.confirm-dialog-icon svg {
  width: 100%;
  height: 100%;
}

/* M3 headline-small */
.confirm-dialog-title {
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.75rem;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
  letter-spacing: 0;
}

/* M3 body-medium */
.confirm-dialog-body {
  font-size: 0.875rem;
  line-height: 1.43;
  color: var(--text-muted);
  margin: 0 0 0.25rem;
}

/* M3 action row */
.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
  width: 100%;
}

/* Shared button base */
.confirm-dialog-btn {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.00625rem;
  line-height: 1.25rem;
  padding: 0.625rem 1.5rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: background-color 0.1s ease, box-shadow 0.1s ease;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

/* M3 text button (Cancel) */
.confirm-dialog-btn--text {
  background: transparent;
  color: var(--brand);
}

.confirm-dialog-btn--text:hover {
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}

.confirm-dialog-btn--text:active {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}

/* M3 filled-tonal (destructive) button */
.confirm-dialog-btn--filled {
  background: var(--error-mid);
  color: var(--white);
}

.confirm-dialog-btn--filled:hover {
  background: var(--error);
  box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
}

.confirm-dialog-btn--filled:active {
  background: var(--error-dark);
  box-shadow: none;
}

/* Non-destructive variant (confirm-dialog-btn--filled when confirmVariant=primary) */
.confirm-dialog-btn--filled.confirm-dialog-btn--primary {
  background: var(--brand);
}

.confirm-dialog-btn--filled.confirm-dialog-btn--primary:hover {
  background: var(--brand-dark);
}

/* Legacy btn variants kept for backward compat */
.btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  background: var(--gray-100);
}

.btn--danger {
  background: var(--error-mid);
  border: 1px solid var(--error-mid);
  color: var(--white);
}

.btn--danger:hover {
  background: var(--error);
  border-color: var(--error);
}

.btn--primary {
  background: var(--brand);
  border: 1px solid var(--brand);
  color: var(--white);
}

.btn--primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

/* ========================================================================
   Compare Cases Page
   ======================================================================== */

.page-compare {
  background: var(--bg-light);
}

/* ── Case selector ── */

.compare-selector {
  margin-bottom: 2rem;
}

.compare-selector__grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: end;
}

.compare-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.compare-field__label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.compare-select {
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font-body);
  background: var(--white);
  color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.compare-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(124, 107, 196, 0.15);
}

.compare-vs {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 0.65rem;
  text-align: center;
}

/* ── Diff legend ── */

.diff-legend {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.diff-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.diff-legend__swatch {
  font-size: 0.75rem;
  border-radius: 3px;
  padding: 1px 6px;
}

/* ── Diff highlighting ── */

.diff-del {
  background: #fecdd3;
  color: #9f1239;
  border-radius: 3px;
  padding: 1px 2px;
}

.diff-add {
  background: #bbf7d0;
  color: #166534;
  border-radius: 3px;
  padding: 1px 2px;
}

/* ── Comparison sections ── */

.compare-section {
  margin-bottom: 2.5rem;
}

.compare-section__title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--brand-tint);
}

/* ── Side-by-side panels ── */

.compare-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.compare-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  overflow: hidden;
}

.compare-panel__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand-dark);
  margin: 0 0 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.compare-panel__text {
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.compare-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.88rem;
}

/* ── Trial groups ── */

.compare-trial-group {
  margin-bottom: 1.5rem;
}

.compare-trial-group__title {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
}

.compare-trial-group__title--common {
  background: var(--brand-tint);
  color: var(--brand-dark);
}

.compare-trial-group__title--only1 {
  background: #fecdd3;
  color: #9f1239;
}

.compare-trial-group__title--only2 {
  background: #bbf7d0;
  color: #166534;
}

/* ── Trial rows ── */

.compare-trial-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.compare-trial-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: box-shadow 0.15s;
}

.compare-trial-row:hover {
  box-shadow: var(--shadow-sm);
}

.compare-trial-row__nct {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.compare-trial-row__manual-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem;
  height: 1.2rem;
  color: #0f766e;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 9999px;
  flex-shrink: 0;
}

.compare-trial-row__nct:hover {
  text-decoration: underline;
}

.compare-trial-row__title {
  flex: 1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compare-trial-row__status {
  flex-shrink: 0;
}

/* ── Responsive: stack on mobile ── */

@media (max-width: 768px) {
  .compare-selector__grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .compare-vs {
    padding-bottom: 0;
  }

  .compare-panels {
    grid-template-columns: 1fr;
  }

  .compare-trial-row {
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
  }

  .compare-trial-row__title {
    white-space: normal;
    order: 3;
    flex-basis: 100%;
  }
}

/* ---------- Experiment workflows ---------- */

.experiment-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.experiment-content h1 {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 1.75rem;
  font-weight: 400;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
}

.experiment-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 1.5rem;
}

.experiment-form .patient-info-section {
  margin-top: 0.5rem;
}

.experiment-submit-status {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.45;
  max-width: 42rem;
}

.experiment-submit-status--success {
  color: #16a34a;
}

.experiment-submit-status--error {
  color: #dc2626;
}

.experiment-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.experiment-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.25rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 0.5rem);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.experiment-card:hover {
  border-color: var(--brand);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.experiment-card-title {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.experiment-card-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.experiment-card-cta {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--brand);
  margin-top: 0.25rem;
}

.experiment-empty {
  color: var(--text-muted);
  padding: 2rem 0;
}

@media (max-width: 640px) {
  .experiment-content {
    padding: 1rem 1rem 2.5rem;
  }

  .experiment-content h1 {
    font-size: 1.5rem;
  }
}

.experiment-content--wide {
  max-width: 880px;
}

/* Lisbon/Barcelona pre-LLM filters (accordion: intervention types, phases) */
.prellm-filters {
  margin: 0.65rem 0 0.85rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 0.5rem);
  background: var(--gray-50, #f8fafc);
  min-width: 0;
  overflow: hidden;
}

.prellm-filters-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 0.9rem;
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.prellm-filters-summary::-webkit-details-marker {
  display: none;
}

.prellm-filters-summary::marker {
  content: "";
}

.prellm-filters-summary:hover {
  background: rgba(15, 23, 42, 0.03);
}

.prellm-filters-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 6px;
  color: #64748b;
  background: #f1f5f9;
  transition: transform 0.18s ease, background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.prellm-filters[open] .prellm-filters-chevron {
  transform: rotate(90deg);
  background: var(--sage);
  color: var(--text-primary);
}

.prellm-filters-title {
  font-weight: 600;
}

.prellm-filters-hint {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.prellm-filters-body {
  padding: 0 0.9rem 0.95rem;
  border-top: 1px solid var(--border);
}

.prellm-filters-help {
  margin: 0.65rem 0 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.prellm-filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.4rem 0.75rem;
}

.prellm-filters-grid--phases {
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
}

.prellm-filter-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  min-height: 2rem;
}

.prellm-filter-option input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--brand);
  flex-shrink: 0;
  cursor: pointer;
}

.prellm-filters-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

@media (max-width: 640px) {
  .prellm-filters-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.experiment-llm-picker {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin: 0.85rem 0 1rem;
}

.experiment-llm-label {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.experiment-llm-select {
  flex: 1;
  min-width: 14rem;
  max-width: 28rem;
  min-height: 44px;
  padding: 0.55rem 2rem 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  cursor: pointer;
}

.experiment-llm-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(124, 107, 196, 0.15);
}

@media (max-width: 640px) {
  .experiment-llm-picker {
    flex-direction: column;
    align-items: stretch;
  }

  .experiment-llm-select {
    max-width: none;
    min-width: 0;
  }
}

/* Tokyo matching UI */
.tokyo-progress {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin: 1.75rem 0 0.5rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 0.5rem);
  background: var(--gray-50, #f8fafc);
}

/* display:flex above would otherwise override the HTML hidden attribute */
.tokyo-progress[hidden] {
  display: none !important;
}

.tokyo-progress-spinner {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.15rem;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: tokyo-spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.tokyo-progress-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.tokyo-progress-detail {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tokyo-section {
  margin-top: 2rem;
}

.tokyo-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tokyo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.tokyo-conditions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.tokyo-condition-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 0.5rem);
  padding: 0.85rem 1rem;
}

.tokyo-condition-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.tokyo-key-slug {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-right: 0.35rem;
}

.tokyo-condition-terms-meta {
  margin-top: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tokyo-condition-conf {
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tokyo-condition-rationale {
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tokyo-condition-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.tokyo-term-chip {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--gray-100, #f1f5f9);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.tokyo-stats {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.tokyo-matches {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.tokyo-match-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 0.5rem);
  padding: 1rem 1.1rem;
  background: #fff;
}

.tokyo-match-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.4rem;
}

.tokyo-match-rank {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.tokyo-match-nct {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--brand);
  text-decoration: none;
}

.tokyo-match-nct:hover {
  text-decoration: underline;
}

.tokyo-match-score {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--gray-50, #f8fafc);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.tokyo-match-score--first-pass {
  margin-left: 0.35rem;
  font-weight: 500;
  color: #64748b;
  background: #f1f5f9;
}

.tokyo-match-title {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0 0 0.4rem;
  line-height: 1.35;
  color: var(--text-primary);
}

.tokyo-match-summary {
  margin: 0 0 0.55rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.tokyo-match-reasons {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.tokyo-match-reasons strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.tokyo-match-reasons ul {
  margin: 0;
  padding-left: 1.15rem;
}

.tokyo-match-reasons li {
  margin-bottom: 0.2rem;
  line-height: 1.4;
}

.tokyo-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .tokyo-match-score {
    margin-left: 0;
  }
}

/* Experiment hub – saved cases list */
.experiment-cases-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.experiment-cases-header h2 {
  margin: 0;
}

.experiment-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.experiment-filter-bar .cases-field {
  display: grid;
  gap: 0.35rem;
  min-width: 200px;
}

.experiment-filter-bar .cases-field span {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.experiment-filter-bar .cases-field select {
  min-height: 44px;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font: inherit;
}

.experiment-filter-clear {
  margin-bottom: 0.15rem;
}

.experiment-cases-table {
  margin-top: 0.5rem;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.experiment-cases-table table {
  width: 100%;
  border-collapse: collapse;
}

.experiment-cases-table thead {
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

.experiment-cases-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 500;
  font-size: 0.75rem;
  color: #6b7280;
}

.experiment-cases-table td {
  padding: 1rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

.experiment-cases-table tbody tr:last-child td {
  border-bottom: none;
}

.experiment-cases-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.04);
}

.experiment-cases-table .case-link {
  font-weight: 500;
  color: var(--brand, #2563eb);
  text-decoration: none;
}

.experiment-cases-table .case-link:hover {
  text-decoration: underline;
}

.experiment-cases-table .cell--muted {
  color: #6b7280;
  font-size: 0.8125rem;
}

.experiment-cases-table .cell--actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

@media (max-width: 720px) {
  .experiment-cases-table thead {
    display: none;
  }

  .experiment-cases-table tr {
    display: block;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #f3f4f6;
  }

  .experiment-cases-table td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border-bottom: none;
  }

  .experiment-cases-table td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    flex-shrink: 0;
  }
}

.exp-status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--gray-50, #f8fafc);
  color: var(--text-muted);
}

.exp-status--done {
  color: #15803d;
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.exp-status--active {
  color: #b45309;
  background: #fffbeb;
  border-color: #fde68a;
}

.exp-status--failed {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}

.exp-status--draft {
  color: var(--text-muted);
}

/* Experiment hub – compare selection + delete */
.experiment-cases-header__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.experiment-compare-btn {
  min-height: 40px;
  padding: 0.45rem 0.95rem;
  font-weight: 600;
}

.experiment-compare-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.experiment-compare-btn__count {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand, #2563eb);
}

.experiment-compare-hint {
  margin: 0 0 0.85rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.experiment-cases-table .col-check,
.cases-table .col-check {
  width: 2.75rem;
  text-align: center;
  vertical-align: middle;
}

.exp-case-check-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  cursor: pointer;
}

.exp-case-check {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--brand, #2563eb);
  cursor: pointer;
}

.exp-case-row--selected {
  background: rgba(37, 99, 235, 0.06);
}

.exp-case-row--disabled {
  opacity: 0.55;
}

.experiment-cases-table .btn-delete-icon {
  background: none;
  border: none;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #9ca3af;
  flex-shrink: 0;
  border-radius: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.experiment-cases-table .btn-delete-icon:hover {
  color: #ef4444;
  background: #fef2f2;
}

.experiment-cases-table .btn-delete-icon:active {
  background: #fee2e2;
}

.compare-experiment-note {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.compare-meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.compare-meta-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 0.5rem);
  background: #fff;
}

.compare-meta-card strong {
  font-size: 0.95rem;
  color: var(--text-primary);
}

.compare-meta-card__side {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.compare-meta-card--left .compare-meta-card__side {
  background: var(--sage);
  color: var(--text-primary);
}

.compare-meta-card--right .compare-meta-card__side {
  background: #ccfbf1;
  color: #115e59;
}

.compare-section__header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--brand-tint);
}

.compare-section__title--inline {
  margin: 0;
  padding: 0;
  border: 0;
}

.exp-trial-toolbar {
  display: inline-flex;
  gap: 0.4rem;
}

.exp-trial-toolbar__btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.exp-trial-toolbar__btn:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: var(--brand-tint);
}

/* ── Experiment trial cards: collapsible left/right match text ── */

.exp-trial-list {
  gap: 0.65rem;
}

.exp-trial-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.exp-trial-card:hover {
  border-color: color-mix(in srgb, var(--sage-dark) 30%, var(--border));
  box-shadow: var(--shadow-sm);
}

.exp-trial-card__details {
  margin: 0;
}

.exp-trial-card__summary {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.55rem 0.7rem;
  padding: 0.75rem 0.95rem;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.exp-trial-card__summary::-webkit-details-marker {
  display: none;
}

.exp-trial-card__summary::marker {
  content: "";
}

.exp-trial-card__chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 6px;
  color: #64748b;
  background: #f1f5f9;
  transition: transform 0.18s ease, background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.exp-trial-card__details[open] .exp-trial-card__chevron {
  transform: rotate(90deg);
  background: var(--sage);
  color: var(--text-primary);
}

.exp-trial-card__nct {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.exp-trial-card__nct:hover {
  text-decoration: underline;
}

.exp-trial-card__title {
  min-width: 0;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exp-trial-card__score {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.exp-trial-card__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-shrink: 0;
  grid-column: 4 / -1;
}

.exp-trial-card__meta .phase-indicator {
  margin-left: 0;
}

.exp-trial-card__hint {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #64748b;
  white-space: nowrap;
  flex-shrink: 0;
}

.exp-trial-card__details[open] .exp-trial-card__hint {
  color: var(--sage-dark);
}

.exp-trial-card__body {
  border-top: 1px solid #e2e8f0;
  background:
    linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  padding: 0.85rem;
}

.exp-match-sides {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  align-items: stretch;
}

.exp-match-side {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 100%;
  padding: 1rem 1.05rem 1.1rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.exp-match-side:first-child {
  border-top: 3px solid var(--sage-dark);
}

.exp-match-side:last-child {
  border-top: 3px solid #2dd4bf;
}

.exp-match-side--empty {
  background: repeating-linear-gradient(
    -45deg,
    #fff,
    #fff 10px,
    #f8fafc 10px,
    #f8fafc 20px
  );
  opacity: 0.92;
}

.exp-match-side__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.exp-match-side__case {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.exp-match-side__case-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.25;
}

.exp-match-side__experiment {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

.exp-match-side__score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  flex-shrink: 0;
}

.exp-match-side__score-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.exp-match-side__score-was {
  font-size: 0.68rem;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.exp-match-side__missing-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  white-space: nowrap;
}

.exp-match-side__block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.exp-match-side__block-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}

.exp-match-side__prose {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
  color: #1e293b;
  white-space: pre-wrap;
  word-break: break-word;
}

.exp-match-side__reasons {
  margin: 0;
  padding: 0 0 0 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.exp-match-side__reasons li {
  font-size: 0.88rem;
  line-height: 1.55;
  color: #334155;
  padding-left: 0.15rem;
}

.exp-match-side__reasons li::marker {
  color: #94a3b8;
}

.exp-match-side__empty-copy {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #94a3b8;
  font-style: italic;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .experiment-cases-table td.col-check,
  .cases-table td.col-check {
    justify-content: flex-start;
  }

  .experiment-cases-table td.col-check::before,
  .cases-table td.col-check::before {
    content: none;
  }

  .compare-meta-row {
    grid-template-columns: 1fr;
  }

  .exp-trial-card__summary {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
  }

  .exp-trial-card__title {
    grid-column: 1 / -1;
    white-space: normal;
    order: 5;
    padding-left: 2.05rem;
  }

  .exp-trial-card__meta {
    grid-column: 1 / -1;
    order: 6;
  }

  .exp-trial-card__hint {
    display: none;
  }

  .exp-match-sides {
    grid-template-columns: 1fr;
  }
}

.case-source-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  background: var(--surface-teal, #d7eee8);
  color: var(--brand-dark, #123);
}

.case-readonly-banner {
  max-width: 1200px;
  margin: 0 auto 1rem;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  padding: 0.75rem 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: #312e81;
  border-radius: 0.375rem;
}

.case-readonly-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  background: var(--gray-100, #f3f4f6);
  color: var(--text-muted, #6b7280);
  border: 1px solid var(--border, #e5e7eb);
}

.api-key-secret-flash code {
  word-break: break-all;
}

/* Match traces (admin) */
.admin-traces .table-container {
  overflow-x: auto;
}

.admin-traces .empty-state,
.admin-trace .empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.admin-traces .text-sm,
.admin-trace .text-sm {
  font-size: 0.8rem;
}

.admin-traces .text-mono,
.admin-trace .text-mono {
  font-family: var(--font-mono);
}

.admin-traces .data-table,
.admin-trace .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-traces .data-table th,
.admin-traces .data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.admin-traces .data-table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.admin-traces .status-badge,
.admin-trace .status-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.admin-traces .status-badge--pending,
.admin-trace .status-badge--pending { background: #fef7e0; color: #a16207; }
.admin-traces .status-badge--running,
.admin-trace .status-badge--running { background: var(--sage); color: var(--text-primary); }
.admin-traces .status-badge--completed,
.admin-trace .status-badge--completed { background: #e6f4ea; color: #1e7e34; }
.admin-traces .status-badge--failed,
.admin-trace .status-badge--failed { background: #fce8e6; color: #c5221f; }
.admin-traces .status-badge--cancelled,
.admin-trace .status-badge--cancelled { background: #f1f3f4; color: #5f6368; }

.admin-trace-links {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

.admin-trace-sep {
  margin: 0 0.4rem;
  color: var(--text-subtle);
}

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

.admin-trace-stat {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
}

.admin-trace-stat-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.admin-trace-stat-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
}

.admin-trace-result {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: var(--brand-tint);
  border-radius: var(--radius-md);
  color: var(--brand-dark);
  font-size: 0.95rem;
  line-height: 1.5;
}

.admin-trace-origin {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.admin-trace-error {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
  font-size: 0.8rem;
  max-height: 12rem;
  overflow: auto;
}

.trace-timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 2rem;
  border-left: 2px solid var(--border);
}

.trace-stage-label {
  margin: 1.25rem 0 0.5rem 0;
  padding: 0 0 0 1rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-dark);
}

.trace-event {
  margin: 0 0 0.55rem;
  padding: 0.7rem 0.9rem 0.7rem 1rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  position: relative;
}

.trace-event::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 1.05rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sage-dark);
}

.trace-event--app::before {
  background: var(--clay);
}

.trace-event--error {
  border-color: var(--error-border, #e8b4b4);
  background: var(--error-bg, #fdecec);
}

.trace-event-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.25rem;
}

.trace-event-meta time {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.trace-source {
  display: inline-flex;
  align-items: center;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trace-source--worker {
  background: var(--sage);
  color: var(--ink);
}

.trace-source--app {
  background: var(--brand-tint);
  color: var(--brand-dark);
}

.trace-event-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.trace-event-raw {
  margin-top: 0.35rem;
}

.trace-event-raw summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.trace-event-raw pre {
  margin: 0.4rem 0 0;
  padding: 0.55rem 0.65rem;
  background: var(--surface-admin);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 12rem;
  overflow: auto;
}

@media (max-width: 640px) {
  .admin-trace-summary {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- Favourites page ---- */
.page-favourites .fav-page-header {
  margin-bottom: 1.25rem;
}

.fav-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.fav-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: start;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
}

.fav-row__mark {
  color: #b45309;
  padding-top: 0.15rem;
}

.fav-row__top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.35rem;
}

.fav-nct {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--brand-dark);
  text-decoration: none;
}

.fav-nct:hover {
  text-decoration: underline;
}

.fav-case {
  font-weight: 600;
  color: var(--brand);
  text-decoration: none;
}

.fav-case:hover {
  text-decoration: underline;
}

.fav-owner {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.fav-summary {
  margin: 0 0 0.5rem;
  color: var(--text-primary);
  font-size: 0.9375rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fav-note {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.fav-note-label {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.fav-note--empty {
  color: var(--text-muted);
  font-style: italic;
}

.fav-remove-btn {
  background: var(--surface-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.5rem 0.85rem;
  min-height: 44px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.fav-remove-btn:hover {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

@media (max-width: 640px) {
  .fav-row {
    grid-template-columns: auto 1fr;
  }

  .fav-remove-btn {
    grid-column: 1 / -1;
    width: 100%;
  }
}



