/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-bottom: 1px solid #1e293b;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 32px;
}

.logo-title {
  font-size: 20px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.3px;
}

.logo-subtitle {
  font-size: 12px;
  color: #64748b;
}

.ai-recommend-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(124,58,237,0.4);
}

.ai-recommend-btn:hover {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(124,58,237,0.5);
}

/* ── Filter Section ── */
.filter-section {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 16px 24px;
}

.filter-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  font-size: 16px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 40px 10px 40px;
  font-size: 14px;
  color: #e2e8f0;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: #6366f1; }
.search-input::placeholder { color: #475569; }

.search-clear {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}

.search-clear:hover { color: #e2e8f0; }

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  min-width: 52px;
  font-weight: 500;
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tag:hover { border-color: #6366f1; color: #a5b4fc; }
.tag.active { background: #6366f1; border-color: #6366f1; color: #fff; font-weight: 600; }

/* ── Search Hint ── */
.search-hint {
  max-width: 1400px;
  margin: 8px auto;
  padding: 6px 24px;
  font-size: 12px;
  color: #a78bfa;
}

/* ── Cards Grid ── */
.cards-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* ── Card ── */
.card {
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

.card.filtered-out { display: none; }

.card-header {
  padding: 20px;
  position: relative;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-bank {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.card-name {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin: 4px 0;
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-max-cashback {
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(4px);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.card-period {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
}

.card-highlight {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  margin-top: 4px;
}

/* Card chip decoration */
.card-chip {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 36px;
  height: 28px;
  background: linear-gradient(135deg, rgba(255,255,255,0.3), rgba(255,255,255,0.1));
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.2);
}

/* ── Card Body ── */
.card-body {
  background: #1e293b;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Benefits list */
.benefits-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.benefit-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(16, 185, 129, 0.06);
  border-left: 3px solid #10b981;
  border-radius: 0 6px 6px 0;
  transition: background 0.15s;
}

.benefit-item.hidden-by-search {
  display: none;
}

.benefit-item.highlighted-by-search {
  background: rgba(99, 102, 241, 0.12);
  border-left-color: #6366f1;
}

.benefit-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }

.benefit-text { flex: 1; }
.benefit-title { font-size: 13px; font-weight: 600; color: #e2e8f0; }
.benefit-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.benefit-tag {
  font-size: 10px;
  color: #6366f1;
  background: rgba(99,102,241,0.1);
  border-radius: 10px;
  padding: 1px 7px;
  border: 1px solid rgba(99,102,241,0.2);
}

/* Warnings */
.warnings-list-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.warning-item-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(251, 146, 60, 0.06);
  border-left: 3px solid #f97316;
  border-radius: 0 6px 6px 0;
}

.warning-item-card.hidden-by-search { display: none; }

.warning-icon-card { font-size: 13px; flex-shrink: 0; }
.warning-text-card { font-size: 12px; color: #fcd34d; font-weight: 500; }

/* Card footer */
.card-footer {
  padding: 12px 16px;
  background: #1e293b;
  border-top: 1px solid #334155;
  display: flex;
  gap: 8px;
}

.view-detail-btn {
  flex: 1;
  background: #334155;
  border: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  cursor: pointer;
  transition: background 0.15s;
}

.view-detail-btn:hover { background: #475569; }

.annual-fee-badge {
  background: rgba(16,185,129,0.15);
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 11px;
  color: #34d399;
  white-space: nowrap;
  display: flex;
  align-items: center;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  backdrop-filter: blur(4px);
}

.modal {
  background: #1e293b;
  border-radius: 16px;
  width: 100%;
  max-width: 760px;
  margin: auto;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
  animation: modalIn 0.25s ease;
}

.modal-ai { max-width: 640px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  color: #fff;
}

.ai-modal-header {
  background: linear-gradient(135deg, #4c1d95, #5b21b6);
}

.modal-title-area h2 { font-size: 20px; font-weight: 700; }
.modal-title-area p { font-size: 13px; color: rgba(255,255,255,0.7); margin-top: 3px; }

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.official-link {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  transition: background 0.15s;
  white-space: nowrap;
}

.official-link:hover { background: rgba(255,255,255,0.25); }

.modal-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.modal-close:hover { background: rgba(255,255,255,0.3); }

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #334155;
}

.warnings-title { color: #fb923c; }
.ai-title { color: #a78bfa; }

/* Switching benefits grid */
.switching-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.switching-card {
  background: #0f172a;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #334155;
}

.switching-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.switching-name {
  font-size: 14px;
  font-weight: 700;
  color: #e2e8f0;
}

.switching-rate {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.switching-payment {
  font-size: 11px;
  color: #64748b;
  margin-bottom: 8px;
}

.switching-channels {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.switching-channels li {
  font-size: 11px;
  color: #94a3b8;
  padding-left: 10px;
  position: relative;
}

.switching-channels li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: #4b5563;
}

.switching-warnings {
  margin-top: 8px;
  border-top: 1px solid #1e293b;
  padding-top: 6px;
}

.switching-warning-item {
  font-size: 10px;
  color: #fbbf24;
  padding-left: 12px;
  position: relative;
}

.switching-warning-item::before {
  content: '⚠';
  position: absolute;
  left: 0;
  font-size: 9px;
}

/* Full benefits content */
.full-benefits-content {
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.8;
  white-space: pre-line;
  max-height: 300px;
  overflow-y: auto;
}

.full-benefits-content::-webkit-scrollbar { width: 4px; }
.full-benefits-content::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

/* Warnings list in modal */
.warnings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.warning-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(251,146,60,0.08);
  border: 1px solid rgba(251,146,60,0.2);
  border-radius: 8px;
}

.warning-icon { font-size: 16px; flex-shrink: 0; }
.warning-content {}
.warning-title { font-size: 13px; font-weight: 600; color: #fcd34d; }
.warning-detail { font-size: 12px; color: #94a3b8; margin-top: 3px; line-height: 1.6; }

.ai-loading {
  text-align: center;
  padding: 20px;
  color: #7c3aed;
}

.ai-loading-dots::after {
  content: '...';
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* AI Recommendation Modal */
.ai-input-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-input-label {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
}

.ai-textarea {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  color: #e2e8f0;
  resize: vertical;
  min-height: 100px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.ai-textarea:focus { border-color: #7c3aed; }
.ai-textarea::placeholder { color: #475569; }

.ai-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.ai-example-label { font-size: 12px; color: #64748b; }

.ai-example-btn {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.15s;
}

.ai-example-btn:hover { border-color: #7c3aed; color: #c4b5fd; }

.ai-run-btn {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(124,58,237,0.3);
}

.ai-run-btn:hover { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.ai-run-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.ai-recommendation-result {
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  font-size: 13px;
  color: #c4b5fd;
  line-height: 1.8;
  white-space: pre-line;
}

/* API Key Section */
.api-key-section {
  border-top: 1px solid #334155;
  padding-top: 12px;
}

.api-key-summary {
  font-size: 12px;
  color: #64748b;
  cursor: pointer;
  list-style: none;
}

.api-key-summary::-webkit-details-marker { display: none; }
.api-key-content { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.api-key-desc { font-size: 12px; color: #64748b; }
.api-key-desc a { color: #7c3aed; }

.api-key-input-row { display: flex; gap: 8px; }

.api-key-input {
  flex: 1;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #e2e8f0;
  outline: none;
}

.api-key-save-btn {
  background: #334155;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  color: #e2e8f0;
  cursor: pointer;
  transition: background 0.15s;
}

.api-key-save-btn:hover { background: #475569; }
.api-key-note { font-size: 11px; color: #10b981; }

/* No results */
.no-results {
  text-align: center;
  padding: 60px 20px;
  color: #475569;
}

.no-results-icon { font-size: 48px; margin-bottom: 12px; }
.no-results p { font-size: 16px; margin-bottom: 16px; }

.reset-btn {
  background: #334155;
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.reset-btn:hover { background: #475569; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .ai-recommend-btn { width: 100%; justify-content: center; }
  .cards-grid { grid-template-columns: 1fr; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 90vh; }
  .switching-grid { grid-template-columns: 1fr; }
}
