/* ===================================================================
   مدیریت مشتری (CRM) — استایل اختصاصی
   Layers on style.css (same Noura tokens). Ported from the Noura design
   project (salam/crm.css) and adapted to live inside the «سلام» SPA as the
   #screen-crm screen instead of a standalone page.
   =================================================================== */

/* ── embedding: the CRM screen behaves like a full-height app shell ──── */
#screen-crm.screen.active{display:flex;flex-direction:column;height:100vh;overflow:hidden;animation:none}
#screen-crm .topbar,#screen-crm .crm-toolbar{flex:none}
#crm-views{flex:1;min-height:0;display:flex;flex-direction:column}

/* view-switcher (segmented) in the topbar — replaces the design's sidebar nav */
.crm-segmented{display:inline-flex;background:var(--panel-3);border-radius:var(--r-pill);padding:4px;gap:2px}
.crm-seg{display:inline-flex;align-items:center;gap:7px;padding:8px 16px;border-radius:var(--r-pill);
  font-size:13px;font-weight:700;color:var(--gray);transition:.16s;white-space:nowrap;cursor:pointer}
.crm-seg svg{width:16px;height:16px}
.crm-seg:hover{color:var(--indigo)}
.crm-seg.active{background:#fff;color:var(--indigo);box-shadow:var(--shadow-soft)}

/* ── structure ───────────────────────────────────────── */
.crm-view{display:none;flex:1;min-height:0;flex-direction:column}
.crm-view.active{display:flex;animation:fadeUp .4s var(--ease-out) both}
.crm-scroll{flex:1;min-height:0;overflow-y:auto;padding:24px 34px 40px}

.crm-toolbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;
  padding:16px 34px;border-bottom:1px solid var(--line);background:rgba(246,248,252,.7)}
.crm-search{display:flex;align-items:center;gap:9px;background:#fff;border:1px solid var(--line-2);
  border-radius:var(--r-pill);padding:9px 15px;min-width:220px;flex:1;max-width:340px;transition:.18s}
.crm-search:focus-within{border-color:var(--cyan);box-shadow:0 0 0 3px rgba(0,174,239,.12)}
.crm-search svg{width:17px;height:17px;color:var(--gray);flex:none}
.crm-search input{border:0;outline:none;background:none;font-family:inherit;font-size:13.5px;color:var(--ink);width:100%}
.crm-tb-spacer{flex:1}

/* ── فیلترها ────────────────────────────────────────── */
.crm-filters{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.crm-fchip{display:inline-flex;align-items:center;gap:6px;padding:8px 13px;border-radius:var(--r-pill);
  border:1px solid var(--line-2);background:#fff;font-size:12.5px;font-weight:600;color:var(--indigo);
  cursor:pointer;transition:.16s;white-space:nowrap}
.crm-fchip:hover{border-color:var(--cyan);color:var(--cyan-deep)}
.crm-fchip.on{background:var(--indigo);border-color:var(--indigo);color:#fff}
.crm-fchip .dot{width:8px;height:8px;border-radius:50%}
.crm-fselect{border:1px solid var(--line-2);background:#fff;color:var(--indigo);border-radius:var(--r-pill);
  padding:8px 13px;font-size:12.5px;font-weight:600;font-family:inherit;outline:none;cursor:pointer;transition:.16s}
.crm-fselect:focus{border-color:var(--cyan);box-shadow:0 0 0 3px rgba(0,174,239,.12)}

/* ===================================================================
   برد کانبان
   =================================================================== */
.crm-board{flex:1;min-height:0;display:flex;gap:14px;overflow-x:auto;overflow-y:hidden;
  padding:20px 34px 28px;align-items:stretch}
.crm-col{flex:0 0 282px;display:flex;flex-direction:column;min-height:0;
  background:var(--panel-3);border-radius:var(--r-md);border:1px solid var(--line)}
.crm-col.parked{background:repeating-linear-gradient(135deg,var(--gray-3) 0 10px,#fff 10px 20px);
  border-style:dashed;border-color:var(--line-2)}
.crm-col-head{display:flex;align-items:center;gap:9px;padding:14px 14px 11px;flex:none}
.crm-col-dot{width:10px;height:10px;border-radius:50%;flex:none}
.crm-col-title{font-size:13.5px;font-weight:800;color:var(--indigo-3)}
.crm-col-count{font-size:11px;font-weight:800;color:var(--gray);background:#fff;border:1px solid var(--line);
  border-radius:var(--r-pill);min-width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;padding:0 6px}
.crm-col-sum{margin-inline-start:auto;font-size:11px;font-weight:700;color:var(--indigo);
  font-variant-numeric:tabular-nums;white-space:nowrap}
.crm-col-body{flex:1;min-height:0;overflow-y:auto;padding:4px 10px 12px;display:flex;flex-direction:column;gap:10px}
.crm-col-body.drag-over{background:rgba(0,174,239,.07);outline:2px dashed var(--cyan);outline-offset:-6px;border-radius:var(--r-sm)}

.crm-col-empty{text-align:center;color:var(--gray-2);font-size:12px;padding:22px 8px;line-height:1.8}

/* کارت مشتری */
.crm-card{background:#fff;border:1px solid var(--line);border-radius:var(--r-sm);padding:13px;
  box-shadow:var(--shadow-soft);cursor:grab;transition:transform .14s,box-shadow .14s,border-color .14s;
  position:relative;border-inline-start:3px solid var(--line-2)}
.crm-card:hover{transform:translateY(-2px);box-shadow:var(--shadow-lift);border-color:var(--line-2)}
.crm-card.dragging{opacity:.45;cursor:grabbing}
.crm-card.stale{border-inline-start-color:var(--amber)}
.crm-card-top{display:flex;align-items:flex-start;gap:9px;margin-bottom:9px}
.crm-card-name{font-size:13.5px;font-weight:800;color:var(--ink);line-height:1.4;flex:1;min-width:0}
.crm-card-type{font-size:10.5px;font-weight:700;padding:2px 8px;border-radius:var(--r-pill);
  display:inline-block;margin-top:4px}
.crm-av{width:30px;height:30px;border-radius:50%;flex:none;display:grid;place-items:center;
  font-weight:800;font-size:11px;color:#fff;letter-spacing:-.5px;background:var(--indigo)}
.crm-av.muted{background:var(--gray-2)}
.crm-card-rows{display:flex;flex-direction:column;gap:6px;font-size:11.5px;color:var(--ink-soft)}
.crm-card-row{display:flex;align-items:center;gap:7px;line-height:1.5}
.crm-card-row svg{width:13px;height:13px;color:var(--gray-2);flex:none}
.crm-ellip{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
.crm-card-row .dim{color:var(--gray-2)}
.crm-ddl-over{color:#c0392b;font-weight:700}
.crm-ddl-over svg{color:#c0392b}
.crm-ddl-today{color:#a96d1c;font-weight:700}
.crm-card-foot{margin-top:10px;padding-top:9px;border-top:1px dashed var(--line);
  font-size:11px;color:var(--gray);line-height:1.55;display:flex;flex-direction:column;gap:3px}
.crm-foot-when{font-weight:700;color:var(--indigo)}
.crm-foot-when.stale{color:var(--amber)}
.crm-foot-txt{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.crm-stale-tag{position:absolute;top:11px;inset-inline-end:11px;font-size:9.5px;font-weight:800;color:#a96d1c;
  background:var(--amber-soft);border-radius:var(--r-pill);padding:2px 7px}
.crm-card-badges{display:flex;gap:5px;flex-wrap:wrap;margin-bottom:8px}

/* نشان اولویت کوچک */
.crm-pri{display:inline-flex;align-items:center;gap:5px;font-size:10px;font-weight:800;
  padding:2px 8px;border-radius:var(--r-pill)}
.crm-pri .d{width:6px;height:6px;border-radius:50%}
.crm-warn-pill{display:inline-flex;align-items:center;gap:4px;font-size:9.5px;font-weight:800;
  padding:2px 8px;border-radius:var(--r-pill);background:rgba(220,80,80,.1);color:#c0392b}

/* ===================================================================
   فهرست (جدول)
   =================================================================== */
.crm-th-sort{cursor:pointer;user-select:none;white-space:nowrap}
.crm-th-sort:hover{color:var(--cyan-deep)}
.crm-th-sort .arr{font-size:9px;opacity:.5;margin-inline-start:3px}
.crm-th-sort.sorted .arr{opacity:1;color:var(--cyan-deep)}
.crm-row-name{font-weight:800;color:var(--ink);cursor:pointer}
.crm-row-name:hover{color:var(--cyan-deep)}
.crm-mini-av{width:24px;height:24px;border-radius:50%;display:inline-grid;place-items:center;
  font-size:9.5px;font-weight:800;color:#fff;background:var(--indigo);vertical-align:middle;margin-inline-end:6px}
.crm-stage-pill{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;font-weight:700}
.crm-stage-pill .d{width:8px;height:8px;border-radius:50%}
tbody tr.crm-trow{cursor:pointer}

/* ===================================================================
   داشبورد
   =================================================================== */
.crm-dash-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:16px;margin-top:4px}
@media (max-width:1000px){.crm-dash-grid{grid-template-columns:1fr}}

.crm-funnel{display:flex;flex-direction:column;gap:11px;margin-top:6px}
.crm-funnel-row{display:grid;grid-template-columns:96px 1fr auto;align-items:center;gap:12px}
.crm-funnel-row .fl{font-size:12.5px;font-weight:700;color:var(--ink-soft)}
.crm-funnel-track{height:26px;background:var(--panel-3);border-radius:8px;overflow:hidden;position:relative}
.crm-funnel-fill{height:100%;border-radius:8px;min-width:3px;transition:width .6s var(--ease-out);
  display:flex;align-items:center;justify-content:flex-end;padding-inline-end:9px}
.crm-funnel-fill span{font-size:11px;font-weight:800;color:#fff}
.crm-funnel-row .fv{font-size:11.5px;font-weight:700;color:var(--indigo);font-variant-numeric:tabular-nums;white-space:nowrap}

.crm-feed{display:flex;flex-direction:column}
.crm-feed-item{display:flex;gap:11px;padding:11px 0;border-bottom:1px solid var(--line)}
.crm-feed-item:last-child{border-bottom:0}
.crm-feed-av{width:32px;height:32px;border-radius:50%;flex:none;display:grid;place-items:center;
  font-size:11px;font-weight:800;color:#fff;background:var(--indigo)}
.crm-feed-body{flex:1;min-width:0}
.crm-feed-top{display:flex;align-items:baseline;gap:7px;flex-wrap:wrap;margin-bottom:2px}
.crm-feed-cust{font-size:12.5px;font-weight:800;color:var(--indigo-3);cursor:pointer}
.crm-feed-cust:hover{color:var(--cyan-deep)}
.crm-feed-when{font-size:10.5px;color:var(--gray-2);margin-inline-start:auto}
.crm-feed-txt{font-size:12px;color:var(--ink-soft);line-height:1.6;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}

.crm-ddl-list{display:flex;flex-direction:column}
.crm-ddl-item{display:flex;align-items:center;gap:11px;padding:10px 0;border-bottom:1px solid var(--line);cursor:pointer}
.crm-ddl-item:last-child{border-bottom:0}
.crm-ddl-item:hover .crm-ddl-cust{color:var(--cyan-deep)}
.crm-ddl-date{flex:none;width:58px;text-align:center;border-radius:9px;padding:6px 4px;
  background:var(--panel-3);font-size:11px;font-weight:700;color:var(--indigo);line-height:1.35}
.crm-ddl-date.over{background:rgba(220,80,80,.1);color:#c0392b}
.crm-ddl-date.soon{background:var(--amber-soft);color:#a96d1c}
.crm-ddl-cust{font-size:12.5px;font-weight:800;color:var(--ink)}
.crm-ddl-meta{font-size:11px;color:var(--gray)}

/* ===================================================================
   پنل جزئیات (کشویی)
   =================================================================== */
.crm-drawer-scrim{position:fixed;inset:0;background:rgba(31,41,102,.5);backdrop-filter:blur(4px);
  opacity:0;pointer-events:none;transition:opacity .3s;z-index:50}
.crm-drawer-scrim.show{opacity:1;pointer-events:auto}
.crm-drawer{position:fixed;top:0;left:0;height:100vh;width:560px;max-width:94vw;
  background:#fff;box-shadow:var(--shadow-pop);z-index:51;display:flex;flex-direction:column;
  transform:translateX(-100%);transition:transform .32s var(--ease-out)}
.crm-drawer.show{transform:translateX(0)}
@media (prefers-reduced-motion:reduce){.crm-drawer{transition:none}}

.crm-dr-head{padding:22px 24px 18px;border-bottom:1px solid var(--line);position:relative;flex:none}
.crm-dr-head-top{display:flex;align-items:flex-start;gap:13px}
.crm-dr-av{width:50px;height:50px;border-radius:15px;flex:none;display:grid;place-items:center;
  font-weight:800;font-size:17px;color:#fff;letter-spacing:-.5px;background:linear-gradient(135deg,var(--indigo),var(--indigo-2))}
.crm-dr-title{font-size:19px;font-weight:800;color:var(--indigo-3);line-height:1.35;letter-spacing:-.3px}
.crm-dr-title[contenteditable]{outline:none;border-radius:6px;padding:2px 5px;margin:-2px -5px;transition:.15s}
.crm-dr-title[contenteditable]:hover{background:var(--panel-3)}
.crm-dr-title[contenteditable]:focus{background:#fff;box-shadow:0 0 0 2px var(--cyan)}
.crm-dr-sub{font-size:12.5px;color:var(--gray);margin-top:3px}
.crm-dr-actions{display:flex;gap:7px;align-items:center;flex-shrink:0}
.crm-dr-badges{display:flex;gap:7px;flex-wrap:wrap;margin-top:13px}

.crm-dr-body{flex:1;min-height:0;overflow-y:auto;padding:20px 24px 32px}
.crm-dr-section{font-size:11px;font-weight:800;color:var(--cyan-deep);letter-spacing:.4px;
  margin:22px 0 12px;display:flex;align-items:center;gap:9px}
.crm-dr-section:first-child{margin-top:0}
.crm-dr-section::after{content:"";flex:1;height:1px;background:var(--line)}

/* فیلدهای قابل ویرایش inline */
.crm-field{display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:10px 0;border-bottom:1px solid var(--line)}
.crm-field:last-child{border-bottom:0}
.crm-field-k{font-size:12.5px;color:var(--gray);font-weight:500;flex:none}
.crm-field-v{font-size:13.5px;color:var(--ink);font-weight:600;text-align:left;flex:1;min-width:0}
.crm-editable{cursor:text;border-radius:7px;padding:5px 9px;margin:-5px -9px;transition:.15s;
  display:inline-flex;align-items:center;gap:6px;max-width:100%}
.crm-editable:hover{background:var(--panel-3);box-shadow:inset 0 0 0 1px var(--line-2)}
.crm-editable .pen{width:12px;height:12px;color:var(--gray-2);opacity:0;transition:.15s;flex:none}
.crm-editable:hover .pen{opacity:1}
.crm-editable.empty{color:var(--gray-2);font-weight:500;font-style:normal}
.crm-edit-input,.crm-edit-select{border:1px solid var(--cyan);background:#fff;color:var(--ink);
  border-radius:8px;padding:6px 10px;font-size:13px;font-family:inherit;outline:none;
  box-shadow:0 0 0 3px rgba(0,174,239,.13);width:200px;max-width:62%}
.crm-edit-select{cursor:pointer}
.crm-field-v.wide{display:block;text-align:right}
.crm-person-note{font-size:12px;color:var(--gray);font-weight:400;margin-top:3px;line-height:1.6}
.crm-deal-text{font-size:13px;color:var(--ink-soft);line-height:1.7;background:var(--panel-2);
  border:1px solid var(--line);border-radius:var(--r-sm);padding:12px 14px;cursor:text;transition:.15s}
.crm-deal-text:hover{border-color:var(--line-2)}
.crm-deal-text.empty{color:var(--gray-2)}

/* انتخاب مرحله در پنل */
.crm-stage-picker{display:flex;gap:6px;flex-wrap:wrap}
.crm-stage-opt{padding:7px 13px;border-radius:var(--r-pill);font-size:12px;font-weight:700;
  border:1px solid var(--line-2);background:#fff;color:var(--gray);cursor:pointer;transition:.15s;
  display:inline-flex;align-items:center;gap:6px}
.crm-stage-opt .d{width:8px;height:8px;border-radius:50%}
.crm-stage-opt:hover{border-color:var(--cyan)}
.crm-stage-opt.on{color:#fff;border-color:transparent}

/* کامنت‌ها */
.crm-composer{background:var(--panel-2);border:1px solid var(--line);border-radius:var(--r-sm);padding:12px}
.crm-composer textarea{width:100%;border:1px solid var(--line-2);background:#fff;border-radius:9px;
  padding:10px 12px;font-family:inherit;font-size:13px;color:var(--ink);outline:none;resize:vertical;
  min-height:62px;transition:.15s}
.crm-composer textarea:focus{border-color:var(--cyan);box-shadow:0 0 0 3px rgba(0,174,239,.13)}
.crm-composer-foot{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:9px}
.crm-composer-hint{font-size:11px;color:var(--gray-2)}
.crm-ctype{display:inline-flex;gap:4px;background:#fff;border:1px solid var(--line-2);border-radius:var(--r-pill);padding:3px}
.crm-ctype button{font-size:11px;font-weight:700;color:var(--gray);padding:4px 10px;border-radius:var(--r-pill);transition:.14s}
.crm-ctype button.on{background:var(--indigo);color:#fff}

.crm-clog{display:flex;flex-direction:column;margin-top:6px}
.crm-clog-item{display:flex;gap:11px;padding:13px 0;border-bottom:1px solid var(--line)}
.crm-clog-item:last-child{border-bottom:0}
.crm-clog-rail{display:flex;flex-direction:column;align-items:center;flex:none}
.crm-clog-av{width:30px;height:30px;border-radius:50%;display:grid;place-items:center;
  font-size:10.5px;font-weight:800;color:#fff;background:var(--indigo)}
.crm-clog-av.sys{background:var(--panel-3);color:var(--gray)}
.crm-clog-av.sys svg{width:15px;height:15px}
.crm-clog-body{flex:1;min-width:0}
.crm-clog-top{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;margin-bottom:3px}
.crm-clog-author{font-size:12.5px;font-weight:800;color:var(--ink)}
.crm-clog-when{font-size:10.5px;color:var(--gray-2)}
.crm-ctag{font-size:9.5px;font-weight:800;padding:2px 8px;border-radius:var(--r-pill);
  background:var(--cyan-soft);color:var(--cyan-deep)}
.crm-ctag.sys{background:var(--panel-3);color:var(--gray)}
.crm-clog-text{font-size:13px;color:var(--ink-soft);line-height:1.7}
.crm-clog-text.sys{color:var(--gray);font-size:12px}

/* ===================================================================
   حالت خالی
   =================================================================== */
.crm-empty{text-align:center;padding:50px 24px;color:var(--gray)}
.crm-empty .ei{width:66px;height:66px;border-radius:50%;background:var(--panel-3);display:grid;
  place-items:center;color:var(--gray-2);margin:0 auto 16px}
.crm-empty .ei svg{width:30px;height:30px}
.crm-empty b{display:block;color:var(--indigo-3);font-size:16px;margin-bottom:6px;font-weight:800}
.crm-empty p{font-size:13px;margin-bottom:16px}

/* مودال مشتری جدید — فیلدها */
.crm-modal{max-width:600px;width:96%;max-height:92vh;overflow-y:auto}
.crm-modal .input-row{grid-template-columns:1fr 1fr}

@media (max-width:880px){
  .crm-scroll{padding:20px 18px 36px}
  .crm-toolbar{padding:14px 18px}
  .crm-board{padding:16px 18px 24px}
  .crm-dash-grid{grid-template-columns:1fr}
  /* let the screen grow with the page instead of squeezing the board under a tall wrapped toolbar */
  #screen-crm.screen.active{height:auto;min-height:100vh;overflow:visible}
  /* keep the view-switcher reachable: allow the topbar to wrap and the segmented control to scroll */
  #screen-crm .topbar{flex-wrap:wrap}
  .crm-segmented{overflow-x:auto;max-width:100%}
  /* collapse the new-customer modal field pairs to one column (overrides .crm-modal .input-row) */
  .crm-modal .input-row{grid-template-columns:1fr}
}
