/* ═══════════════════════════════════════════════════
  MACH Chat — Styles (Modernized)
  Brand: Mach Health
════════════════════════════════════════════════════ */
:root {
  --brand-primary: linear-gradient(90deg, #523693 0%, #8fa9d8 50%, #ee81ad 100%);
  --brand-secondary: linear-gradient(90deg, #330570 0%, #5b2fa6 100%);
  --brand-secondary-ghost: linear-gradient(180deg, rgba(51,5,112,0.06), rgba(143,169,216,0.04));
  --brand-dark:       #655481;
  --brand-light:      rgba(139, 191, 242, 0.08);

  --bg:               #ffffff;
  --bg-surface:       #f8f9fa;
  --bg-input:         #f0f2f5;
  --text-primary:     #1a1a1a;
  --text-secondary:   #5a6472;
  --text-muted:       #9aa2ad;
  --border:           rgba(0,0,0,0.08);
  --border-strong:    rgba(0,0,0,0.12);
  --success:          #10b981;
  --error:            #ef4444;
  --radius-bubble:    16px;
  --radius-ui:        8px;
  --font:             -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --shadow-sm:        0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:        0 4px 6px rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
   --bg:             #0f0f0f;
   --bg-surface:     #1a1a1a;
   --bg-input:       #262626;
   --text-primary:   #f5f5f5;
   --text-secondary: #b0b0b0;
   --text-muted:     #808080;
   --border:         rgba(255,255,255,0.08);
   --border-strong:  rgba(255,255,255,0.12);
  }
}

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

html, body {
  height: 100%; width: 100%;
  font-family: var(--font);
  background: var(--bg-surface);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── DISCLAIMER OVERLAY ── */
#overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end;
}
#disclaimer-sheet {
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px max(20px, env(safe-area-inset-bottom));
  width: 100%;
  animation: slideUp 0.3s ease;
  box-shadow: var(--shadow-md);
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
#disclaimer-sheet h2 { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px; }
#disclaimer-sheet p  { font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 12px; }
#disclaimer-sheet ul { font-size: 14px; color: var(--text-secondary); padding-left: 20px; margin-bottom: 16px; line-height: 1.8; }
#disclaimer-sheet a  { color: var(--brand-dark); text-decoration: none; font-weight: 500; }
#accept-btn {
  width: 100%; padding: 12px 16px;
  background: var(--brand-dark); color: #fff;
  border: none; border-radius: var(--radius-ui);
  font-size: 16px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease;
}
#accept-btn:hover  { opacity: 0.9; }
#accept-btn:active { opacity: 0.85; }

/* ── MAIN APP ── */
#app {
  display: flex; flex-direction: column;
  height: 100%; max-width: 640px;
  margin: 0 auto; background: var(--bg);
}

/* ── HEADER ── */
#header {
  background: linear-gradient(90deg, #523693 0%, #8fa9d8 50%, #ee81ad 100%);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; gap: 12px;
  box-shadow: var(--shadow-sm);
}
#header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
#header-logo { height: 32px; width: auto; }
#header-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: #fff; flex-shrink: 0;
}
#header-name { font-size: 15px; font-weight: 600; color: #fff; line-height: 1.2; }
#header-sub  { font-size: 12px; color: rgba(255,255,255,0.8); }
#header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

#lang-select, #clear-btn {
  background: rgba(255,255,255,0.15); color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-ui); padding: 8px 12px;
  font-size: 13px; cursor: pointer; height: 36px;
  -webkit-appearance: none; appearance: none;
  transition: background 0.2s ease;
}
#lang-select option { background: #523693; color: #fff; }
#lang-select:hover, #clear-btn:hover { background: rgba(255,255,255,0.25); }
#clear-btn { padding: 0 12px; white-space: nowrap; }

/* ── CALL LINK IN HEADER ── */
#call-link {
  width: 36px; height: 36px; border-radius: var(--radius-ui);
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff; display: flex; align-items: center; justify-content: center;
  text-decoration: none; flex-shrink: 0;
  transition: background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
#call-link:hover  { background: rgba(255,255,255,0.25); }
#call-link:active { background: rgba(255,255,255,0.3); }

/* ── MESSAGES ── */
#messages {
  flex: 1; overflow-y: auto; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.msg      { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 2px; }
.msg.user { justify-content: flex-end; }
.msg.bot  { justify-content: flex-start; }
.bot-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(90deg, #330570 0%, #5b2fa6 100%);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #fff; font-weight: 700;
}
.bubble {
  padding: 12px 16px; font-size: 15px; line-height: 1.5;
  max-width: min(75vw, 340px); word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.user .bubble {
  background: var(--brand-dark); color: #fff;
  border-radius: var(--radius-bubble) var(--radius-bubble) 4px var(--radius-bubble);
}
.bot .bubble {
  background: var(--bg-surface); color: var(--text-primary);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 4px;
}
.bubble.crisis { border-left: 3px solid var(--error) !important; }
.msg-col { display: flex; flex-direction: column; gap: 4px; }

/* message footer row — disclaimer + listen button */
.msg-actions {
  display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
  padding: 0 4px;
}
.msg-tag { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* source tag shown when knowledge base is cited */
.source-tag {
  display: inline-block; margin-top: 6px;
  font-size: 11px; color: var(--text-muted); font-style: italic;
}

/* ── LISTEN BUTTON ── */
.speak-btn {
  background: none; border: none;
  color: var(--text-muted); font-size: 11px;
  cursor: pointer; display: flex; align-items: center; gap: 4px;
  padding: 2px 4px; border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap; flex-shrink: 0;
  transition: color 0.15s;
}
.speak-btn:hover { color: var(--brand-dark); }

/* typing dots */
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); margin: 0 2px; animation: bounce 1.2s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-5px)} }

/* ── STARTERS ── */
#starters {
  padding: 12px 12px 8px;
  display: flex; gap: 8px;
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#starters::-webkit-scrollbar { display: none; }
.sq {
  background: var(--bg-surface);
  border: 0.5px solid var(--border-strong);
  border-radius: 20px; padding: 8px 14px;
  font-size: 13px; color: var(--text-secondary);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
}
.sq:hover  { background: var(--brand-light); color: var(--brand-dark); }
.sq:active { background: var(--brand-light); color: var(--brand-dark); }

/* ── INPUT ── */
#input-wrap {
  padding: 12px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 0.5px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end;
  flex-shrink: 0; background: var(--bg);
}
#msg-input {
  flex: 1; background: var(--bg-input);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-ui); padding: 12px 16px;
  font-size: 16px; font-family: var(--font);
  color: var(--text-primary);
  resize: none; min-height: 44px; max-height: 120px;
  line-height: 1.4; outline: none;
  transition: border-color 0.2s ease;
}
#msg-input::placeholder { color: var(--text-muted); }
#msg-input:focus { border-color: var(--brand-dark); }

/* ── MIC BUTTON ── */
#mic-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#mic-btn:hover { background: var(--brand-light); color: var(--brand-dark); }
#mic-btn[data-state="listening"] {
  background: var(--error); border-color: var(--error);
  color: #fff; animation: pulse 1s infinite;
}
#mic-btn[data-state="speaking"] {
  background: var(--brand-dark); border-color: var(--brand-dark);
  color: #fff;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* ── SEND BUTTON ── */
#send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand-dark); border: none; color: #fff;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-sm);
}
#send-btn:disabled { opacity: 0.5; cursor: default; }
#send-btn:not(:disabled):hover  { opacity: 0.9; }
#send-btn:not(:disabled):active { opacity: 0.85; }
#send-btn svg { width: 20px; height: 20px; }

/* ── PRIVACY BAR ── */
#privacy-bar {
  text-align: center; font-size: 11px;
  color: var(--text-muted); padding: 8px 12px; flex-shrink: 0;
}

hr.divider { border: none; border-top: 0.5px solid var(--border); margin: 8px 0; }

/* ── REFERENCE SUPERSCRIPT ── */
.ref-link {
  color: var(--brand-dark);
  text-decoration: none;
  font-size: 11px;
}
.ref-link:hover { text-decoration: underline; }
.ref-link sup {
  font-size: 10px;
  vertical-align: super;
  line-height: 0;
}
