/* ==========================================================================
   PCOS OS design system
   Tokens, components, utilities — everything Tailwind CDN cannot cover.
   ========================================================================== */

/* --------------------------------------------------------------------------
   TOKENS
-------------------------------------------------------------------------- */
:root {
  /* Surfaces */
  --bg-base:      #050505;
  --bg-raised:    #0a0a0a;
  --bg-overlay:   #121212;
  --bg-subtle:    #1a1a1a;
  --bg-hover:     #242424;

  /* Glassmorphism */
  --bg-glass:     rgba(10, 10, 10, 0.75);
  --bg-glass-light: rgba(18, 18, 18, 0.85);

  /* Borders */
  --border-faint: rgba(255, 255, 255, 0.04);
  --border-dim:   rgba(255, 255, 255, 0.08);
  --border-mid:   rgba(255, 255, 255, 0.12);
  --border-loud:  rgba(255, 255, 255, 0.2);

  /* Text */
  --text-primary:   #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted:     #71717a;
  --text-ghost:     #3f3f46;

  /* Accent - soft premium coral/peach */
  --accent:        #e2a595;
  --accent-dim:    #875c51;
  --accent-hover:  #edb5a6;
  --accent-glow:   rgba(226, 165, 149, 0.12);

  /* Status */
  --crisis:           #e05252;
  --crisis-bg:        rgba(224,82,82,0.1);
  --crisis-border:    rgba(224,82,82,0.3);
  --medication:       #d4873a;
  --medication-bg:    rgba(212,135,58,0.1);
  --fertility:        #8e6fc9;
  --fertility-bg:     rgba(142,111,201,0.1);
  --ed:               #c96f3a;
  --ed-bg:            rgba(201,111,58,0.1);
  --diag:             #3aa8c9;
  --diag-bg:          rgba(58,168,201,0.1);
  --doctor:           #5f6ec9;
  --doctor-bg:        rgba(95,110,201,0.1);
  --ok-green:         #4caf7d;
  --ok-green-bg:      rgba(76,175,125,0.1);

  /* Typography */
  --font-body:    'Inter', ui-sans-serif, system-ui, sans-serif;
  --font-display: 'DM Serif Display', ui-serif, Georgia, serif;
  --font-mono:    'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Radius */
  --r-xs:  6px;
  --r-sm:  10px;
  --r-md:  14px;
  --r-lg:  20px;
  --r-xl:  28px;
  --r-full: 9999px;
}

/* --------------------------------------------------------------------------
   RESET + BASE
-------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------------------
   SCROLLBARS
-------------------------------------------------------------------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-mid) transparent;
}
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 2px; }

/* --------------------------------------------------------------------------
   WORDMARK
-------------------------------------------------------------------------- */
.wordmark {
  font-family: var(--font-display);
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1;
}
.wordmark .dot { color: var(--accent); }

/* --------------------------------------------------------------------------
   TYPING INDICATOR
-------------------------------------------------------------------------- */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.typing-dots span {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: lia-pulse 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes lia-pulse {
  0%, 55%, 100% { transform: translateY(0);    opacity: 0.3; }
  27%            { transform: translateY(-5px); opacity: 1;   }
}

/* --------------------------------------------------------------------------
   CHAT BUBBLES & ANIMATIONS
-------------------------------------------------------------------------- */
.bubble-lia {
  background: var(--bg-overlay);
  border: 1px solid var(--border-dim);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  animation: slideUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.bubble-user {
  background: var(--bg-subtle);
  border: 1px solid var(--border-faint);
  border-bottom-right-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  animation: slideUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Glassmorphism helpers */
.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-faint);
}
.glass-panel-top {
  border-bottom: none;
  border-top: 1px solid var(--border-faint);
}

/* --------------------------------------------------------------------------
   FILE ATTACHMENT PILLS
-------------------------------------------------------------------------- */
.attach-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-dim);
  border-radius: var(--r-sm);
  padding: 4px 10px 4px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 180px;
}
.attach-pill .pill-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
}
.attach-pill .pill-remove {
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  font-size: 14px;
}
.attach-pill .pill-remove:hover { color: var(--text-secondary); }

.attach-pill.type-pdf  { border-color: rgba(224,82,82,0.2);   }
.attach-pill.type-img  { border-color: rgba(58,168,201,0.2);  }
.attach-pill.type-scan { border-color: rgba(142,111,201,0.2); }

/* --------------------------------------------------------------------------
   FLAG DOTS
-------------------------------------------------------------------------- */
.flag-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.flag-dot.crisis              { background: var(--crisis);     }
.flag-dot.medication          { background: var(--medication); }
.flag-dot.fertility           { background: var(--fertility);  }
.flag-dot.ed                  { background: var(--ed);         }
.flag-dot.diagnosis_pressure  { background: var(--diag);       }
.flag-dot.doctor_conflict     { background: var(--doctor);     }

/* --------------------------------------------------------------------------
   ADMIN FEEDBACK BUTTONS
-------------------------------------------------------------------------- */
.fb-btn {
  padding: 3px 9px;
  border-radius: var(--r-xs);
  font-size: 11px;
  font-family: var(--font-body);
  cursor: pointer;
  border: 1px solid var(--border-dim);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.12s;
}
.fb-btn:hover { background: var(--bg-subtle); color: var(--text-secondary); }

.fb-btn.active.exemplary  { background: var(--ok-green-bg);  border-color: rgba(76,175,125,0.3);  color: var(--ok-green); }
.fb-btn.active.ok         { background: var(--accent-glow);  border-color: rgba(201,169,110,0.3); color: var(--accent);   }
.fb-btn.active.fix_needed { background: var(--crisis-bg);    border-color: var(--crisis-border);  color: var(--crisis);   }

/* --------------------------------------------------------------------------
   MI TECHNIQUE TAGS
-------------------------------------------------------------------------- */
.mi-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-xs);
  font-size: 10px;
  font-family: var(--font-body);
  letter-spacing: 0.02em;
  background: var(--bg-subtle);
  border: 1px solid var(--border-dim);
  color: var(--text-muted);
}
.mi-tag.reflect    { color: var(--ok-green);  border-color: rgba(76,175,125,0.2);  background: var(--ok-green-bg);  }
.mi-tag.open_q     { color: var(--diag);      border-color: rgba(58,168,201,0.2);  background: var(--diag-bg);      }
.mi-tag.affirm     { color: var(--accent);    border-color: rgba(201,169,110,0.2); background: var(--accent-glow);  }
.mi-tag.summary    { color: var(--fertility); border-color: rgba(142,111,201,0.2); background: var(--fertility-bg); }
.mi-tag.evoke      { color: var(--medication);border-color: rgba(212,135,58,0.2);  background: var(--medication-bg);}
.mi-tag.plan       { color: var(--doctor);    border-color: rgba(95,110,201,0.2);  background: var(--doctor-bg);    }
.mi-tag.safety     { color: var(--crisis);    border-color: var(--crisis-border);  background: var(--crisis-bg);    }

/* --------------------------------------------------------------------------
   QUALITY SCORE RING
-------------------------------------------------------------------------- */
.quality-ring {
  position: relative;
  width: 48px;
  height: 48px;
}
.quality-ring svg {
  transform: rotate(-90deg);
}
.quality-ring .score-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   CONFIDENCE BAR
-------------------------------------------------------------------------- */
.conf-bar {
  height: 2px;
  background: var(--border-dim);
  border-radius: 1px;
  overflow: hidden;
}
.conf-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.4s ease;
}

/* --------------------------------------------------------------------------
   STAT CARD
-------------------------------------------------------------------------- */
.stat-card {
  background: var(--bg-overlay);
  border: 1px solid var(--border-faint);
  border-radius: var(--r-md);
  padding: 16px;
}
.stat-num {
  font-size: 30px;
  font-weight: 300;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.stat-num.crisis-num { color: var(--crisis); }
.stat-num.good-num   { color: var(--ok-green); }
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------------------
   FLAG QUEUE ROW
-------------------------------------------------------------------------- */
.flag-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-overlay);
  border-radius: var(--r-sm);
  border-left: 2px solid var(--border-dim);
  transition: background 0.12s;
}
.flag-row:hover { background: var(--bg-hover); }
.flag-row.crisis-row {
  border-left-color: var(--crisis);
  background: var(--crisis-bg);
}
.flag-row.crisis-row:hover { background: rgba(224,82,82,0.1); }

/* --------------------------------------------------------------------------
   BUTTONS
-------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  transition: all 0.12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent-dim);
  color: var(--accent);
}
.btn-primary:hover { background: #8a7248; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-dim);
}
.btn-ghost:hover { background: var(--bg-subtle); }
.btn-danger {
  background: var(--crisis-bg);
  color: var(--crisis);
  border: 1px solid var(--crisis-border);
}
.btn-danger:hover { background: rgba(224,82,82,0.12); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-xs { padding: 3px 8px; font-size: 10px; }

/* --------------------------------------------------------------------------
   INPUTS
-------------------------------------------------------------------------- */
.input-base {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-dim);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
}
.input-base::placeholder { color: var(--text-muted); }
.input-base:focus { 
  border-color: var(--accent); 
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* --------------------------------------------------------------------------
   SIDEBAR SECTION
-------------------------------------------------------------------------- */
.sidebar-section {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-faint);
}
.sidebar-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.sidebar-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* --------------------------------------------------------------------------
   PHENOTYPE TRACE TIMELINE
-------------------------------------------------------------------------- */
.pheno-trace {
  position: relative;
  padding-left: 16px;
}
.pheno-trace::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--border-dim);
}
.pheno-point {
  position: relative;
  margin-bottom: 10px;
  font-size: 11px;
}
.pheno-point::before {
  content: '';
  position: absolute;
  left: -13px;
  top: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-mid);
}
.pheno-point.latest::before { background: var(--accent); }

/* --------------------------------------------------------------------------
   MODAL
-------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--bg-raised);
  border: 1px solid var(--border-dim);
  border-radius: var(--r-lg);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  margin: 16px;
}

/* --------------------------------------------------------------------------
   MESSAGE STREAM
-------------------------------------------------------------------------- */
#message-stream {
  scroll-behavior: smooth;
}

/* --------------------------------------------------------------------------
   ADMIN NAV
-------------------------------------------------------------------------- */
.admin-nav {
  height: 44px;
  border-bottom: 1px solid var(--border-faint);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
  background: var(--bg-raised);
}
.admin-nav-link {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.12s;
}
.admin-nav-link:hover  { color: var(--text-secondary); }
.admin-nav-link.active { color: var(--text-primary);   }
.admin-nav-title {
  font-size: 12px;
  color: var(--text-secondary);
  margin-right: auto;
}

/* --------------------------------------------------------------------------
   CONVERSATION THREAD
-------------------------------------------------------------------------- */
.thread-msg { margin-bottom: 18px; }
.thread-role {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.thread-role.lia-role { color: var(--accent-dim); }
.thread-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  padding: 10px 13px;
  border-radius: var(--r-sm);
  background: var(--bg-overlay);
}
.thread-content.lia-content {
  border-left: 2px solid var(--accent-dim);
}
.thread-flag-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: var(--r-xs);
  margin-bottom: 5px;
}

/* --------------------------------------------------------------------------
   NOTE POPOVER
-------------------------------------------------------------------------- */
.note-area {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-base);
  border: 1px solid var(--border-dim);
  border-radius: var(--r-sm);
}
.note-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--text-secondary);
  resize: none;
  line-height: 1.6;
}
.note-textarea::placeholder { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   UTILITY
-------------------------------------------------------------------------- */
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mono { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.section-head {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
