/* ============================================================
   ChatLive Admin — Glassmorphism, Light Mode, Vazir
   ============================================================ */
:root{
  --bg: #eef2ff;
  --bg-2:#f8fafc;
  --glass:rgba(255,255,255,0.55);
  --glass-strong:rgba(255,255,255,0.75);
  --glass-border:rgba(255,255,255,0.8);
  --ink:#0f172a;
  --ink-2:#475569;
  --muted:#94a3b8;
  --accent:#4f46e5;
  --accent-2:#7c3aed;
  --ok:#10b981;
  --warn:#f59e0b;
  --err:#ef4444;
  --radius:16px;
  --radius-sm:10px;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
  --blur: 18px;
}

*{box-sizing:border-box}
html,body{margin:0;padding:0;min-height:100vh}
body{
  font-family:'Vazir','Vazirmatn',system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
  color:var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #c7d2fe 0%, transparent 50%),
    radial-gradient(1000px 500px at 110% 10%, #fbcfe8 0%, transparent 50%),
    radial-gradient(800px 500px at 50% 120%, #bae6fd 0%, transparent 55%),
    var(--bg);
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}

body.rtl{direction:rtl}
body.ltr{direction:ltr}

a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}

.glass{
  background:var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.2);
  border:1px solid var(--glass-border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

/* ---- Layout shell ---- */
.app{display:grid;grid-template-columns:260px 1fr;gap:20px;padding:20px;min-height:100vh}
body.rtl .app{grid-template-columns:260px 1fr}
.content{min-width:0}

/* ---- Sidebar ---- */
.sidebar{padding:18px;display:flex;flex-direction:column;gap:16px;position:sticky;top:20px;align-self:start;height:calc(100vh - 40px)}
.brand{display:flex;align-items:center;gap:10px;font-weight:700;font-size:1.1rem}
.brand .logo{width:28px;height:28px;border-radius:8px;background:linear-gradient(135deg,var(--accent),var(--accent-2))}
.site-switcher label{display:block;font-size:.75rem;color:var(--ink-2);margin-bottom:4px}
.site-switcher select{
  width:100%;padding:10px 12px;border-radius:var(--radius-sm);
  border:1px solid rgba(15,23,42,.08);background:var(--glass-strong);color:var(--ink);
  font-family:inherit;font-size:.9rem;cursor:pointer;
}
.nav{display:flex;flex-direction:column;gap:4px;flex:1;overflow:auto}
.nav-item{
  display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:var(--radius-sm);
  color:var(--ink-2);font-weight:500;font-size:.92rem;transition:background .15s
}
.nav-item:hover{background:rgba(79,70,229,.06);text-decoration:none;color:var(--ink)}
.nav-item.active{background:rgba(79,70,229,.12);color:var(--accent)}
.nav-icon{width:20px;height:20px;flex-shrink:0;display:inline-flex;align-items:center;justify-content:center;opacity:.85;color:currentColor}
.nav-icon svg{width:100%;height:100%;display:block}
.nav-item.active .nav-icon{opacity:1}

.sidebar-foot{display:flex;flex-direction:column;gap:10px;padding-top:10px;border-top:1px solid rgba(15,23,42,.06)}
.me{display:flex;align-items:center;gap:10px}
.avatar{width:36px;height:36px;border-radius:50%;background:linear-gradient(135deg,var(--accent),var(--accent-2));color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;text-transform:uppercase}
.who{font-size:.9rem;font-weight:600}
.role{font-size:.72rem;color:var(--muted)}
.lang-switch{display:flex;gap:6px}
.lang-switch.center{justify-content:center;margin-top:14px}
.lang-switch a{padding:4px 10px;border-radius:6px;font-size:.78rem;color:var(--ink-2);background:rgba(15,23,42,.04)}
.lang-switch a.active{background:var(--accent);color:#fff}
.logout{font-size:.85rem;color:var(--err)}

/* ---- Cards / Pages ---- */
.page{display:flex;flex-direction:column;gap:20px}
.page-head{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:10px}
.page-head h1{margin:0;font-size:1.35rem}
.page-head .actions{display:flex;gap:8px}
.card{padding:20px}
.cards-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px}
.stat-card{padding:20px}
.stat-card .n{font-size:2rem;font-weight:700;line-height:1}
.stat-card .l{font-size:.85rem;color:var(--ink-2);margin-top:6px}

/* ---- Form controls ---- */
label{font-size:.8rem;color:var(--ink-2);display:block;margin-bottom:6px}
.input, input[type=text],input[type=email],input[type=password],input[type=number],input[type=url],select,textarea{
  width:100%;padding:10px 12px;border-radius:var(--radius-sm);
  border:1px solid rgba(15,23,42,.1);background:rgba(255,255,255,.7);color:var(--ink);
  font-family:inherit;font-size:.92rem;
}
textarea{min-height:90px;resize:vertical}
.row{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px}
.form-row{display:flex;flex-direction:column;margin-bottom:14px}
.btn{
  display:inline-flex;align-items:center;gap:6px;padding:10px 16px;border-radius:var(--radius-sm);
  border:none;background:var(--accent);color:#fff;font-weight:600;cursor:pointer;font-size:.9rem;font-family:inherit;
  transition:transform .1s, background .15s
}
.btn:hover{background:var(--accent-2)}
.btn:active{transform:translateY(1px)}
.btn.secondary{background:rgba(15,23,42,.06);color:var(--ink)}
.btn.secondary:hover{background:rgba(15,23,42,.1)}
.btn.danger{background:var(--err)}
.btn.ghost{background:transparent;color:var(--ink-2);border:1px solid rgba(15,23,42,.1)}
.btn.sm{padding:6px 10px;font-size:.8rem}
.toggle{position:relative;display:inline-block;width:42px;height:24px}
.toggle input{display:none}
.toggle .slider{position:absolute;cursor:pointer;inset:0;background:rgba(15,23,42,.15);border-radius:24px;transition:.2s}
.toggle .slider:before{content:'';position:absolute;height:18px;width:18px;left:3px;top:3px;background:#fff;border-radius:50%;transition:.2s}
.toggle input:checked + .slider{background:var(--accent)}
.toggle input:checked + .slider:before{transform:translateX(18px)}
body.rtl .toggle input:checked + .slider:before{transform:translateX(-18px)}

.badge{display:inline-flex;align-items:center;gap:4px;padding:2px 8px;border-radius:999px;font-size:.72rem;background:rgba(15,23,42,.08);color:var(--ink-2)}
.badge.ok{background:rgba(16,185,129,.12);color:#047857}
.badge.warn{background:rgba(245,158,11,.12);color:#b45309}
.badge.err{background:rgba(239,68,68,.12);color:#b91c1c}

.table{width:100%;border-collapse:collapse}
.table th,.table td{padding:10px 12px;text-align:start;border-bottom:1px solid rgba(15,23,42,.06);font-size:.9rem}
.table th{color:var(--ink-2);font-weight:600;font-size:.78rem;text-transform:uppercase;letter-spacing:.04em}

/* ---- Auth ---- */
body.auth{display:flex;align-items:center;justify-content:center}
.auth-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px;width:100%}
.auth-card{padding:32px;width:min(420px,100%)}
.auth-card h1{margin:0 0 4px;font-size:1.4rem}
.auth-card p.muted{color:var(--ink-2);margin:0 0 20px;font-size:.9rem}
.alert{padding:10px 12px;border-radius:var(--radius-sm);font-size:.85rem;margin-bottom:12px}
.alert.err{background:rgba(239,68,68,.1);color:#b91c1c}
.alert.ok{background:rgba(16,185,129,.1);color:#047857}

/* ---- Conversations ---- */
.conv-layout{display:grid;grid-template-columns:320px 1fr 300px;gap:16px;height:calc(100vh - 60px)}
@media(max-width:1200px){.conv-layout{grid-template-columns:300px 1fr}.conv-info{display:none}}
@media(max-width:900px){.conv-layout{grid-template-columns:1fr}}

.conv-list{display:flex;flex-direction:column;overflow:hidden}
.conv-tabs{display:flex;gap:4px;padding:10px;border-bottom:1px solid rgba(15,23,42,.06)}
.conv-tab{flex:1;text-align:center;padding:8px;border-radius:8px;font-size:.82rem;color:var(--ink-2);cursor:pointer}
.conv-tab.active{background:rgba(79,70,229,.12);color:var(--accent)}
.conv-items{overflow:auto;flex:1}
.conv-item{display:flex;gap:10px;padding:12px 14px;cursor:pointer;border-bottom:1px solid rgba(15,23,42,.04);position:relative}
.conv-item:hover{background:rgba(79,70,229,.04)}
.conv-item.active{background:rgba(79,70,229,.08)}
.conv-avatar{position:relative;width:40px;height:40px;border-radius:50%;background:linear-gradient(135deg,#fca5a5,#fb7185);color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;flex-shrink:0}
.conv-dot{position:absolute;bottom:0;right:0;width:10px;height:10px;border-radius:50%;border:2px solid #fff}
body.rtl .conv-dot{right:auto;left:0}
.conv-dot.online{background:var(--ok);animation:pulse 2s infinite}
.conv-dot.offline{background:#cbd5e1}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(16,185,129,.5)}70%{box-shadow:0 0 0 8px rgba(16,185,129,0)}100%{box-shadow:0 0 0 0 rgba(16,185,129,0)}}
.conv-body{flex:1;min-width:0}
.conv-name{font-weight:600;font-size:.92rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-last{font-size:.8rem;color:var(--ink-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-meta{display:flex;flex-direction:column;align-items:flex-end;gap:4px;font-size:.72rem;color:var(--muted)}
.conv-unread{background:var(--accent);color:#fff;font-size:.7rem;padding:1px 7px;border-radius:999px;font-weight:700}

.chat-area{display:flex;flex-direction:column;overflow:hidden}
.chat-empty{flex:1;display:flex;align-items:center;justify-content:center;color:var(--muted)}
.chat-head{padding:14px 18px;border-bottom:1px solid rgba(15,23,42,.06);display:flex;align-items:center;gap:12px}
.chat-title{font-weight:600}
.chat-sub{font-size:.78rem;color:var(--ink-2)}
.chat-stream{flex:1;overflow:auto;padding:20px;display:flex;flex-direction:column;gap:8px}
.date-sep{align-self:center;padding:4px 12px;background:rgba(15,23,42,.06);border-radius:999px;font-size:.72rem;color:var(--ink-2);margin:10px 0}
.bubble{max-width:70%;padding:10px 14px;border-radius:14px;position:relative;word-wrap:break-word;font-size:.92rem;line-height:1.45}
.bubble .time{font-size:.68rem;opacity:.7;margin-top:4px;display:block}
.bubble.visitor{align-self:flex-start;background:#fff;border:1px solid rgba(15,23,42,.06);border-bottom-left-radius:4px}
.bubble.operator{align-self:flex-end;background:var(--accent);color:#fff;border-bottom-right-radius:4px}
.bubble.ai{align-self:flex-end;background:linear-gradient(135deg,var(--accent),var(--accent-2));color:#fff;border-bottom-right-radius:4px}
.bubble.system{align-self:center;background:rgba(15,23,42,.04);color:var(--ink-2);font-size:.78rem;padding:6px 12px}

/* RTL: keep "my messages" (operator/ai) on the RIGHT, visitor messages on the LEFT.
   In RTL, flex-start is visually right. So swap the flex-self values. */
body.rtl .bubble.visitor { align-self:flex-end;   border-bottom-left-radius:14px; border-bottom-right-radius:4px; }
body.rtl .bubble.operator,
body.rtl .bubble.ai      { align-self:flex-start; border-bottom-right-radius:14px; border-bottom-left-radius:4px; }

/* Image/file attachments inside bubbles */
.bubble img, .bubble .att-img{max-width:240px;max-height:240px;border-radius:10px;display:block;margin:2px 0}
.bubble a{color:inherit;text-decoration:underline}

.typing{align-self:flex-start;padding:8px 14px;background:#fff;border-radius:14px;font-size:.8rem;color:var(--ink-2)}
body.rtl .typing{align-self:flex-end}
.typing .dots::after{content:'…';animation:ellipsis 1.2s infinite}
@keyframes ellipsis{0%{content:'.'}33%{content:'..'}66%{content:'...'}}

.chat-input{padding:12px;border-top:1px solid rgba(15,23,42,.06);display:flex;flex-direction:column;gap:6px}
.chat-toolbar{display:flex;gap:6px}
.chat-toolbar button{background:transparent;border:none;cursor:pointer;padding:6px 8px;border-radius:6px;color:var(--ink-2);font-size:.85rem}
.chat-toolbar button:hover{background:rgba(15,23,42,.06);color:var(--ink)}
.chat-compose{display:flex;gap:8px;align-items:flex-end}
.chat-compose textarea{flex:1;min-height:44px;max-height:140px;border-radius:10px}

/* ---- Conversation info panel ---- */
.conv-info{padding:18px;overflow:auto}
.info-row{margin-bottom:12px}
.info-k{font-size:.72rem;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
.info-v{font-size:.88rem;color:var(--ink);word-break:break-all}

/* ---- Code / snippet box ---- */
.code-box{background:#0f172a;color:#e2e8f0;padding:14px;border-radius:var(--radius-sm);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.82rem;overflow-x:auto;white-space:pre-wrap;word-break:break-all;position:relative}
.code-box .copy{position:absolute;top:8px;right:8px;background:rgba(255,255,255,.15);border:none;color:#fff;padding:4px 10px;border-radius:6px;cursor:pointer;font-size:.72rem}
body.rtl .code-box .copy{right:auto;left:8px}

/* ---- Small utilities ---- */
.flex{display:flex}
.gap-8{gap:8px}
.gap-12{gap:12px}
.mt-8{margin-top:8px}
.mt-16{margin-top:16px}
.mb-8{margin-bottom:8px}
.mb-16{margin-bottom:16px}
.muted{color:var(--ink-2)}
.small{font-size:.8rem}
.right{display:flex;justify-content:flex-end}
.hidden{display:none !important}

/* ---- Modal ---- */
.modal-overlay{
  position:fixed; inset:0; z-index:9999;
  background:rgba(15,23,42,.5); backdrop-filter:blur(4px);
  display:flex; align-items:center; justify-content:center;
  padding:20px;
}
.modal{
  background:#fff; border-radius:14px; box-shadow:0 30px 80px rgba(15,23,42,.25);
  width:100%; max-width:620px; max-height:90vh;
  display:flex; flex-direction:column; overflow:hidden;
}
.modal-head{
  padding:14px 18px; border-bottom:1px solid rgba(15,23,42,.08);
  display:flex; align-items:center; justify-content:space-between;
}
.modal-body{ padding:18px; overflow-y:auto; flex:1 }
.modal-foot{
  padding:12px 18px; border-top:1px solid rgba(15,23,42,.08);
  display:flex; gap:8px; justify-content:flex-end;
}
.modal textarea{ width:100%; font-family:inherit }
.right{ text-align:end }
.center{ text-align:center }

/* Avatar sizes */
.avatar.sm{ width:32px; height:32px; font-size:.8rem }

/* Toggle switch (used across ops/AI/widget forms) */
.toggle{ position:relative; display:inline-block; width:42px; height:24px; cursor:pointer }
.toggle input{ opacity:0; width:0; height:0 }
.toggle .slider{
  position:absolute; inset:0; background:#cbd5e1; border-radius:999px;
  transition:background .15s;
}
.toggle .slider::before{
  content:''; position:absolute; top:3px; left:3px;
  width:18px; height:18px; border-radius:50%;
  background:#fff; transition:transform .15s;
  box-shadow:0 2px 4px rgba(0,0,0,.2);
}
.toggle input:checked + .slider{ background:var(--accent) }
.toggle input:checked + .slider::before{ transform:translateX(18px) }
body.rtl .toggle input:checked + .slider::before{ transform:translateX(-18px) }

/* Start shift toggle in sidebar */
.shift-toggle{
  display:flex; align-items:center; gap:8px;
  padding:10px 14px; border-radius:10px;
  background:rgba(15,23,42,.06); border:none; color:var(--ink);
  font-weight:600; font-size:.85rem; cursor:pointer;
  font-family:inherit;
  margin:10px 0;
  transition:background .15s;
}
.shift-toggle:hover{ background:rgba(15,23,42,.1) }
.shift-toggle .dot{
  width:8px; height:8px; border-radius:50%;
  background:#94a3b8; display:inline-block;
  box-shadow:0 0 0 2px rgba(148,163,184,.25);
}
.shift-toggle[data-state="on"]{
  background:rgba(16,185,129,.12); color:#065f46;
}
.shift-toggle[data-state="on"] .dot{
  background:#10b981;
  box-shadow:0 0 0 2px rgba(16,185,129,.28);
  animation:pulse 2s infinite;
}
@keyframes pulse{
  0%,100%{ box-shadow:0 0 0 2px rgba(16,185,129,.28) }
  50%    { box-shadow:0 0 0 6px rgba(16,185,129,.12) }
}

/* ---- Bot control toggle (sidebar) ---- */
.bot-toggle{
  width:100%;
  padding:10px 14px; border-radius:10px;
  font-weight:600; font-size:.85rem;
  border:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center; gap:8px;
  transition:transform .1s, box-shadow .15s;
}
.bot-toggle:hover{ transform:translateY(-1px) }
.bot-toggle:active{ transform:translateY(0) }
.bot-toggle:disabled{ opacity:.55; cursor:not-allowed }
.bot-toggle.danger{
  background:linear-gradient(135deg,#f97316,#ef4444); color:#fff;
  box-shadow:0 4px 12px rgba(239,68,68,.25);
}
.bot-toggle.success{
  background:linear-gradient(135deg,#10b981,#059669); color:#fff;
  box-shadow:0 4px 12px rgba(16,185,129,.25);
}

/* System message bubble (centered, pill-shaped) */
.bubble.system{
  align-self:center !important;
  background:rgba(15,23,42,.06);
  color:var(--ink-2);
  font-size:.78rem;
  padding:6px 14px;
  border-radius:999px;
  margin:6px 0;
  max-width:75%;
  text-align:center;
}
body.rtl .bubble.system{ align-self:center !important }

/* ---- Sortable lists (drag/drop) ---- */
.sort-list{
  list-style:none; padding:0; margin:0;
  display:flex; flex-direction:column; gap:6px;
}
.sort-item{
  display:flex; align-items:center; gap:12px;
  padding:10px 14px; border-radius:10px;
  background:rgba(255,255,255,.7);
  border:1px solid rgba(15,23,42,.06);
  cursor:grab; transition:background .15s, border .15s;
}
.sort-item:hover{ background:#fff; border-color:rgba(15,23,42,.12) }
.sort-item.dragging{ opacity:.5; cursor:grabbing }
.sort-item.over{ border-color:var(--accent); background:rgba(99,102,241,.06) }
.sort-item .grip{
  color:#94a3b8; font-weight:700; font-size:1rem; cursor:grab;
  user-select:none; letter-spacing:-2px;
}
.sort-item .sort-label{ flex:1; min-width:0 }
.sort-item .sort-label > div:first-child{ font-weight:500 }
.sort-item .sort-actions{ display:flex; gap:6px; flex-shrink:0 }

/* Pre block */
pre{ white-space:pre-wrap; word-break:break-all; margin:0 }

/* ---- Inline SVG nav icons ---- */
.nav-item{ display:flex; align-items:center; gap:10px }
.nav-icon{
  display:inline-flex; align-items:center; justify-content:center;
  width:20px; height:20px; flex-shrink:0;
  color:currentColor; opacity:.85;
}
.nav-icon svg{ width:100%; height:100% }
.nav-item.active .nav-icon{ opacity:1 }
.nav-label{ flex:1; min-width:0 }

/* ---- Operator site assignment chips ---- */
.op-sites-list{
  display:flex; flex-wrap:wrap; gap:8px;
  padding:8px; border-radius:8px;
  background:rgba(15,23,42,.03);
  border:1px solid rgba(15,23,42,.06);
  max-height:160px; overflow:auto;
}
.op-site-chip{
  display:flex; align-items:center; gap:6px;
  padding:6px 10px; border-radius:8px;
  background:#fff; border:1px solid rgba(15,23,42,.08);
  font-size:.85rem; cursor:pointer;
  user-select:none; transition:border .15s, background .15s;
}
.op-site-chip:has(input:checked){
  background:rgba(79,70,229,.08); border-color:var(--accent);
}
.op-site-chip input{ accent-color:var(--accent) }

/* Voice player (WhatsApp/Telegram-style) — used in operator panel bubbles */
.bubble .vp{
  display:flex; align-items:center; gap:10px;
  min-width:240px; max-width:320px;
  padding:2px 0;
  /* Force LTR so play button stays on the left in any locale. */
  direction:ltr;
}
.bubble .vp-btn{
  flex-shrink:0;
  width:36px; height:36px; border-radius:50%;
  background:var(--accent, #4F46E5); border:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  padding:0; transition:transform .1s;
}
.bubble .vp-btn:hover{ transform:scale(1.05); }
.bubble .vp-btn:active{ transform:scale(.95); }
.bubble .vp-btn svg{ width:14px; height:14px; fill:#fff; }
.bubble .vp-body{
  flex:1; display:flex; flex-direction:column; gap:4px;
  min-width:0;
}
.bubble .vp-wave{
  display:flex; align-items:center; gap:2px;
  height:24px; cursor:pointer;
}
.bubble .vp-wave i{
  display:inline-block; width:2.5px;
  background:rgba(15,23,42,.25);
  border-radius:2px;
  transition:background .08s ease;
  flex-shrink:0;
}
.bubble .vp-wave i.on{ background:var(--accent, #4F46E5); }
/* Meta row: playback time on the left, sent time on the right */
.bubble .vp-meta{
  display:flex; align-items:center; justify-content:space-between;
  font-size:11px; opacity:.7;
  font-variant-numeric:tabular-nums;
  line-height:1;
}
/* Outgoing (operator) — invert */
.bubble.operator .vp-btn{ background:#fff; }
.bubble.operator .vp-btn svg{ fill:var(--accent, #4F46E5); }
.bubble.operator .vp-wave i{ background:rgba(255,255,255,.45); }
.bubble.operator .vp-wave i.on{ background:#fff; }
.bubble.operator .vp-meta{ color:rgba(255,255,255,.85) !important; }
.bubble .vp audio{ display:none; }
/* Hide the redundant external timestamp when the player has its own meta row */
.bubble .vp ~ .time{ display:none; }

/* Rating stars in the conversation sidebar */
.rating-stars{
  display:inline-flex; gap:2px;
  font-size:1rem; line-height:1;
}
.rating-stars .on{ color:#facc15; }
.rating-stars .off{ color:rgba(15,23,42,.18); }
