/* assets/css/style.css */

@font-face {
  font-family: "IRANSansX";
  src: url("../fonts/IRANSansX/Woff2/IRANSansXFaNum-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSansX";
  src: url("../fonts/IRANSansX/Woff2/IRANSansXFaNum-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSansX";
  src: url("../fonts/IRANSansX/Woff2/IRANSansXFaNum-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root{
  --bg1:#0b1220;
  --bg2:#0f1b33;
  --muted:#9fb0d0;
  --text:#e9f0ff;
  --accent:#6d8cff;
  --accent2:#38d9a9;
  --danger:#ff6b6b;
  --border: rgba(255,255,255,.08);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --glass: rgba(15,26,43,.72);
  --glass2: rgba(15,26,43,.56);
}

*{ box-sizing:border-box; font-family:"IRANSansX",system-ui,-apple-system,"Segoe UI",Roboto,Arial; }
html,body{ height:100%; }
body{ margin:0; color:var(--text); background:var(--bg1); }
body.modal-open{ overflow:hidden; }
.hidden{ display:none !important; }

.bg{
  background: radial-gradient(1200px 800px at 20% 10%, #152a55, transparent 60%),
              radial-gradient(900px 700px at 90% 40%, #173b6d, transparent 55%),
              linear-gradient(180deg, var(--bg1), var(--bg2));
  display:flex;
}
.chat-bg{
  background: radial-gradient(900px 700px at 20% 10%, #122a52, transparent 60%),
              radial-gradient(900px 700px at 90% 40%, #0c335b, transparent 55%),
              linear-gradient(180deg, var(--bg1), var(--bg2));
}

input, textarea, select{ font-size:16px; }
input, textarea, button{ -webkit-tap-highlight-color: transparent; }

/* Auth */
.auth-wrap{ width:100%; display:flex; align-items:center; justify-content:center; padding:24px; }
.card{
  background: rgba(15,26,43,.82);
  border:1px solid var(--border);
  border-radius:18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.auth-card{ width:min(520px,100%); padding:22px; }
.brand{ display:flex; align-items:center; gap:14px; margin-bottom:16px; }
.logo{
  width:44px; height:44px; border-radius:14px;
  display:flex; align-items:center; justify-content:center;
  background: rgba(109,140,255,.18);
  border:1px solid var(--border);
}
.title{ font-weight:800; }
.subtitle{ color:var(--muted); font-size:13px; margin-top:2px; }
.form{ display:flex; flex-direction:column; gap:10px; }
.label{ font-size:12px; color:var(--muted); margin-top:4px; }

.input{
  width:100%;
  padding:12px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(10,18,34,.55);
  color:var(--text);
  outline:none;
}
.input:focus{ border-color: rgba(109,140,255,.6); background: rgba(10,18,34,.75); }

.btn{
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color:var(--text);
  border-radius:12px;
  padding:11px 14px;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  text-decoration:none;
  user-select:none;
}
.btn:hover{ background: rgba(255,255,255,.09); }
.btn:active{ transform: translateY(1px); }
.btn.primary{
  background: linear-gradient(135deg, rgba(109,140,255,.95), rgba(56,217,169,.75));
  border-color: rgba(255,255,255,.14);
  font-weight:700;
}
.btn.ghost{ padding:9px 12px; }
.btn.icon{ width:44px; padding:0; font-size:18px; }
.btn.small{ padding:7px 10px; border-radius:10px; font-size:12px; }
.btn.loading{ opacity:.85; pointer-events:none; }

.error{
  margin-top:8px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid rgba(255,107,107,.3);
  background: rgba(255,107,107,.12);
  color:#ffd7d7;
  font-size:13px;
}
.hint{ margin-top:10px; color:var(--muted); font-size:12px; }

/* Spinner */
.spinner{
  width:18px; height:18px; border-radius:50%;
  border:2px solid rgba(255,255,255,.25);
  border-top-color: rgba(255,255,255,.85);
  animation: spin .8s linear infinite;
}
.spinner.small{ width:14px; height:14px; }
@keyframes spin{ to{ transform: rotate(360deg);} }

/* Admin */
.admin-head{
  display:flex; gap:10px; align-items:center; justify-content:space-between;
  margin-bottom: 12px;
}
.admin-actions{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.table-wrap{ width:100%; overflow:auto; border-radius:14px; border:1px solid var(--border); }
.user-table{ width:100%; min-width: 720px; border-collapse:collapse; }
.user-table th,.user-table td{
  padding:10px 10px; text-align:right; font-size:13px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.user-table th{ font-weight:800; background: rgba(255,255,255,.04); }
.user-table tr:hover td{ background: rgba(255,255,255,.03); }

/* Chat shell */
.chat-shell{
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  display:flex;
  flex-direction:column;
  padding: 16px;
  gap: 12px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.chat-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--glass);
  border:1px solid var(--border);
  box-shadow: var(--shadow);
}
.chat-header .left{
  display:flex;
  align-items:center;
  gap:12px;
  min-width: 0;
  flex: 1 1 auto;
}
.chat-header .right{
  display:flex;
  gap:8px;
  align-items:center;
  flex: 0 0 auto;
}

/* Back button should appear on far LEFT visually */
.back-btn{
  display:none;
  width:44px;
  margin-right: auto; /* ✅ pushes to the far left in RTL */
}

.avatar{
  width:40px; height:40px; border-radius:14px;
  background: rgba(109,140,255,.2);
  border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center;
  font-weight:800;
  overflow:hidden;
  flex: 0 0 auto;
}
.avatar img{ width:100%; height:100%; object-fit:cover; display:block; }

.header-meta{ min-width:0; }
.header-name{
  font-weight:800;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.header-status{
  color:var(--muted);
  font-size:13px;
  margin-top:2px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

/* Header menu (for mobile clean) */
.menu-wrap{ position:relative; }
.menu-panel{
  position:absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(15,26,43,.92);
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 50;
}
.menu-item{
  width:100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.06);
  background: rgba(255,255,255,.03);
  color: var(--text);
  padding: 10px 10px;
  cursor: pointer;
  text-decoration: none;
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.menu-item:hover{ background: rgba(255,255,255,.06); }

/* Chat main layout */
.chat-main{
  position:relative;
  flex:1;
  min-height:0;
  border-radius: 16px;
  background: var(--glass2);
  border:1px solid var(--border);
  overflow:hidden;
  display:flex;
  direction: rtl;
}

#sidebar{
  width: 280px;
  flex: 0 0 280px;
  border-left:1px solid rgba(255,255,255,.04);
  background: rgba(10,18,34,.50);
  padding:12px;
  overflow:auto;
}

.sidebar-top{ display:flex; gap:8px; align-items:center; margin-bottom:10px; }
.sidebar-top strong{ font-weight: 900; }
.sidebar-top .btn{ margin-right:auto; }

.userItem{
  padding:10px;
  border-radius:14px;
  margin-bottom:10px;
  background: rgba(255,255,255,.02);
  border: 1px solid rgba(255,255,255,.05);
  cursor:pointer;
}
.userItem:hover{ background: rgba(255,255,255,.04); }
.userRow{ display:flex; gap:10px; align-items:center; }
.userMeta{ min-width:0; flex:1; }
.userName{ font-weight:900; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.userSub{ font-size:12px; color:var(--muted); margin-top:5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.userRight{ display:flex; gap:8px; align-items:center; flex:0 0 auto; }
.badge{
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(56,217,169,.22);
  border:1px solid rgba(56,217,169,.35);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 12px;
  font-weight: 900;
  padding: 0 7px;
}
.userDots{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
}
.userDots:hover{ background: rgba(255,255,255,.07); }

.userMenu{
  position:absolute;
  margin-top: 8px;
  left: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(15,26,43,.94);
  box-shadow: var(--shadow);
  padding: 8px;
  width: 210px;
  z-index: 40;
}
.userMenu .menu-item{ margin-bottom: 8px; }
.userMenu .menu-item:last-child{ margin-bottom: 0; }

#conversationArea{
  flex: 1 1 auto;
  min-width:0;
  height:100%;
  display:flex;
  flex-direction:column;
  position:relative;
}

.top-loader{
  position:absolute;
  top:10px; left:50%;
  transform: translateX(-50%);
  display:flex; gap:10px; align-items:center;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(10,18,34,.75);
  z-index: 20;
  color: var(--muted);
  font-size: 13px;
}

.day-toast{
  position:absolute;
  top: 12px;
  left:50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(10,18,34,.82);
  color: rgba(233,240,255,.85);
  font-size: 12px;
  pointer-events:none;
  opacity: 0;
  transition: opacity .18s ease;
}
.day-toast.show{ opacity: 1; }

.messages{
  flex: 1 1 auto;
  min-height:0;
  overflow:auto;
  padding: 16px;
  display:flex;
  flex-direction:column;
  gap: 10px;
  scroll-behavior:smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Date separator like Telegram */
.day-sep{
  align-self:center;
  padding: 6px 12px;
  border-radius: 999px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  color: rgba(233,240,255,.75);
  font-size: 12px;
  margin: 6px 0;
}

.bubble{
  max-width: min(78%, 680px);
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
}
.bubble.mine{
  align-self:flex-start;
  background: rgba(109,140,255,.16);
  border-color: rgba(109,140,255,.26);
}
.bubble.theirs{
  align-self:flex-end;
  background: rgba(255,255,255,.04);
}

.bubble .text{
  line-height:1.6;
  white-space: pre-wrap;
  word-break: break-word;
  direction: rtl;
  unicode-bidi: plaintext;
}

.bubble .meta{
  margin-top: 8px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  color: rgba(233,240,255,.55);
  font-size: 11px;
}

.reply-btn{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  border-radius: 10px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
}

.reply{
  border-right: 3px solid rgba(109,140,255,.75);
  background: rgba(255,255,255,.04);
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.reply__who{ color: rgba(233,240,255,.75); font-size: 11px; margin-bottom: 3px; }
.reply__text{ color: rgba(233,240,255,.9); font-size: 12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.media img{ max-width:100%; border-radius:12px; display:block; }
.media video{ width:100%; max-width:100%; border-radius:12px; display:block; background:#000; }
.media-actions{ margin-top: 8px; display:flex; gap:8px; }

.bubble.flash{
  outline:2px solid rgba(56,217,169,.8);
  outline-offset:2px;
}

.bubble .meta .seen{ color: var(--accent2); font-weight:900; margin-right: 6px; }
.bubble .meta .pending{ color: var(--muted); margin-right: 6px; }

.chat-footer{
  padding: 12px;
  border-top:1px solid rgba(255,255,255,.06);
  background: rgba(15,26,43,.40);
}

.composer{ display:flex; gap:10px; align-items:flex-end; }
.input.msg{
  flex:1;
  resize:none;
  overflow:hidden;
  min-height:44px;
  max-height:160px;
  overflow-y:auto;
  padding:12px 12px;
}
.file{ display:none; }

.send-btn-inner{
  display:inline-flex;
  align-items:center;
  gap:10px;
}

.replybar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
  margin-bottom: 10px;
}
.replybar__title{ color: rgba(233,240,255,.65); font-size:12px; margin-bottom:4px; }
.replybar__preview{
  color: rgba(233,240,255,.95);
  font-size:13px;
  max-width: 70vw;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

.upload{
  margin-top:10px;
  display:flex;
  align-items:center;
  gap:12px;
  color: var(--muted);
  font-size: 12px;
}
.upload .bar{
  flex:1; height:10px; border-radius:999px;
  background: rgba(255,255,255,.08);
  border:1px solid var(--border);
  overflow:hidden;
}
.upload .fill{
  width:0%;
  height:100%;
  background: linear-gradient(90deg, rgba(109,140,255,.95), rgba(56,217,169,.85));
  transition: width .15s ease;
}

/* ✅ scroll to bottom button - higher so it doesn't overlap send */
.scroll-bottom{
  position:absolute;
  left: 12px;
  bottom: 92px; /* ✅ moved up */
  z-index: 25;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(10,18,34,.75);
  color: var(--text);
  cursor:pointer;
  box-shadow: var(--shadow);
}

/* Modal */
.modal{ position: fixed; inset:0; z-index: 1000; }
.modal__backdrop{ position:absolute; inset:0; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); }
.modal__panel{
  position:absolute; inset:0;
  display:flex; flex-direction:column;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) 12px;
}
.modal__top{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding: 10px 12px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(15,26,43,.82);
}
.modal__body{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 10px;
  padding: 12px 0;
}
.stage{
  width: min(980px, 100%);
  height: 100%;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(10,18,34,.65);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.stage__img{ max-width:100%; max-height:100%; object-fit:contain; }
.stage__video{ width:100%; height:100%; object-fit:contain; background:#000; }
.navbtn{
  width:44px; height:44px; border-radius:999px;
  border:1px solid var(--border);
  background: rgba(15,26,43,.82);
  color: var(--text);
  cursor:pointer;
}
.navbtn:disabled{ opacity:.35; cursor: default; }

/* Settings modal (profile/password) */
.sheet{
  width: min(520px, 100%);
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(15,26,43,.92);
  box-shadow: var(--shadow);
  padding: 14px;
}
.sheet h3{ margin: 0 0 10px 0; }
.sheet .row{ display:flex; gap:10px; flex-wrap:wrap; }
.sheet .row .col{ flex: 1 1 220px; }
.sheet .actions{ display:flex; gap:10px; margin-top:12px; }

@media (max-width: 780px){
  .chat-shell{ padding: 10px; gap: 10px; }
  #sidebar{ width:100%; flex: 1 1 auto; border-left:0; }
  #conversationArea{ width:100%; flex:1 1 auto; }

  body:not(.mobile-chat-open) #conversationArea{ display:none; }
  body.mobile-chat-open #sidebar{ display:none; }
  body.mobile-chat-open #conversationArea{ display:flex; }

  body.mobile-chat-open .back-btn{ display:inline-flex; }
  body:not(.mobile-chat-open) .back-btn{ display:none; }

  .scroll-bottom{ left: 10px; bottom: 104px; width: 42px; height: 42px; } /* ✅ mobile higher */
  .messages{ padding: 12px; gap: 8px; }
  .bubble{ max-width: 92%; }
  .admin-head{ flex-direction: column; align-items: flex-start; gap: 10px; }
}
@media (hover:hover){
  .messages::-webkit-scrollbar{ width: 10px; }
  .messages::-webkit-scrollbar-track{ background: rgba(255,255,255,.04); }
  .messages::-webkit-scrollbar-thumb{
    background: rgba(255,255,255,.12);
    border-radius: 999px;
    border: 2px solid rgba(0,0,0,0);
    background-clip: padding-box;
  }
  textarea::-webkit-scrollbar{ width: 10px; }
  .textarea::-webkit-scrollbar-track{ background: rgba(255,255,255,.04); }
  .textarea::-webkit-scrollbar-thumb{
    background: rgba(255,255,255,.12);
    border-radius: 999px;
    border: 2px solid rgba(0,0,0,0);
    background-clip: padding-box;
  }
}
/* ✅ آنلاین همیشه سبز */
.status-online{
  color:#22c55e;
  font-weight:800;
}

/* ✅ اجازه بده متن‌ها خط بعد برن و بریده نشن */
.userMeta,
.userName,
.userSub,
#headerName,
#headerStatus{
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: unset !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ✅ توی flex اگر min-width:0 نباشه متن درست wrap نمیشه */
.userRow .userMeta{
  min-width: 0;
}

/* اگر جایی nowrap گذاشتی (مثلا برای userSub) اینو هم کمک می‌کنه */
.userSub{
  line-height: 1.35;
}
