/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --color-primary: #1a5c8a;
  --color-primary-dark: #144a70;
  --color-primary-light: #e8f1f8;
  --color-accent: #d4a017;
  --color-accent-dark: #b88a12;
  --color-bg: #fafbfc;
  --color-surface: #ffffff;
  --color-text: #1d2328;
  --color-text-muted: #5a6a78;
  --color-border: #e1e8ed;
  --color-border-focus: #1a5c8a;
  --color-tag-bg: #f0f5f9;
  --color-tag-hover: #dce6f0;
  --color-tag-selected: #1a5c8a;
  --color-tag-text-selected: #ffffff;
  --color-result-bg: #fafbfc;
  --color-result-hover: #f0f5f9;
  --color-highlight: #fff3cd;
  --color-type: #1e7d46;
  --color-type-bg: #e6f5ec;
  --color-type-gps: #144a70;
  --color-type-gps-bg: #e3eef7;
  --color-type-cond: #7a5a10;
  --color-type-cond-bg: #fcf2d0;
  --color-type-weak: #7a4a6b;
  --color-type-weak-bg: #f6e9f2;
  --color-type-other: #4d5f6e;
  --color-type-other-bg: #eef1f4;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05), 0 0 0 1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 3px 6px -1px rgba(15, 23, 42, 0.06), 0 8px 18px -2px rgba(15, 23, 42, 0.07), 0 0 0 1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 6px 12px -2px rgba(15, 23, 42, 0.08), 0 16px 32px -4px rgba(15, 23, 42, 0.1), 0 0 0 1px rgba(15, 23, 42, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: 150ms ease;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --max-width: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #4da8da;
    --color-primary-dark: #3a9bd8;
    --color-primary-light: #1e3a4d;
    --color-accent: #e8c547;
    --color-accent-dark: #d4b03a;
    --color-bg: #0f1720;
    --color-surface: #172030;
    --color-text: #e8edf2;
    --color-text-muted: #8b9cb3;
    --color-border: #2a3d4f;
    --color-border-focus: #4da8da;
    --color-tag-bg: #1e3a4d;
    --color-tag-hover: #2a4a5f;
    --color-tag-selected: #4da8da;
    --color-tag-text-selected: #0f1720;
    --color-result-bg: #132030;
    --color-result-hover: #1a2d40;
    --color-highlight: #3d361a;
    --color-type: #6fd69a;
    --color-type-bg: #1d3a2c;
    --color-type-gps: #a9d2f2;
    --color-type-gps-bg: #1d3446;
    --color-type-cond: #f2d77c;
    --color-type-cond-bg: #45371a;
    --color-type-weak: #e7b8d8;
    --color-type-weak-bg: #3a2440;
    --color-type-other: #b9c6d4;
    --color-type-other-bg: #202c39;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45), 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.55), 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.1);
  }
}

html { font-size: 16px; scroll-behavior: smooth; scroll-padding-top: 5rem; }
body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior-y: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button { touch-action: manipulation; }
h1, h2, h3, .header-center, #results-heading { text-wrap: balance; }

.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; }

.container { width: 100%; max-width: var(--max-width); margin: 0 auto; padding: 0 1.25rem; }

a {
  color: var(--color-primary);
  text-decoration: none;
  text-underline-position: from-font;
  text-decoration-skip-ink: auto;
  transition: color var(--transition);
}
a:hover { color: var(--color-primary-dark); text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* Header */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.875rem 0;
  padding-top: calc(0.875rem + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-content {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 1.25rem;
}
.logo-link { display: flex; align-items: center; justify-self: start; min-width: 0; }
.logo { height: 56px; width: auto; outline: 1px solid rgba(0, 0, 0, 0.06); outline-offset: -1px; border-radius: 4px; }
.header-center {
  text-align: center;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}
.header-info { justify-self: end; min-width: 0; text-align: right; }
.header-info h1 { font-size: 1.25rem; font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-link { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-link a { font-weight: 500; }

/* Header Author Profile Badge (inspired by AIMed & Roshdy Med Suite) */
.header-author {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-left: 1rem;
  border-left: 1px solid var(--color-border);
  justify-self: end;
}
.author-badge-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--color-text);
  border-radius: var(--radius-md);
  padding: 0.25rem;
  transition: transform var(--transition);
}
.author-badge-link:hover {
  text-decoration: none;
  color: var(--color-text);
}
.author-badge-link:active {
  transform: scale(0.97);
}
.author-avatar-wrapper {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}
.author-avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(26, 92, 138, 0.4);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), transform var(--transition);
}
.author-badge-link:hover .author-avatar-img {
  border-color: var(--color-primary);
  transform: scale(1.04);
}
.author-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--color-surface);
  box-shadow: 0 0 4px rgba(16, 185, 129, 0.4);
}
.author-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  text-align: left;
}
.author-name {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.author-badge-link:hover .author-name {
  color: var(--color-primary);
}
.author-role {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-primary);
  white-space: nowrap;
  margin-top: 2px;
}

/* Main */
.main { flex: 1; padding: 2rem 0; }

/* Search Section */
.search-section { margin-bottom: 2rem; }
.search-wrapper { background: var(--color-surface); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-md); border: 1px solid var(--color-border); }
.search-input-group { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 1rem; width: 22px; height: 22px; color: var(--color-text-muted); pointer-events: none; flex-shrink: 0; }
.search-input {
  width: 100%;
  padding: 0.875rem 1rem 0.875rem 3rem;
  font-size: 1.0625rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.search-input::placeholder { color: var(--color-text-muted); opacity: 0.7; }
.search-input:hover { border-color: #c5d0da; }
.search-input:focus { outline: none; border-color: var(--color-border-focus); box-shadow: 0 0 0 3px var(--color-primary-light); background: var(--color-surface); }
.clear-btn {
  position: absolute;
  right: 0.375rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}
.clear-btn:hover { color: var(--color-text); background: var(--color-tag-hover); }
.clear-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-light); }
.clear-btn[hidden] { display: none; }
.search-hint { margin-top: 0.75rem; font-size: 0.8125rem; color: var(--color-text-muted); }
.search-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-top: 1rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--color-border);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.filter-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.filter-topic-field {
  flex: 1 1 240px;
  min-width: 0;
  max-width: 100%;
}
.filter-strength-field {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}
.filter-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.filter-select {
  font-family: inherit;
  font-size: 0.84375rem;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.625rem;
  outline: none;
  transition: border-color var(--transition);
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.filter-select:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-primary-light);
}
.strength-pills {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}
.filter-pill {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.filter-pill:hover {
  border-color: var(--color-primary);
  color: var(--color-text);
}
.filter-pill.active {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}
.filter-pill--strong.active {
  background: var(--color-type-bg);
  color: var(--color-type);
  border-color: var(--color-type);
}
.filter-pill--conditional.active {
  background: var(--color-type-cond-bg);
  color: var(--color-type-cond);
  border-color: var(--color-type-cond);
}
.filter-pill--gps.active {
  background: var(--color-type-gps-bg);
  color: var(--color-type-gps);
  border-color: var(--color-type-gps);
}
.filter-pill:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary-light);
}
@media (prefers-color-scheme: dark) {
  .filter-pill.active {
    color: #0f1720;
  }
  .filter-pill--strong.active {
    color: var(--color-type);
  }
  .filter-pill--conditional.active {
    color: var(--color-type-cond);
  }
  .filter-pill--gps.active {
    color: var(--color-type-gps);
  }
}
.sync-status { margin-top: 0.5rem; font-size: 0.8125rem; color: var(--color-text-muted); display: flex; align-items: center; gap: 0.4rem; }
.sync-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--color-primary); animation: pulse 1.5s ease-in-out infinite; flex: 0 0 auto; }
.sync-status--syncing::before { background: var(--color-primary); animation: pulse 1.5s ease-in-out infinite; }
.sync-status--ok::before { background: #1e7d46; animation: none; }
.sync-status--error::before { background: #b3261e; animation: none; }
.sync-status--ok { color: #1e7d46; }
.sync-status--error { color: #b3261e; }
.sync-status[hidden] { display: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Tags Section */
.tags-section { margin-bottom: 2rem; }
.tags-head { display: flex; align-items: center; gap: 0.75rem; }
.tags-head h2 { margin-bottom: 0; }
.tags-section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.375rem; color: var(--color-text); }
.tags-description { font-size: 0.875rem; color: var(--color-text-muted); margin-bottom: 0.75rem; }
.tags-toggle {
  display: none;
  align-items: center;
  min-height: 44px;
  padding: 0.5rem 0.9375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--color-primary);
  background: var(--color-tag-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.tags-toggle:hover { background: var(--color-tag-hover); border-color: var(--color-primary); }
.tags-toggle:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-primary); }
.js .tags-toggle { display: inline-flex; }
.js .tags-container { max-height: 0; opacity: 0; overflow: hidden; transition: max-height 250ms ease, opacity 180ms ease; }
.js .tags-section.tags-expanded .tags-container,
.js .tags-container:focus-within { max-height: none; opacity: 1; overflow: visible; }
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-height: none;
  overflow: visible;
}
.tag-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.5rem 0.9375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--color-primary);
  background: var(--color-tag-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}
.tag-btn:hover { background: var(--color-tag-hover); border-color: var(--color-primary); color: var(--color-primary-dark); }
.tag-btn.selected { background: var(--color-tag-selected); border-color: var(--color-tag-selected); color: var(--color-tag-text-selected); }
.tag-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-primary); }

/* Results Section */
.results-section { min-height: 300px; }
.results-section h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--color-text); }
.results-section h2:focus { outline: none; box-shadow: 0 0 0 3px var(--color-primary-light); border-radius: 4px; }
.results-stats { font-size: 0.875rem; color: var(--color-text-muted); margin-bottom: 1rem; padding: 0.5rem 0.75rem; background: var(--color-primary-light); border-radius: var(--radius-sm); border: 1px solid var(--color-border); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; min-width: 0; overflow-wrap: anywhere; }

.results-container { display: flex; flex-direction: column; gap: 0.75rem; }

.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
  animation: fadeInUp 0.25s ease backwards;
  opacity: 1;
}
.result-card:hover { box-shadow: var(--shadow-md); border-color: #c5d0da; transform: translateY(-1px); }
.result-card.card-strength-strong,
.result-card:has(.strength--strong) {
  border-left-color: var(--color-type);
}
.result-card.card-strength-conditional,
.result-card:has(.strength--conditional) {
  border-left-color: var(--color-accent-dark);
}
.result-card.card-strength-gps,
.result-card:has(.strength--gps) {
  border-left-color: var(--color-type-gps);
}
.result-card.card-strength-weak,
.result-card:has(.strength--weak) {
  border-left-color: var(--color-type-weak);
}
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.result-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.result-guideline { font-size: 0.875rem; font-weight: 600; color: var(--color-primary); white-space: normal; overflow-wrap: anywhere; min-width: 0; }
.result-guideline a { color: inherit; text-decoration: none; }
.result-guideline a:hover { text-decoration: underline; }
.result-phrase { font-size: 0.9375rem; line-height: 1.7; color: var(--color-text); overflow-wrap: anywhere; text-wrap: pretty; max-width: 75ch; }
.results-stats, .result-book-meta, .phrase-type, .sync-status, .provenance { font-variant-numeric: tabular-nums; }
.tags-description, .clinical-note, .initial-state p, .no-results p { text-wrap: pretty; }
.result-phrase mark {
  background: #ffe380;
  color: #1a202c;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 700;
  font-style: inherit;
  box-shadow: 0 1px 2px rgba(212, 160, 23, 0.2);
}
.phrase-type {
  display: inline-block;
  background: var(--color-type-bg);
  color: var(--color-type);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.25rem;
  white-space: nowrap;
  vertical-align: baseline;
  border: 1px solid var(--color-type);
}
.result-tags { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--color-border); }
.result-tag {
  font-size: 0.7rem;
  font-weight: 600;
  font-family: inherit;
  min-height: 34px;
  padding: 0.3125rem 0.7rem;
  background: var(--color-tag-bg);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}
.result-tag:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); transform: translateY(-1px); }
.result-tag:active { transform: translateY(0); }
.result-tag:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.phrase-type.strength--gps { background: var(--color-type-gps-bg); color: var(--color-type-gps); border-color: var(--color-type-gps); }
.phrase-type.strength--conditional { background: var(--color-type-cond-bg); color: var(--color-type-cond); border-color: var(--color-accent-dark); }
.phrase-type.strength--weak { background: var(--color-type-weak-bg); color: var(--color-type-weak); border-color: var(--color-type-weak); }
.phrase-type.strength--other { background: var(--color-type-other-bg); color: var(--color-type-other); border-color: var(--color-type-other); }

.result-book-meta {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.125rem 0.4375rem;
  background: var(--color-bg);
}
.result-actions { margin-top: 0.625rem; display: flex; justify-content: flex-end; }
.copy-btn {
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  min-height: 34px;
  padding: 0.3125rem 0.875rem;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}
.copy-btn:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); transform: translateY(-1px); }
.copy-btn:active { transform: translateY(0); }
.copy-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Suggestion chips in initial state */
.suggestion-chip {
  background: var(--color-highlight);
  color: #7a5a10;
  border: 1px solid var(--color-accent);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  margin: 0.125rem 0.15rem;
  vertical-align: baseline;
}
.suggestion-chip strong { color: inherit; font-weight: 700; }
.suggestion-chip:hover {
  background: var(--color-accent-dark);
  color: #ffffff;
  border-color: var(--color-accent-dark);
  box-shadow: 0 2px 6px rgba(184, 138, 18, 0.35);
  transform: translateY(-1px);
}
.suggestion-chip:active { transform: translateY(0); }

/* Results toolbar, provenance and clinical note */
.results-head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.375rem; }
.results-toolbar { display: flex; align-items: center; gap: 0.5rem; }
.tool-btn {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3125rem 0.625rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
  cursor: pointer;
}
.tool-btn:hover { background: var(--color-tag-hover); }
.tool-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.toolbar-feedback { font-size: 0.75rem; color: var(--color-type-cond); margin-bottom: 0.75rem; }
.provenance { font-size: 0.8125rem; color: var(--color-text-muted); margin-bottom: 0.625rem; }
.provenance a { color: var(--color-primary); text-decoration: underline; }
.provenance a:hover { color: var(--color-primary-dark); }
/* The data-date and live-sync segments wrap as whole units on small screens
   (no mid-phrase breaks, no horizontal overflow) and line up on one row on
   wide screens. */
.provenance .provenance-date,
.provenance .provenance-sync { display: inline-block; white-space: nowrap; }
.clinical-note {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

/* Empty States */
.no-results, .initial-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
}
.no-results svg, .initial-state svg { width: 64px; height: 64px; margin: 0 auto 1rem; opacity: 0.5; }
.no-results h3, .initial-state h3 { font-size: 1.125rem; font-weight: 600; color: var(--color-text); margin-bottom: 0.5rem; }
.no-results p, .initial-state p { font-size: 0.9375rem; margin-bottom: 0.5rem; }
.no-results strong, .initial-state strong { color: var(--color-primary); }
.no-results-hint { font-size: 0.875rem !important; opacity: 0.7; }
.no-results-badge {
  display: inline-block;
  background: var(--color-danger, #b3261e);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.375rem 0.875rem;
  border-radius: 999px;
  margin-bottom: 0.25rem;
}
.source-note { font-size: 0.8125rem !important; opacity: 0.6; margin-top: 1rem !important; }
.qr-code-wrapper {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.qr-code-img {
  width: 128px;
  height: 128px;
  border-radius: 8px;
  background: #ffffff;
  padding: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--color-border);
  outline: 1px solid rgba(0, 0, 0, 0.08);
  outline-offset: -1px;
  display: block;
}
.qr-code-caption {
  font-size: 0.8125rem !important;
  color: var(--color-text-muted);
  margin-top: 0.5rem !important;
  margin-bottom: 0 !important;
  font-weight: 500;
  text-align: center;
}

/* Footer (inspired by Roshdy Med Suite & AIMed) */
.footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 2.25rem 0 1.75rem;
  margin-top: auto;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.03);
}
.footer-content {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  align-items: center;
  gap: 2.25rem;
}
.footer-author-card {
  display: flex;
  align-items: center;
  gap: 1.125rem;
  padding: 1.125rem 1.25rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.footer-author-card:hover {
  border-color: rgba(26, 92, 138, 0.35);
  box-shadow: var(--shadow-md);
}
.footer-avatar-link {
  display: block;
  flex-shrink: 0;
  border-radius: 50%;
  text-decoration: none;
}
.footer-avatar-wrap {
  position: relative;
  width: 56px;
  height: 56px;
}
.footer-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2.5px solid var(--color-primary);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.footer-avatar-link:hover .footer-avatar {
  transform: scale(1.05);
}
.footer-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--color-bg);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}
.footer-author-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.footer-author-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
}
.footer-author-name {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.015em;
  transition: color var(--transition);
}
.footer-author-name:hover {
  color: var(--color-primary);
  text-decoration: underline;
}
.footer-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(26, 92, 138, 0.12);
  color: var(--color-primary);
  border: 1px solid rgba(26, 92, 138, 0.25);
  border-radius: 999px;
}
.footer-author-role {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
  line-height: 1.35;
  text-wrap: pretty;
}
.footer-author-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.footer-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.325rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
  background: rgba(26, 92, 138, 0.08);
  border: 1px solid rgba(26, 92, 138, 0.2);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}
.footer-pill-btn:hover {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
  text-decoration: none;
  transform: translateY(-1px);
}
.footer-pill-btn:active {
  transform: scale(0.97);
}
.footer-pill-github {
  color: var(--color-text);
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--color-border);
}
.footer-pill-github:hover {
  background: var(--color-text);
  color: var(--color-bg);
  border-color: var(--color-text);
}
.footer-legal {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: right;
  gap: 0.375rem;
}
.footer-legal p {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.45;
}
.footer-legal a {
  font-weight: 600;
}
.footer-disclaimer {
  font-weight: 500;
}
.footer-legal .credit {
  opacity: 0.85;
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .container { padding: 0 1rem; }
  .main { padding: 1.5rem 0; }
  .header-info h1 { white-space: normal; overflow: visible; text-overflow: clip; }
  .source-link { white-space: normal; overflow: visible; text-overflow: clip; }
  .header-center { white-space: normal; }
}

@media (max-width: 640px) {
  body {
    background: linear-gradient(180deg, #edf5fa 0%, #f7fafc 260px, #f2f7fb 100%);
  }
  .header {
    position: static;
    padding-top: calc(0.625rem + env(safe-area-inset-top));
    padding-bottom: 0.75rem;
    background: linear-gradient(135deg, #144a70 0%, #1a5c8a 50%, #206d9e 100%);
    border-bottom: 3.5px solid var(--color-accent);
    box-shadow: 0 3px 12px rgba(20, 74, 112, 0.25);
  }
  .header-content {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "logo title author"
      "source source source";
    gap: 0.375rem 0.625rem;
    align-items: center;
  }
  .logo-link { grid-area: logo; }
  .logo { height: 40px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2)); }
  .header-center {
    grid-area: title;
    align-self: center;
    text-align: left;
    font-size: 1.0625rem;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.25);
  }
  .header-author {
    grid-area: author;
    justify-self: end;
    border-left: none;
    padding-left: 0;
  }
  .header-author .author-meta {
    display: none;
  }
  .header-author .author-badge-link {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }
  .header-author .author-avatar-wrapper,
  .header-author .author-avatar-img {
    width: 36px;
    height: 36px;
  }
  .header-author .author-avatar-img {
    border-color: rgba(255, 255, 255, 0.7);
  }
  .header-info {
    grid-area: source;
    justify-self: stretch;
    text-align: left;
    margin-top: 0.125rem;
  }
  .header-info h1 {
    font-size: 0.875rem;
    line-height: 1.35;
    color: #f0f7fe;
    font-weight: 600;
    letter-spacing: -0.01em;
  }
  .source-link {
    font-size: 0.78125rem;
    margin-top: 0.25rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.22);
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    font-weight: 600;
    width: fit-content;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  }
  .container { padding: 0 0.75rem; }
  .main { padding: 1rem 0 2rem; }
  .search-section {
    position: sticky;
    top: 0;
    z-index: 900;
    background: rgba(237, 245, 250, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1.5px solid rgba(26, 92, 138, 0.18);
    margin-bottom: 1.25rem;
    padding-top: calc(0.375rem + env(safe-area-inset-top));
    padding-bottom: 0.375rem;
  }
  .search-wrapper {
    padding: 0.625rem;
    border-radius: var(--radius-lg);
    background: #ffffff;
    border: 2px solid #1a5c8a;
    box-shadow: 0 4px 16px rgba(26, 92, 138, 0.12), 0 0 0 2px rgba(212, 160, 23, 0.18);
  }
  .search-input {
    padding: 0.875rem 3.25rem 0.875rem 2.75rem;
    font-size: 1rem !important;
    border-radius: var(--radius-md);
    min-height: 48px;
    border: 1.5px solid #cce0f0;
    background: #fafbfc;
    color: var(--color-text);
  }
  .search-input:focus {
    background: #ffffff;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 92, 138, 0.2);
  }
  .search-icon { width: 20px; height: 20px; left: 0.75rem; color: #1a5c8a; }
  .clear-btn { width: 44px; height: 44px; min-width: 44px; min-height: 44px; right: 0.25rem; color: #d32f2f; }
  .search-hint { display: none; }
  .sync-status {
    font-size: 0.75rem;
    background: #ffffff;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid #cce0f0;
    width: fit-content;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  .tags-section { margin-bottom: 1.25rem; }
  .tags-head h2 { color: #144a70; font-size: 1.0625rem; font-weight: 800; letter-spacing: -0.01em; }
  .tags-toggle {
    min-height: 48px;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 800;
    color: #ffffff;
    background: linear-gradient(135deg, #d4a017 0%, #b88a12 100%);
    border: 2px solid #8c6808;
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(184, 138, 18, 0.35);
  }
  .tags-toggle:hover, .tags-toggle:active {
    background: linear-gradient(135deg, #b88a12 0%, #8c6808 100%);
    color: #ffffff;
  }
  .tags-container { gap: 0.5rem; }
  .tag-btn {
    min-height: 44px;
    padding: 0.5rem 0.9rem;
    font-size: 0.84375rem;
    font-weight: 700;
    background: #ffffff;
    color: #144a70;
    border: 1.5px solid #99c4e2;
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(26, 92, 138, 0.08);
  }
  .tag-btn:hover, .tag-btn:active {
    background: #e1effa;
    border-color: #1a5c8a;
    color: #144a70;
  }
  .tag-btn.selected {
    background: linear-gradient(135deg, #1a5c8a 0%, #144a70 100%) !important;
    border: 2px solid #d4a017 !important;
    color: #ffffff !important;
    box-shadow: 0 3px 10px rgba(26, 92, 138, 0.4);
  }
  .result-card {
    padding: 1.125rem 1rem;
    border-radius: var(--radius-lg);
    background: #ffffff;
    border: 1.5px solid #d0e2ef;
    border-left: 5.5px solid #1a5c8a;
    box-shadow: 0 3px 12px rgba(26, 92, 138, 0.07);
    margin-bottom: 0.875rem;
  }
  .result-card.card-strength-strong,
  .result-card:has(.strength--strong) {
    border-left-color: #1e7d46 !important;
    border-top: 1.5px solid #a8e3bd;
  }
  .result-card.card-strength-conditional,
  .result-card:has(.strength--conditional) {
    border-left-color: #d4a017 !important;
    border-top: 1.5px solid #fae8a8;
  }
  .result-card.card-strength-gps,
  .result-card:has(.strength--gps) {
    border-left-color: #144a70 !important;
    border-top: 1.5px solid #b5d2eb;
  }
  .result-card.card-strength-weak,
  .result-card:has(.strength--weak) {
    border-left-color: #7a4a6b !important;
    border-top: 1.5px solid #f0d0e7;
  }
  .result-header { flex-direction: column; gap: 0.25rem; margin-bottom: 0.5rem; }
  .result-guideline {
    white-space: normal;
    font-size: 0.9375rem;
    font-weight: 800;
    color: #144a70;
    line-height: 1.4;
    border-bottom: 1.5px dashed #e1ecf5;
    padding-bottom: 0.45rem;
  }
  .result-phrase {
    font-size: 0.9375rem;
    line-height: 1.65;
    color: #1e293b;
    font-weight: 400;
    text-wrap: pretty;
  }
  .result-phrase mark {
    background: #ffe380;
    color: #1a202c;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-weight: 800;
    border-bottom: 2px solid #d4a017;
    box-shadow: 0 1px 3px rgba(212, 160, 23, 0.25);
  }
  .phrase-type {
    white-space: normal;
    overflow-wrap: anywhere;
    max-width: 100%;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    border-width: 2px;
  }
  .result-tags {
    gap: 0.375rem;
    margin-top: 0.625rem;
    padding-top: 0.625rem;
    border-top: 1.5px solid #ebf1f6;
  }
  .result-tag {
    font-size: 0.78125rem;
    font-weight: 700;
    min-height: 40px;
    padding: 0.4rem 0.85rem;
    background: linear-gradient(135deg, #edf5fa 0%, #ddecfa 100%);
    color: #144a70;
    border: 1.5px solid #a8d0ed;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(26, 92, 138, 0.1);
  }
  .result-tag:hover, .result-tag:active {
    background: #1a5c8a;
    color: #ffffff;
    border-color: #1a5c8a;
  }
  .copy-btn {
    min-height: 44px;
    padding: 0.45rem 1.125rem;
    font-size: 0.8125rem;
    font-weight: 700;
    background: linear-gradient(135deg, #1a5c8a 0%, #144a70 100%);
    color: #ffffff;
    border: 1.5px solid #144a70;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    box-shadow: 0 2px 6px rgba(26, 92, 138, 0.3);
  }
  .copy-btn:hover, .copy-btn:active {
    background: #144a70;
    color: #ffffff;
  }
  .initial-state {
    padding: 1.75rem 1rem;
    background: linear-gradient(135deg, #ffffff 0%, #f3f8fd 100%);
    border: 2px solid #b8d6ec;
    border-top: 4px solid #1a5c8a;
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 20px rgba(26, 92, 138, 0.09);
  }
  .initial-state svg {
    width: 56px;
    height: 56px;
    color: #d4a017;
    filter: drop-shadow(0 2px 6px rgba(212, 160, 23, 0.35));
    opacity: 1;
  }
  .initial-state h3 {
    font-size: 1.1875rem;
    font-weight: 800;
    color: #144a70;
  }
  .suggestion-chip {
    min-height: 44px;
    padding: 0.45rem 0.95rem;
    font-size: 0.875rem;
    border-radius: 999px;
    margin: 0.25rem 0.2rem;
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, #fff9e6 0%, #feebaf 100%);
    color: #6b4d00;
    border: 2px solid #d4a017;
    font-weight: 800;
    box-shadow: 0 2px 6px rgba(212, 160, 23, 0.3);
  }
  .suggestion-chip:hover, .suggestion-chip:active {
    background: #b88a12;
    color: #ffffff;
    border-color: #b88a12;
    box-shadow: 0 2px 8px rgba(184, 138, 18, 0.4);
  }
  .clinical-note {
    background: linear-gradient(135deg, #fffde7 0%, #fff9c4 100%);
    border: 2px dashed #fbc02d;
    color: #825c00;
    font-size: 0.78125rem;
    font-weight: 700;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 6px rgba(251, 192, 45, 0.15);
  }
  .provenance {
    font-size: 0.78125rem;
    line-height: 1.5;
    background: #f0f6fa;
    border: 1.5px solid #cce0f0;
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.85rem;
    color: #3b5061;
  }
  .no-results { padding: 2rem 1rem; }
  .no-results svg { width: 52px; height: 52px; }
  .footer {
    padding-top: 2rem;
    padding-bottom: calc(2.25rem + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, #ffffff 0%, #eaf2f8 100%);
    border-top: 3.5px solid #d4a017;
  }
  .footer-content {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .footer-author-card {
    padding: 1.125rem;
    gap: 1rem;
    background: #ffffff;
    border-radius: var(--radius-lg);
    border: 1px solid #cce0f0;
    box-shadow: 0 2px 10px rgba(26, 92, 138, 0.08);
  }
  .footer-avatar-wrap,
  .footer-avatar {
    width: 48px;
    height: 48px;
  }
  .footer-pill-btn {
    min-height: 44px;
    padding: 0.5rem 0.95rem;
    font-size: 0.8125rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
  }
  .footer-legal {
    text-align: center;
    gap: 0.5rem;
  }
  .footer-legal p { font-size: 0.78125rem; line-height: 1.55; }
  .results-section h2 { color: #144a70; font-size: 1.125rem; font-weight: 800; }
  .results-stats {
    font-size: 0.8125rem;
    padding: 0.625rem 0.875rem;
    background: linear-gradient(90deg, #e3f2fd 0%, #f0f7fe 100%);
    border: 1.5px solid #90caf9;
    border-left: 6px solid #1a5c8a;
    color: #0d47a1;
    font-weight: 700;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(26, 92, 138, 0.1);
  }
  .results-head-row { flex-direction: column; align-items: flex-start; gap: 0.375rem; }
  .results-section,
  #results-heading,
  .result-card,
  .tags-section {
    scroll-margin-top: 6rem;
  }
  .search-options {
    margin-top: 0.5rem;
    border: 1.5px solid #1a5c8a;
    border-radius: var(--radius-md);
    background: #ffffff;
    box-shadow: 0 3px 8px rgba(26, 92, 138, 0.12);
    overflow: hidden;
  }
  .search-options > summary {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.9rem;
    font-size: 0.8125rem;
    font-weight: 800;
    color: #ffffff;
    background: linear-gradient(135deg, #1a5c8a 0%, #144a70 100%);
    cursor: pointer;
    list-style: none;
    user-select: none;
    min-height: 40px;
    transition: background var(--transition);
  }
  .search-options > summary::-webkit-details-marker { display: none; }
  .search-options > summary::after {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    border-right: 2.5px solid #ffe380;
    border-bottom: 2.5px solid #ffe380;
    transform: rotate(45deg);
    transition: transform var(--transition);
  }
  .search-options[open] > summary {
    background: linear-gradient(135deg, #144a70 0%, #0d3450 100%);
    border-bottom: 2px solid #b8d6ec;
  }
  .search-options[open] > summary::after {
    transform: rotate(225deg);
  }
  .search-options-body {
    padding: 0.75rem 0.85rem;
    background: #f7fafc;
  }
  .search-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 0.625rem;
    margin-top: 0;
    padding-top: 0;
  }
  .filter-topic-field,
  .filter-strength-field {
    width: 100%;
    max-width: 100%;
    flex: 1 1 100%;
  }
  .filter-select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 auto;
    font-size: 1rem !important;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid #1a5c8a;
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: #144a70;
    font-weight: 600;
  }
  .strength-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
  }
  .filter-pill {
    min-height: 40px;
    padding: 0.45rem 0.85rem;
    font-size: 0.78125rem;
    font-weight: 700;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    border: 1.5px solid #1a5c8a;
    background: #e3f0fa;
    color: #1a5c8a;
    transition: background-color var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }
  .filter-pill.active {
    background: #1a5c8a !important;
    color: #ffffff !important;
    border-color: #1a5c8a !important;
    box-shadow: 0 2px 8px rgba(26, 92, 138, 0.4);
  }
  .filter-pill--strong {
    background: #e6f5ec;
    color: #1e7d46;
    border: 1.5px solid #1e7d46;
  }
  .filter-pill--strong.active {
    background: #1e7d46 !important;
    color: #ffffff !important;
    border-color: #1e7d46 !important;
    box-shadow: 0 2px 8px rgba(30, 125, 70, 0.4);
  }
  .filter-pill--conditional {
    background: #fff8e1;
    color: #7a5a10;
    border: 1.5px solid #d4a017;
  }
  .filter-pill--conditional.active {
    background: #b88a12 !important;
    color: #ffffff !important;
    border-color: #b88a12 !important;
    box-shadow: 0 2px 8px rgba(184, 138, 18, 0.4);
  }
  .filter-pill--gps {
    background: #e3eef7;
    color: #144a70;
    border: 1.5px solid #144a70;
  }
  .filter-pill--gps.active {
    background: #144a70 !important;
    color: #ffffff !important;
    border-color: #144a70 !important;
    box-shadow: 0 2px 8px rgba(20, 74, 112, 0.4);
  }
  .search-help {
    margin-top: 0.625rem;
  }
  .search-help-toggle {
    min-height: 38px;
    padding: 0.4rem 0.75rem;
    font-size: 0.78125rem;
    background: #e8f1f8;
    border: 1.5px solid #1a5c8a;
    color: #144a70;
    font-weight: 700;
    border-radius: var(--radius-sm);
  }
  .tool-btn {
    min-height: 40px;
    padding: 0.4rem 0.9rem;
    font-size: 0.78125rem;
    font-weight: 700;
    background: linear-gradient(135deg, #e3f0fa 0%, #d4e8f7 100%);
    color: #144a70;
    border: 1.5px solid #1a5c8a;
    border-radius: 999px;
  }
  .search-options:not([open]) .search-options-body { display: none !important; }
  .search-options[open] .search-options-body { display: block; }
  .qr-code-wrapper { display: none !important; }
}

@media (min-width: 641px) {
  .search-options { border: none; margin: 0; padding: 0; }
  .search-options > summary { display: none !important; }
  .search-options-body { display: block !important; padding: 0; border: none; }
  .js .tags-container { max-height: none; opacity: 1; overflow: visible; }
  .js .tags-toggle { display: none; }
  .search-section { position: static; z-index: auto; background: transparent; border-bottom: none; margin: 0 0 2rem; padding: 0; }
}

/* Search help */
.search-help { margin-top: 0.5rem; }
.search-help-toggle {
  display: inline-flex; align-items: center; gap: 0.375rem;
  background: var(--color-primary-light); color: var(--color-primary);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  padding: 0.3125rem 0.625rem; font-size: 0.75rem; font-weight: 600;
  cursor: pointer; list-style: none;
}
.search-help-toggle::-webkit-details-marker { display: none; }
.search-help-toggle::before {
  content: ""; width: 0.375rem; height: 0.375rem;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); transition: transform 0.15s ease;
}
.search-help[open] .search-help-toggle::before { transform: rotate(225deg); }
.search-help[open] .search-help-toggle { border-color: var(--color-primary); }
.search-help-content {
  margin-top: 0.5rem; padding: 0.625rem 0.8125rem;
  background: var(--color-bg-soft, var(--color-bg));
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-size: 0.8125rem; line-height: 1.6; color: var(--color-text);
}
.search-help-content ul { margin: 0; padding-left: 1.125rem; display: grid; gap: 0.3125rem; }
.search-help-content kbd {
  font-family: inherit; font-size: 0.75rem; background: var(--color-primary-light);
  border: 1px solid var(--color-border); border-radius: 3px; padding: 0 0.25rem;
}
.search-help-content strong { font-weight: 600; }

/* No-results variant suggestion */
.variant-suggestion { color: var(--color-primary); font-weight: 600; text-decoration: underline; }

@media (max-width: 360px) {
  .header-info h1 { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* Print */
@media print {
  .header, .search-section, .tags-section, .footer, .clear-btn, .search-help,
  .results-toolbar, .copy-btn, .toolbar-feedback { display: none !important; }
  .main { padding: 0; }
  .result-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
  .result-phrase mark { background: #ffff99; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .clinical-note, .provenance { border: none; background: none; padding: 0; }
  .result-book-meta, .phrase-type { border: 1px solid #ccc; background: none; }
  #provenance, .clinical-note { margin-bottom: 0.5rem; }
}

/* Tactile button press feedback according to interface-polish */
.tag-btn:active,
.filter-pill:active,
.tool-btn:active,
.copy-btn:active,
.tags-toggle:active,
.suggestion-chip:active,
.clear-btn:active {
  transform: scale(0.97);
}

@media (prefers-color-scheme: dark) {
  .header-author .author-avatar-img {
    border-color: rgba(77, 168, 218, 0.45);
  }
  .footer-author-card {
    background: var(--color-surface);
    border-color: var(--color-border);
  }
  .footer-badge {
    background: rgba(77, 168, 218, 0.15);
    color: var(--color-primary);
    border-color: rgba(77, 168, 218, 0.3);
  }
  .footer-pill-btn {
    background: rgba(77, 168, 218, 0.12);
    border-color: rgba(77, 168, 218, 0.25);
  }
  .footer-pill-github {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--color-border);
    color: var(--color-text);
  }
  .footer-status-dot,
  .author-status-dot {
    border-color: var(--color-surface);
  }
}

/* ===== A–Z Tag Word Cards =====
   Each letter is a coloured card with a large capital letter. The hue comes
   from --card-hue (set inline per letter); lightness values are fixed so text
   and chips keep WCAG AA contrast in both light and dark mode. */
.tags-alphabet-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.alpha-nav-btn {
  --card-hue: 205;
  min-width: 40px;
  height: 40px;
  padding: 0 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 800 1rem/1 var(--font-sans);
  color: hsl(var(--card-hue), 70%, 26%);
  background: hsl(var(--card-hue), 85%, 93%);
  border: 1.5px solid hsl(var(--card-hue), 55%, 72%);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), transform var(--transition);
}
.alpha-nav-btn:hover { background: hsl(var(--card-hue), 65%, 27%); color: #fff; border-color: transparent; }
.alpha-nav-btn:active { transform: scale(0.94); }
.alpha-nav-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px hsl(var(--card-hue), 65%, 34%); }

.js .tags-section.tags-expanded .tags-container,
.tags-container { display: block; }

.tag-cards {
  columns: 3 280px;
  column-gap: 0.875rem;
}
.tag-card {
  --card-hue: 205;
  position: relative;
  display: inline-block;
  width: 100%;
  break-inside: avoid;
  margin-bottom: 0.875rem;
  min-width: 0;
  padding: 0.875rem 0.875rem 1rem;
  background: linear-gradient(160deg, hsl(var(--card-hue), 90%, 96%) 0%, hsl(var(--card-hue), 70%, 92%) 100%);
  border: 1px solid hsl(var(--card-hue), 50%, 82%);
  border-top: 5px solid hsl(var(--card-hue), 60%, 42%);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 6px hsla(var(--card-hue), 50%, 30%, 0.08);
  scroll-margin-top: 6rem;
  transition: box-shadow var(--transition), transform var(--transition);
}
.tag-card:hover { box-shadow: 0 6px 18px hsla(var(--card-hue), 50%, 30%, 0.16); }
.tag-card--flash { animation: tagCardFlash 900ms ease; }
@keyframes tagCardFlash {
  0% { box-shadow: 0 0 0 0 hsla(var(--card-hue), 70%, 45%, 0.55); }
  100% { box-shadow: 0 0 0 14px hsla(var(--card-hue), 70%, 45%, 0); }
}
.tag-card-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}
.tag-card-letter {
  font-size: 3rem;
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: hsl(var(--card-hue), 65%, 30%);
  margin: 0;
}
.tag-card-count {
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--card-hue), 60%, 24%);
  background: hsla(0, 0%, 100%, 0.7);
  border: 1px solid hsl(var(--card-hue), 45%, 78%);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}
.tag-card-words {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4375rem;
}
.tag-card .tag-btn {
  min-height: 44px;
  padding: 0.4rem 0.8rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: hsl(var(--card-hue), 70%, 24%);
  background: #fff;
  border: 1px solid hsl(var(--card-hue), 45%, 76%);
  border-radius: 999px;
  white-space: normal;
  text-align: left;
  box-shadow: none;
}
/* Two-word medical expressions get a subtle tinted fill so they stand out */
.tag-card .tag-btn--expr {
  background: hsl(var(--card-hue), 80%, 98%);
  border-style: dashed;
}
.tag-card .tag-btn:hover {
  color: #fff;
  background: hsl(var(--card-hue), 65%, 27%);
  border-color: transparent;
}
.tag-card .tag-btn.selected {
  color: #fff !important;
  background: hsl(var(--card-hue), 70%, 26%) !important;
  border: 2px solid var(--color-accent) !important;
  box-shadow: 0 3px 10px hsla(var(--card-hue), 60%, 25%, 0.35);
}
.tag-card .tag-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px hsl(var(--card-hue), 65%, 34%);
}

@media (prefers-color-scheme: dark) {
  .alpha-nav-btn {
    color: hsl(var(--card-hue), 85%, 82%);
    background: hsl(var(--card-hue), 35%, 18%);
    border-color: hsl(var(--card-hue), 35%, 32%);
  }
  .alpha-nav-btn:hover { background: hsl(var(--card-hue), 60%, 70%); color: #0f1720; }
  .tag-card {
    background: linear-gradient(160deg, hsl(var(--card-hue), 35%, 17%) 0%, hsl(var(--card-hue), 30%, 13%) 100%);
    border-color: hsl(var(--card-hue), 30%, 26%);
    border-top-color: hsl(var(--card-hue), 65%, 60%);
    box-shadow: none;
  }
  .tag-card-letter { color: hsl(var(--card-hue), 85%, 78%); }
  .tag-card-count {
    color: hsl(var(--card-hue), 80%, 85%);
    background: hsla(0, 0%, 0%, 0.25);
    border-color: hsl(var(--card-hue), 30%, 32%);
  }
  .tag-card .tag-btn,
  .tag-card .tag-btn--expr {
    color: hsl(var(--card-hue), 85%, 86%);
    background: hsl(var(--card-hue), 30%, 21%);
    border-color: hsl(var(--card-hue), 30%, 36%);
  }
  .tag-card .tag-btn:hover { color: #0f1720; background: hsl(var(--card-hue), 65%, 72%); }
  .tag-card .tag-btn.selected {
    color: #0f1720 !important;
    background: hsl(var(--card-hue), 70%, 75%) !important;
  }
  .tag-card .tag-btn:focus-visible { box-shadow: 0 0 0 2px #0f1720, 0 0 0 4px hsl(var(--card-hue), 65%, 72%); }
}

@media (max-width: 640px) {
  .tags-alphabet-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 0 0.75rem;
    padding: 0.25rem 0;
  }
  .tags-alphabet-nav::-webkit-scrollbar { display: none; }
  .alpha-nav-btn { flex: 0 0 auto; min-width: 44px; height: 44px; }
  .tag-card { margin-bottom: 0.75rem; }
  .tag-card { padding: 0.75rem 0.75rem 0.875rem; }
  .tag-card-letter { font-size: 2.5rem; }
  .tag-card .tag-btn { min-height: 44px; font-size: 0.875rem; }
}

@media print {
  .tags-alphabet-nav, .tag-cards { display: none !important; }
}

/* Sync status + manual "Check for new guidelines" button */
.sync-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.75rem; margin-top: 0.5rem; }
.sync-row .sync-status { margin-top: 0; flex: 1 1 260px; min-width: 0; }
.check-updates-btn { flex: 0 0 auto; }
.check-updates-btn[disabled] { opacity: 0.6; cursor: progress; }
@media (max-width: 640px) {
  .check-updates-btn { min-height: 44px; width: 100%; justify-content: center; }
}
@media print { .check-updates-btn { display: none !important; } }
