/* ==========================================
   پیام‌رسان خصوصی - استایل اصلی
   ========================================== */
:root{
  --font: 'Vazirmatn', Tahoma, sans-serif;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* پالت پیش‌فرض (پسر - تیره: آبی/مشکی) */
  --bg: #0b0d14;
  --bg-elevated: #12151f;
  --surface: #171b28;
  --surface-2: #1e2333;
  --border: #262c3e;
  --text: #eef0f6;
  --text-dim: #8992ab;
  --accent: #4d6bff;
  --accent-2: #7c5cff;
  --bubble-mine: linear-gradient(135deg,#3d5bff,#6a4dff);
  --bubble-mine-text: #ffffff;
  --bubble-theirs: #1c2131;
  --bubble-theirs-text: #eef0f6;
  --danger: #ff5470;
  --success: #35d68a;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

body.role-girl{
  /* پالت دختر - صورتی */
  --bg: #1a0f16;
  --bg-elevated: #21131b;
  --surface: #271620;
  --surface-2: #331b28;
  --border: #3a2130;
  --text: #f8eef3;
  --text-dim: #b98da2;
  --accent: #ff6fa3;
  --accent-2: #ff9ccb;
  --bubble-mine: linear-gradient(135deg,#ff6fa3,#ff8fb8);
  --bubble-mine-text: #2a0b16;
  --bubble-theirs: #2b1620;
  --bubble-theirs-text: #f8eef3;
}

body.role-girl.theme-light{
  --bg: #fff5f8;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #fff0f5;
  --border: #f3d6e3;
  --text: #351522;
  --text-dim: #9b6f80;
  --accent: #ff6fa3;
  --accent-2: #d94f89;
  --bubble-mine: linear-gradient(135deg,#ff6fa3,#ff8fb8);
  --bubble-mine-text: #ffffff;
  --bubble-theirs: #ffffff;
  --bubble-theirs-text: #351522;
  --shadow: 0 10px 30px rgba(217,79,137,.15);
}

*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{height:100%; margin:0;}
body{
  font-family:var(--font);
  background:var(--bg);
  color:var(--text);
  overflow:hidden;
  padding-top:var(--safe-top);
  padding-bottom:var(--safe-bottom);
}
.hidden{display:none !important;}
button{font-family:inherit; cursor:pointer;}
input,textarea{font-family:inherit;}
img{max-width:100%; display:block;}
::selection{background:var(--accent); color:#fff;}

/* ===== دکمه‌های عمومی ===== */
.icon-btn{
  background:transparent; border:none; color:var(--text);
  width:40px; height:40px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  transition:background .15s ease;
}
.icon-btn:hover{background:var(--surface-2);}
.icon-btn.primary{background:var(--accent); color:#fff;}
.icon-btn.primary:hover{filter:brightness(1.08);}
.primary-btn{
  background:linear-gradient(135deg,var(--accent),var(--accent-2)); color:#fff; border:none;
  border-radius:var(--radius-md); padding:13px; font-size:15px; font-weight:600; width:100%;
  display:flex; align-items:center; justify-content:center; gap:8px; transition:transform .1s ease, opacity .2s;
}
.primary-btn:active{transform:scale(.98);}
.primary-btn:disabled{opacity:.6; pointer-events:none;}
.secondary-btn{
  background:var(--surface-2); color:var(--text); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:10px 14px; font-size:14px; font-weight:500;
}
.danger-btn{background:rgba(255,84,112,.12); color:var(--danger); border:1px solid rgba(255,84,112,.3); border-radius:var(--radius-sm); padding:10px 14px; font-weight:600;}
.full{width:100%;}
.only-mobile{display:none;}

/* ===== صفحه ورود ===== */
#login-screen{
  height:100%; display:flex; align-items:center; justify-content:center; padding:20px;
  background:radial-gradient(circle at 50% 0%, var(--bg-elevated), var(--bg) 70%);
}
.login-card{
  width:100%; max-width:380px; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-lg); padding:36px 28px; text-align:center; box-shadow:var(--shadow);
  animation:cardIn .5s cubic-bezier(.2,.8,.2,1);
}
@keyframes cardIn{from{opacity:0; transform:translateY(16px) scale(.98);} to{opacity:1; transform:none;}}
.login-logo{display:flex; justify-content:center; margin-bottom:14px;}
.login-card h1{font-size:20px; margin:0 0 6px;}
.login-sub{color:var(--text-dim); font-size:13.5px; margin:0 0 24px;}
.input-wrap{position:relative; display:flex; align-items:center; margin-bottom:14px;}
.input-wrap input{
  flex:1; background:var(--surface-2); border:1px solid var(--border); color:var(--text);
  border-radius:var(--radius-sm); padding:13px 44px 13px 14px; font-size:15px; width:100%;
  transition:border-color .15s;
}
.input-wrap input:focus{outline:none; border-color:var(--accent);}
.input-wrap .icon-btn{position:absolute; left:2px; width:36px; height:36px;}
.error-text{color:var(--danger); font-size:13px; margin-top:12px; text-align:center;}
.hint-text{color:var(--text-dim); font-size:12.5px; margin-top:8px;}
.btn-spinner{width:18px; height:18px; border:2.5px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius:50%; animation:spin .7s linear infinite;}
@keyframes spin{to{transform:rotate(360deg);}}

/* ===== لایه اصلی برنامه ===== */
#app-screen{height:100%; display:flex; flex-direction:column;}
#chat-header{
  display:flex; align-items:center; gap:10px; padding:10px 14px;
  padding-top:calc(10px + var(--safe-top)); background:var(--bg-elevated); border-bottom:1px solid var(--border);
  flex-shrink:0; z-index:5;
}
.partner-info{display:flex; align-items:center; gap:10px; flex:1; min-width:0;}
.avatar{width:40px; height:40px; border-radius:50%; object-fit:cover; background:var(--surface-2); flex-shrink:0;}
.avatar.large{width:76px; height:76px;}
.partner-text{display:flex; flex-direction:column; min-width:0;}
#partner-name{font-weight:600; font-size:15px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.status-text{font-size:12.5px; color:var(--text-dim);}
.status-text.online{color:var(--success);}
.status-text.typing{color:var(--accent);}
.header-actions{display:flex; gap:2px;}

/* ===== جستجو ===== */
#search-bar{
  display:flex; flex-wrap:wrap; align-items:center; gap:8px; padding:10px 14px;
  background:var(--bg-elevated); border-bottom:1px solid var(--border); position:relative; z-index:4;
}
#search-input{
  flex:1; background:var(--surface-2); border:1px solid var(--border); color:var(--text);
  border-radius:var(--radius-sm); padding:9px 12px; font-size:14px;
}
#search-results{
  width:100%; max-height:260px; overflow-y:auto; background:var(--surface);
  border-radius:var(--radius-sm); border:1px solid var(--border);
}
.search-result-item{padding:10px 12px; border-bottom:1px solid var(--border); font-size:13.5px; cursor:pointer;}
.search-result-item:hover{background:var(--surface-2);}
.search-result-item .sr-date{color:var(--text-dim); font-size:11.5px; display:block; margin-top:3px;}

/* ===== ناحیه پیام‌ها ===== */
#messages-container{
  flex:1; overflow-y:auto; position:relative; padding:14px 12px 18px;
  background-image:var(--chat-bg, none); background-size:cover; background-position:center;
  scroll-behavior:smooth;
}
#messages-list{display:flex; flex-direction:column; gap:3px; max-width:720px; margin:0 auto;}
.date-sep{align-self:center; background:var(--surface); color:var(--text-dim); font-size:12px; padding:5px 14px; border-radius:20px; margin:14px 0 8px;}
#empty-state{position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; color:var(--text-dim); gap:6px;}
#empty-state span{font-size:13px;}
#scroll-bottom-btn{
  position:absolute; bottom:16px; left:16px; width:38px; height:38px; border-radius:50%;
  background:var(--surface); border:1px solid var(--border); color:var(--text); box-shadow:var(--shadow);
  display:flex; align-items:center; justify-content:center;
}

/* ===== حباب پیام ===== */
.msg-row{display:flex; max-width:78%; align-self:flex-start; animation:msgIn .25s ease; position:relative;}
.msg-row.mine{align-self:flex-end; flex-direction:row-reverse;}
@keyframes msgIn{from{opacity:0; transform:translateY(6px);} to{opacity:1; transform:none;}}
@media (prefers-reduced-motion: reduce){.msg-row{animation:none;}}

.bubble{
  background:var(--bubble-theirs); color:var(--bubble-theirs-text);
  padding:9px 13px; border-radius:var(--radius-md); border-bottom-right-radius:4px;
  font-size:14.5px; line-height:1.7; word-break:break-word; box-shadow:0 1px 2px rgba(0,0,0,.15);
  position:relative; min-width:56px;
}
.msg-row.mine .bubble{background:var(--bubble-mine); color:var(--bubble-mine-text); border-bottom-right-radius:var(--radius-md); border-bottom-left-radius:4px;}
.bubble.deleted{opacity:.6; font-style:italic;}
.bubble-meta{display:flex; align-items:center; gap:4px; justify-content:flex-end; margin-top:4px; font-size:11px; opacity:.75;}
.edited-tag{font-size:10.5px; opacity:.8;}
.seen-icon{display:inline-flex;}

body.text-small .bubble{font-size:12.5px;}
body.text-large .bubble{font-size:16.5px;}
body.text-xlarge .bubble{font-size:19px;}

.reply-quote{
  background:rgba(0,0,0,.15); border-right:3px solid var(--accent); border-radius:8px;
  padding:5px 8px; margin-bottom:6px; font-size:12.5px; opacity:.9; cursor:pointer;
}
.msg-row.mine .reply-quote{border-right:none; border-left:3px solid rgba(255,255,255,.7);}
.reply-quote .rq-name{font-weight:600; display:block; margin-bottom:2px;}

.bubble.highlight{animation:highlightPulse 1.4s ease;}
@keyframes highlightPulse{0%,100%{box-shadow:0 1px 2px rgba(0,0,0,.15);} 30%{box-shadow:0 0 0 4px var(--accent);}}

.bubble img.media-img, .bubble video.media-vid{border-radius:10px; max-width:260px; max-height:320px; cursor:pointer; display:block;}
.media-caption-time{margin-top:4px;}

.voice-msg{display:flex; align-items:center; gap:8px; min-width:190px;}
.voice-play{width:34px; height:34px; border-radius:50%; background:rgba(255,255,255,.15); border:none; display:flex; align-items:center; justify-content:center; color:inherit; flex-shrink:0;}
.msg-row:not(.mine) .voice-play{background:var(--surface-2);}
.voice-wave-bar{flex:1; height:26px; display:flex; align-items:center; gap:2px;}
.voice-wave-bar span{width:3px; background:currentColor; opacity:.5; border-radius:2px;}
.voice-duration{font-size:11px; opacity:.8; flex-shrink:0;}

.msg-row.pressing .bubble{filter:brightness(.9);}

/* ===== نوار پاسخ/ویرایش ===== */
#reply-preview-bar, #edit-bar{
  display:flex; align-items:center; gap:10px; padding:8px 14px; background:var(--surface); border-top:1px solid var(--border);
}
.reply-line{width:3px; height:30px; background:var(--accent); border-radius:2px;}
.reply-content{flex:1; min-width:0; display:flex; flex-direction:column;}
.reply-label{font-size:12px; color:var(--accent);}
#reply-to-text{font-size:13px; color:var(--text-dim); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
#edit-bar{justify-content:space-between; color:var(--accent); font-size:13.5px;}

/* ===== نوار ارسال پیام ===== */
#composer{
  display:flex; align-items:flex-end; gap:6px; padding:10px 12px;
  padding-bottom:calc(10px + var(--safe-bottom)); background:var(--bg-elevated); border-top:1px solid var(--border); position:relative;
}
#text-compose-wrap{flex:1; background:var(--surface-2); border:1px solid var(--border); border-radius:20px; padding:2px 6px;}
#message-input{
  width:100%; background:transparent; border:none; color:var(--text); resize:none;
  padding:9px 10px; font-size:14.5px; max-height:120px; line-height:1.5;
}
#message-input:focus{outline:none;}

#attach-menu{
  position:absolute; bottom:64px; right:12px; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius-md); box-shadow:var(--shadow); overflow:hidden; z-index:6;
}
#attach-menu button{
  display:flex; align-items:center; gap:10px; width:100%; padding:12px 16px; background:none; border:none;
  color:var(--text); font-size:14px; text-align:right;
}
#attach-menu button:hover{background:var(--surface-2);}

/* ===== ضبط صدا ===== */
#voice-recorder{
  display:flex; align-items:center; gap:10px; padding:10px 14px; background:var(--surface); border-top:1px solid var(--border);
}
#voice-wave{display:flex; gap:3px; align-items:center; flex:1; height:24px;}
#voice-wave span{width:3px; background:var(--danger); border-radius:2px; animation:wavePulse 1s ease-in-out infinite;}
#voice-wave span:nth-child(2){animation-delay:.1s;} #voice-wave span:nth-child(3){animation-delay:.2s;}
#voice-wave span:nth-child(4){animation-delay:.3s;} #voice-wave span:nth-child(5){animation-delay:.4s;}
@keyframes wavePulse{0%,100%{height:6px;} 50%{height:22px;}}
#voice-timer{font-variant-numeric:tabular-nums; font-size:13px; color:var(--text-dim);}

/* ===== منوی عملیات پیام ===== */
#msg-action-menu{
  position:fixed; z-index:50; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md);
  box-shadow:var(--shadow); overflow:hidden; min-width:150px; animation:menuIn .15s ease;
}
@keyframes menuIn{from{opacity:0; transform:scale(.95);} to{opacity:1; transform:none;}}
#msg-action-menu button{width:100%; padding:12px 16px; background:none; border:none; color:var(--text); text-align:right; font-size:14px;}
#msg-action-menu button:hover{background:var(--surface-2);}
#msg-action-menu button.danger{color:var(--danger);}

/* ===== دیالوگ تایید ===== */
#confirm-dialog{position:fixed; inset:0; z-index:60; display:flex; align-items:center; justify-content:center;}
.panel-backdrop{position:absolute; inset:0; background:rgba(0,0,0,.5); backdrop-filter:blur(2px);}
.confirm-box{position:relative; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg); padding:22px; width:90%; max-width:320px; text-align:center; box-shadow:var(--shadow);}
.confirm-box p{font-size:14.5px; margin:0 0 18px;}
.confirm-actions{display:flex; gap:10px;}
.confirm-actions button{flex:1;}

/* ===== پنل تنظیمات ===== */
#settings-panel{position:fixed; inset:0; z-index:40; display:flex; justify-content:flex-end;}
.panel-body{
  position:relative; width:100%; max-width:380px; height:100%; background:var(--bg-elevated);
  overflow-y:auto; animation:panelIn .25s ease; box-shadow:var(--shadow);
}
@keyframes panelIn{from{transform:translateX(-100%);} to{transform:none;}}
.panel-header{display:flex; align-items:center; justify-content:space-between; padding:16px; padding-top:calc(16px + var(--safe-top)); border-bottom:1px solid var(--border); position:sticky; top:0; background:var(--bg-elevated); z-index:2;}
.panel-header h2{margin:0; font-size:17px;}
.panel-content{padding:16px;}
.settings-section{margin-bottom:26px; padding-bottom:22px; border-bottom:1px solid var(--border);}
.settings-section:last-of-type{border-bottom:none;}
.settings-section h3{font-size:14px; color:var(--text-dim); margin:0 0 14px; font-weight:600;}
.field-label{display:block; font-size:12.5px; color:var(--text-dim); margin:14px 0 6px;}
.avatar-edit{display:flex; align-items:center; gap:14px; margin-bottom:10px;}
.option-pills{display:flex; gap:8px; flex-wrap:wrap;}
.option-pills button{padding:8px 14px; border-radius:20px; border:1px solid var(--border); background:var(--surface-2); color:var(--text); font-size:13px;}
.option-pills button.active{background:var(--accent); border-color:var(--accent); color:#fff;}
.switch-row{display:flex; align-items:center; justify-content:space-between; padding:10px 0; font-size:14px;}
.switch-row input{width:20px; height:20px;}
.stacked-input{width:100%; background:var(--surface-2); border:1px solid var(--border); color:var(--text); border-radius:var(--radius-sm); padding:11px 12px; font-size:14px; margin-bottom:10px;}

/* ===== نمایشگر رسانه تمام‌صفحه ===== */
#media-viewer{position:fixed; inset:0; z-index:70; background:rgba(0,0,0,.92); display:flex; align-items:center; justify-content:center;}
#media-viewer #media-close{position:absolute; top:calc(16px + var(--safe-top)); left:16px; color:#fff; background:rgba(255,255,255,.1);}
#media-viewer-content{max-width:94vw; max-height:88vh; display:flex; align-items:center; justify-content:center;}
#media-viewer-content img, #media-viewer-content video{max-width:94vw; max-height:88vh; border-radius:6px;}

/* ===== اسکرول‌بار ===== */
::-webkit-scrollbar{width:6px; height:6px;}
::-webkit-scrollbar-thumb{background:var(--border); border-radius:6px;}

/* ===== واکنش‌گرا: موبایل ===== */
@media (max-width: 720px){
  .only-mobile{display:flex;}
  .msg-row{max-width:86%;}
  .login-card{padding:28px 20px;}
  #settings-panel{justify-content:stretch;}
  .panel-body{max-width:100%;}
}

/* ===== واکنش‌گرا: دسکتاپ ===== */
@media (min-width: 900px){
  body{display:flex; align-items:center; justify-content:center;}
  #app-screen, #login-screen{
    max-width:900px; width:100%; height:92vh; max-height:900px;
    border-radius:22px; overflow:hidden; border:1px solid var(--border); box-shadow:var(--shadow);
  }
}

:focus-visible{outline:2px solid var(--accent); outline-offset:2px;}
