/* ═══════════════════════════════════════════════
   Moroccan Student Tutor — مساعد الطالب المغربي
   Design: Warm, scholarly, Moroccan-inspired
   ═══════════════════════════════════════════════ */

:root {
  /* ── Core Palette — warm terracotta & deep teal ── */
  --bg: #FAF7F2;
  --bg-card: #FFFFFF;
  --bg-subtle: #F3EDE4;
  --surface: #FFFDF9;

  --text: #2C1810;
  --text-secondary: #6B5B4E;
  --text-muted: #9B8B7E;

  --accent: #C0622E;
  --accent-light: #E8A87C;
  --accent-bg: #FDF0E8;

  --teal: #1A6B5A;
  --teal-light: #D0EDE6;
  --teal-bg: #EDF7F4;

  --border: #E5DDD3;
  --border-light: #F0EAE0;

  --user-bubble: var(--teal);
  --user-text: #FFFFFF;
  --ai-bubble: var(--bg-card);
  --ai-border: var(--border);

  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 100px;

  --shadow-sm: 0 1px 3px rgba(44,24,16,0.06);
  --shadow-md: 0 4px 12px rgba(44,24,16,0.08);
  --shadow-lg: 0 8px 32px rgba(44,24,16,0.12);

  --font-ar: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --font-fr: 'DM Sans', 'Noto Sans Arabic', sans-serif;

  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100dvh;
  overflow: hidden;
}

[dir="ltr"] body,
body.lang-fr {
  font-family: var(--font-fr);
}

/* ── Decorative Background ── */
.bg-pattern {
  position: fixed;
  inset: 0;
  opacity: 0.025;
  background-image:
    radial-gradient(circle at 25% 25%, var(--accent) 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, var(--teal) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
}

.bg-glow--1 {
  width: 500px; height: 500px;
  background: var(--accent-light);
  top: -150px;
  right: -100px;
}

.bg-glow--2 {
  width: 400px; height: 400px;
  background: var(--teal-light);
  bottom: -100px;
  left: -80px;
}

/* ── App Shell ── */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(250, 247, 242, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  z-index: 10;
}

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

.header__icon {
  flex-shrink: 0;
}

.header__title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.header__sub {
  font-family: var(--font-fr);
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.03em;
}

.header__actions {
  display: flex;
  gap: 6px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.btn--ghost:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.btn--icon {
  background: transparent;
  color: var(--text-muted);
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn--icon:hover {
  background: var(--bg-subtle);
  color: var(--accent);
}

.btn--send {
  background: var(--accent);
  color: white;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.btn--send:hover {
  background: #A8531F;
  transform: scale(1.04);
}

.btn--send:active {
  transform: scale(0.96);
}

.btn--send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Selectors / Pills ── */
.selectors {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
}

.selector-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.selector__label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-width: 50px;
  flex-shrink: 0;
}

.pill-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.pill:hover {
  border-color: var(--accent-light);
  color: var(--accent);
}

.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(192, 98, 46, 0.25);
}

/* Level pills — teal accent for differentiation */
#levelPills .pill.active {
  background: var(--teal);
  border-color: var(--teal);
  box-shadow: 0 2px 8px rgba(26, 107, 90, 0.25);
}

#levelPills .pill:hover {
  border-color: var(--teal-light);
  color: var(--teal);
}

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

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

/* ── Welcome Screen ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  animation: fadeUp 0.6s ease-out;
}

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

.welcome__title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome__text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  max-width: 420px;
  line-height: 1.7;
  margin-bottom: 24px;
}

.welcome__hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.hint-chip {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.hint-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

/* ── Messages ── */
.message {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  animation: fadeUp 0.35s ease-out;
  max-width: 88%;
}

.message--user {
  flex-direction: row-reverse;
  margin-inline-start: auto;
}

.message--ai {
  margin-inline-end: auto;
}

.message__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 4px;
}

.message--user .message__avatar {
  background: var(--teal-light);
}

.message--ai .message__avatar {
  background: var(--accent-bg);
}

.message__bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.75;
  word-break: break-word;
  direction: auto;
}

.message--user .message__bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-end-end-radius: 4px;
}

.message--ai .message__bubble {
  background: var(--ai-bubble);
  color: var(--text);
  border: 1px solid var(--ai-border);
  border-end-start-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* AI response formatting */
.message--ai .message__bubble h1,
.message--ai .message__bubble h2,
.message--ai .message__bubble h3 {
  font-size: 1em;
  font-weight: 700;
  color: var(--accent);
  margin: 12px 0 6px;
}

.message--ai .message__bubble h1:first-child,
.message--ai .message__bubble h2:first-child,
.message--ai .message__bubble h3:first-child {
  margin-top: 0;
}

.message--ai .message__bubble p {
  margin: 6px 0;
}

.message--ai .message__bubble ul,
.message--ai .message__bubble ol {
  padding-inline-start: 20px;
  margin: 8px 0;
}

.message--ai .message__bubble li {
  margin: 4px 0;
}

.message--ai .message__bubble code {
  font-family: 'Courier New', monospace;
  background: var(--bg-subtle);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
  direction: ltr;
}

.message--ai .message__bubble pre {
  background: var(--bg-subtle);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  direction: ltr;
  text-align: left;
}

.message--ai .message__bubble strong {
  color: var(--teal);
  font-weight: 600;
}

/* OCR extracted text notice */
.message__ocr-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  margin-bottom: 8px;
}

/* ── Typing Indicator ── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  animation: fadeUp 0.3s ease-out;
}

.typing-indicator__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.typing-indicator__dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-end-start-radius: 4px;
}

.typing-indicator__dots span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-indicator__dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator__dots span:nth-child(3) { animation-delay: 0.3s; }

/* ── Input Area ── */
.input-area {
  padding: 12px 20px;
  background: rgba(250, 247, 242, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-light);
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192, 98, 46, 0.1);
}

.input-bar__textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text);
  background: transparent;
  padding: 8px 4px;
  max-height: 120px;
  direction: auto;
}

.input-bar__textarea::placeholder {
  color: var(--text-muted);
}

.input-area__note {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 8px;
  opacity: 0.8;
}

/* ── OCR Preview ── */
.ocr-preview {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-bg);
  border: 1.5px solid var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin-bottom: 8px;
}

.ocr-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
}

.ocr-preview__close {
  background: var(--accent);
  color: white;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ocr-preview__label {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
}

/* ── Error Message ── */
.error-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #D32F2F;
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  z-index: 100;
  animation: toastIn 0.3s ease-out forwards;
  box-shadow: var(--shadow-lg);
}

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

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

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

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── LTR mode ── */
body.lang-fr {
  direction: ltr;
}

body.lang-fr .message--user {
  flex-direction: row-reverse;
}

body.lang-fr .header__brand {
  flex-direction: row;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .header { padding: 10px 14px; }
  .selectors { padding: 10px 14px; gap: 8px; }
  .chat { padding: 14px; }
  .input-area { padding: 10px 14px; }

  .selector-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .pill {
    font-size: 0.72rem;
    padding: 4px 10px;
  }

  .message { max-width: 94%; }

  .welcome { padding: 24px 16px; }
  .welcome__title { font-size: 1.3rem; }
  .welcome__text { font-size: 0.85rem; }
  .hint-chip { font-size: 0.74rem; padding: 6px 12px; }

  .bg-glow--1 { width: 300px; height: 300px; }
  .bg-glow--2 { width: 250px; height: 250px; }
}

@media (max-width: 380px) {
  .pill-group { gap: 4px; }
  .pill { font-size: 0.68rem; padding: 3px 8px; }
}
