:root {
  --bg: #0d0f14;
  --bg-2: #151922;
  --bg-3: #1c2230;
  --border: #2a3142;
  --text: #e8ecf3;
  --muted: #8b93a7;
  --primary: #6d5dfc;
  --primary-2: #8b7bff;
  --accent: #e1306c;          /* instagram pink */
  --accent-2: #f77737;
  --green: #2dd4a7;
  --red: #ff5d6c;
  --yellow: #ffce5c;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Vazirmatn, "Segoe UI", Tahoma, "Iran Sans", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 100% -10%, #1a1530 0, transparent 60%),
              radial-gradient(1000px 500px at -10% 110%, #11202b 0, transparent 55%),
              var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-2); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109,93,252,.18);
}
textarea { resize: vertical; min-height: 80px; }
label { font-size: 13px; color: var(--muted); display: block; margin: 0 2px 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover { background: #232a3a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--accent)); border: none; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #4a2630; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--border); color: var(--muted);
}
.badge.green { color: var(--green); border-color: #1d4a3f; background: #0f2a23; }
.badge.red   { color: var(--red);   border-color: #4a2630; background: #2a1217; }
.badge.yellow{ color: var(--yellow);border-color: #4a4126; background: #2a2512; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: rgba(13,15,20,.6);
  border-left: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; font-weight: 800; font-size: 18px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid; place-items: center; font-size: 18px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; color: var(--muted);
  font-size: 14.5px; font-weight: 600; cursor: pointer;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--bg-3); color: var(--text); box-shadow: inset 3px 0 0 var(--primary); }
.nav-item .ico { font-size: 17px; width: 20px; text-align: center; }
.sidebar .spacer { flex: 1; }

.main { padding: 22px 26px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 13.5px; }

.acct-select { display: flex; align-items: center; gap: 8px; }
.acct-select select { width: auto; min-width: 180px; }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px){ .grid.cols-4{grid-template-columns:repeat(2,1fr);} .grid.cols-3{grid-template-columns:repeat(2,1fr);} }
@media (max-width: 720px){ .app{grid-template-columns:1fr;} .sidebar{position:relative;height:auto;flex-direction:row;flex-wrap:wrap;} .grid.cols-4,.grid.cols-3,.grid.cols-2{grid-template-columns:1fr;} }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .num { font-size: 30px; font-weight: 800; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat .ico { font-size: 22px; opacity: .8; }

/* ---------- Auth ---------- */
.auth-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand { justify-content: center; font-size: 22px; }
.tabs { display: flex; gap: 6px; background: var(--bg); padding: 5px; border-radius: 12px; margin-bottom: 18px; }
.tabs button { flex: 1; background: transparent; border: none; color: var(--muted); padding: 9px; border-radius: 9px; font-weight: 700; }
.tabs button.active { background: var(--bg-3); color: var(--text); }
.field { margin-bottom: 14px; }

/* ---------- Lists / tables ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px;
}
.row:hover { border-color: #3a4256; }
.row.clickable { cursor: pointer; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--bg-3); object-fit: cover; flex-shrink: 0; display:grid; place-items:center; color:var(--muted); }
.row .meta { flex: 1; min-width: 0; }
.row .meta .t { font-weight: 700; font-size: 14.5px; }
.row .meta .s { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
tbody tr:hover { background: var(--bg-2); }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 16px; height: calc(100vh - 150px); }
@media (max-width: 820px){ .inbox{grid-template-columns:1fr; height:auto;} }
.thread-list { overflow-y: auto; }
.thread { cursor: pointer; }
.thread.active { border-color: var(--primary); }
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head { padding: 14px; border-bottom: 1px solid var(--border); display:flex; align-items:center; gap:10px; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 75%; padding: 9px 13px; border-radius: 14px; font-size: 14px; }
.bubble.them { background: var(--bg-3); align-self: flex-start; border-bottom-right-radius: 4px; }
.bubble.me { background: linear-gradient(135deg, var(--primary), var(--accent)); color:#fff; align-self: flex-end; border-bottom-left-radius: 4px; }
.bubble .ts { display:block; font-size: 10.5px; opacity: .6; margin-top: 3px; }
.chat-input { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-input input { border-radius: 999px; }

/* media grid */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 12px; }
.media-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; }
.media-card img { width: 100%; height: 150px; object-fit: cover; display:block; background:var(--bg-3); }
.media-card .info { padding: 8px 10px; font-size: 12px; color: var(--muted); display:flex; justify-content:space-between; }
.media-card.active { border-color: var(--primary); }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.help { font-size: 12.5px; color: var(--muted); }
.alert { padding: 11px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px; border:1px solid; }
.alert.info  { background:#10202b; border-color:#1d4458; color:#7fd0ee; }
.alert.warn  { background:#2a2512; border-color:#4a4126; color:var(--yellow); }
.alert.error { background:#2a1217; border-color:#4a2630; color:var(--red); }
.alert.ok    { background:#0f2a23; border-color:#1d4a3f; color:var(--green); }
.row-actions { display:flex; gap:6px; flex-wrap:wrap; }
.flex { display:flex; align-items:center; gap:10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display:grid; place-items:center; z-index: 50; padding: 20px; }
.modal { width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }

/* toast */
#toasts { position: fixed; bottom: 20px; left: 20px; z-index: 100; display:flex; flex-direction:column; gap:8px; }
.toast { padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s ease; border:1px solid var(--border); background: var(--bg-3); }
.toast.ok { border-color:#1d4a3f; } .toast.error { border-color:#4a2630; }
@keyframes pop { from { transform: translateY(10px); opacity:0; } to { transform: none; opacity:1; } }

.spinner { width:18px;height:18px;border:2px solid var(--border);border-top-color:var(--primary);border-radius:50%;animation:spin .7s linear infinite;display:inline-block; }
@keyframes spin { to { transform: rotate(360deg);} }
