:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #1c252c;
  --muted: #66737f;
  --line: #d8dee5;
  --accent: #11695f;
  --accent-soft: #dff3ef;
  --shadow: 0 1px 2px rgba(19, 27, 36, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }

.app { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(245, 247, 248, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.wrap, .layout {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.updated {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.repo-link, .button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.repo-link, .button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.secondary-link {
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
}

.menu-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.header-menu {
  display: grid;
  gap: 10px;
}

.header-menu[hidden] {
  display: none;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 230px 130px 110px auto;
  gap: 8px;
}

.search, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.search:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.metric b {
  display: block;
  font-size: 17px;
  line-height: 1.2;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  gap: 14px;
}

.left-column {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-content: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-title, .results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-title h2 {
  margin: 0;
  font-size: 14px;
}

.panel-title-actions {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#tagCount, #sourceCount, .result-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.panel-toggle {
  display: none;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.panel-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.tags-panel-body[hidden] {
  display: none;
}

.sources {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.source-card {
  width: 100%;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 7px;
  text-align: left;
  cursor: pointer;
}

.source-card:hover, .source-card.active {
  border-color: var(--accent);
  background: #f4fbf9;
}

.source-card.empty-source {
  color: var(--muted);
}

.source-thumb {
  width: 64px;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  object-fit: cover;
  background: #edf1f4;
}

.source-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.source-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.source-meta {
  color: var(--muted);
  font-size: 12px;
}

.source-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.tab:last-child { border-right: 0; }

.tab.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.tag-list {
  max-height: 570px;
  overflow: auto;
  padding: 8px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.active-filters:empty {
  display: none;
}

.filter-chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 9px;
  cursor: pointer;
}

.filter-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-chip b {
  font-size: 14px;
  line-height: 1;
}

.tag-section + .tag-section {
  margin-top: 10px;
}

.tag-section-title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 0 4px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #eef3f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tag-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 7px 8px;
  text-align: left;
  cursor: pointer;
}

.tag-row:hover, .tag-row.active {
  border-color: var(--line);
  background: #f3f7fa;
}

.tag-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.tag-parent {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.count {
  min-width: 42px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.result-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.videos {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.video {
  display: grid;
  grid-template-columns: 138px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease, background .15s ease;
}

.video:hover, .video:focus-visible {
  border-color: var(--accent);
  background: #fbfefd;
  box-shadow: 0 6px 18px rgba(17, 105, 95, .12);
}

.video:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.thumb-link {
  display: block;
  width: 138px;
  color: inherit;
  text-decoration: none;
}

.thumb {
  width: 138px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
  background: #edf1f4;
  display: block;
}

.video-body {
  min-width: 0;
}

.video-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.video-main {
  min-width: 0;
}

.video-title {
  margin: 0 0 5px;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.video-title a {
  color: var(--text);
  text-decoration: none;
}

.video:hover .video-title a,
.video-title a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.video-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  color: var(--muted);
  font-size: 12px;
}

.yt {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  padding: 4px 10px;
}

.yt:hover, .yt:focus-visible {
  background: var(--accent);
  color: #fff;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.chip {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 2px 7px;
  font-size: 12px;
}

.chip.animal {
  border-color: #bdd7c8;
  background: #f0f8f3;
  color: #356448;
}

.chip.disease {
  border-color: #f1c7c3;
  background: #fff4f2;
  color: #8f3d33;
}

.chip.symptom {
  border-color: #d7c8f2;
  background: #f8f5ff;
  color: #5e4a94;
}

.chip.procedure {
  border-color: #c3d5ee;
  background: #f2f7ff;
  color: #315f91;
}

.pager {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
}

.site-footer {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 8px 14px 28px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.loading, .empty, .error {
  padding: 32px 12px;
  text-align: center;
  color: var(--muted);
}

.error {
  color: #9f1239;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 8px;
}

.compact-head {
  margin-bottom: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.admin-page {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 24px 14px 56px;
}

.admin-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.admin-hero > div,
.info-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.admin-hero > div:first-child {
  padding: 24px;
}

.admin-hero h2 {
  margin: 0 0 12px;
  font-size: 28px;
  line-height: 1.25;
  letter-spacing: 0;
}

.admin-hero p,
.info-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.admin-card {
  display: grid;
  align-content: space-between;
  gap: 14px;
  padding: 18px;
}

.admin-name {
  font-size: 22px;
  font-weight: 900;
}

.admin-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.admin-links a {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.admin-links a:hover,
.admin-links a:focus-visible {
  background: var(--accent);
  color: #fff;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.info-block {
  padding: 18px;
}

.info-block h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

@media (max-width: 920px) {
  .head, .controls, .layout {
    grid-template-columns: 1fr;
  }

  .head {
    margin-bottom: 0;
  }

  .head-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .header-menu {
    margin-top: 12px;
  }

  .sources-panel {
    overflow: hidden;
  }

  .sources {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    padding: 8px 12px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .sources::-webkit-scrollbar {
    height: 6px;
  }

  .sources::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #c6d2da;
  }

  .source-card {
    flex: 0 0 min(76vw, 300px);
    scroll-snap-align: start;
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .source-thumb {
    width: 58px;
    border-radius: 13px;
  }

  .tag-list {
    max-height: 310px;
  }

  .panel-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .video {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .thumb, .thumb-link {
    width: 112px;
  }

  .admin-hero,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-hero h2 {
    font-size: 22px;
  }
}

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

  .thumb, .thumb-link {
    width: 100%;
  }

  .source-card {
    flex-basis: min(82vw, 300px);
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .source-thumb {
    width: 56px;
  }

  .video-top {
    display: grid;
    grid-template-columns: 1fr;
  }
}
