/* /public/css/multi-city.css
   =========================================================
   Multi-city selector (scoped to #mc-root)
   - Compatibility: High
   - Performance: Smooth animations + reduced-motion support
   - Font: Inherits from parent (NO font-family override)
   ========================================================= */

#mc-root {
  --mc-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mc-safe-top: env(safe-area-inset-top, 0px);
  --mc-z-index: 9999;

  --mc-bg: #ffffff;
  --mc-surface: #f8fafc;
  --mc-border: #e2e8f0;
  --mc-text-main: #0f172a;
  --mc-text-muted: #64748b;

  --mc-primary: #1e293b;
  --mc-primary-hover: #0f172a;
  --mc-accent: #3b82f6;
  --mc-danger: #ef4444;

  --mc-chip-bg: #eff6ff;
  --mc-chip-text: #1d4ed8;
  --mc-chip-border: #bfdbfe;

  --mc-radius-lg: 16px;
  --mc-radius-md: 12px;
  --mc-input-height: 48px;
  --mc-btn-height: 48px;

  font-family: inherit;
  font-size: inherit;
  color: var(--mc-text-main);
  line-height: 1.5;
  box-sizing: border-box;
}

#mc-root * { box-sizing: border-box; }
#mc-root ul, #mc-root li { list-style: none; margin: 0; padding: 0; }
#mc-root button, #mc-root input { font-family: inherit; font-size: inherit; }
#mc-root [hidden] { display: none !important; }

#mc-root[dir="rtl"], [dir="rtl"] #mc-root { direction: rtl; text-align: right; }

#mc-root :focus-visible{
  outline: 3px solid rgba(59,130,246,.35);
  outline-offset: 2px;
}

/* Modal */
#mc-root.is-open {
  position: fixed;
  inset: 0;
  z-index: var(--mc-z-index);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: mcFadeIn 0.2s ease-out;
}
#mc-root.is-open::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 0;
}
@supports ((-webkit-backdrop-filter: blur(4px)) or (backdrop-filter: blur(4px))) {
  #mc-root.is-open::before { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
}

/* Container */
#mc-root .mc-container {
  position: relative;
  z-index: 1;
  background: var(--mc-bg);
  width: 100%;
  max-width: 520px;

  display: flex;
  flex-direction: column;

  height: 85vh;
  max-height: 800px;

  border-radius: var(--mc-radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
  overflow: hidden;
}
#mc-root:not(.is-open) .mc-container {
  height: auto;
  max-height: none;
  border: 1px solid var(--mc-border);
  box-shadow: none;
  margin: 0 auto;
}
@media (max-width: 640px) {
  #mc-root.is-open { padding: 0; align-items: flex-end; }
  #mc-root.is-open .mc-container {
    max-width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    animation: mcSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

/* Header */
#mc-root .mc-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--mc-bg);
  border-bottom: 1px solid var(--mc-border);
}
#mc-root .mc-title {
  flex-grow: 1;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  color: var(--mc-text-main);
}
#mc-root .mc-back,
#mc-root .mc-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--mc-text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.12s;
}
#mc-root .mc-back:hover,
#mc-root .mc-close:hover {
  background: var(--mc-surface);
  color: var(--mc-text-main);
  border-color: var(--mc-border);
}
#mc-root .mc-back:active,
#mc-root .mc-close:active { transform: scale(0.98); }

/* Search */
#mc-root .mc-field {
  flex-shrink: 0;
  padding: 12px 16px 8px;
}
#mc-root #mc-q {
  width: 100%;
  height: var(--mc-input-height);
  padding: 0 16px;
  border-radius: var(--mc-radius-md);
  border: 1px solid var(--mc-border);
  background: var(--mc-surface);
  font-size: 0.95rem;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
#mc-root #mc-q:focus {
  background: #fff;
  border-color: var(--mc-accent);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.15);
}
#mc-root #mc-q::placeholder { color: #94a3b8; }

/* Clear all */
#mc-root #mc-clear-top {
  display: block;
  margin: 0 16px 8px auto;
  background: none;
  border: none;
  color: var(--mc-danger);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.2s;
}
#mc-root #mc-clear-top:hover { background: rgba(239,68,68,0.06); }

/* Chips */
#mc-root #mc-chips {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#mc-root #mc-chips::-webkit-scrollbar { display: none; }
#mc-root .mc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px 0 12px;
  background: var(--mc-chip-bg);
  border: 1px solid var(--mc-chip-border);
  color: var(--mc-chip-text);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  animation: mcScaleIn 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#mc-root .mc-chip__x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 1.1em;
  opacity: 0.65;
  transition: opacity 0.15s, background 0.15s;
}
#mc-root .mc-chip:hover .mc-chip__x { opacity: 1; background: rgba(0,0,0,0.05); }

/* ✅ Critical: scrollable structure */
#mc-root form {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
  overflow: hidden;
}

/* wrappers MUST be flex column for proper scrolling */
#mc-root #mc-search,
#mc-root #mc-provinces,
#mc-root #mc-cities {
  flex-grow: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* the UL must be the scrolling area */
#mc-root .mc-list,
#mc-root .cities {
  flex-grow: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 20px;
  overscroll-behavior: contain;
}

/* scrollbars */
#mc-root .mc-list::-webkit-scrollbar,
#mc-root .cities::-webkit-scrollbar { width: 5px; }
#mc-root .mc-list::-webkit-scrollbar-thumb,
#mc-root .cities::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

/* Items */
#mc-root .mc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--mc-border);
}
#mc-root .mc-item:last-child { border-bottom: none; }
#mc-root .mc-item:hover { background: linear-gradient(90deg, transparent, var(--mc-surface), transparent); }

#mc-root .mc-item__main {
  flex-grow: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  cursor: pointer;
  background: transparent;
  border: 0;
  text-align: inherit;
  padding: 8px 4px;
}
#mc-root .mc-item__cb {
  width: 20px;
  height: 20px;
  accent-color: var(--mc-accent);
  cursor: pointer;
  flex-shrink: 0;
}
#mc-root .mc-item__name {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#mc-root .mc-item__meta {
  font-size: 0.78rem;
  color: var(--mc-text-muted);
  margin-right: 4px;
  white-space: nowrap;
}
#mc-root .mc-item__open {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--mc-text-muted);
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s, color 0.15s, transform 0.12s;
}
#mc-root .mc-item__open:hover { background: var(--mc-surface); color: var(--mc-accent); }
#mc-root .mc-item__open:active { transform: scale(0.98); }

/* modal provinces: hide province checkbox safety */
#mc-root.is-open .mc-item[data-kind="province"] .mc-item__cb { display: none !important; }

/* select-all rows */
#mc-root .mc-item--all { background: rgba(59,130,246,0.04); }
#mc-root .mc-item--all:hover { background: rgba(59,130,246,0.07); }

/* search headers */
#mc-root .mc-section {
  padding: 8px 0 6px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--mc-text-muted);
}
#mc-root .mc-empty {
  padding: 16px 0;
  color: var(--mc-text-muted);
  font-weight: 700;
}

/* City animation (only on initial render) */
#mc-root .mc-city-anim{
  opacity: 0;
  transform: translateX(-14px);
  animation: mcCityIn 360ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(var(--mc-i, 0) * 28ms);
  will-change: transform, opacity;
}
@keyframes mcCityIn { to { opacity: 1; transform: translateX(0); } }

/* Footer actions */
#mc-root .mc-actions {
  flex-shrink: 0;
  padding: 16px 16px calc(16px + var(--mc-safe-bottom));
  border-top: 1px solid var(--mc-border);
  background: var(--mc-bg);
  display: flex;
  gap: 12px;
  z-index: 10;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.03);
}
#mc-root .btn {
  flex: 1;
  height: var(--mc-btn-height);
  border-radius: var(--mc-radius-md);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, opacity 0.2s, background 0.2s;
}
#mc-root .btn:active { transform: scale(0.98); }
#mc-root .btn.primary {
  background: var(--mc-primary);
  color: #fff;
  border: none;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
#mc-root .btn.primary:hover { background: var(--mc-primary-hover); }
#mc-root .btn.primary:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}
#mc-root .btn.ghost {
  background: transparent;
  color: var(--mc-text-muted);
  border: 1px solid var(--mc-border);
}
#mc-root .btn.ghost:hover { background: var(--mc-surface); color: var(--mc-text-main); }

/* Animations */
@keyframes mcFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes mcSlideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes mcScaleIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce){
  #mc-root *{ animation: none !important; transition: none !important; }
  #mc-root .mc-city-anim{ opacity: 1; transform: none; }
}



/* Status line (fixed height => no layout jump) */
#mc-root .mc-status{
  flex-shrink: 0;
  height: 34px;               /* ✅ ثابت */
  padding: 0 16px;
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--mc-text-muted);
  border-radius: 10px;
  margin: 0 0 8px 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* when empty selection -> warning style (still same height) */
#mc-root .mc-status.is-warn{
  color: var(--mc-danger);
}

/* subtle appear without height change */
#mc-root .mc-status.is-fade{
  opacity: 0.9;
}




/* ✅ Single-row fixed bar: either chips OR placeholder (no height jump) */
#mc-root #mc-chips.mc-chips{
  flex-shrink: 0;
  height: 44px;                 /* ✅ ارتفاع ثابت یک ردیف */
  padding: 6px 16px;
  margin: 0 0 8px 0;

  display: flex;
  align-items: center;
  gap: 8px;

  overflow-x: auto;              /* چیپ‌ها افقی */
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;

  border-radius: 12px;
  background: #f9fafb;
  
scrollbar-width: thin;

}
#mc-root #mc-chips::-webkit-scrollbar{ display:none; }

/* وقتی خالیه و پیام نمایش می‌ده */
#mc-root #mc-chips.is-empty{
  overflow-x: hidden;            /* پیام نباید اسکرول افقی ایجاد کند */
  color: var(--mc-danger);
  font-weight: 800;
}

/* متن placeholder داخل همان ردیف */
#mc-root .mc-chips__placeholder{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* چیپ‌ها داخل این ردیف کاملاً فیت بمانند */
#mc-root .mc-chip{
  height: 32px;
  flex: 0 0 auto;
}
