:root {
  /* لون التمييز المؤقت — غيّره من هنا فقط عند اعتماد هوية سند/فاتورلي النهائية */
  --accent: #5cd6a0;
  --accent-dim: #2f8f66;
  --accent-ink: #06251a;

  --bg: #0e0e0d;
  --bg-2: #171715;
  --card: #1f1f1c;
  --card-2: #262622;
  --gauge-track: #2c2c28;

  --text: #ececea;
  --text-dim: #a3a39c;
  --muted: #6f6f68;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.view {
  display: none;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}
.view.active { display: flex; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.topbar-id { display: flex; align-items: center; gap: 12px; }
.avatar {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px;
  flex-shrink: 0;
}
.online-dot {
  position: absolute;
  bottom: 0; left: 0;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--bg-2);
}
.topbar-text { display: flex; flex-direction: column; line-height: 1.3; }
.topbar-text.center { flex: 1; text-align: center; }
.topbar-text strong { font-size: 16px; font-weight: 600; }
.model-label { font-size: 12px; color: var(--accent); font-weight: 500; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: var(--card); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- الرسائل ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.row { display: flex; gap: 10px; max-width: 100%; }
.row.sanad { justify-content: flex-start; }
.row.user { justify-content: flex-end; }
.row .bubble-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
  align-self: flex-end;
}
.bubble {
  padding: 11px 15px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.7;
  max-width: 74%;
  min-width: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop .22s ease;
}
.row.sanad .bubble {
  background: var(--card);
  color: var(--text);
  border-bottom-right-radius: 6px;
}
.row.user .bubble {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
  border-bottom-left-radius: 6px;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* حالة الفراغ */
.empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  gap: 14px;
  color: var(--muted);
  padding: 40px;
}
.empty .big-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 30px;
}
.empty h3 { color: var(--text); font-size: 18px; font-weight: 600; }
.empty p { font-size: 14px; max-width: 260px; line-height: 1.6; }

/* مؤشر الكتابة */
.typing { display: flex; gap: 4px; padding: 14px 16px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite ease-in-out both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- صندوق الكتابة ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-2);
  border-top: 1px solid rgba(255,255,255,0.04);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  padding: 12px 16px;
  border-radius: 24px;
  max-height: 130px;
}
.composer textarea::placeholder { color: var(--muted); }
.mic-btn, .send-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .15s, background .18s, opacity .18s;
}
.mic-btn { background: var(--card); color: var(--text-dim); }
.mic-btn:hover { color: var(--text); }
.send-btn { background: var(--accent); color: var(--accent-ink); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: .45; cursor: default; }

/* ---------- الإعدادات ---------- */
.settings-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 15px; font-weight: 600; color: var(--text); }
.pill {
  font-size: 12px; font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(92,214,160,0.14);
  color: var(--accent);
}
.pill.gray { background: var(--card-2); color: var(--text-dim); }
.muted { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.6; }

/* القياس الدائري */
.gauge-card { text-align: center; }
.gauge-wrap { position: relative; width: 100%; max-width: 260px; margin: 4px auto 0; }
.gauge { width: 100%; height: auto; display: block; }
#gauge-fill {
  stroke-dasharray: 251.3;
  stroke-dashoffset: 251.3;
  transition: stroke-dashoffset .8s cubic-bezier(.4,0,.2,1);
}
.gauge-center {
  position: absolute;
  bottom: 8px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.gauge-pct { font-size: 34px; font-weight: 700; color: var(--text); line-height: 1; }
.gauge-sub { font-size: 12px; color: var(--text-dim); }
.gauge-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* الموديل المجزّأ */
.segmented {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.seg {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px; font-weight: 600;
  padding: 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.seg.active { background: var(--accent); color: var(--accent-ink); }

/* القنوات */
.channel {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.channel:last-child { border-bottom: none; }
.channel-info strong { display: block; font-size: 14px; font-weight: 600; }
.channel-info span { font-size: 12px; color: var(--muted); }

/* التوفير */
.stat-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.stat-row:last-child { border-bottom: none; }
.stat-row .k { font-size: 14px; color: var(--text-dim); }
.stat-row .v { font-size: 15px; font-weight: 600; color: var(--text); }
.stat-row .v.accent { color: var(--accent); }
.savings-range { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--card-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
