:root {
  --bg: #0b1221;
  --panel: #121b2e;
  --panel-2: #1a2740;
  --line: #243655;
  --text: #e8eef9;
  --muted: #8ea2c4;
  --accent: #f2c14e;
  --accent-2: #4e8cf2;
  --mine: #2a5bd7;
  --theirs: #1f2c47;
  --danger: #ff6b6b;
  --ok: #45d483;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.screen { min-height: 100dvh; }
.center { display: grid; place-items: center; padding: 20px; }

/* ===== البطاقات (دخول/تهيئة) ===== */
.card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.brand { text-align: center; margin-bottom: 20px; }
.logo { font-size: 40px; font-weight: 800; color: var(--accent); text-shadow: 0 0 24px rgba(242,193,78,.45); }
.tag { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.ob-title { text-align: center; font-size: 20px; margin: 4px 0 2px; }
.ob-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.inp {
  width: 100%; padding: 13px 14px; margin: 7px 0; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 15px; outline: none;
}
.inp:focus { border-color: var(--accent-2); }
.btn { width: 100%; padding: 13px; margin-top: 10px; border: 0; border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--accent); color: #1a1407; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { margin-top: 18px; padding: 15px; font-size: 16px; }
.btn.outline { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.outline:hover { background: var(--line); }
.switch { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; }
.switch a { color: var(--accent-2); text-decoration: none; }
.error { color: var(--danger); text-align: center; font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 2px 10px; text-align: center; }
.hint.pad { padding: 14px 10px; }

/* ===== التطبيق ===== */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.sidebar { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: .3s; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.side-actions { display: flex; gap: 6px; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 17px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--line); }

.contacts { overflow-y: auto; flex: 1; padding: 8px; }
.section-label { color: var(--muted); font-size: 12px; padding: 10px 8px 4px; }
.contact { display: flex; align-items: center; gap: 10px; padding: 11px 10px; border-radius: 12px; cursor: pointer; }
.contact:hover, .contact.active { background: var(--panel-2); }
.contact.req { justify-content: space-between; }
.c-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-2); color: #fff; display: grid; place-items: center; font-weight: 700; }
.c-name { font-size: 15px; }
.mini { background: var(--accent); color: #1a1407; border: 0; padding: 5px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }

.main { display: flex; flex-direction: column; min-width: 0; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.back-btn { display: none; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 7px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.lock { opacity: .7; font-size: 13px; margin-right: auto; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 75%; display: flex; flex-direction: column; }
.msg.mine { align-self: flex-start; align-items: flex-start; }
.msg.theirs { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.mine .bubble { background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 4px; }
.media { max-width: 260px; border-radius: 14px; }
.time { font-size: 11px; color: var(--muted); margin: 2px 4px; }

.composer { display: flex; align-items: center; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--panel); }
.msg-input { flex: 1; padding: 12px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-size: 15px; outline: none; }
.msg-input:focus { border-color: var(--accent-2); }
.send { background: var(--accent); color: #1a1407; border-color: transparent; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #000d; color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 14px; z-index: 50; }

/* ===== الجوال ===== */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app:not(.in-chat) .main { display: none; }
  .app.in-chat .sidebar { display: none; }
  .back-btn { display: inline-block; }
  .media { max-width: 200px; }
}
