:root {
  --bg: #0a0a0a;
  --bg-soft: #141414;
  --panel: #1b1b1b;
  --yellow: #ffcc00;
  --yellow-dim: #b38f00;
  --text: #f3f3f3;
  --text-dim: #b3b3b3;
  --danger: #e03131;
  --success: #2fb344;
  --border: #2a2a2a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Tahoma", "Segoe UI", Arial, sans-serif;
  direction: rtl;
}

.hidden { display: none !important; }

button {
  cursor: pointer;
  font-family: inherit;
}

/* ===================== أزرار عامة ===================== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--yellow); color: #111; }
.btn-primary:hover { background: #ffd633; }

.btn-secondary { background: #333; color: var(--text); }
.btn-secondary:hover { background: #3f3f3f; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #f03e3e; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--yellow);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn.big { width: 60px; height: 60px; font-size: 26px; }
.icon-btn.end-call { color: #fff; background: var(--danger); border-color: var(--danger); }
.icon-btn.muted { background: var(--yellow); color: #111; }

/* ===================== الشاشات ===================== */
.screen {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* ===================== شاشة التسجيل ===================== */
#registerScreen {
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 20%, #1a1a1a, #050505 70%);
}

.register-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.logo { width: 160px; max-width: 60%; margin-bottom: 8px; }
.logo-sm { width: 100px; }

.owner-line {
  color: var(--yellow);
  font-size: 13px;
  margin: 4px 0 18px;
}

.register-card h1 { font-size: 20px; margin: 0 0 4px; }
.register-card .sub { color: var(--text-dim); font-size: 14px; margin-bottom: 20px; }

#usernameInput, #messageInput {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f0f0f;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
  outline: none;
}
#usernameInput:focus, #messageInput:focus { border-color: var(--yellow); }

.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 10px; text-align: right; }
.hint { color: var(--text-dim); font-size: 12px; margin-top: 14px; }

#registerBtn { width: 100%; }

/* ===================== شاشة الدردشة ===================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-actions { display: flex; gap: 8px; }

.main-area {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.users-panel {
  width: 240px;
  min-width: 200px;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
}
.users-panel h3 { font-size: 14px; color: var(--yellow); margin: 0 0 10px; }
#usersList { list-style: none; margin: 0; padding: 0; }
#usersList li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.status-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: #2a2a2a;
  color: var(--text-dim);
}
.status-pill.online { color: var(--success); border: 1px solid var(--success); background: transparent; }
.status-pill.in_call { color: var(--yellow); border: 1px solid var(--yellow); background: transparent; }

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

.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 75%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  align-self: flex-start;
}
.msg.mine { align-self: flex-end; border-color: var(--yellow-dim); }
.msg .msg-user { font-size: 12px; color: var(--yellow); font-weight: 700; margin-bottom: 3px; }
.msg .msg-text { font-size: 15px; word-wrap: break-word; white-space: pre-wrap; }
.msg .msg-time { font-size: 10px; color: var(--text-dim); margin-top: 4px; text-align: left; }
.msg audio { width: 220px; max-width: 100%; margin-top: 4px; }

.message-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}
.message-form #messageInput { margin-bottom: 0; flex: 1; }
.send-btn { white-space: nowrap; }

.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #241a00;
  border-top: 1px solid var(--yellow-dim);
  font-size: 14px;
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===================== النوافذ المنبثقة ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.modal h3 { margin-top: 0; color: var(--yellow); }
.modal p { font-size: 15px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions.three { flex-wrap: wrap; }
.modal-actions .btn { flex: 1; min-width: 80px; }

.call-users-list { list-style: none; padding: 0; margin: 10px 0; max-height: 300px; overflow-y: auto; }
.call-users-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.call-users-list button { padding: 6px 14px; font-size: 13px; }

.incoming-title { color: var(--yellow); font-weight: 700; font-size: 18px; }
.incoming-from { font-size: 20px; font-weight: 700; }

/* ===================== واجهة المكالمة ===================== */
#inCallScreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: radial-gradient(circle at 50% 30%, #1a1a1a, #030303 75%);
  align-items: center;
  justify-content: center;
}
.in-call-card { text-align: center; padding: 20px; }
.in-call-with { font-size: 24px; font-weight: 700; margin: 10px 0 4px; }
.in-call-status { color: var(--text-dim); margin-bottom: 30px; }
.in-call-controls { display: flex; gap: 24px; justify-content: center; }

/* ===================== استجابة الشاشات ===================== */
@media (max-width: 720px) {
  .users-panel {
    position: fixed;
    top: 61px;
    right: 0;
    bottom: 0;
    z-index: 20;
    width: 78vw;
    box-shadow: -4px 0 16px rgba(0,0,0,0.5);
  }
  .msg { max-width: 88%; }
}
