/* ========================================
   OTC Consult – App-like design
   Mobile-first, drill-down navigation
   ======================================== */

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

:root {
  --brand:      #0f2747;
  --brand-light:#1a3a5c;
  --accent:     #6366f1;
  --surface:    #f0f4f8;
  --card:       #ffffff;
  --text:       #1e293b;
  --text-muted: #64748b;
  --border:     #e2e8f0;
  --radius:     14px;
  --radius-sm:  10px;
  --shadow:     0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-lg:  0 4px 12px rgba(15,23,42,0.10);
  --top-bar-h:  56px;
  --safe-top:   env(safe-area-inset-top, 0px);
  --safe-bottom:env(safe-area-inset-bottom, 0px);
  --tab-clinical: linear-gradient(135deg, #0ea5e9, #0284c7);
  --tab-referral: linear-gradient(135deg, #f59e0b, #d97706);
  --tab-timeframe:linear-gradient(135deg, #10b981, #059669);
  --tab-strategy: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--surface);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ========================================
   Top bar
   ======================================== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--top-bar-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  background: var(--brand);
  color: #fff;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.10);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .12s;
}
.back-btn:hover { background: rgba(255,255,255,0.18); }

.top-bar-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   Search
   ======================================== */
.search-bar {
  position: sticky;
  top: calc(var(--top-bar-h) + var(--safe-top));
  z-index: 90;
  padding: 10px 16px;
  background: var(--surface);
}

.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 15px;
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
.search-bar input::placeholder { color: var(--text-muted); }

.search-results {
  list-style: none;
  margin: 6px 0 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 340px;
  overflow-y: auto;
  display: none;
}

.search-results.active { display: block; }

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover,
.search-result-item.focused { background: #f1f5f9; }

.search-result-item .sr-label { font-size: 15px; font-weight: 500; }
.search-result-item .sr-meta  { font-size: 12px; color: var(--text-muted); }

/* ========================================
   Views container
   ======================================== */
.views {
  padding: 0 16px 32px;
  max-width: 960px;
  margin: 0 auto;
}

.view { /* visible by default */ }
.view.hidden { display: none !important; }

/* ========================================
   Section labels
   ======================================== */
.section-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 20px 4px 10px;
}

/* ========================================
   System card grid
   ======================================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.system-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 110px;
  padding: 16px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .08s, box-shadow .12s;
  -webkit-tap-highlight-color: transparent;
}
.system-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.system-card:active { transform: scale(0.97); }

.system-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 8px;
  color: #fff;
}

.system-card-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

/* ========================================
   List group (conditions, section pages)
   ======================================== */
.list-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #f8fafc; }
.list-item:active { background: #f1f5f9; }

.list-item-label {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.list-item-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 8px;
  flex-shrink: 0;
}

.list-item-chevron {
  flex-shrink: 0;
  margin-left: 8px;
  color: #cbd5e1;
}

/* ========================================
   Tab bar
   ======================================== */
.tab-bar {
  display: flex;
  gap: 0;
  background: #eef2f7;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1.15;
  text-align: center;
  transition: background .12s, color .12s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn:hover { background: rgba(255,255,255,0.6); color: var(--text); }
.tab-btn:active { transform: scale(0.98); }

.tab-btn.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ========================================
   CSS tab banners (replace blurry images)
   ======================================== */
.tab-banner {
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 16px;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.tab-banner-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.tab-banner-subtitle {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.tab-banner::before {
  content: '';
  position: absolute;
  right: -20px;
  top: -20px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.tab-banner::after {
  content: '';
  position: absolute;
  right: 40px;
  bottom: -30px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}

.tab-banner.clinical  { background: var(--tab-clinical); }
.tab-banner.referral  { background: var(--tab-referral); }
.tab-banner.timeframe { background: var(--tab-timeframe); }
.tab-banner.strategy  { background: var(--tab-strategy); }

/* ========================================
   Content card
   ======================================== */
.content-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: auto;
}

.content-card img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.content-card ul { padding-left: 20px; }
.content-card li { margin-bottom: 6px; }
.content-card table { border-collapse: collapse; width: 100%; }
.content-card td, .content-card th { padding: 8px 10px; border: 1px solid var(--border); }

/* ========================================
   Desktop (wider layout)
   ======================================== */
@media (min-width: 768px) {
  .views { padding: 0 32px 48px; max-width: 1100px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
  .system-card { min-height: 130px; padding: 20px 16px; }
  .system-card-icon { width: 52px; height: 52px; font-size: 26px; border-radius: 14px; }
  .system-card-label { font-size: 15px; }
  .search-bar { padding: 12px 32px; }
  .tab-banner { padding: 36px 32px; }
  .tab-banner-title { font-size: 28px; }
  .content-card { padding: 24px 28px; }
}

/* ========================================
   Focus styles
   ======================================== */
.back-btn:focus-visible,
.system-card:focus-visible,
.list-item:focus-visible,
.tab-btn:focus-visible,
.search-bar input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ========================================
   Animations
   ======================================== */
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to   { opacity: 1; transform: translateX(0); }
}

.view.animate-forward { animation: slideInRight .2s ease-out; }
.view.animate-back    { animation: slideInLeft .2s ease-out; }
