/* modal.css · 全局弹层/抽屉样式
   通用组件，所有页面可调用

   ╔══════════════════════════════════════════════════════════════════╗
   ║  ⚠  弹窗设计标准（业界 SaaS 风格，一屏展示，禁用内部滚动）     ║
   ║                                                                  ║
   ║  DO：                                                            ║
   ║    ✓ 弹窗默认宽 720px（modal-lg 880 / modal-xl 1040）            ║
   ║    ✓ 紧凑 padding：head 12 / body 14 / foot 10                   ║
   ║    ✓ 字段两列（modal-row）或三列（modal-row-3）grid              ║
   ║    ✓ 内容超长才用 modal-body 内部滚动，body height < 86vh        ║
   ║    ✓ min-height 保证基础内容能塞下（不要让 head+body+foot 不足） ║
   ║                                                                  ║
   ║  DON'T（v1.9.1–v1.9.3 踩过的 4 个雷，未来不要再犯）：            ║
   ║    ✗ 不要再用 vh / vw（feishu iframe 视口会被错误计算）          ║
   ║    ✗ 不要再用 `!important`（破坏层叠，反而压死 flex 容器）       ║
   ║    ✗ 不要再给 modal-box 加 `overflow: hidden`（会坍缩高度）      ║
   ║    ✗ 不要再用 `flex: 1 1 0`（= flex: 1，没 height 的容器里=0）   ║
   ║    ✗ 不要再依赖 CSS 变量（feishu 沙箱里 var() 偶尔不生效）       ║
   ║                                                                  ║
   ║  如果未来要改这块，先读 ~/.aily/workspace/MEMORY.md 的           ║
   ║  「弹窗设计教训」段，再改。                                       ║
   ╚══════════════════════════════════════════════════════════════════╝

   版本：
   v1.9.1 强化：高 z-index、深色硬背景、blur 遮罩
   v1.9.2 修正：去掉 overflow:hidden 和过度 !important
   v1.9.3 修正：feishu iframe 视口小导致 vh 触发高度坍缩，改用 min-height + 绝对像素
   v1.9.4 业界 SaaS 弹窗标准：默认宽度 720px + 紧凑 padding + 多列 grid，弹窗一屏展示
*/

/* ====== Modal Mask（全屏遮罩，flex 居中承载 modal-box）====== */
.modal-mask, .drawer-mask {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9999;
  animation: modalFadeIn 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ====== Modal（中央弹层）====== */
.modal-box {
  position: relative;
  width: 720px; max-width: 95vw;
  min-height: 380px;
  max-height: 86vh;
  background: #141a2b;
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-radius: 14px;
  box-shadow:
    0 25px 80px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(139, 92, 246, 0.12) inset,
    0 0 60px rgba(139, 92, 246, 0.15);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.25s ease;
  margin: auto;
}
@keyframes modalSlideIn { from { opacity: 0; transform: translate(-50%, -45%); } to { opacity: 1; transform: translate(-50%, -50%); } }
.modal-box.modal-lg { width: 880px; min-height: 460px; }
.modal-box.modal-xl { width: 1040px; min-height: 520px; }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid rgba(139, 92, 246, 0.2);
  background: #1a2138;
  border-radius: 14px 14px 0 0;
  flex: 0 0 auto;
}
.modal-title { font-size: 15px; font-weight: 600; color: #e8ecf5; display: inline-flex; align-items: center; gap: 8px; }
.modal-close {
  background: transparent; border: 0; cursor: pointer;
  color: #9aa3b8; padding: 4px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: #1f2940; color: #e8ecf5; }

.modal-body {
  padding: 14px 20px;
  overflow-y: auto;
  flex: 1 1 auto;
  background: #141a2b;
}
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 10px 20px; border-top: 1px solid rgba(139, 92, 246, 0.2);
  background: #1a2138;
  border-radius: 0 0 14px 14px;
  flex: 0 0 auto;
}

.modal-btn {
  padding: 8px 16px; border-radius: 8px; font-size: 13px;
  border: 1px solid var(--border-color); background: var(--bg-card);
  color: var(--text-secondary); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.modal-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.modal-btn.primary {
  background: var(--gradient-primary);
  border: 0; color: #fff;
}
.modal-btn.primary:hover { filter: brightness(1.1); }
.modal-btn.danger {
  background: rgba(248,113,113,0.15);
  border-color: rgba(248,113,113,0.3);
  color: #f87171;
}

.modal-field { margin-bottom: 10px; }
.modal-field-label {
  display: block; font-size: 12px; color: var(--text-tertiary);
  margin-bottom: 5px; font-weight: 500;
}
.modal-input, .modal-textarea, .modal-select {
  width: 100%; padding: 7px 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 13px; color: var(--text-primary);
  font-family: inherit;
}
.modal-textarea { min-height: 70px; resize: vertical; }
.modal-input:focus, .modal-textarea:focus, .modal-select:focus {
  outline: none; border-color: var(--primary);
}
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.modal-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.compare-market-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.compare-market-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  background: var(--bg-panel, rgba(255,255,255,0.04));
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.compare-market-card:hover {
  background: var(--bg-hover, rgba(255,255,255,0.08));
  transform: translateY(-1px);
}
.compare-market-card.active {
  border-color: var(--primary, #6366f1);
  background: rgba(99, 102, 241, 0.12);
}
.compare-market-emoji { font-size: 24px; line-height: 1; }
.compare-market-name { font-size: 14px; font-weight: 600; }
.compare-market-meta { font-size: 10px; color: var(--text-tertiary, #94a3b8); }
.modal-chip {
  padding: 5px 12px; font-size: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 999px; color: var(--text-secondary);
  cursor: pointer; user-select: none;
}
.modal-chip.active {
  background: rgba(34,211,238,0.15);
  border-color: var(--primary);
  color: var(--primary);
}

.modal-alert {
  padding: 10px 14px; border-radius: 8px;
  background: rgba(34,211,238,0.08);
  border-left: 3px solid var(--primary);
  font-size: 12px; color: var(--text-secondary);
  margin-bottom: 14px; display: flex; gap: 8px;
}
.modal-alert.warn { background: rgba(245,158,11,0.08); border-left-color: #f59e0b; }
.modal-alert.danger { background: rgba(248,113,113,0.08); border-left-color: #f87171; }

/* ====== Drawer（右侧抽屉）====== */
.drawer-box {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 520px; max-width: 95vw;
  min-height: 480px;
  background: #141a2b;
  border-left: 1px solid rgba(139, 92, 246, 0.4);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.55);
  z-index: 10000;
  display: flex; flex-direction: column;
  animation: drawerSlideIn 0.3s ease;
}
.drawer-box.drawer-lg { width: 720px; }
@keyframes drawerSlideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid rgba(139, 92, 246, 0.2);
  background: #1a2138;
  flex: 0 0 auto;
}
.drawer-title { font-size: 15px; font-weight: 600; color: #e8ecf5; }
.drawer-body {
  padding: 14px 20px; overflow-y: auto; flex: 1 1 auto;
  background: #141a2b;
}
.drawer-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 10px 20px; border-top: 1px solid rgba(139, 92, 246, 0.2);
  background: #1a2138;
  flex: 0 0 auto;
}

/* 列表项选择（在批量确认 / 选择资产等场景用）*/
.modal-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; padding-right: 4px; }
.modal-list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer; transition: all .15s;
}
.modal-list-item:hover { border-color: var(--primary); }
.modal-list-item.selected { border-color: var(--primary); background: rgba(34,211,238,0.06); }
.modal-list-check {
  width: 18px; height: 18px; border-radius: 4px;
  border: 1.5px solid var(--border-color);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.modal-list-item.selected .modal-list-check { background: var(--primary); border-color: var(--primary); color: #fff; }
.modal-list-info { flex: 1; }
.modal-list-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.modal-list-meta { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

/* ====== 扩展（v1.9 灵魂交互补强）====== */
.modal-section { margin-bottom: 16px; }
.modal-section-title {
  font-size: 12px; color: var(--text-tertiary);
  font-weight: 500; margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.modal-section-count {
  font-size: 11px; color: var(--text-tertiary);
  background: var(--bg-elevated);
  padding: 1px 6px; border-radius: 8px;
}
.modal-kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 14px;
}
.modal-kpi-label {
  font-size: 11px; color: var(--text-tertiary);
  margin-bottom: 4px;
}
.modal-kpi-value {
  font-size: 22px; font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  display: flex; align-items: baseline; gap: 4px;
}
.modal-kpi-unit { font-size: 12px; color: var(--text-tertiary); font-weight: 400; }
.modal-kpi-lg .modal-kpi-value { font-size: 28px; }
.modal-kpi-delta { font-size: 11px; margin-top: 4px; color: var(--text-tertiary); }
.modal-kpi-up { color: #34d399; }
.modal-kpi-down { color: #f87171; }

.modal-alert-info { background: rgba(34,211,238,0.08); border-left: 3px solid var(--primary); }
.modal-alert-warning { background: rgba(245,158,11,0.08); border-left: 3px solid #f59e0b; }

.modal-bar {
  height: 28px; background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 6px; position: relative; overflow: hidden;
  display: flex; align-items: center;
}
.modal-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 6px 0 0 6px;
  transition: width .3s ease;
}
.modal-bar-label {
  position: relative; z-index: 1;
  padding: 0 12px;
  font-size: 11px; color: var(--text-primary);
  font-weight: 500;
}

.modal-cover { background-size: cover; background-position: center; border-radius: 8px; }

.modal-list-body { flex: 1; }
.modal-list-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.modal-list-thumb {
  width: 56px; height: 40px;
  border-radius: 6px; flex-shrink: 0;
}
.modal-list-rank {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  flex-shrink: 0;
}

.modal-upload {
  padding: 24px;
  border: 1.5px dashed var(--border-color);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--text-tertiary);
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.modal-upload:hover {
  border-color: var(--primary);
  background: rgba(34,211,238,0.04);
  color: var(--primary);
}
.modal-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-tertiary);
}
.modal-search input {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--text-primary); font-size: 13px;
}
.modal-field-check { color: var(--primary); font-weight: 600; }

.tab-section-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.tab-section-title-row .tab-section-title { margin-bottom: 0; }
.tab-section-title {
  font-size: 12px; color: var(--text-tertiary);
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.tab-section-title .tab-count {
  font-size: 11px;
  background: var(--bg-elevated);
  border-radius: 8px; padding: 1px 6px;
  color: var(--text-tertiary);
}

.dealer-card-actions { display: inline-flex; gap: 12px; }

.quick-add-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}
.quick-add-card {
  display: flex; align-items: center; gap: 10px;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
}
.quick-add-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.quick-add-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(34,211,238,0.1); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.quick-add-body { flex: 1; }
.quick-add-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.quick-add-desc { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.quick-add-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.quick-add-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
