/* -----------------------------------------------------------
   MedAI — clean clinical theme
   ----------------------------------------------------------- */

:root {
  --primary: #1e6fba;       /* medical blue */
  --primary-dark: #155289;
  --primary-light: #e6f1fb;
  --accent: #2cb5a0;        /* soft teal */
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafd;
  --border: #dde5ef;
  --text: #1b2b3a;
  --text-muted: #5b6b7d;
  --danger: #d64545;
  --success: #2e9b5b;
  --shadow: 0 2px 8px rgba(20, 45, 80, 0.06);
  --shadow-lg: 0 8px 32px rgba(20, 45, 80, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.tagline {
  margin: 0;
  font-size: 0.78rem;
  opacity: 0.85;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 6px 10px;
  border-radius: 20px;
}
.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f5c842;
}
.status.ok .dot    { background: #6fe08a; }
.status.error .dot { background: #ff7676; }

/* Language bar */
.lang-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.lang-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-btn:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}
.lang-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Chat area */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 22px 32px;
  scroll-behavior: smooth;
}

.welcome {
  text-align: center;
  padding: 40px 20px 30px;
  color: var(--text-muted);
}
.welcome h2 {
  color: var(--primary-dark);
  font-size: 1.5rem;
  margin: 0 0 10px;
}
.welcome p {
  max-width: 540px;
  margin: 8px auto;
}
.welcome code {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.welcome .disclaimer {
  margin-top: 22px;
  font-size: 0.8rem;
  background: #fff7e6;
  border: 1px solid #ffd699;
  color: #7a5400;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  animation: fadeIn 0.18s ease-out;
}
.message.user  { flex-direction: row-reverse; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  background: var(--primary);
  color: #fff;
}
.message.user .avatar { background: var(--accent); }

.bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
}
.message.user .bubble {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}

.bubble .thumb {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.bubble .meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  align-items: center;
}
.message.user .bubble .meta { color: rgba(255, 255, 255, 0.8); }

.speak-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--primary-dark);
  padding: 3px 10px;
  border-radius: 14px;
  font-size: 0.72rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.speak-btn:hover { background: var(--primary-light); }
.speak-btn.speaking {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.speak-btn svg { width: 12px; height: 12px; }

.bubble.error {
  background: #fff2f2;
  border-color: #ffc2c2;
  color: var(--danger);
}

/* Loading indicator */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* Composer */
.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 18px 14px;
}

.attachment-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.attachment-strip.hidden { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 4px 10px 4px 6px;
  border-radius: 20px;
  font-size: 0.82rem;
  max-width: 260px;
}
.chip img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}
.chip .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip .remove {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--primary-dark);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  transition: border-color 0.15s;
}
.composer-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 111, 186, 0.12);
}

textarea#message-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  padding: 8px 6px;
  min-height: 22px;
  max-height: 180px;
  outline: none;
  line-height: 1.45;
}

/* Buttons */
.icon-btn, .send-btn {
  background: none;
  border: none;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn svg, .send-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--primary-light); color: var(--primary-dark); }
.header-actions .icon-btn { color: #fff; }
.header-actions .icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.send-btn {
  background: var(--primary);
  color: #fff;
}
.send-btn:hover       { background: var(--primary-dark); }
.send-btn:disabled    { opacity: 0.5; cursor: not-allowed; }

#mic-btn.recording {
  background: var(--danger);
  color: #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(214, 69, 69, 0);   }
}

.composer-hint {
  margin-top: 8px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.composer-hint kbd {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.7rem;
}

/* Ko-fi floating support button */
.kofi-btn {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #ff5e5b;
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.2px;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(255, 94, 91, 0.45),
              0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.kofi-btn:hover {
  background: #ff4744;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(255, 94, 91, 0.55),
              0 3px 6px rgba(0, 0, 0, 0.12);
}
.kofi-btn:active { transform: translateY(0); }
.kofi-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Site footer — "Powered by DinizDynamics" */
.site-footer {
  text-align: center;
  padding: 10px 16px 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.site-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.site-footer a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* =========================================================
   Mobile / tablet adjustments
   ========================================================= */

/* Tablet & small laptops — app still bounded but padding shrinks */
@media (max-width: 900px) {
  .app { max-width: 100%; box-shadow: none; }
}

/* Phones */
@media (max-width: 640px) {
  html { font-size: 19px; }   /* bumped — mobile reads much better at this size */

  .app {
    height: 100vh;
    height: 100dvh;             /* iOS dynamic viewport — avoids URL-bar jumps */
    padding-left:  env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* Header */
  .header {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  .brand       { gap: 12px; }
  .brand-icon  { width: 50px; height: 50px; }
  .header h1   { font-size: 1.35rem; }
  .tagline     { display: none; }
  .status      { font-size: 0.9rem; padding: 8px 12px; }
  .header-actions .icon-btn { width: 48px; height: 48px; }
  .header-actions .icon-btn svg { width: 22px; height: 22px; }

  /* Language bar — bigger tap targets */
  .lang-bar  { padding: 10px 8px; gap: 6px; }
  .lang-btn  { padding: 9px 14px; font-size: 0.98rem; min-width: 48px; }

  /* Chat area */
  .chat       { padding: 22px 16px 26px; }
  .welcome    { padding: 32px 12px 24px; }
  .welcome h2 { font-size: 1.6rem; }
  .welcome p  { font-size: 1.08rem; line-height: 1.55; }
  .welcome .disclaimer { font-size: 0.95rem; padding: 14px 16px; }

  /* Messages */
  .message    { gap: 10px; margin-bottom: 18px; }
  .avatar     { width: 42px; height: 42px; font-size: 0.95rem; }
  .bubble     { max-width: 82%; font-size: 1.08rem; padding: 14px 16px; }
  .bubble .thumb { max-width: 220px; max-height: 220px; }
  .speak-btn  { font-size: 0.92rem; padding: 8px 14px; }
  .speak-btn svg { width: 16px; height: 16px; }

  /* Composer — textarea font-size ≥16px so iOS doesn't auto-zoom. */
  .composer {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }
  .composer-hint { display: none; }
  .composer-row  { padding: 10px; gap: 8px; }
  textarea#message-input {
    font-size: 17px;
    padding: 12px 8px;
    min-height: 30px;
  }
  .icon-btn, .send-btn { width: 52px; height: 52px; border-radius: 14px; }
  .icon-btn svg, .send-btn svg { width: 26px; height: 26px; }

  /* Footer */
  .site-footer {
    font-size: 0.88rem;
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  }

  /* Ko-fi floating pill — top-right on mobile so it doesn't cover
     the composer/send button when the keyboard is open. */
  .kofi-btn  {
    bottom: auto;
    top: calc(128px + env(safe-area-inset-top));
    right: 14px;
    padding: 12px 14px;
  }
  .kofi-label { display: none; }          /* icon-only on phones */
  .kofi-icon  { width: 26px; height: 26px; }
}

/* Tiny phones (iPhone SE / narrow Androids) */
@media (max-width: 380px) {
  html            { font-size: 18px; }
  .header         { padding: 12px 14px; }
  .header h1      { font-size: 1.2rem; }
  .brand-icon     { width: 44px; height: 44px; }
  .lang-btn       { padding: 8px 11px; font-size: 0.9rem; min-width: 42px; }
  .welcome h2     { font-size: 1.4rem; }
  .bubble         { max-width: 88%; }
  .icon-btn, .send-btn { width: 48px; height: 48px; }
}
