/* ============================================
   WIKI — Dense Clinical Treatment Database
   Reuses design tokens from main site
   ============================================ */

:root {
  --red: #C41E30;
  --red-dark: #9B1825;
  --black: #F7F4EF;
  --near-black: #F0ECE5;
  --dark: #FFFFFF;
  --cream: #2A2A2A;
  --white: #111111;
  --yellow: #B8960F;
  --yellow-dark: #8A7009;
  --gray: #777777;
  --gray-dark: #BBBBBB;
  --gray-light: #444444;

  --font-display: 'Bebas Neue', 'Oswald', Impact, sans-serif;
  --font-heading: 'Oswald', 'Arial Narrow', sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-data: 'Space Mono', 'Courier New', monospace;

  --sidebar-width: 260px;
  --header-height: 56px;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  background: var(--black);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 0.875rem;
  line-height: 1.65;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

.accent-dot { color: var(--red); }

/* ============================================
   HEADER
   ============================================ */
.wiki-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: var(--header-height);
  background: rgba(247,244,239,0.97);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
}

.wiki-header__inner {
  flex: 1;
  max-width: 100%;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.wiki-header__back {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: var(--gray);
  flex-shrink: 0;
}
.wiki-header__back:hover { color: var(--red); text-decoration: none; }

.wiki-header__title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 3px;
  color: var(--white);
  flex-shrink: 0;
}

.wiki-header__search {
  flex: 1;
  max-width: 400px;
  margin-left: auto;
}

.wiki-header__search input {
  width: 100%;
  padding: 0.4rem 0.8rem;
  font-family: var(--font-data);
  font-size: 0.75rem;
  background: var(--near-black);
  border: 1px solid var(--gray-dark);
  color: var(--cream);
  outline: none;
  transition: border-color 0.2s;
}

.wiki-header__search input:focus {
  border-color: var(--red);
}

.wiki-header__search input::placeholder {
  color: var(--gray);
}

.wiki-header__stripe {
  height: 2px;
  background: var(--red);
}

/* ============================================
   LAYOUT
   ============================================ */
.wiki-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: calc(100vh - var(--header-height));
  margin-top: var(--header-height);
}

/* ============================================
   SIDEBAR
   ============================================ */
.wiki-sidebar {
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 1.2rem 1rem;
  background: var(--near-black);
  border-right: 1px solid var(--gray-dark);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  z-index: 200;
  background: var(--red);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 2px;
}

.sidebar-heading {
  font-family: var(--font-heading);
  font-size: 0.65rem;
  letter-spacing: 2.5px;
  color: var(--gray);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.sidebar-filters {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-btn {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--gray-light);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.filter-btn:hover {
  background: rgba(196, 30, 48, 0.06);
  color: var(--cream);
}

.filter-btn.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.sidebar-stats {
  padding-top: 0.5rem;
  border-top: 1px solid var(--gray-dark);
}

.stat-line {
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--gray);
}

.stat-label { color: var(--gray-dark); }

/* Tier Legend */
.tier-legend {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tier-legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--gray);
}

.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.tier-badge--s { background: var(--red); }
.tier-badge--a { background: var(--yellow); color: var(--black); }
.tier-badge--b { background: var(--gray-light); }
.tier-badge--c { background: var(--gray); }
.tier-badge--f { background: var(--gray-dark); color: var(--cream); }

/* ============================================
   MAIN CONTENT
   ============================================ */
.wiki-main {
  padding: 1.2rem 1.5rem 3rem;
  min-height: 80vh;
}

.wiki-results {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.wiki-empty {
  padding: 4rem 2rem;
  text-align: center;
  font-family: var(--font-heading);
  font-size: 1rem;
  letter-spacing: 2px;
  color: var(--gray);
}

/* ============================================
   TREATMENT ENTRY (details/summary)
   ============================================ */
.treatment-entry {
  background: var(--dark);
  border: 1px solid rgba(0,0,0,0.07);
  transition: border-color 0.2s;
}

.treatment-entry[open] {
  border-color: var(--red);
}

.treatment-entry.highlight {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(196, 30, 48, 0.2);
}

.treatment-summary {
  display: grid;
  grid-template-columns: 36px 1fr 60px 80px 200px;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  list-style: none;
  transition: background 0.15s;
  user-select: none;
}

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

.treatment-summary:hover {
  background: rgba(196, 30, 48, 0.03);
}

.treatment-rank {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--gray);
  text-align: center;
}

.treatment-name-block {
  min-width: 0;
}

.treatment-name {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  letter-spacing: 1px;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.treatment-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1px;
}

.treatment-cat {
  font-family: var(--font-data);
  font-size: 0.6rem;
  letter-spacing: 1px;
  color: var(--gray);
  text-transform: uppercase;
}

.treatment-aliases {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--gray-dark);
  font-style: italic;
}

.treatment-confidence {
  font-family: var(--font-data);
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
}

.conf-c1 { color: var(--red); }
.conf-c2 { color: var(--yellow); }
.conf-c3 { color: var(--gray-light); }
.conf-c4 { color: var(--gray); }
.conf-c5 { color: var(--gray-dark); }

.treatment-cost {
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--gray-light);
  text-align: right;
}

/* Effectiveness Bar */
.eff-bar-container {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.eff-bar {
  flex: 1;
  height: 8px;
  background: rgba(0,0,0,0.06);
  position: relative;
  overflow: hidden;
}

.eff-bar__fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  transition: width 0.3s ease;
}

.eff-bar__fill--s { background: var(--red); }
.eff-bar__fill--a { background: var(--yellow); }
.eff-bar__fill--b { background: var(--gray-light); }
.eff-bar__fill--c { background: var(--gray); }
.eff-bar__fill--f { background: var(--gray-dark); }

.eff-score {
  font-family: var(--font-display);
  font-size: 0.85rem;
  min-width: 28px;
  text-align: right;
}

.eff-score--s { color: var(--red); }
.eff-score--a { color: var(--yellow); }
.eff-score--b { color: var(--gray-light); }
.eff-score--c { color: var(--gray); }
.eff-score--f { color: var(--gray-dark); }

/* ============================================
   TREATMENT DETAIL (expanded)
   ============================================ */
.treatment-detail {
  padding: 0.8rem 1.2rem 1.4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.5rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--cream);
  border-top: 1px solid rgba(0,0,0,0.06);
  animation: wikiSlideDown 0.2s ease;
}

/* Plain-english description block at top of detail */
.treatment-description {
  grid-column: 1 / -1;
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--cream);
  padding: 0.6rem 0 0.4rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  margin-bottom: 0.3rem;
}

/* Limitations block */
.detail-limitations {
  background: rgba(196, 30, 48, 0.04);
  border-left: 3px solid var(--red);
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
  color: var(--cream);
  line-height: 1.65;
}

@keyframes wikiSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-block {
  min-width: 0;
}

.detail-block--full {
  grid-column: 1 / -1;
}

.detail-label {
  font-family: var(--font-heading);
  font-size: 0.65rem;
  letter-spacing: 2px;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.detail-text {
  white-space: pre-line;
  color: var(--cream);
}

.detail-text p {
  margin-bottom: 0.4rem;
}

.detail-text strong {
  color: var(--white);
}

/* Condition effectiveness grid inside detail */
.condition-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}

.condition-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-data);
  font-size: 0.7rem;
}

.condition-label {
  color: var(--gray);
  min-width: 85px;
}

.condition-score {
  font-weight: 700;
}

/* Key studies */
.detail-studies {
  font-size: 0.78rem;
  color: var(--gray-light);
  line-height: 1.65;
}

/* Sources */
.detail-sources {
  font-family: var(--font-data);
  font-size: 0.65rem;
  color: var(--gray);
  word-break: break-all;
}

.detail-sources a { color: var(--red); }

/* Rx badge */
.rx-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 1px;
  padding: 0.1rem 0.4rem;
  background: rgba(196, 30, 48, 0.1);
  color: var(--red);
  border: 1px solid rgba(196, 30, 48, 0.3);
  vertical-align: middle;
  margin-left: 0.3rem;
}

/* ============================================
   FOOTER
   ============================================ */
.wiki-footer {
  text-align: center;
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--gray);
  border-top: 2px solid var(--red);
  background: var(--near-black);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 860px) {
  .wiki-layout {
    grid-template-columns: 1fr;
  }

  .wiki-sidebar {
    position: fixed;
    left: -280px;
    top: var(--header-height);
    width: 280px;
    z-index: 150;
    transition: left 0.3s ease;
    border-right: 2px solid var(--red);
  }

  .wiki-sidebar.open {
    left: 0;
  }

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

  .treatment-summary {
    grid-template-columns: 28px 1fr 50px;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
  }

  .treatment-cost,
  .eff-bar-container {
    display: none;
  }

  .treatment-detail {
    grid-template-columns: 1fr;
  }

  .wiki-header__search {
    max-width: 200px;
  }
}

@media (max-width: 480px) {
  .wiki-header__title {
    font-size: 1.1rem;
    letter-spacing: 1px;
  }

  .wiki-header__search {
    max-width: 140px;
  }

  .treatment-name {
    font-size: 0.8rem;
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--near-black); }
::-webkit-scrollbar-thumb { background: var(--red); }

/* Selection */
::selection { background: var(--red); color: #fff; }
