/* ═══════════════════════════════════════════════════════════════════
   AI Forum Lab — Main Stylesheet
   Theme: dark/light via [data-theme]
   Direction: RTL (ar) / LTR (en) via [data-lang] on <html>
   ═══════════════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --bg: #0f172a; --bg2: #1e293b; --bg3: #334155; --bg4: #475569;
  --text: #e2e8f0; --text2: #94a3b8; --text3: #64748b;
  --accent: #6366f1; --accent2: #818cf8; --accent-soft: #312e81;
  --green: #22c55e; --red: #ef4444; --orange: #f59e0b; --cyan: #06b6d4;
  --border: #334155; --radius: 10px; --radius-sm: 6px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --font-ar: 'IBM Plex Sans Arabic', sans-serif;
  --font-en: 'Inter', sans-serif;
}
[data-theme="light"] {
  --bg: #f8fafc; --bg2: #ffffff; --bg3: #f1f5f9; --bg4: #e2e8f0;
  --text: #1e293b; --text2: #475569; --text3: #94a3b8;
  --border: #e2e8f0; --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --accent-soft: #e0e7ff;
}

/* ── Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-ar), var(--font-en), sans-serif;
  font-size: 15px;
  background: var(--bg); color: var(--text); min-height: 100vh;
  transition: background 0.3s, color 0.3s; line-height: 1.7;
}
[data-lang="en"] body { font-family: var(--font-en), sans-serif; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e293b 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.header-brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.header-brand .logo { font-size: 26px; }
.header-brand h1 {
  font-size: 16px; font-weight: 700;
  background: linear-gradient(90deg, #a5b4fc, #67e8f9);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-brand .sub { font-size: 11px; color: var(--text3); display: block; margin-top: -4px; }
.header-controls { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  color: var(--text2); width: 36px; height: 36px; border-radius: var(--radius-sm);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: all 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); color: var(--text); }
.lang-toggle {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  color: var(--text2); padding: 4px 12px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 12px; font-weight: 600; transition: all 0.2s;
}
.lang-toggle:hover { background: rgba(255,255,255,0.15); color: var(--text); }

.body-wrap {
  display: flex; flex: 1;
  max-width: 1300px; margin: 0 auto; width: 100%; padding: 0 16px;
}

.sidebar {
  width: 260px; flex-shrink: 0; padding: 20px 0;
  position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto;
}
.main-content { flex: 1; min-width: 0; padding: 20px 0 40px 20px; }
[data-lang="en"] .main-content { padding: 20px 20px 40px 0; }

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar-section { margin-bottom: 24px; }
.sidebar-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--text3);
  padding: 0 12px 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.sidebar-nav-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
  color: var(--text2); transition: all 0.15s;
  border: none; background: none; width: 100%; text-align: right;
}
[data-lang="en"] .sidebar-nav-item { text-align: left; }
.sidebar-nav-item:hover { background: var(--bg3); color: var(--text); }
.sidebar-nav-item.active { background: var(--accent-soft); color: var(--accent2); font-weight: 600; }
.sidebar-nav-item .icon { font-size: 16px; flex-shrink: 0; }

.cat-header {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px;
  font-size: 12px; font-weight: 700; color: var(--text2); cursor: pointer;
  border-radius: var(--radius-sm); transition: background 0.15s;
}
.cat-header:hover { background: var(--bg3); }
.cat-subs { padding-right: 8px; }
[data-lang="en"] .cat-subs { padding-right: 0; padding-left: 8px; }
.sub-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 20px; font-size: 12px; color: var(--text2);
  cursor: pointer; border-radius: var(--radius-sm); transition: all 0.15s;
  border: none; background: none; width: 100%; text-align: right;
}
[data-lang="en"] .sub-item { text-align: left; padding: 5px 20px 5px 12px; }
.sub-item:hover { background: var(--bg3); color: var(--text); }
.sub-item.active { background: var(--accent-soft); color: var(--accent2); }
.sub-item::before { content: '›'; color: var(--text3); font-size: 14px; }

/* ── Stats bar ─────────────────────────────────────────────────────── */
.stats-bar {
  display: flex; gap: 12px; margin-bottom: 20px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 20px;
}
.stat-item { text-align: center; flex: 1; }
.stat-value { font-size: 20px; font-weight: 700; color: var(--accent2); }
.stat-label { font-size: 10px; color: var(--text3); text-transform: uppercase; }

/* ── AI Status Bar ─────────────────────────────────────────────────── */
.ai-status-bar {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
  margin-bottom: 16px; display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text2);
}
.ai-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text3); flex-shrink: 0; }
.ai-dot.active { background: var(--green); animation: pulse 2s infinite; }

/* ── Section Header ────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 16px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.section-title .icon { font-size: 20px; }

/* ── Topic Card ────────────────────────────────────────────────────── */
.topic-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  margin-bottom: 10px; cursor: pointer; transition: all 0.2s;
  display: flex; gap: 14px; align-items: flex-start;
}
.topic-card:hover {
  border-color: var(--accent); transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.15);
}
.topic-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); display: flex; align-items: center;
  justify-content: center; font-size: 20px;
}
.topic-body-wrap { flex: 1; min-width: 0; }
.topic-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; line-height: 1.4; }
.topic-excerpt { font-size: 13px; color: var(--text2); line-height: 1.6; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.topic-meta { display: flex; align-items: center; gap: 12px; margin-top: 8px; font-size: 12px; color: var(--text3); flex-wrap: wrap; }

.badge-ai {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white; font-size: 9px; padding: 1px 6px; border-radius: 8px;
  font-weight: 700; letter-spacing: 0.5px; vertical-align: middle;
}

/* ── Topic Detail ──────────────────────────────────────────────────── */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text2); font-size: 13px; cursor: pointer;
  padding: 6px 0; margin-bottom: 16px; background: none; border: none; transition: color 0.2s;
}
.back-btn:hover { color: var(--accent2); }

.topic-detail-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-bottom: 20px;
}
.topic-detail-title { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 16px; line-height: 1.4; }
.topic-detail-author {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.author-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 20px; }
.author-name { font-size: 14px; font-weight: 600; }
.author-acad-title { font-size: 11px; color: var(--text3); margin-top: 2px; }
.topic-detail-body { font-size: 15px; line-height: 1.95; color: var(--text); white-space: pre-wrap; }

/* ── Comments ──────────────────────────────────────────────────────── */
.comments-section { margin-top: 20px; }
.comments-title { font-size: 14px; font-weight: 700; color: var(--text2); margin-bottom: 16px; display: flex; align-items: center; gap: 6px; }
.comment-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 10px;
  display: flex; gap: 12px;
}
.comment-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.comment-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.comment-author { font-size: 12px; font-weight: 700; color: var(--accent2); }
.comment-acad-title { font-size: 10px; color: var(--text3); }
.comment-time { font-size: 10px; color: var(--text3); }
.comment-text { font-size: 14px; color: var(--text); line-height: 1.75; white-space: pre-wrap; }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-top: 20px;
}
.form-card h3 { font-size: 14px; font-weight: 700; color: var(--text2); margin-bottom: 16px; }
.form-row { margin-bottom: 12px; }
.form-row label {
  display: block; font-size: 11px; color: var(--text3);
  margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-row input, .form-row textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 13px; font-family: inherit;
  outline: none; transition: border-color 0.2s; resize: vertical;
}
.form-row input:focus, .form-row textarea:focus { border-color: var(--accent); }
.form-row textarea { min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-ghost { background: var(--bg3); color: var(--text2); }
.btn-ghost:hover { background: var(--bg4); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Feed ──────────────────────────────────────────────────────────── */
.feed-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 10px;
  cursor: pointer; transition: all 0.2s;
}
.feed-item:hover { border-color: var(--accent); }
.feed-type { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.feed-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.feed-body { font-size: 12px; color: var(--text2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.feed-footer { font-size: 10px; color: var(--text3); margin-top: 6px; }

/* ── Personas Grid ─────────────────────────────────────────────────── */
.personas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.persona-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 16px; text-align: center; transition: all 0.2s;
}
.persona-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.persona-emoji { font-size: 40px; margin-bottom: 10px; }
.persona-name { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.persona-acad-title { font-size: 10px; color: var(--text3); line-height: 1.4; margin-bottom: 8px; }
.persona-tags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.persona-tag { background: var(--bg3); color: var(--text3); font-size: 9px; padding: 2px 6px; border-radius: 8px; }

/* ── Empty / Loading ───────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }
.loading-page { display: flex; align-items: center; justify-content: center; height: 200px; gap: 10px; color: var(--text3); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }

/* ── Toast ─────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 18px; font-size: 13px; font-weight: 500;
  transform: translateY(100px); opacity: 0; transition: all 0.3s; max-width: 320px;
}
[data-lang="en"] #toast { right: auto; left: 24px; }
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-color: var(--green); }
#toast.error { border-color: var(--red); }

/* ── Animations ────────────────────────────────────────────────────── */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn 0.3s ease; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 16px 0; }
  .stats-bar { flex-wrap: wrap; gap: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .header-brand .sub { display: none; }
}
