/* ================================================================
   Ayrah — Modern Chat UI Stylesheet
   Inspired by ChatGPT / Gemini design language
   ================================================================ */

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

:root {
  /* Palette */
  --bg-primary:      #212121;
  --bg-secondary:    #171717;
  --bg-sidebar:      #171717;
  --bg-input:        #303030;
  --bg-hover:        #2a2a2a;
  --bg-user-msg:     #303030;
  --bg-ai-msg:       transparent;
  --bg-suggestion:   #2a2a2a;

  --text-primary:    #ececec;
  --text-secondary:  #b4b4b4;
  --text-muted:      #888;
  --text-accent:     #7c9eff;

  --border:          #424242;
  --border-light:    #383838;

  --accent:          #7c9eff;
  --accent-hover:    #95b0ff;
  --green:           #6bcf8f;
  --amber:           #e8b931;
  --red:             #ef6461;

  /* Sizing */
  --sidebar-w:       280px;
  --max-chat-w:      780px;
  --topbar-h:        56px;
  --input-h:         68px;

  /* Radius */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast: 150ms ease;
  --t-med:  250ms ease;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────────────────────── */
body {
  display: flex;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-light);
  transition: transform var(--t-med);
  z-index: 100;
}

.sidebar-top {
  padding: 12px;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast);
}
.new-chat-btn:hover { background: var(--bg-hover); }

.sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  cursor: pointer;
  transition: background var(--t-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.history-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.history-item.active { background: var(--bg-hover); color: var(--text-primary); }

.history-item svg {
  flex-shrink: 0;
  opacity: .55;
}

.sidebar-bottom {
  padding: 14px 16px;
  border-top: 1px solid var(--border-light);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon { font-size: 24px; }
.brand-name { font-weight: 600; font-size: 15px; color: var(--text-primary); }
.brand-sub  { font-size: 11.5px; color: var(--text-muted); }

/* Scrollbar */
.sidebar-history::-webkit-scrollbar { width: 4px; }
.sidebar-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Main ─────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 12px;
  border-bottom: 1px solid transparent;
}
.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}
.topbar-spacer { flex: 1; }

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.menu-btn:hover { background: var(--bg-hover); }

/* ── Chat Area ────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

/* ── Welcome Screen ───────────────────────────────────────────── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 40px;
  max-width: 680px;
  margin: 0 auto;
  min-height: calc(100vh - var(--topbar-h) - var(--input-h) - 80px);
}

.welcome-icon {
  font-size: 56px;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.welcome-title {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--accent), #c095f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-sub {
  font-size: 15.5px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
  margin-bottom: 40px;
  max-width: 440px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 560px;
}

.suggestion-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 16px;
  background: var(--bg-suggestion);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
  text-align: left;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.45;
}
.suggestion-card:hover {
  border-color: var(--border);
  background: var(--bg-hover);
  color: var(--text-primary);
}
.suggestion-icon { font-size: 22px; }

/* ── Messages ─────────────────────────────────────────────────── */
.messages {
  max-width: var(--max-chat-w);
  margin: 0 auto;
  padding: 12px 24px 32px;
  width: 100%;
}

.msg-row {
  display: flex;
  gap: 16px;
  padding: 20px 0;
  animation: fadeUp .35s ease;
}

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

/* Avatar */
.msg-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}

.msg-avatar.user-av {
  background: linear-gradient(135deg, #5a6abf, #7c9eff);
  color: #fff;
}
.msg-avatar.ai-av {
  background: linear-gradient(135deg, #1e6b47, #2ea87e);
  color: #fff;
  font-size: 17px;
}

/* Content */
.msg-content {
  flex: 1;
  min-width: 0;
}

.msg-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.msg-body {
  font-size: 15px;
  line-height: 1.72;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Markdown-like rendering */
.msg-body p               { margin-bottom: 12px; }
.msg-body p:last-child     { margin-bottom: 0; }
.msg-body strong           { font-weight: 600; color: var(--text-primary); }
.msg-body em               { color: var(--text-secondary); }
.msg-body ul, .msg-body ol { padding-left: 20px; margin-bottom: 12px; }
.msg-body li               { margin-bottom: 6px; }
.msg-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 16px;
  margin: 12px 0;
  color: var(--text-secondary);
  font-style: italic;
}
.msg-body code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13.5px;
}
.msg-body h1, .msg-body h2, .msg-body h3 {
  margin: 18px 0 8px;
  font-weight: 600;
}
.msg-body h2 { font-size: 17px; }
.msg-body h3 { font-size: 15.5px; }
.msg-body hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 16px 0;
}

/* Arabic text in messages */
.msg-body .arabic {
  font-family: 'Amiri', serif;
  font-size: 22px;
  direction: rtl;
  text-align: right;
  line-height: 1.9;
  color: var(--accent);
  margin: 8px 0;
}

/* Crisis message */
.msg-crisis {
  border-left: 4px solid var(--red);
  background: rgba(239,100,97,.08);
  padding: 16px 20px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin: 8px 0;
}

/* Metadata pills */
.msg-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.meta-pill .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot-emotion  { background: var(--accent); }
.dot-topic    { background: var(--green); }
.dot-method   { background: var(--amber); }

/* ── Typing indicator ─────────────────────────────────────────── */
/* (Styles moved to bottom of file with updated layout) */

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ── Input Area ───────────────────────────────────────────────── */
.input-wrapper {
  padding: 0 24px 16px;
  max-width: var(--max-chat-w);
  margin: 0 auto;
  width: 100%;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 8px 10px 8px 20px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(124,158,255,.15);
}

#msgInput {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.55;
  resize: none;
  max-height: 160px;
  padding: 6px 0;
  overflow-y: auto;
  scrollbar-width: none;           /* Firefox */
  -ms-overflow-style: none;        /* IE/Edge */
}
#msgInput::-webkit-scrollbar { display: none; } /* Chrome/Safari */
#msgInput::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--r-full);
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast), opacity var(--t-fast);
  flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .35; cursor: default; }

.disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 10px;
  padding: 0 12px;
  line-height: 1.5;
}

/* ── Sidebar Overlay (mobile) ─────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 90;
}
.sidebar-overlay.active { display: block; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: flex; }

  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .welcome-title { font-size: 26px; }

  .messages { padding: 12px 14px 32px; }

  .input-wrapper { padding: 0 12px 12px; }

  /* Topbar has many icons (lang, theme, mood, bookmarks, summary,
     weekly, goals). On phones the cluster overflows the viewport and
     pushes the language switcher off-screen. Compact spacing + allow
     horizontal scroll as a safety net so every icon is reachable. */
  .topbar {
    padding: 0 10px;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar-icon-btn { width: 36px; height: 36px; }
  .topbar-title { font-size: 16px; }
}

@media (max-width: 480px) {
  .msg-row { gap: 10px; }
  .msg-avatar { width: 28px; height: 28px; font-size: 13px; }

  /* On the smallest screens, hide the redundant centre title (the
     sidebar brand already shows it) so the language + theme + panel
     icons all fit comfortably without scrolling. */
  .topbar-title { display: none; }
  .topbar { gap: 2px; padding: 0 6px; }
  .topbar-icon-btn { width: 34px; height: 34px; }
  .topbar-icon-btn svg { width: 17px; height: 17px; }
}

/* ── Verse of Day ─────────────────────────────────────────────── */
.verse-of-day {
  background: linear-gradient(135deg, rgba(124,158,255,.08), rgba(192,149,240,.06));
  border: 1px solid rgba(124,158,255,.2);
  border-radius: var(--r-md);
  padding: 18px 22px;
  text-align: center;
  margin-bottom: 32px;
  width: 100%;
  max-width: 520px;
}
.vod-loading     { color: var(--text-muted); font-size: 13px; }
.vod-label       { font-size: 11.5px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px; }
.vod-arabic      { font-family: 'Amiri', serif; font-size: 26px; color: var(--accent); direction: rtl; line-height: 1.8; margin-bottom: 8px; }
.vod-translation { font-size: 14px; color: var(--text-primary); font-style: italic; line-height: 1.6; margin-bottom: 6px; }
.vod-ref         { font-size: 12px; color: var(--text-muted); }

/* ── Topbar icon buttons ──────────────────────────────────────── */
.topbar-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  border: none;
  background: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.topbar-icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Slide-in Panels ──────────────────────────────────────────── */
.panel {
  display: none;
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-light);
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--t-med);
  z-index: 200;
  overflow: hidden;
}
.panel.open {
  display: flex;
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 15px;
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: background var(--t-fast), color var(--t-fast);
}
.panel-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
}
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.panel-empty { color: var(--text-muted); font-size: 13.5px; line-height: 1.7; text-align: center; margin-top: 40px; }
.panel-sub   { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 190;
}
.panel-overlay.active { display: block; }

/* ── Mood Panel ───────────────────────────────────────────────── */
.mood-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.mood-label {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 110px;
  flex-shrink: 0;
}
.mood-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}
.mood-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #c095f0);
  border-radius: 4px;
  transition: width .4s ease;
}
.mood-count {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 16px;
  text-align: right;
}
.mood-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.mood-dot {
  font-size: 22px;
  cursor: default;
  transition: transform var(--t-fast);
}
.mood-dot:hover { transform: scale(1.3); }

/* ── Bookmark Button ──────────────────────────────────────────── */
.bookmark-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-light);
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.bookmark-btn:hover   { color: var(--accent); border-color: var(--accent); }
.bookmark-btn.bookmarked {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(124,158,255,.08);
}

/* ── Bookmarks Panel ──────────────────────────────────────────── */
.bookmark-card {
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.bookmark-text {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 10px;
  max-height: 130px;
  overflow: hidden;
  position: relative;
}
.bookmark-text::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 30px;
  background: linear-gradient(transparent, var(--bg-hover));
}
.bookmark-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bookmark-chat   { font-size: 11.5px; color: var(--text-muted); }
.bookmark-delete {
  font-size: 11.5px;
  color: var(--red);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--t-fast);
}
.bookmark-delete:hover { background: rgba(239,100,97,.1); }

/* ── Summary Panel ────────────────────────────────────────────── */
.summary-gen-btn {
  width: 100%;
  padding: 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--accent);
  background: rgba(124,158,255,.1);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast);
  margin-bottom: 18px;
}
.summary-gen-btn:hover { background: rgba(124,158,255,.18); }

.summary-box {
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: 16px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
}

.summary-loading {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 20px 0;
  justify-content: center;
}
.summary-loading span {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}
.summary-loading span:nth-child(2) { animation-delay: .2s; }
.summary-loading span:nth-child(3) { animation-delay: .4s; }

@media (max-width: 480px) {
  .panel { width: 100%; }
  .verse-of-day { max-width: 100%; }
}

/* ── Light Theme ──────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-primary:      #ffffff;
  --bg-secondary:    #f7f7f8;
  --bg-sidebar:      #f7f7f8;
  --bg-input:        #f0f0f0;
  --bg-hover:        #ebebeb;
  --bg-user-msg:     #f0f0f0;
  --bg-ai-msg:       transparent;
  --bg-suggestion:   #f5f5f5;

  --text-primary:    #1a1a1a;
  --text-secondary:  #5a5a5a;
  --text-muted:      #8a8a8a;
  --text-accent:     #4a6fd6;

  --border:          #d4d4d4;
  --border-light:    #e5e5e5;

  --accent:          #4a6fd6;
  --accent-hover:    #5b7fe6;
}

[data-theme="light"] .msg-avatar.user-av {
  background: linear-gradient(135deg, #4a6fd6, #6b8de8);
}
[data-theme="light"] .msg-avatar.ai-av {
  background: linear-gradient(135deg, #1a7a50, #2ea87e);
}
[data-theme="light"] .welcome-title {
  background: linear-gradient(135deg, #4a6fd6, #9b6fd6);
  -webkit-background-clip: text;
  background-clip: text;
}
[data-theme="light"] .verse-of-day {
  background: linear-gradient(135deg, rgba(74,111,214,.06), rgba(155,111,214,.04));
  border-color: rgba(74,111,214,.18);
}
[data-theme="light"] .msg-crisis {
  background: rgba(239,100,97,.06);
}

/* ── Updated Typing Indicator ─────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}
.typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
.typing-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Language Selector ────────────────────────────────────────── */
.lang-selector {
  position: relative;
}
.lang-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: 6px 0;
  min-width: 150px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 300;
}
.lang-option {
  display: block;
  width: 100%;
  padding: 9px 16px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.lang-option:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.lang-option.active {
  color: var(--accent);
  font-weight: 600;
}

/* ── RTL Support ──────────────────────────────────────────────── */
[dir="rtl"] body { direction: rtl; }
[dir="rtl"] .sidebar { border-right: none; border-left: 1px solid var(--border-light); }
[dir="rtl"] .history-item { text-align: right; }
[dir="rtl"] .new-chat-btn { flex-direction: row-reverse; }
[dir="rtl"] .msg-row { direction: rtl; }
[dir="rtl"] .msg-body { text-align: right; }
[dir="rtl"] .msg-body blockquote { border-left: none; border-right: 3px solid var(--accent); padding: 4px 16px 4px 0; }
[dir="rtl"] .input-bar { padding: 8px 20px 8px 10px; }
[dir="rtl"] .msg-body .arabic { text-align: right; }
[dir="rtl"] .panel { right: auto; left: 0; border-left: none; border-right: 1px solid var(--border-light); transform: translateX(-100%); }
[dir="rtl"] .panel.open { transform: translateX(0); }
[dir="rtl"] .lang-menu { right: auto; left: 0; }
[dir="rtl"] .lang-option { text-align: right; }
[dir="rtl"] .bookmark-btn { flex-direction: row-reverse; }
[dir="rtl"] .msg-crisis { border-left: none; border-right: 4px solid var(--red); border-radius: var(--r-sm) 0 0 var(--r-sm); }

/* Urdu font */
[lang="ur"] .msg-body,
[lang="ur"] .welcome-sub,
[lang="ur"] .suggestion-text,
[lang="ur"] .disclaimer,
[lang="ur"] .panel-body,
[lang="ur"] #msgInput {
  font-family: 'Noto Nastaliq Urdu', 'Amiri', serif;
  font-size: 16px;
  line-height: 2;
}

@media (max-width: 768px) {
  [dir="rtl"] .sidebar {
    left: auto; right: 0;
    transform: translateX(100%);
  }
  [dir="rtl"] .sidebar.open { transform: translateX(0); }

  /* On mobile the topbar uses overflow-x:auto / overflow-y:hidden so
     a position:absolute dropdown anchored to .lang-selector gets
     clipped vertically. Anchor the menu to the viewport instead so it
     stays fully visible regardless of where the lang button scrolled to. */
  .lang-menu {
    position: fixed;
    top: calc(var(--topbar-h) - 4px);
    right: 8px;
    left: auto;
    margin-top: 0;
    min-width: 170px;
    max-height: calc(100vh - var(--topbar-h) - 16px);
    overflow-y: auto;
  }
  [dir="rtl"] .lang-menu { right: auto; left: 8px; }
}

/* ── Mic / Voice Input Button ─────────────────────────────────── */
.mic-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--r-full);
  border: none;
  background: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
  flex-shrink: 0;
}
.mic-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.mic-btn.recording {
  color: var(--red);
  animation: pulse-mic 1.2s ease-in-out infinite;
}
@keyframes pulse-mic {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: .7; }
}

/* ── Breathing Exercise Overlay ───────────────────────────────── */
.breathe-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(6px);
}
.breathe-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 40px 36px;
  width: 360px;
  max-width: 92vw;
  text-align: center;
  position: relative;
}
.breathe-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background var(--t-fast), color var(--t-fast);
}
.breathe-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.breathe-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.breathe-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}
.breathe-circle-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}
.breathe-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124,158,255,.25), rgba(124,158,255,.05));
  border: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 4s ease-in-out, border-color .5s, background .5s;
}
.breathe-circle.inhale {
  transform: scale(1.35);
  border-color: var(--green);
  background: radial-gradient(circle, rgba(107,207,143,.3), rgba(107,207,143,.05));
}
.breathe-circle.hold {
  transform: scale(1.35);
  border-color: var(--amber);
  background: radial-gradient(circle, rgba(232,185,49,.2), rgba(232,185,49,.05));
}
.breathe-circle.exhale {
  transform: scale(1);
  border-color: var(--accent);
  background: radial-gradient(circle, rgba(124,158,255,.2), rgba(124,158,255,.05));
}
.breathe-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: .02em;
}
.breathe-timer {
  font-size: 22px;
  font-weight: 300;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 20px;
}
.breathe-start-btn {
  padding: 11px 32px;
  border-radius: var(--r-full);
  border: 1px solid var(--accent);
  background: rgba(124,158,255,.12);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast);
}
.breathe-start-btn:hover { background: rgba(124,158,255,.22); }

/* Breathing exercise offer button in chat */
.breathe-offer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--r-full);
  border: 1px solid var(--accent);
  background: rgba(124,158,255,.08);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
  margin-top: 4px;
}
.breathe-offer-btn:hover { background: rgba(124,158,255,.18); transform: translateY(-1px); }

/* ── Dua Recommendation Card ─────────────────────────────────── */
.dua-card {
  background: linear-gradient(135deg, rgba(124,158,255,.08), rgba(107,207,143,.06));
  border: 1px solid rgba(124,158,255,.2);
  border-radius: var(--r-md);
  padding: 18px 20px;
  margin-top: 6px;
}
.dua-card-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Inline dua: lives *inside* an AI message bubble (no extra avatar/row) */
.dua-inline {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, rgba(124,158,255,.08), rgba(107,207,143,.06));
  border: 1px solid rgba(124,158,255,.18);
  border-left: 3px solid var(--accent);
}
.dua-inline-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.dua-inline .dua-arabic { margin-bottom: 6px; }
.dua-inline .dua-transliteration,
.dua-inline .dua-translation,
.dua-inline .dua-source,
.dua-inline .dua-context {
  text-align: left;
}
.dua-inline .dua-source { margin-top: 8px; }

/* Follow-up question bubble — uses default Ayrah message styling. */
.dua-arabic {
  font-family: 'Amiri', serif;
  font-size: 22px;
  line-height: 1.8;
  color: var(--text-primary);
  text-align: center;
  direction: rtl;
  margin-bottom: 8px;
  padding: 8px 0;
}
.dua-transliteration {
  font-size: 13px;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 10px;
}
.dua-translation {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 10px;
  line-height: 1.6;
}
.dua-source {
  font-size: 11.5px;
  color: var(--accent);
  text-align: center;
  font-weight: 500;
  margin-bottom: 6px;
}
.dua-context {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* ── Grounding Exercise ──────────────────────────────────────── */
.ground-modal {
  width: 420px;
  max-width: 95vw;
}
.ground-progress {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}
.ground-step {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  border: 2px solid var(--border-light);
  color: var(--text-muted);
  transition: all var(--t-med);
}
.ground-step.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(124,158,255,.12);
  transform: scale(1.15);
}
.ground-step.done {
  border-color: var(--green);
  color: var(--green);
  background: rgba(107,207,143,.12);
}
.ground-prompt {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 10px;
}
.ground-emoji {
  font-size: 36px;
  margin-bottom: 16px;
}
.ground-input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  width: 100%;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}
.ground-input {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  color: var(--text-primary);
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--t-fast);
}
.ground-input:focus {
  border-color: var(--accent);
}
.ground-done-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 8px 0;
}
.ground-offer-btn {
  border-color: var(--green) !important;
  color: var(--green) !important;
  background: rgba(107,207,143,.08) !important;
}
.ground-offer-btn:hover {
  background: rgba(107,207,143,.18) !important;
}

/* ── Weekly Emotional Report ─────────────────────────────────── */
.weekly-summary {
  text-align: center;
  margin-bottom: 20px;
}
.weekly-stat {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.weekly-dominant {
  font-size: 15px;
  color: var(--text-primary);
}
.weekly-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.weekly-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.weekly-bar-label {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 110px;
  white-space: nowrap;
}
.weekly-bar-track {
  flex: 1;
  height: 10px;
  background: var(--bg-input);
  border-radius: var(--r-full);
  overflow: hidden;
}
.weekly-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: var(--r-full);
  transition: width var(--t-med);
}
.weekly-bar-pct {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
}

/* ── Shared Add Button ───────────────────────────────────────── */
.sp-add-row {
  display: flex;
  gap: 6px;
}
.sp-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--t-fast);
}
.sp-input:focus { border-color: var(--accent); }
.sp-add-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  border: 1px solid var(--accent);
  background: rgba(124,158,255,.1);
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast);
}
.sp-add-btn:hover { background: rgba(124,158,255,.2); }

/* ── Goal Setting & Tracking ─────────────────────────────────── */
.goals-add {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.goals-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--t-fast);
}
.goals-input:focus { border-color: var(--accent); }
.goals-section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 12px 0 8px;
}
.goal-card {
  background: var(--bg-input);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.goal-card.goal-done {
  opacity: .65;
}
.goal-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.goal-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: none;
  color: var(--green);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.goal-check.checked {
  border-color: var(--green);
  background: rgba(107,207,143,.15);
}
.goal-title {
  flex: 1;
  font-size: 13.5px;
  color: var(--text-primary);
}
.goal-title-done {
  text-decoration: line-through;
  color: var(--text-muted);
}
.goal-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.goal-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-secondary);
  border-radius: var(--r-full);
  overflow: hidden;
}
.goal-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: var(--r-full);
  transition: width var(--t-med);
}
.goal-progress-text {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}
.goal-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.goal-inc-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-light);
  background: none;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
.goal-inc-btn:hover { border-color: var(--accent); color: var(--accent); }
.goal-date {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── v6.0 — Ayrah-suggested goals ───────────────────────────── */
.goal-card.goal-proposed {
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.08), transparent);
}
.goal-source-badge {
  display: inline-block;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 9px;
  margin-right: 6px;
  font-weight: 600;
  letter-spacing: 0.2px;
  background: rgba(120, 130, 145, 0.18);
  color: var(--text-muted);
}
.goal-source-badge.ayrah {
  background: rgba(212, 175, 55, 0.18);
  color: #d4af37;
}
.goal-source-badge.user {
  background: rgba(102, 153, 204, 0.18);
  color: #8ab8e0;
}
.goal-rationale {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 6px 0 8px 0;
  line-height: 1.45;
  font-style: italic;
}
.goal-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.goal-days {
  font-size: 11.5px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  padding: 2px 8px;
  border-radius: 8px;
}
.goal-accept-btn,
.goal-dismiss-btn {
  flex: 1;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-light);
  background: none;
  color: var(--text-secondary);
  font-size: 12.5px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.goal-accept-btn {
  border-color: rgba(212, 175, 55, 0.5);
  color: #d4af37;
}
.goal-accept-btn:hover {
  background: rgba(212, 175, 55, 0.15);
}
.goal-dismiss-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

/* ── Daily Check-in Banner ───────────────────────────────────── */
.checkin-banner {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  z-index: 600;
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  max-width: 480px;
  width: 95%;
}
.checkin-banner.show {
  transform: translateX(-50%) translateY(12px);
}
.checkin-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  padding: 16px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  position: relative;
}
.checkin-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 12px;
}
.checkin-emojis {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.checkin-emoji {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  background: var(--bg-input);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
.checkin-emoji:hover {
  border-color: var(--accent);
  transform: scale(1.12);
  background: rgba(124,158,255,.1);
}
.checkin-dismiss {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 4px;
  transition: color var(--t-fast);
}
.checkin-dismiss:hover { color: var(--text-primary); }
