/* css/style.css */
/* لوحة الألوان منقولة من نسخة سطح المكتب — هوية بصرية متّسقة عبر النسختين */

:root {
  --bg: #0C0F14;
  --card: #13181F;
  --input: #1C232E;
  --border: #252E3C;
  --accent: #FF6B35;
  --accent-hover: #D95A2B;
  --purple: #9D5BDE;
  --green: #2ECC71;
  --red: #E74C3C;
  --yellow: #F39C12;
  --blue: #3498DB;
  --text: #ECF0F1;
  --dim: #7F8C8D;
  --user-bub: #1A2F4A;
  --ai-bub: #251A3C;
  --sys-bub: #161B24;
  --ptt-off: #1A2230;
  --ptt-on: #0B2E18;
  --log-bg: #0A0D12;

  --font-display: "Cairo", "Tajawal", sans-serif;
  --font-body: "Tajawal", "Cairo", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  height: 100%;
  direction: rtl;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, select {
  font-family: inherit;
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ═══════════════ شريط علوي ═══════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .status-pill {
  font-size: 0.8rem;
  color: var(--dim);
}
.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--dim);
  cursor: pointer;
  background: var(--input);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
}
.topbar .user-chip img {
  width: 26px; height: 26px; border-radius: 50%;
}

/* ═══════════════ تخطيط رئيسي ═══════════════ */
.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--card);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 14px 90px;
}
.sidebar h3 {
  font-size: 0.82rem;
  color: var(--dim);
  margin: 18px 0 6px;
  font-weight: 600;
}
.sidebar h3:first-child { margin-top: 0; }

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ═══════════════ منطقة المحادثة ═══════════════ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap;
}
.bubble.user { align-self: flex-start; background: var(--user-bub); }
.bubble.ai   { align-self: flex-end;   background: var(--ai-bub); }
.bubble.sys  { align-self: center; background: var(--sys-bub); color: var(--dim); font-size: 0.85rem; max-width: 90%; text-align: center; }
.bubble .speaker { display: block; font-size: 0.75rem; color: var(--accent); margin-bottom: 3px; font-weight: 600; }

/* ═══════════════ منطقة التحكم السفلية ═══════════════ */
.control-bar {
  flex-shrink: 0;
  padding: 14px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.level-meter {
  width: 100%;
  max-width: 420px;
  height: 6px;
  border-radius: 4px;
  background: var(--input);
  overflow: hidden;
}
.level-meter > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  transition: width 60ms linear;
}

.ptt-btn {
  width: 100%;
  max-width: 420px;
  padding: 16px;
  border-radius: 16px;
  background: var(--ptt-off);
  border: 2px solid var(--border);
  color: var(--dim);
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-display);
  transition: all 120ms ease;
  user-select: none;
  touch-action: none;
}
.ptt-btn.armed {
  border-color: var(--accent);
  color: var(--accent);
}
.ptt-btn.active {
  background: var(--ptt-on);
  border-color: var(--green);
  color: var(--green);
  transform: scale(0.98);
}

.connect-btn {
  width: 100%;
  max-width: 420px;
  padding: 12px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-family: var(--font-display);
}
.connect-btn:hover { background: var(--accent-hover); }
.connect-btn.connected { background: var(--red); }
.connect-btn.connected:hover { background: #C0392B; }

/* ═══════════════ عناصر الشريط الجانبي ═══════════════ */
.field-row { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.field-row select, .field-row input { flex: 1; width: 100%; }
.hint { font-size: 0.72rem; color: var(--dim); margin: 2px 0 0; }
.persona-preview {
  font-size: 0.78rem;
  color: var(--text);
  background: var(--input);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 6px;
  line-height: 1.6;
}
.icon-btn {
  background: var(--input);
  color: var(--text);
  border-radius: 8px;
  width: 34px; height: 34px;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--border); }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ═══════════════ سجل الأخطاء (Modal) ═══════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center; z-index: 50;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  width: min(720px, 100%); max-height: 80vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-box header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.modal-box .log-content {
  flex: 1; overflow-y: auto; background: var(--log-bg);
  font-family: ui-monospace, monospace; font-size: 0.78rem;
  padding: 12px 16px; white-space: pre-wrap; direction: ltr; text-align: left;
}
.modal-box footer {
  display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border);
}
.modal-box footer button {
  flex: 1; padding: 8px; border-radius: 8px; background: var(--input); color: var(--text);
}

/* ═══════════════ شاشة تسجيل الدخول ═══════════════ */
.auth-screen {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1a1420 0%, var(--bg) 70%);
}
.hero-scene-container {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none; /* لا يحجب النقر على البطاقة فوقه؛ تتبّع الماوس يتم عبر window */
}
.hero-scene-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.auth-card {
  background: rgba(19, 24, 31, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px; width: min(380px, 100%); text-align: center;
  position: relative;
  z-index: 1;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,107,53,0.06);
}
.auth-card h2 { font-family: var(--font-display); margin: 0 0 4px; }
.auth-card p.sub { color: var(--dim); font-size: 0.85rem; margin: 0 0 20px; }
.auth-card input { width: 100%; margin-bottom: 10px; }
.btn-google {
  width: 100%; background: #fff; color: #1f1f1f; border-radius: 10px;
  padding: 11px; font-weight: 600; display: flex; align-items: center;
  justify-content: center; gap: 8px; margin-bottom: 14px;
}
.btn-primary {
  width: 100%; background: var(--accent); color: #fff; border-radius: 10px;
  padding: 11px; font-weight: 700; margin-top: 4px;
}
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 0.78rem; margin: 4px 0 14px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-switch { margin-top: 14px; font-size: 0.83rem; color: var(--dim); }
.auth-switch a { color: var(--accent); cursor: pointer; text-decoration: none; }
.auth-error { color: var(--red); font-size: 0.8rem; min-height: 1.2em; margin-top: 6px; }

/* ═══════════════ مساحة إعلانية (placeholder) ═══════════════ */
.ad-slot {
  background: var(--input);
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--dim);
  font-size: 0.72rem;
  text-align: center;
  padding: 10px;
  margin: 10px 0;
}
.ad-slot.banner { min-height: 60px; display: flex; align-items: center; justify-content: center; }

/* ═══════════════ تجاوب الهاتف ═══════════════ */
@media (max-width: 820px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-bottom: 1px solid var(--border);
    order: 2;
  }
  .main-panel { order: 1; }
  .bubble { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
