/* ===========================================================================
   Devil Project — مینیمال مشکی مات، مدرن
   فونت‌ها: Geist (لاتین/UI) · Vazirmatn (فارسی) · Geist Mono (اعداد)
   =========================================================================== */

:root {
  /* رنگ‌ها — مشکی عمیق مات */
  --bg:          #08080a;
  --bg-1:        #0c0c0f;
  --surface:     #121216;
  --surface-2:   #16161b;
  --surface-3:   #1c1c22;
  --line:        #232329;
  --line-soft:   #1a1a1f;

  --text:        #f4f4f6;
  --text-2:      #a8a8b3;
  --text-3:      #6e6e7a;
  --text-4:      #4a4a54;

  --accent:      #e8e8ec;      /* تأکید سفید مات — مینیمال */
  --accent-ink:  #08080a;
  --ring:        rgba(255,255,255,0.14);

  --red-brand:   #d62828;      /* قرمز شیطانی لوگو — برای لهجهٔ رنگی */
  --red-glow:    rgba(214, 40, 40, 0.22);

  --green:       #4ade80;
  --amber:       #fbbf24;
  --red:         #fb7185;
  --blue:        #60a5fa;

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow:    0 1px 0 rgba(255,255,255,0.03) inset, 0 12px 40px -12px rgba(0,0,0,0.8);
  --shadow-lg: 0 24px 70px -20px rgba(0,0,0,0.9);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', 'Geist', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
}

body { overflow-x: hidden; }

.mono { font-family: 'Geist Mono', 'SF Mono', ui-monospace, monospace; letter-spacing: 0; }

/* بافت ظریف نویز/گرید روی پس‌زمینه برای حس «مات» */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(900px 480px at 50% -12%, var(--red-glow), transparent 58%),
    radial-gradient(1200px 600px at 50% -10%, rgba(255,255,255,0.03), transparent 60%),
    var(--bg);
}
body::after {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 70%);
          mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 70%);
  opacity: 0.5;
  pointer-events: none;
}

/* ───────────────────────── دکمه‌ها ───────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: #2e2e36; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: #fff; border-color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--red); border-color: transparent; background: transparent; }
.btn-danger:hover { background: rgba(251,113,133,0.1); border-color: rgba(251,113,133,0.25); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ───────────────────────── ورودی‌ها ───────────────────────── */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 13px; color: var(--text-3); font-weight: 500; }
.input, select.input {
  width: 100%;
  padding: 12px 15px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit; font-size: 14px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.input:focus, select.input:focus {
  outline: none;
  border-color: #34343c;
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--ring);
}
.input::placeholder { color: var(--text-4); }

/* ═══════════════════════ صفحه ورود ═══════════════════════ */
.auth-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-1) 100%);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 40px 34px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.5s var(--ease);
}
.auth-logo {
  width: 110px; height: 110px;
  display: grid; place-items: center;
  margin: 0 auto 18px;
}
.auth-logo img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 0 26px rgba(214, 40, 40, 0.45));
  animation: logoFloat 4s ease-in-out infinite;
}
@keyframes logoFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.auth-card h1 {
  text-align: center; font-size: 23px; font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-card .sub {
  text-align: center; color: var(--text-3); font-size: 14px;
  margin: 6px 0 28px;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form .btn-primary { margin-top: 6px; padding: 13px; }
.auth-error {
  background: rgba(251,113,133,0.08);
  border: 1px solid rgba(251,113,133,0.2);
  color: var(--red);
  padding: 11px 14px; border-radius: var(--r-sm);
  font-size: 13px; text-align: center;
  display: none;
}
.auth-error.show { display: block; animation: shake 0.4s; }

/* ═══════════════════════ چیدمان اپ ═══════════════════════ */
.app { display: none; }
.app.show { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px;
  background: rgba(8,8,10,0.72);
  backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
}
.brand-mark img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(214, 40, 40, 0.35));
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.brand-name span { color: var(--text-3); font-weight: 400; }

.nav { display: flex; gap: 4px; }
.nav-item {
  padding: 8px 15px; border-radius: var(--r-sm);
  color: var(--text-3); font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; background: transparent; font-family: inherit;
  transition: all 0.16s;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--text); background: var(--surface-3); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 6px 6px 12px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface);
}
.user-chip .uname { font-size: 13px; color: var(--text-2); }
.user-chip .role-tag {
  font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-3);
  font-family: 'Geist Mono', monospace; text-transform: uppercase; letter-spacing: 0.04em;
}
.user-chip .role-tag.admin { background: rgba(96,165,250,0.12); color: var(--blue); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2a2a32, #16161b);
  border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--text);
}

.container { max-width: 1120px; margin: 0 auto; padding: 44px 26px 90px; }

.page-head { margin-bottom: 30px; }
.page-head h1 {
  font-size: 30px; font-weight: 700; letter-spacing: -0.03em;
  display: flex; align-items: center; gap: 12px;
}
.page-head .count {
  font-size: 13px; font-family: 'Geist Mono', monospace;
  color: var(--text-3); background: var(--surface-2);
  border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px;
}
.page-head .desc { color: var(--text-3); margin-top: 5px; font-size: 14px; }

.toolbar { display: flex; gap: 12px; margin: 22px 0; flex-wrap: wrap; align-items: center; }
.search-wrap { position: relative; flex: 1; min-width: 220px; }
.search-wrap .ico {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-4); font-size: 16px; pointer-events: none;
}
.search-wrap .input { padding-right: 42px; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 8px 15px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-3); font-size: 13px; cursor: pointer;
  transition: all 0.16s; font-family: inherit;
}
.chip:hover { color: var(--text); border-color: #2e2e36; }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* ───────────── کارت‌های محتوا ───────────── */
.grid { display: grid; gap: 12px; }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  cursor: pointer;
  transition: transform 0.2s var(--ease), border-color 0.2s, background 0.2s;
  animation: fadeUp 0.45s var(--ease) backwards;
  overflow: hidden;
}
.card::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(400px circle at var(--mx,50%) var(--my,0%), rgba(255,255,255,0.04), transparent 40%);
  opacity: 0; transition: opacity 0.3s;
}
.card:hover { transform: translateY(-2px); border-color: var(--line); background: var(--surface-2); }
.card:hover::before { opacity: 1; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.card-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.card-meta { display: flex; gap: 14px; margin-top: 8px; color: var(--text-4); font-size: 12.5px; flex-wrap: wrap; }
.card-meta span { display: flex; align-items: center; gap: 5px; }
.card-body { color: var(--text-2); margin-top: 12px; font-size: 14px; }

.badge {
  padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 500;
  white-space: nowrap; border: 1px solid transparent;
}
.badge.open    { background: rgba(74,222,128,0.1);  color: var(--green); border-color: rgba(74,222,128,0.18); }
.badge.pending { background: rgba(251,191,36,0.1);  color: var(--amber); border-color: rgba(251,191,36,0.18); }
.badge.closed  { background: rgba(251,113,133,0.1); color: var(--red);   border-color: rgba(251,113,133,0.18); }
.badge.default { background: var(--surface-3);      color: var(--text-3); border-color: var(--line); }

/* ───────────── جدول ادمین ───────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line-soft);
}
.panel-head h3 { font-size: 15px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 14px 22px; font-size: 14px; }
th { color: var(--text-3); font-weight: 500; font-size: 12.5px; border-bottom: 1px solid var(--line-soft); }
td { border-bottom: 1px solid var(--line-soft); color: var(--text-2); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.14s; }
tbody tr:hover { background: var(--surface-2); }
td .uname { color: var(--text); font-weight: 500; }
.dot-status { display: inline-flex; align-items: center; gap: 7px; }
.dot-status .d { width: 7px; height: 7px; border-radius: 50%; }
.dot-status.active .d { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot-status.inactive .d { background: var(--text-4); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ───────────── اسکلتون / حالت‌ها ───────────── */
.skeleton { height: 104px; border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.state { text-align: center; padding: 80px 20px; color: var(--text-3); }
.state .ico { font-size: 44px; opacity: 0.4; margin-bottom: 14px; }
.state h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ───────────── مودال ───────────── */
.modal-bg {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(6px);
  display: none; place-items: center; padding: 24px;
}
.modal-bg.show { display: grid; animation: fade 0.2s; }
.modal {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 28px;
  box-shadow: var(--shadow-lg); animation: pop 0.3s var(--ease);
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.modal .sub { color: var(--text-3); font-size: 13px; margin-bottom: 22px; }
.modal-form { display: flex; flex-direction: column; gap: 15px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

/* ═══════════════════ صفحهٔ چت تمام‌صفحه ═══════════════════ */
.chat-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: none;
  background: var(--bg);
}
.chat-overlay.show { display: block; animation: chatIn 0.32s var(--ease); }
@keyframes chatIn { from { opacity: 0; transform: scale(1.01); } to { opacity: 1; transform: none; } }

.chat-loading, .chat-empty {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 10px; color: var(--text-3); text-align: center;
}
.chat-loading .ico, .chat-empty .ico { font-size: 46px; opacity: 0.4; }
.chat-loading h3 { color: var(--text); }
.logo-pulse {
  width: 84px; height: 84px; object-fit: contain;
  filter: drop-shadow(0 0 22px rgba(214, 40, 40, 0.5));
  animation: logoPulse 1.5s ease-in-out infinite;
}
@keyframes logoPulse {
  0%, 100% { opacity: 0.55; transform: scale(0.96); }
  50%      { opacity: 1;    transform: scale(1.04); }
}

.chat-panel {
  max-width: 860px; height: 100%; margin: 0 auto;
  display: flex; flex-direction: column;
  background:
    radial-gradient(700px 360px at 50% -5%, rgba(255,255,255,0.03), transparent 60%),
    var(--bg);
  border-inline: 1px solid var(--line-soft);
}

/* هدر چت */
.chat-header {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: rgba(12,12,15,0.85);
  backdrop-filter: blur(20px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
}
.chat-back {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-2);
  font-size: 20px; cursor: pointer; transition: all 0.18s;
}
.chat-back:hover { background: var(--surface-3); color: var(--text); transform: translateX(-3px); }
.chat-owner { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.chat-avatar {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 50%;
  background: linear-gradient(135deg, #2e2e38, #16161b);
  border: 1px solid var(--line); color: var(--text);
  font-size: 16px; font-weight: 600;
}
.chat-owner-info { min-width: 0; }
.chat-owner-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-owner-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ناحیهٔ اسکرول پیام‌ها */
.chat-scroll {
  flex: 1; overflow-y: auto; padding: 22px 20px 30px;
  scroll-behavior: smooth;
}
.chat-thread { display: flex; flex-direction: column; gap: 2px; }

/* فیلدهای اضافه (اطلاعات تیکت) — کارت بالای گفتگو */
.chat-fields {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 16px 18px; margin-bottom: 22px;
}
.cf-title { font-size: 12px; color: var(--text-4); margin-bottom: 12px; font-weight: 500; letter-spacing: 0.02em; }
.cf-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 13.5px;
}
.cf-row:last-child { border-bottom: none; }
.cf-key { color: var(--text-3); }
.cf-val { color: var(--text); text-align: left; word-break: break-word; }

/* خط‌فاصلهٔ روز */
.chat-day { display: flex; align-items: center; justify-content: center; margin: 18px 0 14px; }
.chat-day span {
  font-size: 12px; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  padding: 4px 14px; border-radius: 999px;
}

/* ردیف حباب */
.bubble-row {
  display: flex; align-items: flex-end; gap: 9px;
  margin-top: 12px; max-width: 78%;
  animation: bubbleIn 0.35s var(--ease) backwards;
}
.bubble-row.grouped { margin-top: 2px; }
.bubble-row.admin { flex-direction: row-reverse; margin-inline-start: auto; }
.bubble-row.user  { margin-inline-end: auto; }

@keyframes bubbleIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.bub-avatar {
  width: 34px; height: 34px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 50%;
  font-size: 13px; font-weight: 600; border: 1px solid var(--line);
}
.bub-avatar.user  { background: linear-gradient(135deg, #26262e, #17171c); color: var(--text-2); }
.bub-avatar.admin { background: linear-gradient(135deg, #1e3a5f, #16263b); color: var(--blue); }
.bub-avatar.ghost { background: transparent; border: none; }

.bub-wrap { display: flex; flex-direction: column; min-width: 0; }
.bub-name {
  font-size: 12px; color: var(--text-3); margin-bottom: 4px; padding: 0 4px;
  display: flex; align-items: center; gap: 7px;
}
.bubble-row.admin .bub-name { flex-direction: row-reverse; }
.bub-tag { font-size: 10px; padding: 1px 7px; border-radius: 999px; background: rgba(96,165,250,0.15); color: var(--blue); }
.bub-phone { font-size: 11px; color: var(--text-4); }

/* خود حباب */
.bubble {
  position: relative;
  padding: 10px 14px 18px;
  border-radius: 18px;
  font-size: 14px; line-height: 1.7;
  border: 1px solid var(--line-soft);
  word-break: break-word;
  box-shadow: var(--shadow);
}
.bubble.user {
  background: var(--surface-2); color: var(--text);
  border-bottom-left-radius: 6px;
}
.bubble.admin {
  background: linear-gradient(135deg, #1b2a40, #16202f);
  border-color: rgba(96,165,250,0.18); color: var(--text);
  border-bottom-right-radius: 6px;
}
.bubble-row.grouped .bubble.user  { border-bottom-left-radius: 18px; border-top-left-radius: 6px; }
.bubble-row.grouped .bubble.admin { border-bottom-right-radius: 18px; border-top-right-radius: 6px; }

.bub-text { white-space: pre-wrap; }
.bub-text a { color: var(--blue); text-decoration: underline; }
.bub-time {
  position: absolute; bottom: 5px; inset-inline-end: 12px;
  font-size: 10.5px; color: var(--text-4);
}
.bubble.admin .bub-time { color: rgba(96,165,250,0.55); }

/* پیوست‌ها */
.bub-img { display: block; margin: 4px 0 6px; }
.bub-img img { max-width: 260px; max-height: 320px; border-radius: 12px; border: 1px solid var(--line); display: block; }
.bub-file {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 6px;
  font-size: 13px; color: var(--blue);
  background: rgba(96,165,250,0.08); border: 1px solid rgba(96,165,250,0.18);
  padding: 7px 12px; border-radius: var(--r-sm);
}
.bub-file:hover { background: rgba(96,165,250,0.14); }

@media (max-width: 640px) {
  .bubble-row { max-width: 88%; }
  .chat-panel { border-inline: none; }
}

/* ───────────── Toast ───────────── */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  padding: 12px 20px; border-radius: var(--r); font-size: 14px;
  background: var(--surface-3); border: 1px solid var(--line); color: var(--text);
  box-shadow: var(--shadow-lg); animation: toastIn 0.3s var(--ease);
}
.toast.ok  { border-color: rgba(74,222,128,0.3); }
.toast.err { border-color: rgba(251,113,133,0.3); }

.footer { text-align: center; padding: 30px; color: var(--text-4); font-size: 12.5px;
  border-top: 1px solid var(--line-soft); }

/* ───────────── انیمیشن‌ها ───────────── */
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-3); }

.hidden { display: none !important; }

@media (max-width: 640px) {
  .nav { display: none; }
  .user-chip .uname { display: none; }
  th:nth-child(3), td:nth-child(3) { display: none; }
}
