/* ============================================================
   MT Apartment — پنل مدیریت (کاملا لوکال، بدون CDN)
   ============================================================ */

@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-SemiBold.woff2') format('woff2');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

:root {
  --primary: #5b5bd6;
  --primary-2: #8b5cf6;
  --primary-soft: #ececfb;
  --bg: #e9ecf5;
  --bg-2: #dfe3ef;
  --card: #ffffff;
  --card-2: #f5f6fb;
  --text: #1a1f36;
  --muted: #667085;
  --line: #dfe3ee;
  --line-2: #eceef6;
  --green: #15803d; --green-bg: #e7f7ec;
  --red: #dc2626;   --red-bg: #fdeaea;
  --orange: #c2410c; --orange-bg: #fff1e6;
  --blue: #1d4ed8;  --blue-bg: #e6eefc;
  --purple: #6d28d9; --purple-bg: #efe9fd;
  --gray-bg: #eef0f6;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(20,24,50,.04), 0 8px 24px -12px rgba(20,24,50,.18);
  --shadow-lg: 0 24px 48px -16px rgba(20,24,50,.28);
  --sidebar-w: 256px;
  --sidebar-bg: linear-gradient(180deg, #23215b 0%, #3b1d7a 100%);
  --topbar-h: 64px;
  --input-bg: #f7f8fc;
  --hover: #f3f4fa;
}
html[data-theme="dark"] {
  --primary: #8b8cf6;
  --primary-2: #a78bfa;
  --primary-soft: #2a2b4a;
  --bg: #0f1120;
  --bg-2: #0a0c18;
  --card: #181b2e;
  --card-2: #1f2238;
  --text: #e6e8f2;
  --muted: #9aa1b9;
  --line: #2a2e47;
  --line-2: #232640;
  --green: #4ade80; --green-bg: #12301f;
  --red: #f87171;   --red-bg: #3a1a1a;
  --orange: #fb923c; --orange-bg: #3a2412;
  --blue: #60a5fa;  --blue-bg: #14243f;
  --purple: #c4b5fd; --purple-bg: #2a1f4a;
  --gray-bg: #232640;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg: 0 24px 48px -16px rgba(0,0,0,.7);
  --sidebar-bg: linear-gradient(180deg, #14132b 0%, #1e1440 100%);
  --input-bg: #12142a;
  --hover: #1f2238;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
body { background: radial-gradient(1200px 600px at 100% -10%, var(--primary-soft) 0%, transparent 60%), var(--bg); min-height: 100vh; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 700; }
h3 { margin: 0 0 14px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
h3::before { content: ''; width: 4px; height: 16px; border-radius: 2px; background: linear-gradient(180deg, var(--primary), var(--primary-2)); }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt-2 { margin-top: 12px; }
::selection { background: var(--primary); color: #fff; }

/* ---------------- چیدمان ---------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #e0e7ff;
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
  box-shadow: 4px 0 24px -12px rgba(0,0,0,.35);
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(255,255,255,.22), rgba(255,255,255,.08));
  border: 1px solid rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.brand-name { font-weight: 700; font-size: 15px; color: #fff; }
.brand-sub { font-size: 11px; opacity: .7; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  color: #c7cdf5; padding: 11px 12px; border-radius: 12px;
  font-weight: 500; transition: background .15s, color .15s, transform .15s;
}
.sidebar nav a svg { width: 20px; height: 20px; flex-shrink: 0; opacity: .85; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 #a78bfa; }
.sidebar nav a.active svg { opacity: 1; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.admin-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.admin-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-weight: 700; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.admin-avatar.lg { width: 56px; height: 56px; font-size: 22px; border-radius: 16px; }
.admin-meta { line-height: 1.5; font-size: 13px; color: #fff; min-width: 0; }
.admin-meta small { color: #c7cdf5; font-size: 11px; direction: ltr; display: block; overflow: hidden; text-overflow: ellipsis; }
.sidebar .btn-ghost { border-color: rgba(255,255,255,.18); color: #e0e7ff; }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,.1); }

.content { flex: 1; padding: 20px 28px 40px; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 20px; min-height: 44px;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-side { display: flex; align-items: center; gap: 8px; }
.topbar-date { color: var(--muted); direction: ltr; font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: none; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(10,12,30,.55); backdrop-filter: blur(2px); z-index: 39; }

/* ---------------- کارت و جدول ---------------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  text-align: right; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 10px 12px; background: var(--card-2); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table th:first-child { border-radius: 0 10px 10px 0; }
.table th:last-child { border-radius: 10px 0 0 10px; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--hover); }

/* ---------------- آمار ---------------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px;
}
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--line-2); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::after { content: ''; position: absolute; inset-inline-end: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%; background: var(--stat-tint, var(--primary-soft)); opacity: .5; }
.stat-icon {
  width: 46px; height: 46px; border-radius: 14px; font-size: 20px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--stat-tint, var(--primary-soft)); color: var(--stat-color, var(--primary));
  position: relative; z-index: 1;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-value { font-size: 20px; font-weight: 700; position: relative; z-index: 1; }
.stat-label { color: var(--muted); font-size: 12px; position: relative; z-index: 1; }
.tint-indigo { --stat-tint: var(--primary-soft); --stat-color: var(--primary); }
.tint-green  { --stat-tint: var(--green-bg);  --stat-color: var(--green); }
.tint-red    { --stat-tint: var(--red-bg);    --stat-color: var(--red); }
.tint-orange { --stat-tint: var(--orange-bg); --stat-color: var(--orange); }
.tint-blue   { --stat-tint: var(--blue-bg);   --stat-color: var(--blue); }
.tint-purple { --stat-tint: var(--purple-bg); --stat-color: var(--purple); }

/* ---------------- فرم ---------------- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.field input, .select, .search, textarea {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--input-bg); color: var(--text);
  font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .select:focus, .search:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--card); }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0 16px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.err { color: var(--red); font-size: 12px; margin: -6px 0 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: span 1; } }

.otp-input { text-align: center; letter-spacing: 10px; font-size: 22px !important; font-weight: 700; }

/* ---------------- دکمه ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; transition: filter .15s, background .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border: none; box-shadow: 0 6px 16px -6px rgba(91,91,214,.6);
}
.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: transparent; }
.btn-danger:hover { filter: brightness(.97); background: var(--red-bg); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 10px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- برچسب وضعیت ---------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill-green { background: var(--green-bg); color: var(--green); }
.pill-red { background: var(--red-bg); color: var(--red); }
.pill-orange { background: var(--orange-bg); color: var(--orange); }
.pill-gray { background: var(--gray-bg); color: var(--muted); }
.pill-blue { background: var(--blue-bg); color: var(--blue); }
.pill-purple { background: var(--purple-bg); color: var(--purple); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------------- ابزار بالای جدول ---------------- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 220px; }
.toolbar .select { width: auto; }
.toolbar-side { margin-inline-start: auto; color: var(--muted); }

.flash { padding: 12px 18px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.flash-ok { background: var(--green-bg); color: var(--green); border: 1px solid transparent; }
.flash-ok::before { content: '✓'; font-weight: 900; }

/* ---------------- صفحه‌بندی ---------------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 14px; }
.pager-btn {
  padding: 7px 16px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--card); font: inherit; font-weight: 600; cursor: pointer; color: var(--primary);
}
.pager-btn.disabled { color: var(--line); cursor: default; }
.pager-info { color: var(--muted); font-size: 13px; }

/* ---------------- صفحات ورود ---------------- */
.auth-body {
  background: radial-gradient(900px 500px at 20% 0%, #4c1d95 0%, transparent 60%), linear-gradient(135deg, #1e1b4b, #312e81 55%, #4c1d95);
  min-height: 100vh; margin: 0;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { text-align: center; padding: 32px 28px; box-shadow: var(--shadow-lg); }
.auth-card h2 { margin: 12px 0 4px; font-size: 18px; }
.auth-card form { text-align: right; margin-top: 20px; }
.auth-logo {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; font-size: 30px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex; align-items: center; justify-content: center;
}
.steps { text-align: right; color: var(--muted); font-size: 13px; padding-inline-start: 18px; line-height: 2; }
.qr-box { display: flex; justify-content: center; margin: 12px 0; }
.qr-box svg { border: 8px solid #fff; border-radius: 12px; box-shadow: var(--shadow); }
.secret-box {
  background: var(--primary-soft); border: 1px dashed var(--primary-2); border-radius: 12px;
  padding: 10px; font-weight: 700; letter-spacing: 1px; color: var(--primary);
  margin-bottom: 16px; font-size: 13px;
}

/* ---------------- نتیجه پرداخت / لندینگ ---------------- */
.pay-card { text-align: center; padding: 36px 28px; }
.pay-icon {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 50%;
  font-size: 34px; color: #fff; display: flex; align-items: center; justify-content: center;
}
.pay-ok { background: var(--green); }
.pay-fail { background: var(--red); }
.pay-table { width: 100%; margin: 18px 0; border-collapse: collapse; }
.pay-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; }
.pay-table td:last-child { text-align: left; }

.landing { background: linear-gradient(135deg, #1e1b4b, #312e81, #4c1d95); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.landing-card { background: #fff; color: #1a1f36; border-radius: 24px; padding: 48px 40px; text-align: center; max-width: 440px; box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.landing-logo { width: 80px; height: 80px; margin: 0 auto 16px; border-radius: 22px; font-size: 40px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); display: flex; align-items: center; justify-content: center; }
.landing-card h1 { margin: 0 0 8px; font-size: 22px; }
.landing-card p { line-height: 2; margin: 0 0 8px; }

/* هدر کاربر */
.user-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.user-head-meta { flex: 1; min-width: 220px; }
.user-head-meta h3 { margin: 4px 0 4px; }
.user-head-meta h3::before { display: none; }
.user-head-side { text-align: left; line-height: 2; font-size: 13px; }

/* ---------------- اعطای پلن هدیه ---------------- */
.gift-box {
  background: var(--primary-soft);
  border: 1px solid var(--line); border-radius: 14px; padding: 16px 16px 6px; margin-top: 4px;
}
.gift-title { font-weight: 700; margin-bottom: 12px; color: var(--purple); }
.gift-box .field input, .gift-box .select { background: var(--card); }
.gift-box .btn { margin-bottom: 10px; }
.vip-box { background: var(--orange-bg); border-color: transparent; }
.vip-box .gift-title { color: var(--orange); }
.vip-box p { font-size: 12.5px; line-height: 1.9; margin: 0 0 12px; }

/* ---------------- تیکت‌های پشتیبانی ---------------- */
.nav-badge {
  margin-inline-start: auto; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 999px; padding: 0 6px;
}
.text-red { color: var(--red); }
.row-unread td { background: var(--orange-bg); }
.row-unread .ticket-subject { font-weight: 700; }
.ticket-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
@media (max-width: 960px) { .ticket-layout { grid-template-columns: 1fr; } }
.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.ticket-thread { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow-y: auto; padding: 4px 2px; }
.bubble { max-width: 82%; border-radius: 16px; padding: 12px 16px; font-size: 13.5px; line-height: 2; }
.bubble-user { align-self: flex-start; background: var(--card-2); border: 1px solid var(--line); border-top-right-radius: 4px; }
.bubble-admin { align-self: flex-end; background: var(--primary-soft); border: 1px solid var(--line); border-top-left-radius: 4px; }
.bubble-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.bubble-admin .bubble-meta b { color: var(--purple); }
.bubble-body { white-space: pre-wrap; word-break: break-word; }
.thread-note { text-align: center; font-size: 12px; color: var(--muted); padding: 6px; }
.ticket-reply { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.ticket-reply textarea { width: 100%; resize: vertical; }
.ticket-reply-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.user-mini { display: flex; align-items: center; gap: 12px; }

/* ============================================================
   موبایل (≤ 900px): سایدبار کشویی، جدول‌های اسکرول‌شونده
   ============================================================ */
@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; height: 100dvh;
    transform: translateX(100%); transition: transform .25s ease;
    width: min(300px, 84vw);
  }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-overlay { display: block; }
  body.nav-open { overflow: hidden; }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px 14px 40px; }
  .topbar { position: sticky; top: 0; z-index: 30; background: var(--bg); margin: -14px -14px 16px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .topbar h1 { font-size: 17px; }
  .topbar-date { display: none; }
  .card { padding: 14px; border-radius: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-value { font-size: 17px; }
  .stat-icon { width: 40px; height: 40px; }
  .toolbar .search { min-width: 100%; }
  .toolbar .select { flex: 1; }
  .toolbar-side { margin-inline-start: 0; width: 100%; }
  /* جدول‌ها: اسکرول افقی نرم به‌جای شکستن */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .table td, .table th { padding: 10px 10px; }
  .ticket-thread { max-height: none; }
  .bubble { max-width: 94%; }
  .user-head-side { text-align: right; width: 100%; }
  .btn-block { width: 100%; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 24px 18px; }
}
