/* ============================================================
   MohdChat – Global Styles
   ============================================================ */

:root {
  --primary:       #1a6b5a;
  --primary-light: #2a8a74;
  --primary-dark:  #134e42;
  --gold:          #c9a84c;
  --gold-light:    #e8c97a;
  --bg:            #0f1117;
  --bg-2:          #161b22;
  --bg-3:          #1e242e;
  --surface:       #21282f;
  --border:        #2d3748;
  --text:          #e8edf3;
  --text-muted:    #8a9ab5;
  --text-light:    #c0cce0;
  --user-bubble:   #1a6b5a;
  --ai-bubble:     #1e2530;
  --radius:        14px;
  --sidebar-w:     280px;
  --font-main:     'Inter', system-ui, sans-serif;
  --font-arabic:   'Amiri', serif;
  --shadow:        0 4px 24px rgba(0,0,0,.4);
  --transition:    .22s cubic-bezier(.4,0,.2,1);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition);
  z-index: 200;
  height: 100dvh;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo-img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold);
  flex-shrink: 0;
}
.logo-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand {
  font-size: .95rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: .02em;
  white-space: nowrap;
}
.tagline {
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 12px 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
}
.new-chat-btn:hover { opacity: .9; transform: translateY(-1px); }
.new-chat-btn i { font-size: .85rem; }

.history-label {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 6px 16px 4px;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: .84rem;
  color: var(--text-light);
  transition: background var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-3); }
.history-item.active { background: var(--surface); color: var(--text); }
.history-item i { color: var(--text-muted); font-size: .8rem; flex-shrink: 0; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lang-selector-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.lang-selector-wrap label {
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
}
.lang-select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-main);
  font-size: .82rem;
  padding: 7px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
.lang-select:focus { border-color: var(--primary-light); }
.lang-select option { background: var(--bg-2); }

.footer-note {
  font-size: .7rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.footer-note i { color: var(--gold); margin-right: 4px; }
.footer-note em { font-family: var(--font-arabic); font-style: normal; color: var(--gold-light); }

/* ============================================================
   MAIN WRAP
   ============================================================ */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  min-width: 0;
}

/* ---- TOP BAR ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.topbar-brand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}
.model-badge {
  font-size: .72rem;
  background: rgba(201,168,76,.12);
  color: var(--gold-light);
  border: 1px solid rgba(201,168,76,.3);
  border-radius: 20px;
  padding: 3px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.model-badge i { font-size: .65rem; }
.topbar-actions { display: flex; gap: 6px; }

/* ---- BUTTONS ---- */
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-3); color: var(--text); }
.sidebar-close { display: none; }

/* ============================================================
   CHAT AREA
   ============================================================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  position: relative;
}

/* ---- WELCOME SCREEN ---- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
  animation: fadeUp .5s ease both;
}
.welcome-logo img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  object-fit: cover;
  box-shadow: 0 0 40px rgba(201,168,76,.25);
  margin-bottom: 20px;
}
.welcome-title {
  font-size: 1.7rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
  line-height: 1.25;
}
.welcome-sub {
  font-size: .95rem;
  color: var(--text-muted);
  max-width: 520px;
  line-height: 1.6;
  margin-bottom: 32px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 620px;
  width: 100%;
}
.suggestion-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: .84rem;
  color: var(--text-light);
  font-family: var(--font-main);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  line-height: 1.45;
}
.suggestion-card:hover {
  border-color: var(--primary-light);
  background: var(--surface);
  transform: translateY(-2px);
}
.suggestion-card i {
  color: var(--gold);
  font-size: .9rem;
  margin-top: 2px;
  flex-shrink: 0;
}

/* ---- MESSAGES CONTAINER ---- */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 20px 0 8px;
}

/* ---- MESSAGE ROW ---- */
.message-row {
  display: flex;
  padding: 6px 20px;
  gap: 14px;
  animation: fadeUp .28s ease both;
}
.message-row.user { flex-direction: row-reverse; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  margin-top: 2px;
}
.avatar.ai-avatar {
  background: var(--primary-dark);
  border: 2px solid var(--gold);
  overflow: hidden;
}
.avatar.ai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar.user-avatar {
  background: var(--surface);
  border: 2px solid var(--primary-light);
  color: var(--primary-light);
}

.message-content {
  max-width: 72%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message-row.user .message-content { align-items: flex-end; }

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.65;
  font-size: .92rem;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.bubble.ai {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  color: var(--text);
}
.bubble.user {
  background: var(--user-bubble);
  border-top-right-radius: 4px;
  color: #fff;
}
/* RTL Arabic content */
.bubble[dir="rtl"] { font-family: var(--font-arabic); font-size: 1rem; text-align: right; }

.message-meta {
  font-size: .7rem;
  color: var(--text-muted);
  padding: 0 4px;
}

/* ---- TYPING INDICATOR ---- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-top-left-radius: 4px;
  width: fit-content;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary-light);
  animation: bounce .9s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }

/* ---- Markdown-like formatting inside AI bubbles ---- */
.bubble.ai strong { color: var(--gold-light); font-weight: 600; }
.bubble.ai em { color: var(--text-light); font-style: italic; }
.bubble.ai ul, .bubble.ai ol { padding-left: 20px; margin: 6px 0; }
.bubble.ai li { margin: 3px 0; }
.bubble.ai blockquote {
  border-left: 3px solid var(--gold);
  padding: 4px 12px;
  margin: 8px 0;
  background: rgba(201,168,76,.07);
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--text-light);
}
.bubble.ai h3 { color: var(--gold-light); font-size: .95rem; margin: 6px 0 2px; }
.bubble.ai code {
  background: rgba(255,255,255,.07);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: .85rem;
}

/* ============================================================
   INPUT AREA
   ============================================================ */
.input-area {
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  padding: 14px 20px 16px;
  flex-shrink: 0;
}
.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-box:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(42,138,116,.15);
}
.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-main);
  font-size: .92rem;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
  padding: 4px 4px;
  scrollbar-width: thin;
}
.chat-input::placeholder { color: var(--text-muted); }
.send-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: 10px;
  color: #fff;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .9rem;
  flex-shrink: 0;
  transition: opacity var(--transition), transform var(--transition);
}
.send-btn:hover { opacity: .88; transform: scale(1.05); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.mic-btn { color: var(--text-muted); }
.mic-btn.recording { color: #e05555; animation: pulse 1s infinite; }

.input-footer-note {
  font-size: .68rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
}
.input-footer-note em { font-family: var(--font-arabic); font-style: normal; color: var(--gold-light); }

/* ============================================================
   OVERLAY (mobile)
   ============================================================ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 100;
}
.overlay.active { display: block; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   RTL LANGUAGE SUPPORT
   ============================================================ */
html[dir="rtl"] .sidebar { border-right: none; border-left: 1px solid var(--border); }
html[dir="rtl"] .message-row.user { flex-direction: row; }
html[dir="rtl"] .message-row { flex-direction: row-reverse; }
html[dir="rtl"] .message-row.user .message-content { align-items: flex-start; }
html[dir="rtl"] .suggestion-card { text-align: right; flex-direction: row-reverse; }
html[dir="rtl"] .bubble.user { border-top-right-radius: 18px; border-top-left-radius: 4px; }
html[dir="rtl"] .bubble.ai { border-top-left-radius: 18px; border-top-right-radius: 4px; }
html[dir="rtl"] .chat-input { text-align: right; direction: rtl; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .main-wrap { width: 100%; }

  .suggestion-grid { grid-template-columns: 1fr; }
  .welcome-title { font-size: 1.3rem; }
  .message-content { max-width: 86%; }
  .topbar { padding: 10px 14px; }
  .input-area { padding: 10px 12px 12px; }

  html[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    transform: translateX(100%);
  }
  html[dir="rtl"] .sidebar.open { transform: translateX(0); }
}

@media (max-width: 440px) {
  .welcome-logo img { width: 72px; height: 72px; }
  .welcome-title { font-size: 1.15rem; }
  .welcome-sub { font-size: .85rem; }
  .model-badge { display: none; }
}
