/**
 * chat.css — تنسيقات صفحة الدردشة
 * يستورد من: styles/theme.css (المتغيرات الأساسية)
 *
 * القاعدة: لا تُعرِّف :root هنا — كل المتغيرات في theme.css
 */

/* ═══ App Shell ════════════════════════════════════════════ */
html, body {
  height: 100%;
  overflow: hidden;
  direction: rtl;
}

.app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  direction: rtl;
}

/* ═══ Sidebar ══════════════════════════════════════════════ */
.chat-region {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  order: 2;
}

.sb-head {
  padding: 18px 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand .spark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(16,185,129,0.04));
  border: 1px solid var(--accent-dim);
  font-size: 15px;
  box-shadow: 0 0 18px rgba(16,185,129,0.15), inset 0 0 0 1px rgba(255,255,255,0.02);
}

.ver {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-mute);
  padding: 3px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgba(255,255,255,0.02);
  letter-spacing: 0.02em;
}

/* ═══ New Chat Button ══════════════════════════════════════ */
.new-chat {
  margin: 4px 14px 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(16,185,129,0.45);
  border-radius: 9px;
  font-size: 13.5px; font-weight: 600;
  transition: background var(--transition), border-color var(--transition), transform .05s;
}
.new-chat:hover { background: var(--accent-soft); border-color: var(--accent); }
.new-chat:active { transform: translateY(1px); }
.new-chat svg { width: 14px; height: 14px; }

/* ═══ Search ════════════════════════════════════════════════ */
.search {
  margin: 0 14px 10px;
  position: relative;
}
.search input {
  width: 100%; height: 34px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 0 32px 0 12px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
.search input::placeholder { color: var(--text-mute); }
.search input:focus { border-color: rgba(16,185,129,0.45); background: rgba(255,255,255,0.04); }
.search svg {
  position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--text-mute);
}

/* ═══ Sessions List ════════════════════════════════════════ */
.sessions {
  flex: 1; overflow-y: auto;
  padding: 6px 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,0.18) transparent;
}
.sessions::-webkit-scrollbar { width: 6px; }
.sessions::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.18); border-radius: 3px; }

.sg-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-mute);
  padding: 12px 10px 6px;
  font-weight: 600;
}

.session {
  display: block;
  padding: 8px 10px;
  border-radius: 7px;
  margin: 1px 0;
  cursor: pointer;
  position: relative;
  transition: background .12s;
  border-inline-start: 2px solid transparent;
}
.session:hover { background: rgba(255,255,255,0.035); }
.session.active {
  background: rgba(16,185,129,0.07);
  border-inline-start-color: var(--accent);
}
.session .title {
  font-size: 13px; color: var(--text); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.35;
}
.session .meta {
  display: flex; align-items: center; gap: 6px;
  margin-top: 3px;
  font-size: 11px; color: var(--text-mute);
}
.session .meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-mute); }

/* ═══ Sidebar Footer ════════════════════════════════════════ */
.sb-foot {
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.sb-links { display: flex; gap: 14px; font-size: 12px; }
.sb-links a {
  color: var(--text-dim);
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 5px;
  transition: color var(--transition);
}
.sb-links a:hover { color: var(--text); }
.sb-links svg { width: 12px; height: 12px; }

.sb-user {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 0 2px;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #0891b2);
  display: grid; place-items: center;
  color: white; font-weight: 600; font-size: 12px;
  flex-shrink: 0;
}
.sb-user .name { font-size: 13px; font-weight: 500; }
.sb-user .role { font-size: 11px; color: var(--text-mute); }
.sb-user .info { flex: 1; min-width: 0; line-height: 1.25; }
.sb-user .menu {
  color: var(--text-mute); padding: 4px; border-radius: 6px;
  background: transparent; border: 0;
}
.sb-user .menu:hover { color: var(--text); background: rgba(255,255,255,0.04); }

/* ═══ Header ════════════════════════════════════════════════ */
.header {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 22px; gap: 14px;
  flex-shrink: 0;
}
.h-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.h-title h1 {
  font-size: 14.5px; font-weight: 600; margin: 0;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 360px;
}
.h-title .star {
  color: var(--text-mute); background: transparent; border: 0; padding: 4px; border-radius: 6px;
}
.h-title .star:hover { color: var(--text); background: rgba(255,255,255,0.04); }

.model-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 12.5px; color: var(--text);
  transition: background var(--transition), border-color var(--transition);
}
.model-pill:hover { background: rgba(255,255,255,0.06); border-color: rgba(148,163,184,0.28); }
.model-pill .m-logo {
  width: 16px; height: 16px;
  background: linear-gradient(135deg, #d97706, #f59e0b);
  border-radius: 4px; display: grid; place-items: center;
  font-size: 9px; font-weight: 700; color: white;
}
.model-pill .m-name { font-weight: 500; }
.model-pill .m-ver { color: var(--text-mute); font-family: var(--font-mono); font-size: 11px; }
.model-pill .chev { color: var(--text-mute); width: 12px; height: 12px; }

.h-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 6px; }
.h-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 12.5px; font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.h-btn:hover { background: rgba(255,255,255,0.04); color: var(--text); border-color: var(--border); }
.h-btn.icon-only { padding: 0; width: 32px; justify-content: center; }
.h-btn .ico { font-size: 13px; line-height: 1; }
.h-btn.agent {
  color: var(--agent); background: var(--agent-soft);
  border-color: rgba(108,99,255,0.32);
}
.h-btn.agent:hover { background: rgba(108,99,255,0.22); }
.h-btn.agent .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--agent);
  box-shadow: 0 0 8px var(--agent);
}

/* ═══ Token Bar ═════════════════════════════════════════════ */
.token-bar {
  padding: 8px 22px 10px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tb-track {
  flex: 1; height: 3px;
  background: rgba(255,255,255,0.04);
  border-radius: 999px; overflow: hidden;
}
.tb-fill {
  height: 100%; width: 6.4%;
  background: linear-gradient(90deg, var(--accent), #34d399);
  border-radius: 999px;
  box-shadow: 0 0 8px var(--accent-glow);
}
.tb-label {
  font-size: 11.5px; color: var(--text-mute);
  font-family: var(--font-mono); letter-spacing: 0.01em;
}
.tb-label b { color: var(--text-dim); font-weight: 500; }

/* ═══ Messages ══════════════════════════════════════════════ */
.messages {
  flex: 1; overflow-y: auto;
  padding: 28px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,0.18) transparent;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.15); border-radius: 4px; }

.msg-wrap {
  max-width: 780px; margin: 0 auto;
  padding: 0 24px;
  display: flex; flex-direction: column; gap: 22px;
}

.msg { display: flex; gap: 12px; }
.msg.user { justify-content: flex-start; }
.msg.ai   { justify-content: flex-start; flex-direction: row; }

.msg-bubble {
  max-width: 75%;
  padding: 12px 15px;
  border-radius: 14px;
  font-size: 14px; line-height: 1.7;
  word-wrap: break-word;
}
.msg.user .msg-bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border-strong);
  border-end-end-radius: 4px;
}

.ai-row { display: flex; gap: 12px; width: 100%; }
.ai-avatar {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(16,185,129,0.22), rgba(16,185,129,0.06));
  border: 1px solid rgba(16,185,129,0.28);
  display: grid; place-items: center;
  font-size: 13px; margin-top: 2px;
}
.ai-body {
  flex: 1; min-width: 0;
  background: rgba(255,255,255,0.015);
  border: 1px solid var(--border);
  border-radius: 14px; border-start-end-radius: 4px;
  padding: 14px 16px 12px;
}
.ai-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--text-mute);
  margin-bottom: 8px;
}
.ai-meta .pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 6px var(--accent);
}
.ai-meta .model-tag {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 2px 6px; border: 1px solid var(--border-strong);
  border-radius: 4px; color: var(--text-dim);
}
.ai-meta .lat { margin-inline-start: auto; }

/* ═══ Markdown Content ══════════════════════════════════════ */
.md { font-size: 14px; line-height: 1.75; color: var(--text); }
.md h3 { font-size: 14.5px; font-weight: 600; margin: 4px 0 8px; color: #f1f5f9; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md ul { margin: 6px 0 12px; padding-inline-start: 20px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--accent); }
.md strong { color: #f8fafc; font-weight: 600; }
.md code:not(pre code) {
  font-family: var(--font-mono); font-size: 12.5px;
  background: rgba(16,185,129,0.10); color: #6ee7b7;
  padding: 1px 6px; border-radius: 4px;
  direction: ltr; unicode-bidi: embed;
}
.md pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 0; margin: 10px 0 12px;
  direction: ltr; overflow: hidden;
}
.md pre .code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 11px; color: var(--text-mute);
}
.md pre .code-head .copy {
  background: transparent; border: 0; color: var(--text-mute);
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
}
.md pre .code-head .copy:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.md pre code {
  display: block; font-family: var(--font-mono); font-size: 12.5px;
  line-height: 1.65; padding: 12px 14px; color: #cbd5e1; overflow-x: auto;
}
.md .tok-key { color: #c084fc; }
.md .tok-str { color: #6ee7b7; }
.md .tok-num { color: #fbbf24; }
.md .tok-com { color: #475569; font-style: italic; }
.md .tok-fn  { color: #60a5fa; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 13px; width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 10px; text-align: start; }
.md th { background: rgba(255,255,255,0.02); font-weight: 600; color: var(--text-dim); }

/* ═══ AI Actions ════════════════════════════════════════════ */
.ai-actions {
  display: flex; gap: 2px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.ai-actions button {
  background: transparent; border: 0;
  color: var(--text-mute); padding: 4px 8px; border-radius: 6px;
  font-size: 11.5px;
  display: inline-flex; align-items: center; gap: 5px;
  transition: color var(--transition), background var(--transition);
}
.ai-actions button:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.ai-actions svg { width: 12px; height: 12px; }

/* ═══ Typing Indicator ══════════════════════════════════════ */
.typing { display: inline-flex; align-items: center; gap: 4px; padding: 8px 0 4px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: 0.4;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ═══ Composer ══════════════════════════════════════════════ */
.composer-wrap { padding: 14px 24px 18px; flex-shrink: 0; }
.composer {
  max-width: 780px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 10px 12px 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.composer:focus-within {
  border-color: rgba(16,185,129,0.45);
  box-shadow: 0 0 0 4px rgba(16,185,129,0.06);
}
.composer textarea {
  width: 100%; background: transparent; border: 0; outline: 0;
  color: var(--text); font-family: inherit; font-size: 14px;
  line-height: 1.65; resize: none;
  min-height: 24px; max-height: 200px;
  padding: 6px 4px 4px;
}
.composer textarea::placeholder { color: var(--text-mute); }

.comp-row { display: flex; align-items: center; gap: 4px; padding-top: 4px; }
.ic-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 0; color: var(--text-mute);
  display: grid; place-items: center;
  transition: color var(--transition), background var(--transition);
}
.ic-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.ic-btn svg { width: 16px; height: 16px; }
.comp-spacer { flex: 1; }

.send-btn {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); border: 0; color: #022c1d;
  display: grid; place-items: center;
  box-shadow: 0 0 0 1px rgba(16,185,129,0.5), 0 4px 12px rgba(16,185,129,0.18);
  transition: background var(--transition), transform .05s;
}
.send-btn:hover { background: #34d399; }
.send-btn:active { transform: translateY(1px); }
.send-btn svg { width: 16px; height: 16px; }

.comp-tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 9px; border-radius: 7px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border); color: var(--text-dim); font-size: 12px;
}
.comp-tag:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.comp-tag .x { color: var(--text-mute); }

.comp-hint {
  max-width: 780px; margin: 8px auto 0;
  text-align: center; color: var(--text-mute); font-size: 11.5px;
}
.comp-hint kbd {
  font-family: var(--font-mono); font-size: 10.5px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  padding: 1px 5px; border-radius: 4px; color: var(--text-dim); margin: 0 2px;
}

/* ═══ Empty State ═══════════════════════════════════════════ */
.empty {
  height: 100%; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 24px; text-align: center;
}
.empty .glow {
  width: 64px; height: 64px; display: grid; place-items: center;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 50%, rgba(16,185,129,0.35), rgba(16,185,129,0.04) 70%);
  font-size: 30px; margin-bottom: 18px; position: relative;
}
.empty .glow::before {
  content: ''; position: absolute; inset: -20px;
  background: radial-gradient(circle, rgba(16,185,129,0.18), transparent 60%);
  z-index: -1; border-radius: 50%;
}
.empty h2 { font-size: 22px; margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
.empty p  { color: var(--text-dim); font-size: 14px; max-width: 480px; margin: 0 0 24px; line-height: 1.7; }
.empty .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 560px; }
.empty .chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-strong);
  border-radius: 999px; font-size: 12.5px; color: var(--text-dim);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.empty .chip:hover { color: var(--text); background: rgba(255,255,255,0.05); border-color: rgba(148,163,184,0.28); }
.empty .chip .dot { width: 6px; height: 6px; border-radius: 50%; }

/* ═══ State Toggles ═════════════════════════════════════════ */
body[data-state="empty"] .messages > .msg-wrap { display: none !important; }
body[data-state="empty"] .messages > .empty    { display: flex !important; }
body[data-state="active"] .messages > .msg-wrap { display: flex; }
body[data-state="active"] .messages > .empty    { display: none !important; }
body[data-state="empty"] .token-bar             { opacity: 0.5; }

/* Ensure messages area is never invisible */
.messages {
  background: var(--bg, #0d1117);
  min-height: 200px;
}

/* ═══ Model Picker Dropdown ═════════════════════════════════ */
.model-picker {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 9999;
  min-width: 300px;
  max-width: 380px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface, #1a1f2e);
  border: 1px solid var(--border-strong, rgba(148,163,184,0.2));
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6), 0 4px 16px rgba(0,0,0,0.4);
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,0.2) transparent;
}
.model-picker::-webkit-scrollbar { width: 5px; }
.model-picker::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.2); border-radius: 3px; }

.mp-group { margin-bottom: 4px; }

.mp-prov {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-mute, #64748b);
  padding: 8px 10px 4px;
}

.mp-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--text-dim, #94a3b8);
  font-size: 12.5px;
  text-align: right;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.mp-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text, #e2e8f0);
}
.mp-item.active {
  background: rgba(16,185,129,0.1);
  color: var(--accent, #10b981);
  font-weight: 600;
}
.mp-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent, #10b981);
  flex-shrink: 0;
  opacity: 0.5;
}
.mp-item.active .mp-dot { opacity: 1; }
.mp-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
}
.mp-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-mute, #64748b);
  font-size: 12px;
}

/* send-btn disabled state */
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

