/* CRM چهره — استایل مشترک همه‌ی صفحه‌ها */
/* فونت وزیرمتن (@fontsource-variable/vazirmatn 5.3.0، مجوز OFL) */
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/vazirmatn-arabic.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/vazirmatn-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --brand: #1e5bd8;
  --brand-dark: #1747ad;
  --brand-soft: #eaf1fe;
  --accent: #f5b400;
  --accent-soft: #fff6d6;
  --bg: #f6f8fb;
  --bg-panel: #ffffff;
  --ink: #1b2433;
  --ink-dim: #5d6b82;
  --ink-faint: #8f9bb0;
  --line: #dfe5ee;
  --line-soft: #edf1f6;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --font: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); font-size: 12px; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ===== دکمه‌ها ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  font: inherit; font-weight: 500; color: var(--ink);
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-faint); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { color: #fff; background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-accent { color: var(--ink); background: var(--accent); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: #f3c4c4; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
.btn-ghost:hover { background: var(--line-soft); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; padding: 0; }

/* ===== فرم‌ها ===== */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--ink-dim); }
.field .req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=password], input[type=search], input[type=tel], input[type=number], select, textarea {
  width: 100%; height: 38px; padding: 0 10px;
  font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  outline: none;
}
textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input.ltr { direction: ltr; text-align: left; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }

/* ===== کارت و جدول ===== */
.card { background: var(--bg-panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; color: var(--ink-dim); background: #fafbfd; }
.table tbody tr:hover { background: #fafcff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.wrap { white-space: normal; min-width: 220px; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-faint); }

.badge { display: inline-block; padding: 1px 9px; font-size: 12px; border-radius: 99px; background: var(--line-soft); color: var(--ink-dim); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar .grow { flex: 1; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--ink-dim); }

/* ===== تب‌ها ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 9px 14px; color: var(--ink-dim); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ===== مودال ===== */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 16px 16px; background: rgba(15, 23, 42, .38);
  overflow-y: auto;
}
.modal { width: 100%; max-width: 520px; background: #fff; border-radius: 12px; box-shadow: 0 20px 50px rgba(15, 23, 42, .25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 18px; border-top: 1px solid var(--line-soft); background: #fafbfd; border-radius: 0 0 12px 12px; }

/* ===== پیام کوتاه ===== */
.toasts { position: fixed; bottom: 18px; left: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 220px; max-width: 360px; padding: 10px 14px; color: #fff; background: #1f2937; border-radius: 8px; box-shadow: var(--shadow); }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

/* ===== صفحه‌ی ورود ===== */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; justify-content: center; }
.logo-img { width: 40px; height: 40px; object-fit: contain; border-radius: 10px; background: #fff; }
.logo-img.logo-lg { width: 110px; height: 110px; border-radius: 18px; }
.logo-mark {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: inset 0 -4px 0 var(--accent);
}

/* ===== پوسته‌ی برنامه ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  width: 220px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-panel); border-left: 1px solid var(--line);
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 16px; font-weight: 700; }
.sidebar nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 2px;
  color: var(--ink-dim); border-radius: 8px;
}
.sidebar nav a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .side-foot { padding: 10px; border-top: 1px solid var(--line-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 58px; padding: 0 20px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.topbar .search { position: relative; flex: 1; max-width: 460px; }
.topbar .search input { padding-left: 52px; background: var(--bg); }
.topbar .search kbd { position: absolute; left: 10px; top: 9px; font: 11px var(--font); color: var(--ink-faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; background: #fff; }
.topbar .user { margin-right: auto; display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; }
.content { padding: 22px 20px 40px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 180px; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
}
.dropdown-menu button { display: block; width: 100%; padding: 8px 10px; font: inherit; text-align: right; background: none; border: 0; border-radius: 6px; cursor: pointer; color: var(--ink); }
.dropdown-menu button:hover { background: var(--line-soft); }

/* ===== انتخابگر تاریخ ===== */
.datepicker {
  position: absolute; z-index: 70; width: 252px; padding: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(15, 23, 42, .16);
  direction: rtl; user-select: none;
}
.datepicker button { font: inherit; border: 0; background: none; cursor: pointer; border-radius: 6px; color: var(--ink); }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dp-head button { width: 30px; height: 30px; font-size: 18px; }
.dp-head button:hover { background: var(--line-soft); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dp-week span { font-size: 11px; color: var(--ink-faint); padding: 2px 0; }
.dp-grid button { height: 30px; font-variant-numeric: tabular-nums; }
.dp-grid button:hover { background: var(--brand-soft); }
.dp-grid button.today { box-shadow: inset 0 0 0 1px var(--accent); font-weight: 700; }
.dp-grid button.sel { background: var(--brand); color: #fff; }
.dp-foot { display: flex; justify-content: space-between; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line-soft); }
.dp-foot button { padding: 2px 8px; font-size: 13px; color: var(--brand); }
.dp-foot button:hover { background: var(--brand-soft); }

/* ===== دکمه‌های انتخاب سریع (نتیجه تماس، تاریخ پیگیری) ===== */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 12px; font: inherit; font-size: 13px;
  color: var(--ink-dim); background: #fff; border: 1px solid var(--line); border-radius: 99px; cursor: pointer;
}
.chip:hover { border-color: var(--ink-faint); color: var(--ink); }
.chip.on { color: var(--brand); background: var(--brand-soft); border-color: var(--brand); font-weight: 600; }
details.more > summary { cursor: pointer; color: var(--brand); margin: 4px 0 12px; list-style: none; font-size: 13px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "+ "; }
details.more[open] > summary::before { content: "− "; }
.dup-warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }
.dup-warn a { font-weight: 600; }

/* ===== جدول قابل مرتب‌سازی ===== */
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--ink); }
.table th.sorted::after { content: " ▾"; }
.table th.sorted.asc::after { content: " ▴"; }
.table tr.clickable { cursor: pointer; }
.overdue { color: var(--danger); font-weight: 600; }

/* ===== پرونده‌ی مشتری ===== */
.profile { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.profile-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.profile-head .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.info-list { margin: 0; }
.info-list div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.info-list div:last-child { border-bottom: 0; }
.info-list dt { color: var(--ink-dim); white-space: nowrap; }
.info-list dd { margin: 0; text-align: left; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 10px 18px 10px 0; border-right: 2px solid var(--line-soft); margin-right: 6px; }
.timeline li::before { content: ""; position: absolute; right: -6px; top: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; }
.timeline li.sys::before { background: var(--ink-faint); }
.timeline li.sys { color: var(--ink-dim); font-size: 13px; }
.timeline .when { font-size: 12px; color: var(--ink-faint); }
.timeline .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.fu-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.fu-item:last-child { border-bottom: 0; }
.fu-item .body { flex: 1; min-width: 0; }
.fu-item .actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ===== Kanban ===== */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.board-col { flex: 0 0 250px; background: #eef2f7; border-radius: var(--radius); padding: 8px; }
.board-col.drop { background: var(--brand-soft); outline: 2px dashed var(--brand); }
.board-col h3 { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 8px; font-size: 13px; }
.board-card { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: grab; color: var(--ink); }
.board-card:hover { border-color: var(--brand); text-decoration: none; }
.board-card.dragging { opacity: .5; }

/* ===== ردیف‌های ویرایشگر فاکتور ===== */
#e-rows td { white-space: normal; vertical-align: top; padding: 8px 6px; }
#e-rows td input, #e-rows td select { display: block; }
#e-rows td[data-line] { padding-top: 16px; }

/* ===== جست‌وجوی سراسری ===== */
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 30; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
}
.search-results a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--ink); }
.search-results a:hover, .search-results a.active { background: var(--brand-soft); text-decoration: none; }

/* ===== واکنش‌گرا ===== */
@media (max-width: 900px) {
  .sidebar { position: fixed; right: 0; z-index: 40; transform: translateX(100%); transition: transform .2s; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: -10px 0 30px rgba(15, 23, 42, .15); }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .topbar .search kbd { display: none; }
  .topbar .search input { padding-left: 10px; }
  .content { padding: 16px 12px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .user-name { display: none; }
  .profile { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* ===== مرحله ۴: داشبورد، گزارش‌ها، هزینه‌ها ===== */
.period { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.period .chips { margin-left: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats .card { margin-bottom: 0; }
.stat-value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat-sub { font-size: 12px; margin-top: 2px; }
.sec-title { font-size: 14px; margin: 0 0 10px; }

/* نمودار ستونی ساده: ستون نازک با سر گرد، خط پایه‌ی کم‌رنگ */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 6px; }
.bar-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; cursor: default; }
.bar-track { flex: 1; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--line); }
.bar { width: min(28px, 70%); background: var(--brand); border-radius: 4px 4px 0 0; transition: opacity .15s; }
.bar.neg { background: var(--danger); }
.bar-col:hover .bar { opacity: .75; }
.bar-label { font-size: 11px; color: var(--ink-faint); text-align: center; margin-top: 4px; white-space: nowrap; overflow: hidden; }

.table.pl td:last-child { text-align: left; }
.table.pl tr.pl-total td { font-weight: 700; border-top: 2px solid var(--line); }

.home-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 14px; align-items: start; margin-bottom: 6px; }
.home-period { padding: 4px 0 10px; flex-wrap: wrap; gap: 8px; border: 0; }
.due-sum { display: flex; gap: 16px; padding: 8px 18px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.due-item { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.due-item:last-child { border-bottom: 0; }
.due-item .body { flex: 1; min-width: 0; }
.due-item .amount { font-weight: 700; white-space: nowrap; }
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
}
/* ===== مرحله ۵: ورود از Excel ===== */
.import-drop { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 18px; border: 2px dashed var(--line); border-radius: 10px; }
.import-help { margin: 14px 0 0; padding-right: 18px; line-height: 2; }
.form-error-inline { color: var(--danger); }