:root {
  --bg: #0d0f14;
  --surface: #161b25;
  --surface2: #1e2535;
  --border: #2a3347;
  --accent: #0068ff;
  --accent2: #00c2ff;
  --green: #00d68f;
  --red: #ff4757;
  --yellow: #ffd32a;
  --text: #e8ecf4;
  --text2: #8896b3;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.logo svg { width: 28px; height: 28px; flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 10px; }
#status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--surface2);
  border: 1px solid var(--border);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: pulse 2s infinite; }
.dot.online { background: var(--green); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── LAYOUT ── */
.container {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr;
  gap: 20px;
  padding: 20px 28px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 18px; }

/* ── SEND PANEL (left) ── */
.send-panel { grid-row: span 2; display: flex; flex-direction: column; gap: 16px; }

/* ── FORM ELEMENTS ── */
label { font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
input, textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  transition: border-color 0.2s;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ── TAB GROUP ── */
.tab-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab-btn { padding: 8px; border-radius: 7px; font-size: 13px; font-weight: 500; background: transparent; color: var(--text2); border: none; cursor: pointer; transition: all 0.2s; }
.tab-btn.active { background: var(--accent); color: #fff; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.2s; width: 100%;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn-primary:hover { opacity: .85; transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-sm { padding: 5px 12px; font-size: 12px; width: auto; border-radius: 8px; }
.btn-green { background: var(--green); color: #000; font-weight: 700; }
.btn-green:hover { opacity: .85; transform: translateY(-1px); }

/* ── LIST ── */
.list-wrap { max-height: 260px; overflow-y: auto; padding-right: 4px; }
.list-wrap::-webkit-scrollbar { width: 4px; }
.list-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; cursor: pointer; transition: background 0.15s; }
.list-item:hover { background: var(--surface2); }
.list-item.selected { background: rgba(0,104,255,.15); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg,#667eea,#764ba2); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: #fff; flex-shrink: 0; }
.avatar.group { background: linear-gradient(135deg,#0068ff,#00c2ff); }
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-id { font-size: 11px; color: var(--text2); font-family: monospace; }
.use-btn { font-size: 11px; padding: 3px 10px; border-radius: 6px; background: var(--accent); color: #fff; border: none; cursor: pointer; opacity: 0; transition: opacity 0.15s; }
.list-item:hover .use-btn { opacity: 1; }

/* ── LOGS ── */
.log-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.log-list::-webkit-scrollbar { width: 4px; }
.log-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.log-entry { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--surface2); }
.log-time { color: var(--text2); font-size: 11px; white-space: nowrap; padding-top: 1px; }
.log-dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.log-entry.success .log-dot { background: var(--green); }
.log-entry.error .log-dot { background: var(--red); }
.log-entry.info .log-dot { background: var(--accent2); }
.log-msg { flex: 1; color: var(--text); }

/* ── TOAST ── */
#toast { position: fixed; bottom: 24px; right: 24px; padding: 12px 20px; border-radius: 12px; font-size: 14px; font-weight: 500; opacity: 0; transform: translateY(10px); transition: all 0.3s; z-index: 9999; pointer-events: none; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { background: var(--green); color: #000; }
#toast.error { background: var(--red); color: #fff; }
#toast.info { background: var(--accent); color: #fff; }

/* ── EMPTY STATE ── */
.empty { text-align: center; padding: 30px; color: var(--text2); font-size: 13px; }
.empty-icon { font-size: 32px; margin-bottom: 8px; }

/* ── SPINNER ── */
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PHONE SEARCH ── */
.phone-row { display: flex; gap: 8px; }
.phone-row input { flex: 1; }
.found-user { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: rgba(0,214,143,.1); border: 1px solid rgba(0,214,143,.3); margin-top: 10px; cursor: pointer; }
.found-user:hover { background: rgba(0,214,143,.2); }
.found-user .avatar { background: linear-gradient(135deg,#00d68f,#00c2ff); }
.found-user .item-name { color: var(--green); font-weight: 600; }

/* ── CRM CONTACTS ── */
.crm-stats-bar { font-size: 11px; color: var(--text2); margin-bottom: 6px; }
.crm-filter-row { display: flex; gap: 4px; margin-bottom: 8px; }
.crm-filter-btn { flex: 1; padding: 4px 6px; font-size: 11px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface2); color: var(--text2); cursor: pointer; text-align: center; transition: all .15s; }
.crm-filter-btn:hover { border-color: var(--accent); color: var(--text); }
.crm-filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.crm-search-row { display: flex; gap: 6px; margin-bottom: 8px; }
.crm-search-row input { flex: 1; padding: 7px 10px; font-size: 13px; }
.crm-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.crm-list::-webkit-scrollbar { width: 4px; }
.crm-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.crm-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; background: var(--surface2); font-size: 13px; transition: background .15s; }
.crm-item:hover { background: rgba(0,104,255,.08); }
.crm-item.non-friend { border-left: 3px solid var(--yellow); }
.crm-item-info { flex: 1; min-width: 0; cursor: pointer; }
.crm-item-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-item-sub { font-size: 11px; color: var(--text2); font-family: monospace; }
.crm-item-notes { font-size: 11px; color: var(--text2); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crm-item-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.del-phone-btn { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px; flex-shrink: 0; }
.del-phone-btn:hover { color: var(--red); background: rgba(255,71,87,.1); }

/* ── FRIEND STATUS BADGES ── */
.badge-friend    { display:inline-block; font-size:10px; padding:1px 6px; border-radius:4px; background:rgba(0,214,143,.15); color:var(--green); font-weight:600; vertical-align:middle; }
.badge-nonfriend { display:inline-block; font-size:10px; padding:1px 6px; border-radius:4px; background:rgba(255,211,42,.15); color:var(--yellow); font-weight:600; vertical-align:middle; }
.badge-unknown   { display:inline-block; font-size:10px; padding:1px 6px; border-radius:4px; background:rgba(136,150,179,.1); color:var(--text2); vertical-align:middle; }
.badge-group     { display:inline-block; font-size:10px; padding:1px 6px; border-radius:4px; background:rgba(0,104,255,.15); color:var(--accent2); font-weight:600; vertical-align:middle; }

/* ── IMAGE PREVIEW ── */
.img-attach-area { display: flex; flex-direction: column; gap: 8px; }
.img-attach-row { display: flex; gap: 8px; align-items: center; }
.img-preview-wrap {
  position: relative;
  display: inline-block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.img-preview-wrap img { display: block; max-width: 100%; max-height: 130px; border-radius: 9px; }
.img-preview-info { font-size: 11px; color: var(--text2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.img-clear-btn {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,.7); color: #fff; border: none;
  border-radius: 50%; width: 22px; height: 22px;
  cursor: pointer; font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.img-clear-btn:hover { background: var(--red); }

/* ── BROADCAST ── */
.broadcast-targets { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; margin-bottom: 12px; }
.broadcast-targets::-webkit-scrollbar { width: 4px; }
.broadcast-targets::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.bc-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; background: var(--surface2); font-size: 13px; }
.bc-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.bc-item label { flex: 1; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0; text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 400; color: var(--text); }
.bc-item .bc-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: rgba(0,104,255,.2); color: var(--accent2); flex-shrink: 0; }
.bc-stats { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.bc-select-row { display: flex; gap: 6px; margin-bottom: 10px; }
.bc-select-row button { flex: 1; padding: 5px; font-size: 11px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface2); color: var(--text2); cursor: pointer; }
.bc-select-row button:hover { border-color: var(--accent); color: var(--text); }

/* ══════════════════════════════════════════
   LOGIN MODAL
══════════════════════════════════════════ */
#login-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-overlay.hidden { display: none; }
.login-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px;
  width: 380px;
  text-align: center;
  box-shadow: 0 40px 80px rgba(0,0,0,.6);
}
.login-modal h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-modal p { font-size: 13px; color: var(--text2); margin-bottom: 24px; }
#qr-box {
  width: 220px; height: 220px;
  margin: 0 auto 20px;
  border-radius: 16px;
  background: var(--surface2);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
#qr-box img { width: 100%; height: 100%; object-fit: contain; display: none; }
#qr-placeholder { color: var(--text2); font-size: 13px; text-align: center; padding: 20px; }
#qr-placeholder .big-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.login-steps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.step { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text2); padding: 8px 12px; border-radius: 10px; background: var(--surface2); }
.step.active { color: var(--text); background: rgba(0,104,255,.15); border: 1px solid rgba(0,104,255,.3); }
.step.done { color: var(--green); }
.step-icon { font-size: 16px; }
.step-num { width: 20px; height: 20px; border-radius: 50%; background: var(--border); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.step.active .step-num { background: var(--accent); color: #fff; }
.step.done .step-num { background: var(--green); color: #000; }
#login-success { display: none; flex-direction: column; align-items: center; gap: 12px; }
.success-icon { font-size: 64px; animation: pop .4s cubic-bezier(.34,1.56,.64,1); }
@keyframes pop { from{transform:scale(0)} to{transform:scale(1)} }
#login-success h3 { font-size: 18px; font-weight: 700; color: var(--green); }
#login-success p { font-size: 13px; color: var(--text2); }
