:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --line: #2a323c;
  --text: #e8edf2;
  --muted: #97a3b2;
  --brand: #1f6f5c;      /* أخضر قانوني هادئ */
  --brand-2: #2e9e83;
  --gold: #c8a24a;
  --user: #23408e;
  --radius: 14px;
  --font: "Readex Pro", "Segoe UI", "Tahoma", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== الشريط الجانبي ===== */
.sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 16px;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 22px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.4; }
.brand-text strong { font-size: 17px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.new-chat {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px; font-family: inherit; font-size: 14px; cursor: pointer;
  transition: .15s;
}
.new-chat:hover { border-color: var(--brand-2); color: #fff; }

.side-section h4 {
  font-size: 12px; color: var(--muted); font-weight: 600;
  margin-bottom: 10px; letter-spacing: .3px;
}
.cats, .samples { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.cats li {
  font-size: 13px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface-2); color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.cats li::before { content: "▸"; color: var(--brand-2); }
.samples li {
  font-size: 12.5px; color: var(--muted); cursor: pointer;
  padding: 8px 10px; border-radius: 8px; line-height: 1.5;
  border: 1px solid transparent; transition: .15s;
}
.samples li:hover { background: var(--surface-2); color: var(--text); border-color: var(--line); }

.side-foot {
  margin-top: auto; font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7280; }
.status-dot.ok { background: #33c48d; box-shadow: 0 0 8px #33c48d88; }
.status-dot.ai { background: var(--gold); box-shadow: 0 0 8px #c8a24a88; }

/* ===== منطقة المحادثة ===== */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.menu-btn { display: none; background: none; border: none; color: var(--text); font-size: 22px; cursor: pointer; }
.head-title h1 { font-size: 17px; }
.head-title p { font-size: 12px; color: var(--muted); margin-top: 2px; }

.messages { flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth; }

.welcome { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.welcome-icon {
  width: 68px; height: 68px; margin: 0 auto 18px; border-radius: 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 34px;
}
.welcome h2 { font-size: 24px; margin-bottom: 10px; }
.welcome p { color: var(--muted); font-size: 14px; line-height: 1.8; max-width: 520px; margin: 0 auto 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); font-family: inherit; font-size: 13px;
  padding: 9px 14px; border-radius: 20px; cursor: pointer; transition: .15s;
}
.chip:hover { border-color: var(--brand-2); background: #223028; }

/* الرسائل */
.msg { max-width: 820px; margin: 0 auto 22px; display: flex; gap: 12px; }
.msg .avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 16px;
}
.msg.user .avatar { background: var(--user); }
.msg.bot .avatar { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.msg .body { flex: 1; min-width: 0; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  font-size: 14.5px; line-height: 1.9; white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble { background: var(--surface-2); }
.bubble strong { color: #fff; }

/* المصادر */
.sources { margin-top: 12px; }
.sources-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.source-card {
  display: block; background: var(--surface-2); border: 1px solid var(--line);
  border-inline-start: 3px solid var(--brand-2);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  text-decoration: none; color: var(--text); transition: .15s;
}
.source-card:hover { border-inline-start-color: var(--gold); background: #20272f; }
.source-card .sc-ref { font-size: 12px; color: var(--brand-2); font-weight: 600; }
.source-card .sc-title { font-size: 13.5px; margin: 3px 0; }
.source-card .sc-meta { font-size: 11px; color: var(--muted); }

.official {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: #16211d; border: 1px dashed #2f5a4a; font-size: 12.5px;
}
.official b { color: var(--brand-2); }
.official a { color: var(--gold); text-decoration: none; }
.official a:hover { text-decoration: underline; }

.mode-badge {
  display: inline-block; font-size: 10.5px; padding: 2px 8px; border-radius: 10px;
  margin-inline-start: 8px; vertical-align: middle;
}
.mode-badge.ai { background: #3a2f12; color: var(--gold); }
.mode-badge.retrieval { background: #1d2a33; color: #6fb3d6; }

/* مؤشر الكتابة */
.typing { display: inline-flex; gap: 4px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* ===== صندوق الكتابة ===== */
.composer { padding: 16px 24px 20px; border-top: 1px solid var(--line); background: var(--surface); }
.composer-inner {
  max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 8px 8px 8px 14px;
}
.composer-inner:focus-within { border-color: var(--brand-2); }
#input {
  flex: 1; background: none; border: none; color: var(--text);
  font-family: inherit; font-size: 14.5px; resize: none; outline: none;
  max-height: 160px; line-height: 1.7; padding: 6px 0;
}
#send {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  border: none; border-radius: 10px; padding: 10px 18px; font-family: inherit;
  font-size: 14px; cursor: pointer; white-space: nowrap; transition: .15s;
}
#send:hover { filter: brightness(1.1); }
#send:disabled { opacity: .5; cursor: not-allowed; }
.disclaimer { max-width: 820px; margin: 10px auto 0; text-align: center; font-size: 11px; color: var(--muted); }

/* ===== الجوال ===== */
.menu-btn { }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset-inline-end: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(100%); transition: transform .25s;
    box-shadow: -8px 0 30px #0008;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .messages { padding: 16px; }
  .composer { padding: 12px 14px 16px; }
}
