/* ==========================================================================
   سیستم مدیریت اقساط — استایل اصلی
   ========================================================================== */

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

:root {
  /* رنگ‌های پایه */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --line: #e8edf3;
  --line-soft: #f1f5f9;

  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;

  /* رنگ برند — در هر صفحه قابل تغییر است */
  --brand: #2563eb;
  --brand-600: #1d4ed8;
  --brand-soft: #eff6ff;

  --green: #16a34a;
  --green-soft: #e9f8ef;
  --amber: #f59e0b;
  --amber-soft: #fef6e7;
  --red: #ef4444;
  --red-soft: #fdecec;
  --blue: #3b82f6;
  --blue-soft: #eaf1fe;

  --sidebar-bg: #131b2e;
  --sidebar-text: #c3ccdd;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --sidebar-w: 240px;
  --topbar-h: 78px;
}

/* پوسته سبز برای صفحه جزئیات قرارداد */
[data-theme="green"] {
  --brand: #16a34a;
  --brand-600: #15803d;
  --brand-soft: #e9f8ef;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: Vazirmatn, 'IRANSans', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }

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

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

/* ---------- نوار کناری ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

.brand .brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
  flex: 0 0 auto;
}

.nav { padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }

.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: background .18s ease, color .18s ease;
}

.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.is-active { background: var(--brand); color: #fff; font-weight: 600; }
.nav a svg { flex: 0 0 auto; }

.sidebar-foot { margin-top: auto; padding: 16px 16px 22px; }

.sidebar-cta {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 14px 12px;
  border: 0; border-radius: 12px;
  background: var(--brand); color: #fff;
  font-weight: 600;
  transition: background .18s ease;
}
.sidebar-cta:hover { background: var(--brand-600); }

.sidebar-logout {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: var(--sidebar-text);
}
.sidebar-logout:hover { background: rgba(255, 255, 255, .06); color: #fff; }

/* ---------- محتوای اصلی ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 26px;
  position: sticky; top: 0; z-index: 20;
}

.menu-toggle {
  display: none;
  background: none; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px;
}

.search {
  flex: 0 1 420px;
  position: relative;
  display: flex; align-items: center;
}
.search input {
  width: 100%;
  padding: 11px 42px 11px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  font: inherit;
  font-size: 13px;
  color: var(--text);
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; border-color: var(--brand); background: #fff; }
.search svg { position: absolute; right: 14px; color: var(--text-3); pointer-events: none; }

.topbar-actions { margin-right: auto; display: flex; align-items: center; gap: 6px; }

.icon-btn {
  position: relative;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--text-2);
  transition: background .18s ease, color .18s ease;
}
.icon-btn:hover { background: var(--line-soft); color: var(--text); }

.badge-dot {
  position: absolute; top: 6px; right: 6px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid #fff;
}
.badge-dot.is-plain { min-width: 9px; height: 9px; padding: 0; top: 8px; right: 9px; background: var(--blue); }

.user {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: none; border: 0;
}
.user:hover { background: var(--line-soft); }
.user span { font-size: 13px; font-weight: 500; }

/* آواتار */
.avatar {
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
  color: #fff;
  flex: 0 0 auto;
  letter-spacing: -.02em;
  overflow: hidden;
}
.avatar-40 { width: 40px; height: 40px; font-size: 14px; }
.avatar-36 { width: 36px; height: 36px; font-size: 13px; }
.avatar-96 { width: 96px; height: 96px; font-size: 30px; border: 4px solid #fff; box-shadow: 0 0 0 3px var(--brand-soft); }

.av-1 { background: linear-gradient(140deg, #64748b, #334155); }
.av-2 { background: linear-gradient(140deg, #3b82f6, #1d4ed8); }
.av-3 { background: linear-gradient(140deg, #14b8a6, #0f766e); }
.av-4 { background: linear-gradient(140deg, #f59e0b, #b45309); }
.av-5 { background: linear-gradient(140deg, #a855f7, #6d28d9); }
.av-6 { background: linear-gradient(140deg, #ec4899, #9d174d); }

/* ---------- ناحیه صفحه ---------- */
.page { padding: 26px; display: flex; flex-direction: column; gap: 20px; flex: 1; }

.breadcrumb {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-3); font-size: 13px;
}
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb .sep { font-size: 11px; }
.breadcrumb .current { color: var(--text); font-weight: 500; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line-soft);
}
.card-title {
  margin: 0;
  font-size: 15px; font-weight: 700;
  display: flex; align-items: center; gap: 9px;
}
.card-title svg { color: var(--brand); }
.card-body { padding: 20px 22px; }
.card-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}

/* ---------- کارت‌های آمار ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.stat { padding: 20px 22px 12px; }
.stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.stat-label { color: var(--text-2); font-size: 13px; }
.stat-value { font-size: 27px; font-weight: 700; letter-spacing: -.01em; line-height: 1.5; }
.stat-unit { color: var(--text-3); font-size: 12px; }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.stat-icon.blue { background: var(--blue-soft); color: var(--blue); }
.stat-icon.green { background: var(--green); color: #fff; }
.stat-icon.amber { background: var(--amber-soft); color: var(--amber); }
.stat-icon.red { background: var(--red-soft); color: var(--red); }

.stat-link {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between;
  color: var(--blue); font-size: 13px; font-weight: 500;
}
.stat-link:hover { color: var(--brand-600); }
.stat-link .arrow { transition: transform .18s ease; }
.stat-link:hover .arrow { transform: translateX(-4px); }

.value-green { color: var(--green); }
.value-amber { color: var(--amber); }
.value-red { color: var(--red); }

/* ---------- شبکه دو ستونی ---------- */
.grid-2 { display: grid; grid-template-columns: 1.05fr .95fr; gap: 18px; align-items: start; }
.grid-2.reverse { grid-template-columns: .95fr 1.05fr; }

/* چیدمان صفحه جزئیات قرارداد */
.grid-contract { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.contract-main-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ---------- نمودار ---------- */
.chart-wrap { padding: 10px 14px 6px; }
.chart { width: 100%; height: 250px; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; font-family: inherit; }
.chart .area { fill: url(#areaFill); }
.chart .line { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .dot { fill: var(--blue); stroke: #fff; stroke-width: 2.5; }
.chart .dot-hit { fill: transparent; cursor: pointer; }

.select {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font: inherit; font-size: 12.5px;
  color: var(--text-2);
}

.chart-tip {
  position: absolute;
  transform: translate(50%, -130%);
  background: var(--sidebar-bg); color: #fff;
  padding: 6px 10px; border-radius: 8px;
  font-size: 12px; white-space: nowrap;
  pointer-events: none; opacity: 0;
  transition: opacity .15s ease;
}
.chart-tip.is-visible { opacity: 1; }

/* ---------- فهرست سررسید ---------- */
.due-list { display: flex; flex-direction: column; }

.due-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  transition: background .15s ease;
}
.due-row:hover { background: #fafcfe; }
.due-flag { width: 3px; align-self: stretch; border-radius: 3px; background: var(--red); flex: 0 0 auto; }
.due-flag.amber { background: var(--amber); }
.due-name { font-weight: 600; font-size: 13.5px; }
.due-meta { color: var(--text-3); font-size: 12px; }
.due-amount { margin-right: auto; text-align: left; font-weight: 600; font-size: 13.5px; }
.due-amount small { display: block; color: var(--text-3); font-weight: 400; font-size: 11px; }

.link-more {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 14px 22px;
  color: var(--blue); font-size: 13px; font-weight: 500;
}
.link-more:hover { color: var(--brand-600); }

/* ---------- جدول ---------- */
.table-wrap { overflow-x: auto; }

.table th {
  text-align: right;
  padding: 13px 18px;
  color: var(--text-2);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcfe; }
.table .num { font-weight: 600; }

.table-boxed { margin: 0 22px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.table-boxed th { background: #f8fafc; }
.table-boxed td, .table-boxed th { text-align: center; }
.table-boxed th:first-child, .table-boxed td:first-child { text-align: center; }

/* ---------- نشان‌ها ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.chip-green { background: var(--green-soft); color: var(--green); }
.chip-amber { background: var(--amber-soft); color: #b45309; }
.chip-red { background: var(--red-soft); color: var(--red); }
.chip-gray { background: #f1f5f9; color: var(--text-3); }
.chip-blue { background: var(--blue-soft); color: var(--blue); }

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; }

/* ---------- دکمه‌ها ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px; font-weight: 600;
  transition: background .18s ease, border-color .18s ease, color .18s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-dark { background: var(--sidebar-bg); color: #fff; }
.btn-dark:hover { background: #0b1120; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-block { width: 100%; padding: 14px; }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 8px; }

.icon-link {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  color: var(--blue);
}
.icon-link:hover { background: var(--blue-soft); }

/* ---------- خلاصه سریع (نمودار حلقه‌ای) ---------- */
.donut-wrap { display: grid; place-items: center; padding: 12px 0 4px; }
.donut { position: relative; width: 168px; height: 168px; }
.donut svg { transform: rotate(-90deg); }
.donut-center {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
}
.donut-center strong { font-size: 24px; font-weight: 700; display: block; line-height: 1.4; }
.donut-center span { font-size: 11px; color: var(--text-3); }

.legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; text-align: center; }
.legend-item { font-size: 12.5px; }
.legend-key { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.legend-key i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend-item strong { display: block; font-weight: 600; font-size: 13px; margin-top: 2px; }

/* ---------- سرصفحه قرارداد ---------- */
.contract-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.contract-head-right { display: flex; align-items: center; gap: 14px; }
.contract-title { margin: 0; font-size: 18px; font-weight: 700; }
.contract-sub { color: var(--text-3); font-size: 12.5px; }
.contract-mark {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; flex: 0 0 auto;
}
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- فهرست اطلاعات ---------- */
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 40px; }
.info-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.info-row:last-child, .info-grid .info-row:nth-last-child(-n+2) { border-bottom: 0; }
.info-row dt { color: var(--text-2); }
.info-row dd { margin: 0; font-weight: 600; text-align: left; }

.summary-list .info-row { border-bottom: 1px dashed var(--line); }
.summary-list .info-row:last-child { border-bottom: 0; }

/* ---------- تب‌ها ---------- */
.tabs {
  display: flex; gap: 4px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  padding: 15px 14px;
  border: 0; background: none;
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }

.tab-panel { padding: 18px 0 4px; }
.tab-panel[hidden] { display: none; }

.empty {
  padding: 46px 22px; text-align: center; color: var(--text-3);
  display: grid; gap: 8px; justify-items: center;
}
.empty strong { color: var(--text-2); font-weight: 600; }

/* ---------- ستون کناری مشتری ---------- */
.aside-col { display: flex; flex-direction: column; gap: 18px; position: sticky; top: calc(var(--topbar-h) + 26px); }

.customer-card { display: grid; justify-items: center; gap: 4px; padding: 8px 22px 22px; }
.customer-top { width: 100%; display: flex; justify-content: flex-end; }
.customer-name { font-size: 17px; font-weight: 700; margin: 12px 0 2px; }

.footer {
  padding: 18px 26px 26px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
}

/* ---------- واکنش‌گرایی ---------- */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-2.reverse, .grid-contract { grid-template-columns: 1fr; }
  .aside-col { position: static; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 60; right: 0; top: 0;
    transform: translateX(100%);
    transition: transform .25s ease;
    box-shadow: -12px 0 40px rgba(2, 6, 23, .3);
  }
  .sidebar.is-open { transform: translateX(0); }
  .menu-toggle { display: grid; place-items: center; }
  .scrim {
    position: fixed; inset: 0; background: rgba(2, 6, 23, .45);
    z-index: 50; opacity: 0; pointer-events: none; transition: opacity .25s ease;
  }
  .scrim.is-open { opacity: 1; pointer-events: auto; }
  .page { padding: 16px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .user span { display: none; }
  .info-grid { grid-template-columns: 1fr; }
  .info-grid .info-row:nth-last-child(2) { border-bottom: 1px dashed var(--line); }
  .stat-value { font-size: 22px; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .search { flex: 1; }
}

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

@media print {
  .sidebar, .topbar, .head-actions, .sidebar-cta { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
