/* =====================================================================
   CRM Design System
   RTL, Persian, professional office tool - not a generic SaaS template.
   Typography: B Titr (headings/titles) + Mahak (body text) — the
   organization's own brand fonts, served locally (no CDN dependency).
   ===================================================================== */

@font-face {
  font-family: 'B Titr';
  src: url('/fonts/BTITRBD.TTF') format('truetype');
  font-weight: bold;
  font-display: swap;
}
@font-face {
  font-family: 'Mahak';
  src: url('/fonts/MAHAKNUM.TTF') format('truetype');
  font-weight: normal;
  font-display: swap;
}

:root {
  /* Core palette - deep slate/navy accent instead of default "purple SaaS" */
  --color-bg:        #f4f5f7;
  --color-surface:   #ffffff;
  --color-border:    #e2e5ea;
  --color-text:      #1f2430;
  --color-text-soft: #626a7a;
  --color-text-mute: #8a90a0;

  --color-primary:      #1d4645;   /* deep teal - organizational accent */
  --color-primary-dark: #143231;
  --color-primary-soft: #e6efee;

  --color-success:    #1f7a52;
  --color-success-bg: #e6f4ec;
  --color-warning:    #a5680a;
  --color-warning-bg: #fdf2e0;
  --color-danger:     #b3352c;
  --color-danger-bg:  #fbe9e7;
  --color-info:       #2c5f8a;
  --color-info-bg:    #e8f1f8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20,20,30,0.06);
  --shadow-md: 0 4px 16px rgba(20,20,30,0.08);

  --sidebar-w: 232px;
  --header-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: 'Mahak', Tahoma, sans-serif;
  direction: rtl;
  font-size: 14px;
  line-height: 1.7;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: bold; font-family: 'B Titr', Tahoma, sans-serif; }

/* ---------------- Layout ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--color-primary-dark);
  color: #eef4f3;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
}
.sidebar-brand {
  padding: 18px 20px;
  font-size: 17px;
  font-weight: bold;
  font-family: 'B Titr', Tahoma, sans-serif;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 8px;
}
.sidebar-brand .dot { width: 9px; height: 9px; border-radius: 50%; background: #5fbfa8; }
.sidebar-nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.78);
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: #2a6863; color: #fff; font-weight: 600; }
.sidebar-nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.9; }
.sidebar-footer { padding: 12px 16px; font-size: 11px; color: rgba(255,255,255,0.4); border-top: 1px solid rgba(255,255,255,0.08); }

.main-col { margin-right: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 16px; font-weight: bold; font-family: 'B Titr', Tahoma, sans-serif; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.topbar-user .role-badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--color-primary-soft); color: var(--color-primary-dark); font-weight: 600; }
.topbar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--color-primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.logout-btn { background: none; border: none; color: var(--color-text-mute); cursor: pointer; font-family: inherit; font-size: 13px; }
.logout-btn:hover { color: var(--color-danger); }

.content { padding: 22px; flex: 1; }

/* ---------------- Flash messages ---------------- */
.flash { padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.flash-success { background: var(--color-success-bg); color: var(--color-success); }
.flash-error { background: var(--color-danger-bg); color: var(--color-danger); }

/* ---------------- Cards / stat cards ---------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 14px; font-weight: bold; font-family: 'B Titr', Tahoma, sans-serif; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.stat-card .stat-value { font-size: 26px; font-weight: bold; font-family: 'B Titr', Tahoma, sans-serif; color: var(--color-primary-dark); }
.stat-card .stat-label { font-size: 12.5px; color: var(--color-text-soft); margin-top: 4px; }
.stat-card.warn .stat-value { color: var(--color-warning); }
.stat-card.danger .stat-value { color: var(--color-danger); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid-2, .grid-2col { grid-template-columns: 1fr; } }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; font-family: inherit; transition: all .15s;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- Forms ---------------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--color-text-soft); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel],
select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13.5px; background: var(--color-surface); color: var(--color-text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.helper-text { font-size: 11.5px; color: var(--color-text-mute); margin-top: 4px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: right; padding: 10px 12px; background: var(--color-bg); color: var(--color-text-soft);
  font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--color-border); white-space: nowrap;
}
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
table.data-table tbody tr:hover { background: #fafbfc; }
table.data-table tbody tr:last-child td { border-bottom: none; }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info    { background: var(--color-info-bg); color: var(--color-info); }
.badge-mute    { background: var(--color-bg); color: var(--color-text-mute); }

/* ---------------- Alerts ---------------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert-warning { background: var(--color-warning-bg); color: #7a4d08; border: 1px solid #f0d69b; }
.alert-info { background: var(--color-info-bg); color: #1e435f; border: 1px solid #b9d6e8; }

/* ---------------- Pagination ---------------- */
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.pagination a, .pagination span {
  padding: 6px 12px; border-radius: var(--radius-sm); font-size: 12.5px; border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.pagination a:hover { background: var(--color-bg); }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------------- Empty state ---------------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--color-text-mute); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .5; }

/* ---------------- Timeline (customer profile) ---------------- */
.timeline { position: relative; padding-right: 22px; }
.timeline::before { content: ''; position: absolute; right: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--color-border); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item::before {
  content: ''; position: absolute; right: -22px; top: 3px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--color-primary); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--color-border);
}
.timeline-item .tl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.timeline-item .tl-date { font-size: 12px; color: var(--color-text-mute); }
.timeline-item .tl-body { background: var(--color-bg); border-radius: var(--radius-md); padding: 10px 14px; font-size: 13px; }

/* ---------------- Login ---------------- */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--color-primary-dark), #0d2321); }
.login-card { background: #fff; border-radius: var(--radius-lg); padding: 36px 32px; width: 360px; box-shadow: var(--shadow-md); }
.login-card h1 { font-size: 19px; text-align: center; margin-bottom: 4px; }
.login-card p.sub { text-align: center; color: var(--color-text-mute); font-size: 12.5px; margin-bottom: 22px; }
.login-hint { margin-top: 18px; font-size: 11.5px; color: var(--color-text-mute); background: var(--color-bg); border-radius: var(--radius-sm); padding: 10px 12px; }

/* ---------------- Misc utility ---------------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mb-16 { margin-bottom: 16px; }
.text-mute { color: var(--color-text-mute); }
.text-soft { color: var(--color-text-soft); }
.text-sm { font-size: 12px; }
.w-full { width: 100%; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 16px; }
.tabs a { padding: 9px 16px; font-size: 13px; color: var(--color-text-soft); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--color-primary-dark); border-color: var(--color-primary); font-weight: 700; }


/* =====================================================================
   Responsive layout
   Desktop 16:9 (لپ‌تاپ/کامپیوتر) و موبایل 9:16 (گوشی عمودی) هر دو
   پشتیبانی می‌شوند. هدف: استفاده کامل با مرورگر گوشی، بدون نیاز به اپ.
   ===================================================================== */

.mobile-menu-btn {
  display: none;
  background: var(--color-primary);
  color: #fff; border: 0; border-radius: 8px;
  padding: 9px 13px; cursor: pointer; font-family: inherit; font-size: 16px;
  line-height: 1; margin-left: 10px;
}
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  /* ---- Navigation ---- */
  .mobile-menu-btn { display: inline-flex; align-items: center; }
  .sidebar {
    transform: translateX(100%);
    transition: transform .22s ease;
    z-index: 100;
    width: min(82vw, 290px);
  }
  .sidebar.open { transform: translateX(0); box-shadow: -6px 0 24px rgba(0,0,0,.25); }
  .sidebar-backdrop { display: none; }
  .sidebar.open ~ .sidebar-backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 90;
  }
  .main-col { margin-right: 0; }

  /* ---- Header ---- */
  .topbar { padding: 0 12px; position: sticky; top: 0; }
  .topbar-title { font-size: 14px; }
  .topbar-user { gap: 7px; }
  .topbar-user .role-badge { display: none; }
  .topbar-user .avatar { width: 30px; height: 30px; }

  /* ---- Spacing / cards ---- */
  .content { padding: 14px; }
  .card { padding: 14px; }
  .card + .card { margin-top: 12px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
  .stat-card { padding: 12px; }
  .stat-card .stat-value { font-size: 21px; }

  /* ---- Forms: single column, comfortable touch targets ---- */
  .form-row, .grid-2, .grid-2col { grid-template-columns: 1fr; }
  input[type=text], input[type=password], input[type=number], input[type=date],
  input[type=tel], select, textarea { font-size: 16px; padding: 11px 12px; }
  /* 16px جلوی زوم خودکار iOS هنگام فوکوس روی فیلد را می‌گیرد */
  .btn { padding: 11px 15px; min-height: 42px; }

  /* ---- Toolbars stack vertically ---- */
  .toolbar { align-items: stretch; flex-direction: column; gap: 8px; }
  .toolbar > * { max-width: 100% !important; width: 100%; }
  .toolbar .spacer { display: none; }

  /* ---- Tabs scroll horizontally instead of wrapping ---- */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .tabs a { display: inline-block; padding: 10px 13px; }

  /* ---- Tables: stack each row as a card (9:16 friendly) ----
     به‌جای اسکرول افقی سخت، هر ردیف مثل یک کارت نمایش داده می‌شود و
     عنوان هر ستون از data-label کنار مقدارش می‌آید. */
  .table-wrap { overflow-x: visible; }
  table.data-table thead { display: none; }
  table.data-table, table.data-table tbody, table.data-table tr, table.data-table td { display: block; width: 100%; }
  table.data-table tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    padding: 6px 10px;
    background: var(--color-surface);
  }
  table.data-table td {
    border: none;
    border-bottom: 1px dashed var(--color-border);
    padding: 8px 2px;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    font-size: 13px;
  }
  table.data-table td:last-child { border-bottom: none; }
  table.data-table td::before {
    content: attr(data-label);
    color: var(--color-text-soft);
    font-size: 12px; font-weight: 600;
    flex-shrink: 0;
  }
  table.data-table td:not([data-label]) { justify-content: flex-start; }
  table.data-table tbody tr:hover { background: var(--color-surface); }
  /* ردیف‌های «خالی» (Empty state) نباید کارت‌بندی شوند */
  table.data-table td.empty-state { display: block; text-align: center; }

  .login-card { width: min(92vw, 360px); padding: 28px 22px; }
  .timeline { padding-right: 18px; }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .topbar-user span:not(.role-badge) {
    max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .timeline { padding-right: 16px; }
  h2 { font-size: 17px; }
}

/* روی گوشی در حالت افقی (landscape) هم فضای عمودی کم است: هدر کوچک‌تر */
@media (max-height: 460px) and (orientation: landscape) {
  .topbar { height: 48px; }
  .content { padding: 10px; }
}


/* CRM v10 mobile hardening */
html, body { max-width: 100%; overflow-x: hidden; }
button, input, select, textarea { max-width: 100%; }
.sidebar { will-change: transform; }
@media (max-width: 900px) {
  .topbar { min-height: 56px; height: auto; }
  .topbar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-user { flex-shrink: 0; }
  .content { min-width: 0; }
  .card { min-width: 0; overflow: hidden; }
  .table-wrap { max-width: 100%; }
  .sidebar-backdrop { pointer-events: none; }
  .sidebar.open ~ .sidebar-backdrop { pointer-events: auto; }
}
@media (max-width: 520px) {
  .content { padding: 10px; }
  .card { padding: 11px; border-radius: 10px; }
  .flex-between { flex-wrap: wrap; gap: 10px; }
  .flex.gap-8 { flex-wrap: wrap; }
  .btn { max-width: 100%; white-space: normal; }
}


/* ---- صفحه‌بندی مشتریان (v12): صفحه قبل / شماره صفحه از کل / صفحه بعد ---- */
.pager { display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:10px; padding:14px 8px; }
.pager-info { font-size:14px; white-space:nowrap; }
.pager-disabled { opacity:.45; pointer-events:none; }
.pager-jump { display:flex; gap:6px; align-items:center; margin:0; }
.pager-jump input { width:110px; padding:6px 8px; }
