:root {
  --bg: #f7f3ee;
  --bg2: #ede8e0;
  --surface: #ffffff;
  --surface2: #f0ebe3;
  --border: #d9d0c4;
  --text: #2c2416;
  --text2: #7a6e62;
  --accent: #2d6a4f;
  --accent2: #40916c;
  --accent-light: #d8f3dc;
  --gold: #b5893a;
  --gold-light: #f4e4c0;
  --arabic: #1b4332;
  --shadow: 0 2px 16px rgba(44,36,22,0.08);
  --shadow-lg: 0 8px 32px rgba(44,36,22,0.13);
  --pattern-color: rgba(45,106,79,0.06);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0f1a14;
  --bg2: #141f18;
  --surface: #1a2a1f;
  --surface2: #1f3328;
  --border: #2a3d30;
  --text: #e8e0d5;
  --text2: #8a9e90;
  --accent: #52b788;
  --accent2: #74c69d;
  --accent-light: #1b4332;
  --gold: #d4a853;
  --gold-light: #2d2010;
  --arabic: #95d5b2;
  --shadow: 0 2px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --pattern-color: rgba(82,183,136,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Islamic Geometric Background Pattern ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    repeating-linear-gradient(45deg, var(--pattern-color) 0px, var(--pattern-color) 1px, transparent 1px, transparent 28px),
    repeating-linear-gradient(-45deg, var(--pattern-color) 0px, var(--pattern-color) 1px, transparent 1px, transparent 28px);
  pointer-events: none;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image: radial-gradient(circle, var(--pattern-color) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: 14px 14px;
  pointer-events: none;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 2px 8px rgba(45,106,79,0.3);
}

.logo-text h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  line-height: 1.1;
}

.logo-text span {
  font-size: 10px;
  color: var(--text2);
  font-weight: 400;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
  color: var(--text);
}

.theme-toggle:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px;
  position: relative;
  z-index: 1;
}

/* ── Welcome ── */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0 20px;
  text-align: center;
  gap: 24px;
}

.welcome-ornament {
  font-family: 'Amiri', serif;
  font-size: 28px;
  color: var(--gold);
  letter-spacing: 2px;
  line-height: 1.6;
  opacity: 0.9;
}

.welcome h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.welcome p {
  font-size: 14px;
  color: var(--text2);
  max-width: 300px;
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 400px;
}

.suggestion-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  color: var(--text2);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

.suggestion-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.suggestion-btn .s-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* ── Messages ── */
.messages {
  flex: 1;
  padding: 20px 0;
  display: none;
  flex-direction: column;
  gap: 20px;
}

.messages.visible { display: flex; }

.message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { align-items: flex-end; }

.message.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 2px 12px rgba(45,106,79,0.25);
}

.message.assistant { align-items: flex-start; }

.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 4px;
  padding: 16px;
  max-width: 100%;
  font-size: 14px;
  line-height: 1.7;
  box-shadow: var(--shadow);
}

.assistant-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.assistant-avatar {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.assistant-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.3px;
}

.answer-text {
  color: var(--text);
  white-space: pre-wrap;
}

/* ── Ayah Cards ── */
.ayah-cards {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ayah-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  padding: 14px;
  transition: all 0.2s;
}

.ayah-card:hover {
  border-left-color: var(--accent);
  box-shadow: var(--shadow);
}

.ayah-ref {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ayah-ref::before {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
}

.ayah-arabic {
  font-family: 'Amiri', serif;
  font-size: 20px;
  color: var(--arabic);
  text-align: right;
  direction: rtl;
  line-height: 1.8;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.ayah-english {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.6;
  font-style: italic;
}

/* ── Typing Indicator ── */
.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 4px;
  width: fit-content;
  box-shadow: var(--shadow);
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.typing-text {
  font-size: 12px;
  color: var(--text2);
}

/* ── Error ── */
.error-bubble {
  background: #fff0f0;
  border: 1px solid #ffcccc;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  color: #c0392b;
}

[data-theme="dark"] .error-bubble {
  background: #2a1515;
  border-color: #5c2020;
  color: #e87070;
}

/* ── Input Area ── */
.input-area {
  position: sticky;
  bottom: 0;
  z-index: 100;
  background: var(--bg);
  padding: 12px 0 20px;
  border-top: 1px solid var(--border);
}

.input-area::before {
  content: '';
  position: absolute;
  top: -20px;
  left: 0;
  right: 0;
  height: 20px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
}

.input-wrapper {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow-lg);
  transition: border-color 0.2s;
}

.input-row:focus-within {
  border-color: var(--accent);
}

textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  color: var(--text);
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  min-height: 22px;
}

textarea::placeholder { color: var(--text2); }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(45,106,79,0.3);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(45,106,79,0.4);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.send-btn svg {
  width: 16px;
  height: 16px;
  fill: white;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text2);
  margin-top: 8px;
  opacity: 0.7;
}

/* ── Section Divider ── */
.section-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
}

.section-divider span {
  font-size: 11px;
  color: var(--text2);
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.answer-text h1, .answer-text h2, .answer-text h3 {
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  margin: 12px 0 6px;
}

.answer-text p {
  margin-bottom: 10px;
}

.answer-text strong {
  color: var(--text);
  font-weight: 700;
}

.answer-text em {
  color: var(--text2);
  font-style: italic;
}

.answer-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.answer-text blockquote {
  border-left: 3px solid var(--gold);
  padding-left: 12px;
  color: var(--text2);
  font-style: italic;
  margin: 10px 0;
}