/* ═══════════════════════════════════════════════════════════
   TAIM AI LAB — Design System & Styles
   Product: Taim AI Lab | مختبر تيم للذكاء الاصطناعي
   Brand: Taim Academy | أكاديمية تيم
   Subdomain: ai.taim.om
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&display=swap');

/* ─── CSS VARIABLES ─── */
:root {
  /* Brand Colors */
  --navy:              #091C3A;
  --navy-light:        #122850;
  --navy-mid:          #1e3a5f;
  --navy-surface:      #0d2440;
  --accent:            #D96C4E;
  --accent-light:      #e8896f;
  --accent-hover:      #c45a3c;
  --accent-glow:       rgba(217, 108, 78, 0.15);

  /* UI Colors */
  --success:           #10b981;
  --success-bg:        rgba(16,185,129,0.1);
  --warning:           #f59e0b;
  --warning-bg:        rgba(245,158,11,0.1);
  --danger:            #ef4444;
  --danger-bg:         rgba(239,68,68,0.1);
  --info:              #3b82f6;
  --info-bg:           rgba(59,130,246,0.1);

  /* Neutrals */
  --white:             #ffffff;
  --gray-50:           #f8fafc;
  --gray-100:          #f1f5f9;
  --gray-200:          #e2e8f0;
  --gray-300:          #cbd5e1;
  --gray-400:          #94a3b8;
  --gray-500:          #64748b;
  --gray-600:          #475569;
  --gray-700:          #334155;
  --gray-800:          #1e293b;
  --gray-900:          #0f172a;
  --text:              #1e293b;
  --text-muted:        #64748b;
  --text-light:        #94a3b8;

  /* Layout */
  --sidebar-width:     280px;
  --header-height:     64px;
  --radius-sm:         6px;
  --radius-md:         10px;
  --radius-lg:         14px;
  --radius-xl:         20px;
  --radius-full:       50px;

  /* Shadows */
  --shadow-sm:         0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:         0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:         0 10px 28px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
  --shadow-xl:         0 20px 48px rgba(0,0,0,0.16);
  --shadow-navy:       0 8px 24px rgba(9,28,58,0.4);

  /* Typography */
  --font-en:           'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-ar:           'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;

  /* Transitions */
  --transition:        all 0.2s ease;
  --transition-slow:   all 0.35s ease;
}

/* ─── RESET & BASE ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; font-size: 16px; }
body {
  font-family: var(--font-en);
  color: var(--text);
  background: var(--gray-50);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.rtl {
  font-family: var(--font-ar);
  direction: rtl;
  text-align: right;
}
body.rtl .ltr-only { display: none !important; }
body:not(.rtl) .rtl-only { display: none !important; }

img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; }
ul, ol { list-style: none; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ═══════════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════════ */

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 480px;
  background: var(--navy);
}

.login-hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 50%, var(--navy-mid) 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 4rem;
  position: relative;
  overflow: hidden;
}
.login-hero::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217,108,78,0.12) 0%, transparent 70%);
  top: -100px; right: -200px;
}
.login-hero::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59,130,246,0.08) 0%, transparent 70%);
  bottom: -80px; left: -100px;
}

.hero-content { position: relative; z-index: 1; max-width: 480px; }

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(217,108,78,0.15);
  border: 1px solid rgba(217,108,78,0.3);
  color: var(--accent-light);
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  margin-bottom: 2rem;
}
.hero-badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2s infinite;
}

.hero-title {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--white);
  line-height: 1.2;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}
.hero-title-ar {
  font-family: var(--font-ar);
  font-size: 1.8rem;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  margin-bottom: 1.5rem;
  direction: rtl;
}
.hero-tagline {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.65);
  margin-bottom: 3rem;
}

.hero-features {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.hero-feature {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  color: rgba(255,255,255,0.8);
  font-size: 0.95rem;
}
.hero-feature-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.hero-providers {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.hero-providers-label {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
}
.provider-badges {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.provider-badge {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
}

/* Login Panel */
.login-panel {
  background: var(--white);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 3rem;
  box-shadow: var(--shadow-xl);
}

.login-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2.5rem;
}

.login-logo { height: 52px; width: auto; }

.lang-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--gray-100);
  border-radius: var(--radius-full);
  padding: 0.25rem;
}
.lang-btn {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: var(--transition);
}
.lang-btn.active {
  background: var(--white);
  color: var(--navy);
  box-shadow: var(--shadow-sm);
}
.lang-btn:hover:not(.active) { color: var(--text); }

.login-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.3rem;
}
.login-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* Form */
.form-group { margin-bottom: 1.2rem; }
.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.45rem;
}
.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--gray-50);
  transition: var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: var(--navy);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(9,28,58,0.08);
}
.form-input::placeholder { color: var(--text-light); }
.input-wrapper { position: relative; }
.input-icon {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  cursor: pointer;
  font-size: 1.05rem;
}
body.rtl .input-icon { right: auto; left: 12px; }

.btn-primary {
  width: 100%;
  padding: 0.85rem 1.5rem;
  background: var(--navy);
  color: var(--white);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.btn-primary:hover {
  background: var(--navy-light);
  box-shadow: var(--shadow-navy);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary.loading { opacity: 0.7; pointer-events: none; }

.login-notice {
  margin-top: 2rem;
  padding: 1rem 1.1rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.notice-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}

.login-help {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.login-help a { color: var(--accent); font-weight: 500; }
.login-help a:hover { color: var(--accent-hover); }

.login-error {
  background: var(--danger-bg);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  margin-bottom: 1rem;
  display: none;
}
.login-error.show { display: block; }


/* ═══════════════════════════════════════════════════════════
   APP SHELL — SIDEBAR + MAIN
   ═══════════════════════════════════════════════════════════ */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--gray-50);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition-slow);
  position: relative;
  z-index: 100;
}
body.rtl .sidebar { border-right: none; }

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.sidebar-logo { height: 42px; width: auto; }

.sidebar-section {
  padding: 0.75rem 0.75rem 0.5rem;
  flex-shrink: 0;
}
.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 0.5rem;
  margin-bottom: 0.25rem;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,0.6);
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}
.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.9);
}
.nav-item.active {
  background: rgba(217,108,78,0.18);
  color: var(--white);
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { font-size: 1.05rem; flex-shrink: 0; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}
body.rtl .nav-badge { margin-left: 0; margin-right: auto; }

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.75rem;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  color: rgba(255,255,255,0.55);
  font-size: 0.82rem;
  position: relative;
}
.conv-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.8); }
.conv-item.active { background: rgba(255,255,255,0.09); color: rgba(255,255,255,0.9); }
.conv-icon { font-size: 0.85rem; flex-shrink: 0; color: rgba(255,255,255,0.3); }
.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-time { font-size: 0.72rem; color: rgba(255,255,255,0.25); flex-shrink: 0; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.user-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}
.user-card:hover { background: rgba(255,255,255,0.07); }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.user-name { font-size: 0.85rem; font-weight: 600; color: rgba(255,255,255,0.85); }
.user-role { font-size: 0.75rem; color: rgba(255,255,255,0.4); }
.user-actions { margin-left: auto; display: flex; gap: 0.25rem; }
body.rtl .user-actions { margin-left: 0; margin-right: auto; }
.user-action-btn {
  color: rgba(255,255,255,0.4);
  font-size: 0.9rem;
  padding: 0.2rem;
  border-radius: 4px;
  transition: var(--transition);
}
.user-action-btn:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.08); }


/* ─── MAIN CONTENT ─── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Header */
.main-header {
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 50;
}
.header-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
}
.header-subtitle { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }

.header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* Credit Indicator */
.credit-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-full);
  padding: 0.35rem 0.9rem;
  cursor: default;
}
.credit-icon { font-size: 0.9rem; color: var(--accent); }
.credit-text { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.credit-bar-wrap {
  width: 60px;
  height: 4px;
  background: var(--gray-200);
  border-radius: 99px;
  overflow: hidden;
}
.credit-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  transition: width 0.5s ease;
}
.credit-bar.warning { background: var(--warning); }
.credit-bar.danger { background: var(--danger); }

/* Header Button */
.hdr-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 1rem;
  transition: var(--transition);
}
.hdr-btn:hover { background: var(--gray-100); color: var(--text); }


/* ═══════════════════════════════════════════════════════════
   STUDENT CHAT INTERFACE
   ═══════════════════════════════════════════════════════════ */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Model Selector Bar */
.model-bar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  padding: 0.6rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow-x: auto;
  flex-shrink: 0;
}
.model-bar-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.model-options {
  display: flex;
  gap: 0.5rem;
}
.model-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--gray-200);
  background: var(--white);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.model-chip:hover { border-color: var(--navy); color: var(--navy); }
.model-chip.active {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--white);
}
.model-chip .chip-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.model-chip.tier-fast .chip-dot { background: var(--success); }
.model-chip.tier-smart .chip-dot { background: var(--info); }
.model-chip.tier-premium .chip-dot { background: var(--accent); }
.model-chip.tier-compare .chip-dot { background: var(--warning); }
.model-chip.active .chip-dot { background: rgba(255,255,255,0.7); }

.model-cost-badge {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}
body.rtl .model-cost-badge { margin-left: 0; margin-right: auto; }

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.messages-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  gap: 1rem;
}
.empty-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy), var(--navy-mid));
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  margin-bottom: 0.5rem;
}
.empty-title { font-size: 1.2rem; font-weight: 700; color: var(--navy); }
.empty-subtitle { font-size: 0.9rem; color: var(--text-muted); max-width: 380px; }

/* Prompt Templates Grid */
.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  width: 100%;
  max-width: 680px;
  margin-top: 0.5rem;
}
.prompt-chip {
  padding: 0.65rem 0.9rem;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 0.83rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
  line-height: 1.4;
}
.prompt-chip:hover {
  border-color: var(--navy);
  color: var(--navy);
  box-shadow: var(--shadow-sm);
}
body.rtl .prompt-chip { text-align: right; }

/* Message Bubbles */
.message {
  display: flex;
  gap: 0.85rem;
  max-width: 820px;
  width: 100%;
}
.message.user { margin-left: auto; flex-direction: row-reverse; }
body.rtl .message.user { margin-left: 0; margin-right: auto; flex-direction: row; }
body.rtl .message.assistant { flex-direction: row-reverse; }

.message-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}
.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
}
.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--navy), var(--navy-mid));
  color: white;
}

.message-body { flex: 1; min-width: 0; }
.message-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.message-sender { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.message-model-tag {
  font-size: 0.72rem;
  background: var(--gray-100);
  color: var(--text-muted);
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
}
.message-time { font-size: 0.72rem; color: var(--text-light); margin-left: auto; }
body.rtl .message-time { margin-left: 0; margin-right: auto; }

.message-bubble {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-lg);
  font-size: 0.92rem;
  line-height: 1.7;
}
.message.user .message-bubble {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}
body.rtl .message.user .message-bubble { border-bottom-right-radius: var(--radius-lg); border-bottom-left-radius: 4px; }
.message.assistant .message-bubble {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--gray-100);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
body.rtl .message.assistant .message-bubble { border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: 4px; }

/* Streaming cursor */
.typing-cursor::after {
  content: '▋';
  animation: blink 0.8s step-start infinite;
  color: var(--accent);
}

.message-actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.4rem;
  opacity: 0;
  transition: var(--transition);
}
.message:hover .message-actions { opacity: 1; }
.msg-action-btn {
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: var(--transition);
  display: flex; align-items: center; gap: 0.3rem;
}
.msg-action-btn:hover { background: var(--gray-100); color: var(--text); }

/* Credit warning banners */
.credit-warning {
  margin: 0 1.5rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}
.credit-warning.low { background: var(--warning-bg); border: 1px solid rgba(245,158,11,0.3); color: #92400e; }
.credit-warning.critical { background: var(--danger-bg); border: 1px solid rgba(239,68,68,0.3); color: #991b1b; }
.credit-warning.empty { background: var(--danger-bg); border: 1px solid rgba(239,68,68,0.4); color: #991b1b; font-weight: 500; }

/* Input Area */
.input-area {
  background: var(--white);
  border-top: 1px solid var(--gray-100);
  padding: 1rem 1.5rem;
  flex-shrink: 0;
}
.input-wrapper-main {
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-xl);
  transition: var(--transition);
  overflow: hidden;
}
.input-wrapper-main:focus-within {
  border-color: var(--navy);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(9,28,58,0.07);
}
.chat-textarea {
  width: 100%;
  padding: 0.9rem 1.2rem;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  color: var(--text);
  resize: none;
  outline: none;
  min-height: 52px;
  max-height: 160px;
  line-height: 1.6;
  display: block;
}
.chat-textarea::placeholder { color: var(--text-light); }
.input-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-top: 1px solid var(--gray-200);
}
.toolbar-btn {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: var(--transition);
  display: flex; align-items: center; gap: 0.3rem;
}
.toolbar-btn:hover { background: var(--gray-100); color: var(--text); }
.send-btn {
  margin-left: auto;
  padding: 0.45rem 1.1rem;
  background: var(--navy);
  color: var(--white);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  transition: var(--transition);
  display: flex; align-items: center; gap: 0.4rem;
}
body.rtl .send-btn { margin-left: 0; margin-right: auto; }
.send-btn:hover:not(:disabled) { background: var(--navy-light); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.input-hint {
  font-size: 0.75rem;
  color: var(--text-light);
  text-align: center;
  margin-top: 0.5rem;
}

/* ── Drag-over highlight ──────────────────────────────────── */
.input-area.drag-over {
  background: rgba(217,108,78,.04);
  border-top-color: var(--coral);
  outline: 2px dashed var(--coral);
  outline-offset: -4px;
}

/* ── Attachment preview row ──────────────────────────────── */
.attachment-preview-row {
  padding: 0.5rem 0.75rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
}
.att-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  padding: 0.3rem 0.7rem 0.3rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text-mid);
  max-width: 200px;
  position: relative;
  transition: border-color .15s;
}
.att-chip:hover { border-color: var(--coral); }
.att-chip-icon { font-size: 1rem; flex-shrink: 0; }
.att-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 130px;
}
.att-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 0;
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}
.att-chip-remove:hover { color: var(--error); }
.att-chip-thumb {
  width: 28px; height: 28px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}
.att-chip.uploading { opacity: .6; }
.att-chip.error { border-color: var(--error); color: var(--error); }

/* ── Recording indicator ─────────────────────────────────── */
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  background: #fff5f5;
  border-top: 1px solid #fed7d7;
  font-size: 0.82rem;
  color: var(--error);
  font-weight: 500;
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--error);
  animation: recPulse 1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.8); }
}
.rec-cancel-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--error);
  font-size: 1rem;
  padding: 0 4px;
}
/* Active mic button */
#mic-btn.recording { color: var(--error); background: #fff5f5; }

/* ── Message attachment display ──────────────────────────── */
.msg-attachments {
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.msg-att-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 12px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
}
.msg-att-image {
  max-width: 320px;
  max-height: 240px;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  display: block;
  cursor: zoom-in;
}
/* Image lightbox */
.img-lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
}
.img-lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }


/* ═══════════════════════════════════════════════════════════
   COMPARE MODE
   ═══════════════════════════════════════════════════════════ */
.compare-grid {
  display: grid;
  gap: 1rem;
  flex: 1;
  overflow: hidden;
  padding: 1rem 1.5rem;
}
.compare-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.compare-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.compare-panel {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.compare-panel-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--gray-50);
}
.compare-model-name { font-size: 0.88rem; font-weight: 600; color: var(--navy); }
.compare-tokens { font-size: 0.75rem; color: var(--text-muted); margin-left: auto; }
body.rtl .compare-tokens { margin-left: 0; margin-right: auto; }
.compare-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

/* Teaching note */
.teaching-note {
  margin: 0 1.5rem;
  padding: 0.65rem 1rem;
  background: var(--info-bg);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  color: #1e40af;
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  flex-shrink: 0;
}


/* ═══════════════════════════════════════════════════════════
   ADMIN DASHBOARD
   ═══════════════════════════════════════════════════════════ */

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.35rem;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); border-color: var(--gray-300); }
.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.1;
  margin-bottom: 0.2rem;
}
.stat-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.stat-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 0.85rem;
}
.stat-icon.orange { background: var(--accent-glow); color: var(--accent); }
.stat-icon.navy   { background: rgba(9,28,58,0.08); color: var(--navy); }
.stat-icon.green  { background: var(--success-bg); color: var(--success); }
.stat-icon.blue   { background: var(--info-bg); color: var(--info); }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red    { background: var(--danger-bg); color: var(--danger); }

.stat-trend {
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.35rem;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
}
.section-actions { display: flex; gap: 0.5rem; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: 1.5px solid transparent;
}
.btn-navy { background: var(--navy); color: white; }
.btn-navy:hover { background: var(--navy-light); box-shadow: var(--shadow-navy); }
.btn-accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-hover); }
.btn-outline { background: white; color: var(--text); border-color: var(--gray-200); }
.btn-outline:hover { border-color: var(--gray-400); box-shadow: var(--shadow-sm); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--gray-100); color: var(--text); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: white; }

/* Tables */
.table-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table-toolbar {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
.search-input {
  flex: 1;
  max-width: 280px;
  padding: 0.5rem 0.85rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition);
  background: var(--gray-50);
}
.search-input:focus { border-color: var(--navy); background: white; }
.filter-select {
  padding: 0.5rem 0.85rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  outline: none;
  background: var(--gray-50);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}
.filter-select:focus { border-color: var(--navy); }

table { width: 100%; border-collapse: collapse; }
thead { background: var(--gray-50); }
th {
  padding: 0.75rem 1.1rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
body.rtl th { text-align: right; }
td {
  padding: 0.9rem 1.1rem;
  font-size: 0.875rem;
  color: var(--text);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.td-name { font-weight: 600; color: var(--navy); }
.td-sub { font-size: 0.78rem; color: var(--text-muted); }

/* Badges/Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: var(--success-bg); color: #065f46; }
.badge-orange { background: var(--accent-glow); color: #9a3412; }
.badge-blue   { background: var(--info-bg); color: #1e40af; }
.badge-gray   { background: var(--gray-100); color: var(--text-muted); }
.badge-red    { background: var(--danger-bg); color: #991b1b; }
.badge-yellow { background: var(--warning-bg); color: #92400e; }
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* Provider Health Cards */
.providers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}
.provider-card {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.provider-card.active { border-color: rgba(16,185,129,0.3); }
.provider-card.error { border-color: rgba(239,68,68,0.3); }
.provider-card.disabled { opacity: 0.5; }
.provider-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.provider-name { font-size: 0.88rem; font-weight: 600; color: var(--navy); }
.provider-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
}
body.rtl .provider-status-dot { margin-left: 0; margin-right: auto; }
.provider-status-dot.active { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.provider-status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.provider-status-dot.disabled { background: var(--gray-300); }

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--gray-100);
  border-radius: 99px;
  overflow: hidden;
  flex: 1;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--navy), var(--navy-mid));
  transition: width 0.5s ease;
}
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }


/* ═══════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(9,28,58,0.5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(8px);
  transition: transform 0.2s ease;
}
.modal-overlay.show .modal { transform: scale(1) translateY(0); }
.modal-lg { max-width: 760px; }
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; gap: 0.75rem;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--navy); flex: 1; }
.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: var(--transition);
}
.modal-close:hover { background: var(--gray-100); color: var(--text); }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-100);
  display: flex; gap: 0.75rem; justify-content: flex-end;
}
body.rtl .modal-footer { justify-content: flex-start; }

/* ─── TABS ─── */
.tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-100);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}
.tab-item {
  padding: 0.65rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  white-space: nowrap;
}
.tab-item:hover { color: var(--navy); }
.tab-item.active { color: var(--navy); border-bottom-color: var(--navy); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }


/* ─── CARDS ─── */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.1rem;
}
.card-title { font-size: 0.92rem; font-weight: 700; color: var(--navy); }


/* ─── ACTIVITY CARDS ─── */
.activity-list { display: flex; flex-direction: column; gap: 0.75rem; }
.activity-card {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  background: var(--white);
  cursor: pointer;
  transition: var(--transition);
}
.activity-card:hover { border-color: var(--navy); box-shadow: var(--shadow-sm); }
.activity-header { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.5rem; }
.activity-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--navy);
  color: white;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.activity-title-text { font-size: 0.9rem; font-weight: 600; color: var(--navy); }
.activity-desc { font-size: 0.83rem; color: var(--text-muted); padding-left: 2.4rem; }
body.rtl .activity-desc { padding-left: 0; padding-right: 2.4rem; }
.activity-meta {
  display: flex;
  gap: 0.6rem;
  padding-left: 2.4rem;
  margin-top: 0.5rem;
}
body.rtl .activity-meta { padding-left: 0; padding-right: 2.4rem; }


/* ─── USAGE PAGE ─── */
.usage-chart-placeholder {
  height: 160px;
  background: var(--gray-50);
  border: 1px dashed var(--gray-300);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}


/* ─── NOTIFICATIONS / TOASTS ─── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
body.rtl .toast-container { right: auto; left: 1.5rem; }
.toast {
  background: var(--navy);
  color: white;
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideInUp 0.25s ease forwards;
  max-width: 320px;
}
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
.toast.warning { background: #92400e; }


/* ─── RESPONSIVE ─── */
@media (max-width: 1024px) {
  .login-page { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-panel { padding: 2.5rem 2rem; justify-content: flex-start; padding-top: 3rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 72px; }
  .sidebar .nav-item span,
  .sidebar .sidebar-section-label,
  .sidebar .conv-item .conv-title,
  .sidebar .conv-item .conv-time,
  .sidebar .user-name,
  .sidebar .user-role,
  .sidebar .user-actions,
  .sidebar .nav-badge { display: none; }
  .sidebar .nav-item { justify-content: center; padding: 0.65rem; }
  .sidebar .nav-icon { width: auto; }
  .sidebar .user-card { justify-content: center; }
  .sidebar .sidebar-header { padding: 1rem 0.75rem; justify-content: center; display: flex; }
  .sidebar .sidebar-logo { display: none; }
  .compare-grid.cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .main-header { padding: 0 1rem; }
  .page-content { padding: 1rem; }
  .messages-area { padding: 1rem; }
  .input-area { padding: 0.75rem 1rem; }
  .prompt-grid { grid-template-columns: 1fr; }
  .compare-grid.cols-2, .compare-grid.cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}


/* ─── ANIMATIONS ─── */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.8); }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
@keyframes slideInUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Markdown-like rendering in messages */
.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; }
.message-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.87em;
  font-family: 'Fira Code', 'Courier New', monospace;
}
.message.user .message-bubble code {
  background: rgba(255,255,255,0.15);
}
.message-bubble pre {
  background: var(--gray-900);
  color: #e2e8f0;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85em;
  overflow-x: auto;
  margin: 0.5rem 0;
}
.message-bubble ul, .message-bubble ol {
  padding-left: 1.25rem;
  margin: 0.35rem 0;
}
body.rtl .message-bubble ul, body.rtl .message-bubble ol { padding-left: 0; padding-right: 1.25rem; }
.message-bubble li { margin-bottom: 0.2rem; }
