/* =========================================================
   سیستم تیکتینگ — Design Tokens
   Concept: هر تیکت مثل یک «بلیت/کوپن پاره‌شونده» رندر می‌شود؛
   کد تیکت با فونت مونو مثل بارکد، وضعیت‌ها مثل مهرهای پستی.
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&family=Lalezar&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* رنگ‌ها */
  --paper:        #EEF1F6;
  --surface:      #FFFFFF;
  --ink:          #1B2333;
  --ink-soft:     #5B6478;
  --muted:        #8C94A6;
  --border:       #DEE3EC;
  --border-soft:  #E9ECF3;

  --brand:        #243B5E;
  --brand-dark:   #16213A;
  --brand-light:  #3E5C89;
  --brand-tint:   #E9EEF6;

  --accent:       #E4572E;
  --accent-dark:  #C7431C;
  --accent-tint:  #FCE6DD;

  --success:      #2F9E6E;
  --success-tint: #E1F3EA;
  --warning:      #E0A033;
  --warning-tint: #FCF0DA;
  --info:         #3F7CD6;
  --info-tint:    #E5EEFB;
  --danger:       #D94F4F;
  --danger-tint:  #FBE7E7;

  /* تایپوگرافی */
  --font-body: 'Vazirmatn', sans-serif;
  --font-display: 'Lalezar', 'Vazirmatn', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* هندسه */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(23, 34, 54, .06);
  --shadow-md: 0 8px 24px rgba(23, 34, 54, .08);
  --shadow-lg: 0 16px 40px rgba(23, 34, 54, .14);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  direction: rtl;
  text-align: right;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
img { max-width: 100%; display: block; }

::selection { background: var(--accent-tint); color: var(--accent-dark); }

:focus-visible {
  outline: 2px solid var(--brand-light);
  outline-offset: 2px;
  border-radius: 4px;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===================== دکمه‌ها ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-outline:hover { border-color: var(--brand-light); color: var(--brand); background: var(--brand-tint); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--border-soft); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #C13F3F; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon { padding: 9px; border-radius: 10px; }

/* ===================== فرم‌ها ===================== */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
}
.input, select.input, textarea.input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--brand-light);
  box-shadow: 0 0 0 4px var(--brand-tint);
  outline: none;
}
textarea.input { resize: vertical; min-height: 110px; }
.field-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.field-error { font-size: 12.5px; color: var(--danger); margin-top: 6px; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: '';
  position: absolute; left: 14px; top: 50%;
  width: 8px; height: 8px;
  border-left: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(-45deg);
  pointer-events: none;
}
.select-wrap select { appearance: none; -webkit-appearance: none; padding-left: 34px; }

/* ===================== نشان‌ها (Badges) — مهر پستی ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  border: 1.5px dashed transparent;
  white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-open     { background: var(--info-tint);    color: var(--info); }
.badge-answered { background: var(--success-tint);  color: var(--success); }
.badge-pending  { background: var(--warning-tint);  color: var(--warning); }
.badge-closed   { background: var(--border-soft);   color: var(--muted); border-color: var(--border); }

.priority-tag { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 6px; }
.priority-low    { background: var(--border-soft); color: var(--ink-soft); }
.priority-medium { background: var(--info-tint); color: var(--info); }
.priority-high   { background: var(--warning-tint); color: var(--warning); }
.priority-urgent { background: var(--danger-tint); color: var(--danger); }

/* ===================== هدر عمومی (سمت کاربر) ===================== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  height: 68px;
}
.brand-logo {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display);
  font-size: 22px; color: var(--brand);
}
.brand-logo .mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-body); font-weight: 800; font-size: 16px;
  transform: rotate(-6deg);
}
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav a {
  padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14.5px; color: var(--ink-soft);
}
.topnav a:hover, .topnav a.active { background: var(--brand-tint); color: var(--brand); }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 14px; border-radius: 999px; border: 1px solid var(--border);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0;
}

/* ===================== صفحات ورود/ثبت‌نام ===================== */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}
.auth-side {
  flex: 1.1;
  background: var(--brand-dark);
  color: #fff;
  padding: 56px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-side::before {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(circle at 20% 20%, rgba(228,87,46,.18), transparent 40%),
                     radial-gradient(circle at 80% 75%, rgba(63,124,214,.18), transparent 45%);
}
.auth-side .content { position: relative; z-index: 1; }
.auth-side .stub-preview {
  position: relative; z-index: 1;
  background: rgba(255,255,255,.06);
  border: 1.5px dashed rgba(255,255,255,.28);
  border-radius: var(--radius-lg);
  padding: 22px;
}
.auth-form-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px 24px; background: var(--paper);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 38px 34px;
}
.auth-card h1 { font-size: 21px; margin: 0 0 6px; }
.auth-card p.sub { color: var(--muted); font-size: 14px; margin: 0 0 26px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--ink-soft); }
.auth-switch a { color: var(--brand); font-weight: 700; }

@media (max-width: 900px) {
  .auth-side { display: none; }
}

/* ===================== کارت تیکت (سبک بلیت پاره‌شونده) ===================== */
.ticket-stub {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow .15s ease, transform .15s ease;
}
.ticket-stub:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.stub-main { flex: 1; padding: 20px 22px; min-width: 0; }
.stub-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.stub-code {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 600;
  color: var(--brand); background: var(--brand-tint);
  padding: 3px 9px; border-radius: 6px; letter-spacing: .5px;
}
.stub-subject { font-size: 16.5px; font-weight: 700; margin: 4px 0 6px; }
.stub-meta { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.stub-meta span { display: flex; align-items: center; gap: 5px; }

.stub-perforation {
  width: 0; position: relative;
  border-left: 2px dashed var(--border);
  flex-shrink: 0;
}
.stub-perforation::before, .stub-perforation::after {
  content: ''; position: absolute; right: -9px;
  width: 18px; height: 18px; background: var(--paper);
  border-radius: 50%; border: 1px solid var(--border);
}
.stub-perforation::before { top: -9px; }
.stub-perforation::after { bottom: -9px; }

.stub-side {
  width: 150px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 20px 14px; text-align: center;
}
.stub-side .count {
  font-family: var(--font-mono); font-size: 20px; font-weight: 700; color: var(--ink);
}
.stub-side .count-label { font-size: 11.5px; color: var(--muted); }

@media (max-width: 640px) {
  .ticket-stub { flex-direction: column; }
  .stub-perforation {
    width: auto; height: 0; border-left: none; border-top: 2px dashed var(--border);
  }
  .stub-perforation::before { top: -9px; right: auto; left: -9px; }
  .stub-perforation::after { bottom: auto; top: -9px; right: -9px; left: auto; }
  .stub-side { width: 100%; flex-direction: row; justify-content: space-between; padding: 14px 22px; }
}

/* ===================== صفحه لیست/داشبورد ===================== */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin: 36px 0 22px; flex-wrap: wrap;
}
.page-head h1 { font-size: 25px; margin: 0 0 6px; }
.page-head .sub { color: var(--muted); font-size: 14.5px; }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 20px; display: flex; align-items: center; gap: 14px;
}
.stat-card .icon-box {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.stat-card .num { font-family: var(--font-mono); font-size: 24px; font-weight: 700; line-height: 1; }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; }

@media (max-width: 900px) { .stats-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stats-row { grid-template-columns: 1fr; } }

.filter-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 16px; margin-bottom: 20px;
}
.filter-bar .input, .filter-bar select { width: auto; padding: 9px 14px; }
.filter-bar .search-input { flex: 1; min-width: 180px; }

.ticket-list { display: flex; flex-direction: column; gap: 14px; }

.empty-state {
  text-align: center; padding: 70px 20px; background: var(--surface);
  border: 1.5px dashed var(--border); border-radius: var(--radius-lg); color: var(--muted);
}
.empty-state .emoji { font-size: 40px; margin-bottom: 14px; }
.empty-state h3 { color: var(--ink); margin: 0 0 8px; }

/* ===================== جزئیات تیکت / گفتگو ===================== */
.ticket-detail-grid {
  display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start;
}
@media (max-width: 900px) { .ticket-detail-grid { grid-template-columns: 1fr; } }

.thread-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden;
}
.thread-head {
  padding: 20px 24px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.thread-head h2 { font-size: 18.5px; margin: 0; }

.thread-body { padding: 24px; display: flex; flex-direction: column; gap: 18px; max-height: 560px; overflow-y: auto; }

.msg { display: flex; gap: 12px; max-width: 78%; }
.msg .avatar { margin-top: 2px; }
.msg-bubble {
  background: var(--border-soft); border-radius: var(--radius-md); border-top-right-radius: 4px;
  padding: 13px 16px;
}
.msg-bubble p { margin: 0; white-space: pre-wrap; word-wrap: break-word; }
.msg-time { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg-name { font-size: 12.5px; font-weight: 700; margin-bottom: 4px; color: var(--ink-soft); }

.msg.from-admin { margin-inline-start: auto; flex-direction: row-reverse; }
.msg.from-admin .msg-bubble { background: var(--brand-tint); border-top-right-radius: var(--radius-md); border-top-left-radius: 4px; }
.msg.from-admin .msg-time, .msg.from-admin .msg-name { text-align: left; }

.msg-attachment {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 10px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; font-size: 13px;
}

.reply-box { border-top: 1px solid var(--border-soft); padding: 20px 24px; background: #FAFBFD; }
.reply-box textarea { min-height: 90px; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 10px; flex-wrap: wrap; }
.file-pick {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-soft);
  border: 1.5px dashed var(--border); padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
}
.file-pick:hover { border-color: var(--brand-light); color: var(--brand); }

.meta-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px; display: flex; flex-direction: column; gap: 18px;
}
.meta-card h3 { font-size: 15px; margin: 0; color: var(--ink-soft); }
.meta-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.meta-row .k { color: var(--muted); }
.meta-row .v { font-weight: 600; }

.stamp {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 2.5px dashed var(--success); color: var(--success);
  padding: 10px; border-radius: 12px; font-weight: 800; font-size: 14px;
  transform: rotate(-3deg);
}

/* ===================== لایوت ادمین ===================== */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 258px; flex-shrink: 0; background: var(--brand-dark); color: #fff;
  padding: 26px 18px; display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand-logo { color: #fff; padding: 0 6px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  color: rgba(255,255,255,.68); font-weight: 600; font-size: 14.5px;
}
.sidebar nav a .ico { width: 20px; text-align: center; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px;
  background: rgba(255,255,255,.05);
}
.sidebar-user .name { font-size: 13.5px; font-weight: 700; }
.sidebar-user .role { font-size: 11.5px; color: rgba(255,255,255,.55); }

.admin-main { flex: 1; min-width: 0; }
.admin-topbar {
  height: 68px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 28px;
  position: sticky; top: 0; z-index: 40;
}
.admin-content { padding: 28px; max-width: 1280px; }

.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink); }

@media (max-width: 980px) {
  .sidebar {
    position: fixed; right: 0; top: 0; z-index: 100; transform: translateX(100%);
    transition: transform .25s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-block; }
  .admin-content { padding: 18px; }
}

/* ===================== جدول (ادمین) ===================== */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 14px 18px; text-align: right; font-size: 14px; }
.data-table thead th { background: #FAFBFD; color: var(--muted); font-size: 12.5px; font-weight: 700; border-bottom: 1px solid var(--border); }
.data-table tbody tr { border-bottom: 1px solid var(--border-soft); transition: background .12s; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #FAFBFD; }
.data-table .subject-link { font-weight: 700; }
.data-table .subject-link:hover { color: var(--brand); }

.table-scroll { overflow-x: auto; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 26px 0; }
.pagination a, .pagination span {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid var(--border); font-size: 13.5px; font-weight: 600;
}
.pagination a:hover { border-color: var(--brand-light); color: var(--brand); }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ===================== نوتیفیکیشن / Toast ===================== */
.alert {
  padding: 13px 18px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 18px;
  display: flex; align-items: center; gap: 10px; border: 1px solid transparent;
}
.alert-success { background: var(--success-tint); color: #206A4A; border-color: rgba(47,158,110,.25); }
.alert-error   { background: var(--danger-tint); color: #A63737; border-color: rgba(217,79,79,.25); }

.toast-wrap { position: fixed; bottom: 22px; left: 22px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow-lg); animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== متفرقه ===================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 26px; }
.section-title { font-size: 17px; font-weight: 700; margin: 0 0 16px; }
.text-muted { color: var(--muted); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }

.footer-note { text-align: center; padding: 30px 0; color: var(--muted); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
