/* =========================
   Country Selector Modal
   ========================= */

/* 打开弹窗时，锁定页面滚动 */
body.cm-lock {
  overflow: hidden;
}

/* 蒙层背景 */
.cm-overlay {
  position: fixed;
  inset: 0;
  z-index: 80; /* 高于 header */
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 90px 16px 24px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

/* 显示状态 */
.cm-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* 弹窗主体 */
.cm-dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 150px);
  background: #f9fafb;
  border-radius: 24px;
  padding: 22px 24px 20px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  border: 1px solid rgba(148, 163, 184, 0.35);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 关闭按钮 */
.cm-close {
  position: absolute;
  right: 16px;
  top: 14px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: rgba(148, 163, 184, 0.12);
  color: #4b5563;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  transition: background 150ms ease, transform 150ms ease;
}

.cm-close:hover {
  background: rgba(148, 163, 184, 0.2);
  transform: translateY(-1px);
}

/* 标题区域 */
.cm-header h2 {
  margin: 0 48px 4px 0; /* 给关闭按钮留空间 */
  font-size: 18px;
  font-weight: 700;
  color: #111827;
}

.cm-header p {
  margin: 0;
  font-size: 13px;
  color: #6b7280;
}

/* 当前地区条 */
.cm-current {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.04);
  font-size: 12px;
  color: #4b5563;
}

.cm-current .cm-flag {
  font-size: 16px;
}

.cm-current .cm-label {
  font-weight: 600;
  color: #6b7280;
}

.cm-current .cm-sep {
  opacity: 0.6;
}

/* 搜索框 */
.cm-search {
  margin-top: 4px;
}

.cm-search input[type="search"] {
  width: 100%;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.cm-search input[type="search"]::placeholder {
  color: #9ca3af;
}

.cm-search input[type="search"]:focus {
  border-color: #16a34a;
  box-shadow:
    0 0 0 1px rgba(34, 197, 94, 0.18),
    0 10px 22px rgba(15, 23, 42, 0.08);
}

/* 内容区（可滚动） */
.cm-body {
  margin-top: 4px;
  padding-right: 2px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.7) transparent;
}

.cm-body::-webkit-scrollbar {
  width: 6px;
}

.cm-body::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.7);
  border-radius: 999px;
}

/* 小分组标题 */
.cm-section {
  margin-top: 6px;
}

.cm-section-title {
  font-size: 12px;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

/* 国家网格 */
.cm-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

/* 单个国家卡片 */
.cm-country {
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 16px;
  padding: 9px 10px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: #111827;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.03);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease,
    background-color 160ms ease;
}

.cm-country .cm-flag {
  font-size: 18px;
}

.cm-country .cm-name {
  font-size: 13px;
  font-weight: 600;
}

.cm-country .cm-sub {
  font-size: 11px;
  color: #6b7280;
}

.cm-country:hover {
  border-color: rgba(34, 197, 94, 0.7);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
  transform: translateY(-1px);
}

/* 选中状态 */
.cm-country.cm-country--active {
  border-color: transparent;
  background: radial-gradient(
    circle at top left,
    rgba(34, 197, 94, 0.14),
    rgba(34, 197, 94, 0.02)
  );
  box-shadow: 0 18px 40px rgba(16, 185, 129, 0.3);
}

/* “推荐” 小标签 */
.cm-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(34, 197, 94, 0.14);
  color: #059669;
  margin-left: 4px;
}

/* 小屏优化 */
@media (max-width: 600px) {
  .cm-overlay {
    align-items: flex-end;
    padding: 0 0 16px;
  }

  .cm-dialog {
    width: 100%;
    max-height: 80vh;
    border-radius: 24px 24px 0 0;
    padding: 16px 18px 18px;
  }

  .cm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
/* ✅ 兼容 is-open / is-active 两套写法 */
#country_modal.cm-overlay { opacity: 0; pointer-events: none; transition: opacity .2s ease-out; }
#country_modal.cm-overlay.is-open,
#country_modal.cm-overlay.is-active { opacity: 1; pointer-events: auto; }

/* ✅ 手机弹窗可滚动 */
@media (max-width: 768px){
  #country_modal .cm-dialog{
    width: min(520px, calc(100vw - 24px));
    max-height: calc(100vh - 80px);
    overflow: auto;
    border-radius: 18px;
  }
}
