* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --green: #00a884; --green-dark: #008069; --bg: #f0f2f5; --panel: #ffffff;
  --sidebar-head: #f0f2f5; --chat-bg: #efeae2; --bubble-me: #d9fdd3; --bubble-them: #ffffff;
  --text: #111b21; --muted: #667781; --border: #e9edef; --read: #53bdeb; --danger: #ea0038;
}
html, body { height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; font-size: 15px; }
code { background: #fff3cd; padding: 2px 8px; border-radius: 4px; font-size: 16px; letter-spacing: 1px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, var(--green-dark) 0 28%, var(--bg) 28% 100%); padding: 16px; }
.login-card { background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 36px 32px; width: 100%; max-width: 400px; }
.login-logo { font-size: 46px; text-align: center; }
.login-card h1 { text-align: center; font-size: 26px; margin: 8px 0 4px; }
.login-sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }
.login-card input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 17px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }
.btn-primary { background: var(--green); color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 15px; font-weight: 600; width: 100%; margin-top: 12px; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: #e9edef; color: var(--text); padding: 10px 18px; border-radius: 8px; font-size: 14px; }
.btn-danger { background: #fde8ec; color: var(--danger); padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.btn-small { background: var(--green); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 13px; }
.btn-small.danger { background: #fde8ec; color: var(--danger); }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; max-width: 1600px; margin: 0 auto; background: #fff; }
.sidebar { width: 34%; min-width: 300px; max-width: 430px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--panel); }
.side-header { display: flex; align-items: center; justify-content: space-between; background: var(--sidebar-head); padding: 10px 14px; min-height: 60px; }
.me-block { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-actions { display: flex; gap: 2px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: #6a7f8a; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 17px; flex: none; text-transform: uppercase; }
.avatar.large { width: 84px; height: 84px; font-size: 34px; }
.icon-btn { font-size: 19px; padding: 9px; border-radius: 50%; line-height: 1; min-width: 40px; min-height: 40px; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
.icon-btn.big { font-size: 22px; }
.search-row { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.search-row input { width: 100%; padding: 9px 14px; border: none; background: var(--bg); border-radius: 8px; font-size: 14px; }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item { display: flex; gap: 12px; padding: 12px 14px; cursor: pointer; align-items: center; }
.chat-item:hover { background: #f5f6f6; }
.chat-item.active { background: #f0f2f5; }
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--muted); flex: none; margin-left: 8px; }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.chat-item-preview { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge { background: var(--green); color: #fff; font-size: 12px; font-weight: 700; border-radius: 999px; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; padding: 0 6px; flex: none; }
.presence-dot { width: 11px; height: 11px; border-radius: 50%; background: #c3c9cd; border: 2px solid #fff; position: relative; margin-left: -14px; margin-top: 28px; flex: none; z-index: 1; }
.presence-dot.on { background: #25d366; }

.main-pane { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; }
.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.empty-emoji { font-size: 60px; }
.empty-state h2 { color: var(--text); margin: 14px 0 8px; font-weight: 400; }
.chat-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 10px; background: var(--sidebar-head); padding: 8px 14px; min-height: 60px; }
.back-btn { display: none; }
.chat-title-block { flex: 1; min-width: 0; }
.chat-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-subtitle { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-actions { display: flex; }
.messages { flex: 1; overflow-y: auto; padding: 18px 6% 8px; display: flex; flex-direction: column; gap: 3px; }
.msg { max-width: 68%; padding: 7px 10px 5px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.08); position: relative; word-wrap: break-word; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.4; }
.msg.me { align-self: flex-end; background: var(--bubble-me); border-top-right-radius: 0; }
.msg.them { align-self: flex-start; background: var(--bubble-them); border-top-left-radius: 0; }
.msg.system { align-self: center; background: #fdf3c6; color: #54656f; font-size: 12.5px; text-align: center; max-width: 85%; box-shadow: none; }
.msg .sender-name { font-size: 12.5px; font-weight: 700; color: #7b4d9e; margin-bottom: 2px; }
.msg .meta { float: right; font-size: 11px; color: var(--muted); margin: 8px 0 0 10px; display: flex; gap: 3px; align-items: center; }
.msg .ticks { letter-spacing: -3px; font-size: 11px; }
.msg .ticks.read { color: var(--read); }
.msg img.attachment { max-width: 320px; width: 100%; border-radius: 6px; display: block; }
.msg .file-attachment { display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.04); padding: 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 13.5px; }
.msg audio { max-width: 260px; width: 100%; height: 38px; }
.reactions-row { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.reaction-chip { background: #fff; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; padding: 1px 7px; box-shadow: 0 1px 1px rgba(0,0,0,.1); cursor: pointer; }
.reaction-chip.mine { background: #d9fdd3; border-color: var(--green); }
.typing-bar { padding: 4px 6%; font-size: 12.5px; color: var(--muted); font-style: italic; }
.call-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #dcf8c6; border-bottom: 1px solid var(--border); padding: 8px 6%; font-size: 13.5px; }
.call-banner.hidden { display: none; }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px 10px; background: var(--sidebar-head); position: relative; }
.composer textarea { flex: 1; border: none; border-radius: 22px; padding: 11px 16px; resize: none; max-height: 110px; font-size: 15px; outline: none; }
.send-btn { color: var(--green-dark); }
.rec-bar { flex: 1; display: flex; align-items: center; gap: 12px; padding: 8px 6px; font-size: 15px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.emoji-picker { position: absolute; bottom: 132px; left: 12px; background: #fff; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 10px; width: min(92vw, 350px); max-height: 300px; overflow-y: auto; z-index: 30; }
.chat-pane { position: relative; }
.emoji-picker h4 { font-size: 12px; color: var(--muted); margin: 6px 2px 4px; font-weight: 600; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid button { font-size: 23px; padding: 5px 0; border-radius: 8px; }
.emoji-grid button:hover { background: var(--bg); }

/* ---------- modals ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 14px; }
.modal { background: #fff; border-radius: 12px; padding: 22px; width: 100%; max-width: 430px; max-height: 88dvh; overflow-y: auto; }
.modal.wide { max-width: 640px; }
.modal h3 { margin-bottom: 12px; font-size: 19px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.modal input[type="text"] { width: 100%; padding: 11px; border: 1px solid #ccc; border-radius: 8px; }
.modal-hint { color: var(--muted); font-size: 13.5px; margin-bottom: 8px; }
.modal-close { margin-top: 14px; width: 100%; }
.modal-row { display: flex; gap: 10px; margin-top: 16px; }
.modal-row .btn-primary { margin-top: 0; }
.pick-list { display: flex; flex-direction: column; }
.pick-item { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.pick-item:hover { background: var(--bg); }
.pick-item input[type="checkbox"] { width: 19px; height: 19px; }
.pick-item .sub { color: var(--muted); font-size: 12.5px; }
.pick-item .spacer { flex: 1; }
.admin-create { display: flex; gap: 8px; }
.admin-create input { flex: 1; padding: 11px; border: 1px solid #ccc; border-radius: 8px; min-width: 0; }
.admin-create .btn-primary { width: auto; margin-top: 0; }
.created-box { background: #e7f8f0; border: 1px solid var(--green); border-radius: 8px; padding: 12px; margin-top: 12px; font-size: 14.5px; }
.admin-table { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: var(--bg); border-radius: 8px; font-size: 14px; flex-wrap: wrap; }
.admin-row .uid { color: var(--muted); font-size: 12.5px; }
.admin-row button { font-size: 12.5px; padding: 6px 10px; border-radius: 6px; background: #fff; border: 1px solid #ccc; }
.admin-row button.warn { color: var(--danger); border-color: #f3b7c6; }

/* ---------- calls ---------- */
.incoming-call { position: fixed; inset: 0; background: rgba(11,20,26,.9); z-index: 80; display: flex; align-items: center; justify-content: center; }
.incoming-card { text-align: center; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.incoming-name { font-size: 26px; font-weight: 600; margin-top: 10px; }
.incoming-kind { color: #b6c2c9; }
.incoming-actions { display: flex; gap: 52px; margin-top: 30px; }
.call-btn { width: 64px; height: 64px; border-radius: 50%; font-size: 26px; color: #fff; display: flex; align-items: center; justify-content: center; }
.call-btn.accept { background: #25d366; animation: pulse 1.2s infinite; }
.call-btn.reject { background: var(--danger); }
.call-btn.hangup { background: var(--danger); transform: rotate(135deg); }
.call-btn.ctrl { background: rgba(255,255,255,.16); color: #fff; width: 56px; height: 56px; font-size: 22px; }
.call-btn.ctrl.off { background: #fff; color: #111; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(37,211,102,.5); } 70% { box-shadow: 0 0 0 18px rgba(37,211,102,0); } 100% { box-shadow: 0 0 0 0 rgba(37,211,102,0); } }
.call-screen { position: fixed; inset: 0; background: #0b141a; z-index: 70; display: flex; flex-direction: column; }
.call-top { color: #fff; padding: 16px 20px; display: flex; gap: 16px; align-items: baseline; font-size: 17px; }
.call-note { color: #ffb3c0; font-size: 13px; }
#callTimer { color: #b6c2c9; font-size: 14px; }
.video-grid { flex: 1; display: grid; gap: 8px; padding: 8px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-content: center; }
.video-tile { position: relative; background: #1f2c34; border-radius: 12px; overflow: hidden; min-height: 180px; display: flex; align-items: center; justify-content: center; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.video-tile .v-name { position: absolute; left: 10px; bottom: 8px; color: #fff; font-size: 13px; background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 6px; z-index: 2; }
.video-tile .v-avatar { font-size: 44px; color: #fff; background: #6a7f8a; width: 96px; height: 96px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.video-tile.me video { transform: scaleX(-1); }
.call-controls { display: flex; justify-content: center; gap: 22px; padding: 20px; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: #111b21; color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 14px; z-index: 100; max-width: 90vw; text-align: center; }
.msg-menu { position: fixed; background: #fff; border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.28); z-index: 90; padding: 8px; min-width: 190px; }
.msg-menu .react-row { display: flex; gap: 2px; justify-content: space-between; padding: 2px 2px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.msg-menu .react-row button { font-size: 21px; padding: 4px; border-radius: 50%; }
.msg-menu .react-row button:hover { background: var(--bg); transform: scale(1.15); }
.msg-menu .menu-item { display: block; width: 100%; text-align: left; padding: 9px 10px; font-size: 14.5px; border-radius: 6px; }
.msg-menu .menu-item:hover { background: var(--bg); }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; min-width: 0; max-width: none; border-right: none; }
  .main-pane { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .main-pane { display: flex; position: fixed; inset: 0; z-index: 20; }
  .back-btn { display: block; }
  .msg { max-width: 84%; }
  .messages { padding: 14px 4% 8px; }
  .emoji-picker { bottom: 128px; left: 6px; }
}
