:root {
  --bg: #f5f2ec; --surface: #ffffff; --text: #1c2321; --muted: #6b7673;
  --primary: #0d7a6f; --primary-text: #ffffff; --border: #ddd6cc;
  --bubble-user: #0d7a6f; --bubble-user-text: #fff; --bubble-ai: #ffffff;
  --danger: #b3382e; --ok: #1d7a3a;
}
[data-theme="dark"] {
  --bg: #101615; --surface: #1a2221; --text: #e8edec; --muted: #8fa39f;
  --primary: #2bb5a3; --primary-text: #06231f; --border: #2a3533;
  --bubble-user: #2bb5a3; --bubble-user-text: #06231f; --bubble-ai: #1f2a29;
  --danger: #e06c60; --ok: #4fc07a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }
.view { height: 100%; }
.center-view { display: flex; align-items: center; justify-content: center; padding: 16px; }

/* الدخول */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 22px; width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 10px 0 4px; }
.logo { width: 64px; height: 64px; border-radius: 18px; background: var(--primary); color: var(--primary-text); font-size: 30px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.login-card input { width: 100%; margin: 18px 0 10px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-family: inherit; font-size: 16px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.ok { color: var(--ok); font-size: 13px; margin-top: 8px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.7; }
.small { font-size: 12px; }

/* الهيكل */
#appView { height: 100%; display: flex; flex-direction: column; }
#appView section.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar h2 { font-size: 16px; }
.topbar-actions { display: flex; gap: 8px; }

/* الأزرار */
.btn { font-family: inherit; font-size: 14px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; display: inline-block; text-align: center; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 500; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.icon { padding: 8px 12px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.file-btn { margin-top: 8px; width: 100%; }

/* المحادثة */
.messages { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; line-height: 1.9; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-start; background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-left-radius: 4px; }
.msg.ai { align-self: flex-end; background: var(--bubble-ai); border: 1px solid var(--border); border-bottom-right-radius: 4px; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg.user .meta { color: inherit; opacity: .75; }
.msg code, .msg pre { direction: ltr; text-align: left; display: block; background: rgba(127,127,127,.15); border-radius: 8px; padding: 6px 8px; font-family: monospace; font-size: 13px; overflow-x: auto; }
.empty-hint { text-align: center; color: var(--muted); margin-top: 40px; font-size: 13.5px; line-height: 2; padding: 0 30px; }
.status-line { padding: 4px 16px; font-size: 12px; color: var(--muted); }
.composer { display: flex; gap: 6px; align-items: flex-end; padding: 8px; background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-family: inherit; font-size: 15px; background: var(--bg); color: var(--text); max-height: 120px; }
.model-select { max-width: 92px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font-family: inherit; font-size: 12px; padding: 8px 4px; }
#searchToggle.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* قائمة المحادثات */
.convo-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.convo-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.convo-item .t { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-item .d { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.convo-item .del { color: var(--danger); border: none; background: none; font-size: 16px; cursor: pointer; padding: 4px 8px; }

/* صفحات المحتوى */
.scroll-pad { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.field span { display: block; font-size: 13px; margin-bottom: 5px; color: var(--muted); }
.field textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text); resize: vertical; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
hr { border: none; border-top: 1px solid var(--border); }

/* شريط التنقل */
.bottomnav { display: flex; background: var(--surface); border-top: 1px solid var(--border); }
.navbtn { flex: 1; border: none; background: none; color: var(--muted); font-family: inherit; font-size: 11px; padding: 8px 0 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.navbtn span { font-size: 11px; }
.navbtn.active { color: var(--primary); }

/* أيقونات SVG */
.btn svg { width: 20px; height: 20px; display: block; margin: 0 auto; }
.navbtn svg { width: 22px; height: 22px; display: block; }
