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

:root {
  --navy:     #1a3a5c;
  --navy-mid: #234e78;
  --blue:     #2563eb;
  --blue-lt:  #dbeafe;
  --teal:     #0e7490;
  --teal-lt:  #cffafe;
  --green:    #15803d;
  --green-lt: #dcfce7;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --white:    #ffffff;
  --radius:   10px;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg:0 4px 16px rgba(0,0,0,.12);
}

html { font-size: 16px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 100%);
  color: var(--white);
  padding: 1.5rem 1rem 1.25rem;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.header-title {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.header-icon {
  font-size: 2rem;
  line-height: 1;
  opacity: .9;
}

.header-title h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.header-sub {
  font-size: .8rem;
  opacity: .7;
  margin-top: .15rem;
}

/* ─── Search ─────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: .9rem;
  color: rgba(255,255,255,.5);
  pointer-events: none;
  display: flex;
}

#searchInput {
  width: 100%;
  padding: .75rem 2.5rem .75rem 2.6rem;
  border: 2px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  background: rgba(255,255,255,.12);
  color: var(--white);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color .15s, background .15s;
}

#searchInput::placeholder { color: rgba(255,255,255,.45); }
#searchInput:focus {
  border-color: rgba(255,255,255,.55);
  background: rgba(255,255,255,.18);
}
#searchInput::-webkit-search-cancel-button { display: none; }

.clear-btn {
  position: absolute;
  right: .75rem;
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  font-size: .85rem;
  cursor: pointer;
  padding: .2rem .3rem;
  border-radius: 4px;
  display: none;
  transition: color .15s;
}
.clear-btn:hover { color: rgba(255,255,255,.9); }
.clear-btn.visible { display: block; }

/* ─── Main ───────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.results-meta {
  font-size: .8rem;
  color: var(--gray-400);
  margin-bottom: .75rem;
  padding-left: .1rem;
  min-height: 1.2em;
}

/* ─── Diagnosis List ─────────────────────────────────────── */
.diagnosis-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.diag-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow .15s;
}

.diag-card:hover { box-shadow: var(--shadow-lg); }

.diag-card.has-template {
  border-left: 4px solid var(--blue);
}

/* ─── Card Header (always visible) ──────────────────────── */
.diag-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background .1s;
}
.diag-header:hover { background: var(--gray-50); }

.diag-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: .8rem;
  font-weight: 500;
  background: var(--blue-lt);
  color: var(--blue);
  padding: .2rem .5rem;
  border-radius: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.diag-card.has-template .diag-code {
  background: var(--blue);
  color: var(--white);
}

.diag-name {
  font-size: .95rem;
  font-weight: 500;
  flex: 1;
  line-height: 1.35;
}

.diag-badge {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .15rem .45rem;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-template {
  background: var(--green-lt);
  color: var(--green);
}

.diag-chevron {
  color: var(--gray-400);
  font-size: .75rem;
  flex-shrink: 0;
  transition: transform .2s;
}

.diag-card.open .diag-chevron { transform: rotate(180deg); }

/* ─── Card Body (expanded) ───────────────────────────────── */
.diag-body {
  display: none;
  border-top: 1px solid var(--gray-200);
}
.diag-card.open .diag-body { display: block; }

.diag-tabs {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.tab-btn {
  padding: .6rem 1rem;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-600);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--navy); }
.tab-btn.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.tab-panel { display: none; padding: 1rem; }
.tab-panel.active { display: block; }

/* ─── Criteria Block ─────────────────────────────────────── */
.criteria-block {
  font-size: .875rem;
  line-height: 1.7;
  color: var(--gray-800);
}

.criteria-note {
  margin-bottom: .75rem;
  color: var(--gray-600);
  font-style: italic;
  font-size: .82rem;
}

/* Top-level: A, B, C… */
.criteria-ol { margin: 0; padding: 0; }

.criteria-top {
  list-style-type: upper-alpha;
  padding-left: 1.6rem;
}
.criteria-top > li {
  margin-bottom: .75rem;
  padding-left: .25rem;
}
.criteria-top > li > .crit-body { display: block; }

/* Second level: 1, 2, 3… */
.criteria-numbered {
  list-style-type: decimal;
  padding-left: 1.5rem;
  margin-top: .4rem;
}
.criteria-numbered > li { margin-bottom: .3rem; }

/* Third level: a, b, c… */
.criteria-alpha {
  list-style-type: lower-alpha;
  padding-left: 1.5rem;
  margin-top: .3rem;
}

/* ─── Template ───────────────────────────────────────────── */
.template-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: .6rem;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  background: var(--blue);
  color: var(--white);
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.copy-btn:hover { background: #1d4ed8; }
.copy-btn:active { transform: scale(.97); }
.copy-btn.copied { background: var(--green); }

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

.template-text {
  font-size: .875rem;
  line-height: 1.7;
  color: var(--gray-800);
  white-space: pre-wrap;
  font-family: 'Inter', sans-serif;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: .85rem 1rem;
}

/* Bullet lines get a small left indent */
.template-text {
  /* override: indent lines that start with bullet */
}

/* Highlight CAPS_UNDERSCORED variables */
.template-text .var {
  background: #fef9c3;
  color: #854d0e;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 500;
}

.no-template-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--gray-600);
  font-size: .875rem;
}
.no-template-notice strong { color: var(--gray-800); }
.no-template-notice .notice-icon { font-size: 1.75rem; }

/* ─── Category Tag ───────────────────────────────────────── */
.diag-category {
  font-size: .7rem;
  color: var(--gray-400);
  padding: 0 1rem .75rem;
}

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--gray-600);
}
.empty-icon { font-size: 2.5rem; display: block; margin-bottom: .75rem; }
.empty-state p { font-size: .95rem; }
.empty-sub { font-size: .82rem; color: var(--gray-400); margin-top: .35rem; }

/* ─── Footer ─────────────────────────────────────────────── */
.site-footer {
  background: var(--gray-100);
  border-top: 1px solid var(--gray-200);
  padding: 1rem;
  text-align: center;
  font-size: .72rem;
  color: var(--gray-400);
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--gray-800);
  color: var(--white);
  padding: .6rem 1.1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ─── Responsive ─────────────────────────────────────────── */
@media (min-width: 600px) {
  .header-inner { flex-direction: row; align-items: center; gap: 1.5rem; }
  .search-wrap { flex: 1; max-width: 420px; }
  .header-title h1 { font-size: 1.5rem; }
}
