/* ═══════════════════════════════════════════════════════════════
 * SWAG · 統一搜尋元件
 * ───────────────────────────────────────────────────────────────
 * 三頁（指令百科 / 排行 / 主播社群）的搜尋框統一視覺：
 *   - 左側放大鏡 icon
 *   - 右側 ✕ clear 按鈕（有字才出現）
 *   - 統一 placeholder 字級、focus 邊框、shadow
 *
 * 用法：
 *   <div class="swag-search">
 *     <input type="search" class="swag-search-input" placeholder="搜尋指令…">
 *   </div>
 * 也可以用 SwagSearch.upgrade('#你的-input') 自動包裝。
 * ═══════════════════════════════════════════════════════════════ */

.swag-search {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.swag-search-input {
  flex: 1;
  width: 100%;
  height: 44px;
  padding: 0 38px 0 40px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.005em;
  color: var(--text, #1a1916);
  background: #fff;
  border: 1px solid var(--line2, #d4d0c8);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  -webkit-appearance: none;
  appearance: none;
}
.swag-search-input::-webkit-search-decoration,
.swag-search-input::-webkit-search-cancel-button,
.swag-search-input::-webkit-search-results-button,
.swag-search-input::-webkit-search-results-decoration {
  -webkit-appearance: none;
  display: none;
}
.swag-search-input::placeholder {
  color: var(--muted, #9a9690);
  font-weight: 500;
}
.swag-search-input:hover {
  border-color: var(--mid, #5a5750);
}
.swag-search-input:focus {
  border-color: var(--swag, #2BC5B4);
  box-shadow: 0 0 0 3px rgba(43, 197, 180, 0.15);
  background: #fff;
}

/* 左側放大鏡 icon（純 SVG inline，不依賴外部資源） */
.swag-search::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9690' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  pointer-events: none;
  transition: opacity .15s ease;
}
.swag-search:focus-within::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232BC5B4' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}

/* 右側 ✕ clear 按鈕 */
.swag-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted, #9a9690);
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.swag-search-clear::before {
  content: "";
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}
.swag-search.has-value .swag-search-clear {
  display: inline-flex;
}
.swag-search-clear:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text, #1a1916);
}
.swag-search-clear:active {
  transform: translateY(-50%) scale(0.92);
}

/* ── Hint row（搜尋下方的提示／結果數） ─────────────────── */
.swag-search-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted, #9a9690);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 16px;
}
.swag-search-hint .count {
  font-weight: 600;
  color: var(--text, #1a1916);
  font-variant-numeric: tabular-nums;
}

/* ── Disabled / Empty 狀態 ────────────────────────────────── */
.swag-search-input:disabled {
  background: rgba(0, 0, 0, 0.03);
  color: var(--muted, #9a9690);
  cursor: not-allowed;
}

/* ── 尺寸變體 ───────────────────────────────────────────── */
.swag-search--sm .swag-search-input { height: 36px; font-size: 14px; padding: 0 32px 0 34px; }
.swag-search--sm::before { left: 11px; width: 14px; height: 14px; }
.swag-search--sm .swag-search-clear { width: 24px; height: 24px; right: 6px; }

.swag-search--lg .swag-search-input { height: 52px; font-size: 16px; padding: 0 44px 0 46px; border-radius: 14px; }
.swag-search--lg::before { left: 16px; width: 18px; height: 18px; }

/* ── 手機微調 ─────────────────────────────────────────── */
@media (max-width: 480px) {
  .swag-search-input {
    height: 42px;
    font-size: 14.5px;
    border-radius: 11px;
  }
}

/* ── 暗色模式 ─────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  .swag-search-input {
    background: var(--surface, #1d1c1a);
    color: var(--text, #f1ede5);
    border-color: var(--line, #2f2d2a);
  }
  .swag-search-input:hover {
    border-color: var(--mid, #b8b1a3);
  }
  .swag-search-input:focus {
    border-color: var(--swag, #2BC5B4);
    box-shadow: 0 0 0 3px rgba(43, 197, 180, 0.20);
  }
  .swag-search-clear:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #f1ede5);
  }
}
