* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1222;
  --card: #1b2038;
  --card2: #242b4d;
  --accent: #4f7cff;
  --accent2: #28c76f;
  --danger: #ff4d6d;
  --text: #eef1ff;
  --muted: #9aa3c7;
  --radius: 16px;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #26307a55, transparent),
              radial-gradient(900px 500px at 10% 110%, #7a265c44, transparent),
              var(--bg);
  color: var(--text);
  overflow: hidden;
}

.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== شاشة البداية ===== */
#setup-screen { align-items: center; justify-content: center; padding: 20px; }

.setup-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid #ffffff14;
  border-radius: var(--radius);
  padding: 30px 26px;
  box-shadow: 0 20px 60px #00000066;
  text-align: center;
}

.logo { font-size: 44px; }

.setup-card h1 { font-size: 30px; margin: 8px 0 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 26px; }

.field { text-align: right; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #ffffff1f;
  background: var(--card2);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

.room-row { display: flex; gap: 8px; }
.room-row input { flex: 1; }

.actions { display: flex; gap: 10px; margin-top: 22px; }
.actions .btn { flex: 1; }

.hint { margin-top: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.7; }

/* ===== أزرار عامة ===== */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  background: var(--card2);
  transition: transform .08s, filter .2s;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--accent); }
.btn-outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: transparent; }
.btn.small { padding: 8px 10px; font-size: 13px; }
.btn:hover { filter: brightness(1.12); }

/* ===== شاشة الغرفة ===== */
#room-screen { flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid #ffffff12;
}

.room-info { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #888; display: inline-block; }
.status-dot.online { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }
.status-dot.offline { background: #777; }
.topbar-actions { display: flex; gap: 6px; }

/* ===== منطقة المكالمة ===== */
.call-area { flex: 1; position: relative; display: flex; flex-direction: column; min-height: 0; }

.video-wrap {
  flex: 1;
  position: relative;
  background: #00000044;
  margin: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}

#remote-video { width: 100%; height: 100%; object-fit: cover; }
#remote-video.hidden, #local-video.hidden { display: none; }

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  color: var(--muted);
}
.ph-emoji { font-size: 70px; filter: grayscale(.3); }
.placeholder.hidden { display: none; }

#local-video {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 96px;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid #ffffff44;
  background: #000;
}

.avatar {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 96px;
  aspect-ratio: 3/4;
  border-radius: 12px;
  background: var(--card2);
  border: 2px solid #ffffff44;
  display: flex; align-items: center; justify-content: center;
}
.avatar.hidden { display: none; }
#local-avatar-text { font-size: 26px; color: var(--muted); }

.call-banner {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  background: #00000099;
  border: 1px solid #ffffff2e;
  padding: 8px 18px;
  border-radius: 30px;
  font-size: 14px;
}
.call-banner.hidden { display: none; }

/* ===== أزرار التحكم ===== */
.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 14px 20px;
}

.ctl {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  font-size: 22px;
  cursor: pointer;
  background: var(--card2);
  color: var(--text);
  transition: transform .08s, filter .2s;
  display: flex; align-items: center; justify-content: center;
}
.ctl:active { transform: scale(.92); }
.ctl:hover { filter: brightness(1.12); }
.ctl-video { background: var(--accent); }
.ctl-audio { background: var(--accent2); }
.ctl-end { background: var(--danger); }
.ctl.off { opacity: .45; background: #333; }
.ctl.disabled { opacity: .35; pointer-events: none; }
.ctl.hidden { display: none; }

/* ===== مكالمة واردة ===== */
.incoming-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: #000000cc;
  display: flex; align-items: center; justify-content: center;
}
.incoming-overlay.hidden { display: none; }

.incoming-card {
  text-align: center;
  background: var(--card);
  padding: 40px 36px;
  border-radius: var(--radius);
  border: 1px solid #ffffff1a;
  max-width: 340px;
  width: 90%;
}
.ring {
  width: 80px; height: 80px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--accent2);
  animation: ring 1.2s infinite;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
@keyframes ring {
  0% { box-shadow: 0 0 0 0 #28c76f88; }
  70% { box-shadow: 0 0 0 24px #28c76f00; }
  100% { box-shadow: 0 0 0 0 #28c76f00; }
}
.incoming-card h2 { margin-bottom: 6px; }
.incoming-card p { color: var(--muted); margin-bottom: 22px; }
.incoming-actions { display: flex; flex-direction: column; gap: 10px; }

/* ===== لوحة الشات ===== */
.chat-panel {
  position: fixed;
  top: 0; bottom: 0;
  left: 0;
  width: min(360px, 100%);
  background: var(--card);
  border-right: 1px solid #ffffff12;
  display: flex;
  flex-direction: column;
  z-index: 30;
  transform: translateX(100%);
  transition: transform .28s ease;
}
.chat-panel.open { transform: translateX(0); }

.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  font-weight: 600;
  border-bottom: 1px solid #ffffff12;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  background: var(--card2);
  align-self: flex-start;
  border-bottom-right-radius: 4px;
}
.msg.mine { background: var(--accent); align-self: flex-end; border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }
.msg .meta { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }
.msg img { max-width: 100%; border-radius: 8px; display: block; max-height: 260px; }
.msg video { max-width: 100%; border-radius: 8px; display: block; max-height: 260px; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ffffff14;
  border: 1px solid #ffffff2e;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  word-break: break-all;
}
.file-chip em { font-style: normal; opacity: .6; font-size: 11px; white-space: nowrap; }
.file-chip:hover { background: #ffffff22; }

.chat-input {
  display: flex; gap: 8px;
  padding: 10px;
  border-top: 1px solid #ffffff12;
}
.chat-input input[type="text"] { flex: 1; padding: 10px 12px; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #000000dd;
  border: 1px solid #ffffff2e;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 14px;
  z-index: 60;
  white-space: nowrap;
}
.toast.hidden { display: none; }

/* ===== للأجهزة الواسعة ===== */
@media (min-width: 900px) {
  #local-video, .avatar { width: 140px; }
  .chat-panel {
    top: auto; bottom: auto;
    top: 60px; bottom: 90px;
    right: 12px; left: auto;
    border-right: none;
    border-radius: var(--radius);
    border: 1px solid #ffffff12;
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    width: 320px;
  }
  .chat-panel.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
}
