/* زميل · Zameel — نظام التصميم */
:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #5B6474;
  --border: #E3E6EB;
  --border-2: #D9DDE4;
  --accent: #1F4FD8;
  --accent-hover: #173CA6;
  --accent-soft: #EEF2FD;
  --accent-ink: #34446E;
  --panel: #EEF0F3;
  --warn-bg: #FFF8E6;
  --warn-border: #F0DDA8;
  --warn-ink: #6B4E00;
  --radius: 14px;
  --font: 'Vazirmatn', system-ui, sans-serif;
  --paper-font: 'Amiri', 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* أزرار */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: none; border-radius: 12px; padding: 12px 18px; font-size: 15px; font-weight: 600; min-height: 44px; transition: background .15s, border-color .15s; }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #1E293B; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-line { background: var(--surface); color: var(--ink); border: 1px solid var(--border-2); }
.btn-line:hover { border-color: var(--ink-2); }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; border-radius: 10px; }
.icon-btn { width: 44px; height: 44px; border: none; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; background: var(--bg); color: var(--ink); flex: none; }
.icon-btn:hover { background: var(--border); }
.icon-btn.dark { background: var(--ink); color: #fff; }
.icon-btn.soft { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: .5; cursor: default; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--ink-2); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.pill { font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 6px 12px; border-radius: 999px; white-space: nowrap; }

/* الشعار */
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark { width: 38px; height: 38px; border-radius: 11px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.logo-text b { font-size: 19px; font-weight: 800; }
.logo-text small { font-size: 11px; color: var(--muted); letter-spacing: .08em; }

/* ========== البداية ========== */
.onboard { min-height: 100%; display: flex; flex-direction: column; }
.onboard header { display: flex; align-items: center; justify-content: space-between; padding: 20px 40px; gap: 12px; flex-wrap: wrap; }
.onboard header span { color: var(--muted); font-size: 14px; }
.onboard main { flex: 1; display: flex; justify-content: center; padding: 16px 20px 56px; }
.onboard .wrap { width: 100%; max-width: 760px; display: flex; flex-direction: column; gap: 26px; }
.steps { display: flex; gap: 8px; justify-content: center; }
.steps span { width: 32px; height: 6px; border-radius: 3px; background: var(--border-2); }
.steps span.on { background: var(--accent); }
.hero { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.hero h1 { margin: 0; font-size: 40px; font-weight: 800; letter-spacing: -.01em; }
.hero p { margin: 0; font-size: 17px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card h2 { margin: 0; font-size: 18px; font-weight: 700; }
.card-head span { font-size: 13px; color: var(--muted); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choice { padding: 18px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; color: var(--ink); transition: border-color .15s, background .15s; }
.choice:hover { border-color: var(--border-2); background: var(--bg); }
.choice b { font-size: 17px; }
.choice small { font-size: 12px; color: var(--muted); }
.choice.wide { align-items: flex-start; text-align: start; padding: 20px; gap: 6px; }
.choice.wide small { font-size: 14px; line-height: 1.6; }
.choice[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); padding: 17px 13px; }
.choice.wide[aria-pressed="true"] { padding: 19px; }
.choice[aria-pressed="true"] b { color: var(--accent); }
.choice[aria-pressed="true"] small { color: var(--accent-ink); }
.onboard .btn-dark { align-self: center; min-width: 260px; padding: 16px 28px; font-size: 17px; border-radius: var(--radius); }
.onboard .btn-dark:disabled { opacity: .4; cursor: default; }

/* ========== الحساب ========== */
.auth-wrap { max-width: 480px; }
.lang-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field input { border: 1px solid var(--border-2); border-radius: 12px; padding: 12px 14px; font-size: 16px; font-weight: 400; color: var(--ink); background: #fff; min-height: 48px; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.muted { color: var(--muted); font-size: 13px; }
.link-btn { border: none; background: none; color: var(--accent); font-size: 14px; font-weight: 600; padding: 8px; align-self: center; min-height: 44px; }
.link-btn:hover { text-decoration: underline; }
.auth-wrap .btn-dark { align-self: stretch; min-width: 0; }
.loading { height: 100%; display: flex; align-items: center; justify-content: center; }
.loading .logo-mark { width: 56px; height: 56px; border-radius: 16px; animation: blink 1.4s infinite; }
.trial-badge { margin-top: auto; background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-ink); border-radius: 10px; padding: 8px 12px; font-size: 13px; text-align: center; }
.trial-badge + .profile-row { margin-top: 0; }
.profile-row { margin-top: auto; display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.profile-row .profile { margin-top: 0; border-top: none; padding: 0 4px; flex: 1; min-width: 0; }
.profile-row .profile span { overflow: hidden; }

/* ========== لوحة الإدارة ========== */
.table-wrap { max-width: 1100px; margin: 0 auto; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { text-align: start; font-size: 12px; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table small { color: var(--muted); }
.admin-table select { border: 1px solid var(--border-2); border-radius: 8px; padding: 6px 8px; font-family: inherit; font-size: 13px; background: #fff; }
.admin-note { max-width: 1100px; margin: 12px auto 0; }

/* ========== هيكل التطبيق ========== */
.shell { display: flex; height: 100vh; height: 100dvh; }
.sidebar { width: 264px; flex: none; background: var(--surface); border-inline-end: 1px solid var(--border); padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.sidebar .logo { padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: none; background: none; color: var(--ink-2); font-size: 15px; text-align: start; min-height: 44px; }
.nav button:hover { background: var(--bg); }
.nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.recent { display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.recent-label { font-size: 12px; color: var(--muted); padding: 0 12px 6px; }
.recent button { border: none; background: none; text-align: start; font-size: 14px; color: var(--ink-2); padding: 9px 12px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent button:hover { background: var(--bg); }
.recent button.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.recent .empty { font-size: 13px; color: var(--muted); padding: 4px 12px; }
.profile { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--border); border-radius: 0; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: start; width: 100%; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--border); display: flex; align-items: center; justify-content: center; color: var(--ink-2); flex: none; }
.profile span { display: flex; flex-direction: column; line-height: 1.35; font-size: 14px; font-weight: 600; color: var(--ink); }
.profile small { font-size: 12px; color: var(--muted); font-weight: 400; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface); min-height: 72px; }
.topbar .title { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.topbar .title b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .actions { display: flex; align-items: center; gap: 8px; }
.menu-btn, .draft-toggle { display: none; }

/* ========== المحادثة ========== */
.workspace { flex: 1; display: flex; min-height: 0; }
.chat { flex: 1 1 400px; min-width: 0; display: flex; flex-direction: column; }
.chat.centered .messages, .chat.centered .composer { width: 100%; max-width: 800px; margin-inline: auto; }
.messages { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 10px; align-items: flex-start; max-width: 100%; }
.msg .bot-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; margin-top: 2px; }
.bubble { border-radius: 4px 16px 16px 16px; padding: 13px 16px; font-size: 15px; line-height: 1.85; max-width: 560px; overflow-wrap: anywhere; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--border); }
.msg.user { justify-content: flex-start; flex-direction: row-reverse; }
.msg.user .bubble { background: var(--accent); color: #fff; border-radius: 16px 4px 16px 16px; white-space: pre-wrap; }
.msg.wide .bubble { max-width: 720px; width: 100%; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ol, .bubble ul { margin: 6px 0; padding-inline-start: 22px; }
.bubble h4 { margin: 14px 0 4px; font-size: 13px; font-weight: 700; color: var(--accent); }
.bubble h4:first-child { margin-top: 0; }
.bubble strong { font-weight: 700; }
.draft-card { display: flex; align-items: center; gap: 12px; margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--accent-soft); border: none; width: 100%; text-align: start; color: var(--ink); }
.draft-card .icon { width: 40px; height: 40px; border-radius: 10px; background: #fff; color: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.draft-card span { display: flex; flex-direction: column; font-size: 14px; font-weight: 700; line-height: 1.4; }
.draft-card small { font-size: 12px; font-weight: 400; color: var(--accent-ink); }
.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; } }
.error-note { background: #FDECEC; border: 1px solid #F3C2C2; color: #8A1C1C; border-radius: 12px; padding: 10px 14px; font-size: 14px; }

.composer { padding: 10px 28px 18px; display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.input-row { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 16px; padding: 8px; }
.input-row:focus-within { border-color: var(--accent); }
.input-row textarea { flex: 1; border: none; outline: none; resize: none; font-size: 15px; line-height: 1.7; background: transparent; padding: 9px 0; max-height: 180px; color: var(--ink); }
.hint { font-size: 12px; color: var(--muted); text-align: center; }

/* المرفقات */
.attach-btn { background: transparent; color: var(--muted); }
.attach-btn:hover { background: var(--bg); color: var(--ink); }
.staged { display: flex; gap: 8px; flex-wrap: wrap; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px 6px 6px 10px; font-size: 13px; color: var(--ink-2); }
.file-chip img { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; flex: none; }
.file-chip > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip button { border: none; background: var(--bg); color: var(--muted); width: 26px; height: 26px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.file-chip button:hover { color: #8A1C1C; background: #FDECEC; }
.msg-atts { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 6px; }
.msg-thumb { width: 120px; height: 90px; object-fit: cover; border-radius: 10px; border: 2px solid rgba(255,255,255,.4); }
.msg-file { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.18); border-radius: 8px; padding: 4px 10px; font-size: 13px; white-space: normal; }
body.dragging::after { content: attr(data-drop); position: fixed; inset: 12px; border: 2px dashed var(--accent); background: rgba(238,242,253,.9); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: var(--accent); z-index: 70; pointer-events: none; }

/* الصوت */
.mic-btn { background: transparent; color: var(--muted); }
.mic-btn:hover { background: var(--bg); color: var(--ink); }
.mic-btn.listening { background: #FDECEC; color: #B42318; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(180,35,24,.35); } 50% { box-shadow: 0 0 0 6px rgba(180,35,24,0); } }
.speak-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: 12px; min-height: 30px; }
.speak-btn:hover, .speak-btn.on { color: var(--accent); border-color: var(--accent); }

/* ========== لوحة المسودة ========== */
.draft-panel { flex: 1 1 460px; min-width: 0; background: var(--panel); border-inline-start: 1px solid var(--border); padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.draft-panel .bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.draft-panel .bar b { font-size: 14px; color: var(--ink-2); }
.draft-panel .bar div { display: flex; gap: 8px; flex-wrap: wrap; }
.notes { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-ink); border-radius: 12px; padding: 10px 14px; font-size: 13px; line-height: 1.8; white-space: pre-wrap; }
.paper { background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(15,23,42,.08); padding: 40px 44px; font-family: var(--paper-font); font-size: 17px; line-height: 2; color: #111827; min-height: 400px; outline: none; }
.paper[contenteditable="true"] { box-shadow: 0 0 0 2px var(--accent); }
.paper h3 { margin: 0 0 14px; text-align: center; font-size: 22px; }
.paper h5 { margin: 12px 0 2px; font-size: 17px; font-weight: 700; }
.paper p { margin: 0; min-height: 1em; }
.panel-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); text-align: center; padding: 40px; font-size: 15px; line-height: 1.8; }
.panel-empty .icon { width: 56px; height: 56px; border-radius: 16px; background: #fff; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* ========== مستنداتي ========== */
.docs { flex: 1; overflow-y: auto; padding: 28px; }
.docs .list { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.doc-row { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.doc-row .icon { width: 42px; height: 42px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.doc-row .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.doc-row .meta b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row .meta small { font-size: 12px; color: var(--muted); }
.docs .empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ========== نافذة الرمز ========== */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 20px; padding: 28px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 20px; }
.modal input { border: 1px solid var(--border-2); border-radius: 12px; padding: 12px 14px; font-size: 16px; }
.toast { position: fixed; bottom: 24px; inset-inline-start: 50%; transform: translateX(50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; z-index: 60; }
[dir="ltr"] .toast { transform: translateX(-50%); }
.backdrop { display: none; }

/* ========== الموبايل والشاشات الصغيرة ========== */
.panel-close { display: none !important; }
@media (max-width: 1100px) {
  .draft-panel { position: fixed; inset: 0; z-index: 30; border: none; display: none; padding-top: 16px; }
  .draft-panel.open { display: flex; }
  .draft-toggle { display: inline-flex; }
  .panel-close { display: inline-flex !important; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40; transform: translateX(105%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  [dir="ltr"] .sidebar { transform: translateX(-105%); }
  .sidebar.open { transform: none !important; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 35; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 14px; }
  .topbar .pill { display: none; }
  .messages { padding: 18px 14px; }
  .composer { padding: 8px 12px 14px; }
  .paper { padding: 26px 22px; font-size: 16px; }
  .onboard header { padding: 16px 20px; }
  .hero h1 { font-size: 30px; }
  .card { padding: 20px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .docs { padding: 16px; }
}
.code-input { font-size: 24px !important; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }

.phone-row { display: flex; gap: 8px; }
.phone-row select { flex: none; border: 1px solid var(--border-2); border-radius: 12px; padding: 0 10px; font-size: 15px; font-family: inherit; background: #fff; min-height: 48px; }
.phone-row input { flex: 1; min-width: 0; border: 1px solid var(--border-2); border-radius: 12px; padding: 12px 14px; font-size: 16px; min-height: 48px; }
.phone-row input:focus, .phone-row select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
