
:root {
  --bg: #0a0a0f; --surface: #14141c; --surface-2: #1c1c28; --border: #2a2a3a;
  --text: #f0f0f5; --text-dim: #9090a8; --accent: #ff3b6b; --accent-2: #ff6b3b;
  --gold: #ffd700; --blue: #4a9eff; --green: #4ade80; --red: #ff4757;
  --elite: #ff4757; --high: #ff9f43; --good: #4ade80;
  --radius: 12px; --radius-sm: 8px;
  --topbar-bg: rgba(10,10,15,0.85);
  --card-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
/* Light mode */
body.light {
  --bg: #f5f5f8; --surface: #ffffff; --surface-2: #f0f0f5; --border: #d8d8e0;
  --text: #1a1a24; --text-dim: #6a6a7a; --accent: #e63960; --accent-2: #e55a30;
  --elite: #e63960; --high: #e8902a; --good: #22a865;
  --topbar-bg: rgba(245,245,248,0.9);
  --card-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Bai Jamjuree', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; transition: background 0.2s, color 0.2s; }

/* Top Bar */
.topbar { position: sticky; top: 0; z-index: 100; background: var(--topbar-bg); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; gap: 16px; }
.brand { font-size: 18px; font-weight: 700; }
.brand a { color: inherit; text-decoration: none; }
.search-box { flex: 1; max-width: 600px; position: relative; }
.search-box input { width: 100%; padding: 10px 36px 10px 40px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; color: var(--text); font-size: 14px; font-family: inherit; transition: border-color 0.2s; }
.search-box input:focus { outline: none; border-color: var(--accent); }
.search-box::before { content: '🔍'; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 16px; opacity: 0.6; }
.search-box .clear { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 16px; padding: 4px 8px; display: none; }
.search-box .clear:hover { color: var(--text); }
.search-box .clear.visible { display: block; }
.kbd-hint { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 10px; color: var(--text-dim); background: var(--surface-2); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border); }
.search-box:focus-within .kbd-hint { display: none; }
.user-area { display: flex; align-items: center; gap: 8px; }
.btn { padding: 8px 16px; border: none; border-radius: var(--radius-sm); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn:hover { background: var(--border); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; border: none; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(255,59,107,0.3); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; background: var(--surface-2); border-radius: 20px; font-size: 13px; }
.user-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.guest-api-key { display: flex; align-items: center; gap: 5px; padding: 4px 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.guest-api-key label { display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.guest-api-key input { width: 150px; min-width: 90px; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: inherit; font-size: 12px; }
.guest-api-key input:focus { outline: none; border-color: var(--accent); }
.guest-api-key .key-btn { padding: 6px 8px; font-size: 11px; white-space: nowrap; }
.guest-api-key-status { color: var(--text-dim); font-size: 10px; white-space: nowrap; }
.guest-api-key-status.saved { color: var(--good); }

/* Filter Bar */
.filterbar { position: sticky; top: 56px; z-index: 99; background: var(--topbar-bg); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border); padding: 10px 20px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.filterbar::-webkit-scrollbar { display: none; }
.chip { padding: 6px 14px; border-radius: 16px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); cursor: pointer; white-space: nowrap; transition: all 0.2s; }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.chip:hover:not(.active) { background: var(--border); color: var(--text); }
.chip.indicator-elite { border-color: var(--elite); color: var(--elite); }
.chip.indicator-high { border-color: var(--high); color: var(--high); }
.chip.indicator-good { border-color: var(--good); color: var(--good); }
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.filter-toggle { padding: 6px 14px; border-radius: 16px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px dashed var(--border); color: var(--text-dim); cursor: pointer; white-space: nowrap; }
.filter-toggle:hover { background: var(--border); color: var(--text); }
.filter-toggle.active { background: var(--blue); color: white; border-color: var(--blue); border-style: solid; }

/* Advanced filter panel (slides down) */
.adv-panel { position: sticky; top: 110px; z-index: 98; background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 20px; display: none; }
.adv-panel.open { display: block; }
.adv-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.adv-group { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.adv-group label { min-width: 70px; }
.adv-group input[type="number"] { width: 100px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: inherit; font-size: 12px; }
.adv-group input:focus { outline: none; border-color: var(--accent); }
.adv-range { display: flex; align-items: center; gap: 4px; }
.range-track { position: relative; width: 240px; height: 6px; background: var(--bg); border-radius: 3px; margin: 0 8px; }
.range-fill { position: absolute; top: 0; left: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 3px; pointer-events: none; }
.range-input { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.range-input::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 16px; height: 16px; background: white; border-radius: 50%; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.3); }
.range-input::-moz-range-thumb { pointer-events: auto; width: 16px; height: 16px; background: white; border-radius: 50%; cursor: pointer; border: none; box-shadow: 0 2px 4px rgba(0,0,0,0.3); }
.adv-actions { margin-left: auto; display: flex; gap: 8px; }
.adv-btn { padding: 6px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; cursor: pointer; }
.adv-btn:hover { background: var(--border); }
.adv-btn.primary { background: var(--accent); color: white; border-color: var(--accent); }

/* Saved filters dropdown */
.saved-filters { position: relative; }
.saved-list { position: absolute; top: 100%; right: 0; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-width: 220px; max-height: 300px; overflow-y: auto; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.4); display: none; }
.saved-list.open { display: block; }
.saved-item { padding: 10px 14px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.saved-item:hover { background: var(--surface-2); }
.saved-item:last-child { border-bottom: none; }
.saved-item .name { flex: 1; }
.saved-item .del { color: var(--red); opacity: 0.5; padding: 2px 6px; }
.saved-item .del:hover { opacity: 1; }

/* Layout */
.main { display: flex; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); padding: 20px 0; position: sticky; top: 100px; height: calc(100vh - 100px); overflow-y: auto; }
.sidebar h3 { font-size: 11px; text-transform: uppercase; color: var(--text-dim); padding: 0 20px; margin: 16px 0 8px; letter-spacing: 0.05em; }
.cat-list { list-style: none; }
.cat-item { padding: 8px 20px; font-size: 13px; cursor: pointer; color: var(--text-dim); transition: all 0.15s; display: flex; justify-content: space-between; align-items: center; border-left: 2px solid transparent; }
.cat-item:hover { background: var(--surface-2); color: var(--text); }
.cat-item.active { background: var(--surface-2); color: var(--accent); border-left-color: var(--accent); }
.cat-count { font-size: 11px; opacity: 0.6; }

.content { flex: 1; padding: 20px; min-width: 0; }
.results-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; font-size: 13px; color: var(--text-dim); flex-wrap: wrap; gap: 8px; }
.results-count { font-weight: 600; color: var(--text); }
.perf-badge { font-size: 11px; padding: 2px 8px; background: var(--surface-2); border-radius: 4px; }
.toolbar { display: flex; gap: 6px; align-items: center; }
.toolbar-btn { padding: 4px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); font-size: 12px; cursor: pointer; }
.toolbar-btn:hover { color: var(--text); background: var(--border); }
.toolbar-btn.active { color: var(--accent); border-color: var(--accent); }
.selected-count { padding: 4px 10px; background: var(--accent); color: white; border-radius: 6px; font-size: 12px; font-weight: 600; display: none; }
.selected-count.visible { display: inline-block; }

/* Product Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: all 0.2s; display: flex; flex-direction: column; position: relative; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card-checkbox { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; background: rgba(0,0,0,0.5); border: 2px solid white; border-radius: 4px; z-index: 5; display: none; cursor: pointer; }
.card.selecting .card-checkbox { display: block; }
.card-checkbox.checked { background: var(--accent); border-color: var(--accent); display: flex; align-items: center; justify-content: center; color: white; }
.card-img { aspect-ratio: 1; background: var(--surface-2); position: relative; overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.3s; }
.card-img img.loaded { opacity: 1; }
.card-img .img-skeleton { position: absolute; inset: 0; background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
.card-img img.loaded + .img-skeleton { display: none; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.ai-badge { position: absolute; top: 6px; right: 6px; padding: 3px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.ai-badge.elite { background: var(--elite); }
.ai-badge.high { background: var(--high); }
.ai-badge.good { background: var(--good); }
.flag-stack { position: absolute; top: 6px; left: 6px; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; z-index: 4; }
.flag-badge { padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.3); backdrop-filter: blur(4px); }
.flag-badge.vdo { background: rgba(74,158,255,0.85); }
.flag-badge.comm { background: rgba(255,215,0,0.9); color: #000; text-shadow: none; }
.flag-badge.disc { background: rgba(255,71,87,0.9); }
.flag-badge.ship { background: rgba(74,222,128,0.85); color: #000; text-shadow: none; }
.card-body { padding: 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.card-name { font-size: 13px; font-weight: 500; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 34px; }
.card-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.card-price { color: var(--accent); font-size: 14px; font-weight: 600; }
.card-rev { font-size: 11px; color: var(--text-dim); }
.card-actions { display: flex; gap: 4px; margin-top: 6px; }
.card-freestyle-row { margin-top: 8px; }
.btn-freestyle-action {
  width: 100%;
  padding: 8px 12px;
  background: linear-gradient(135deg, #ff3366 0%, #ff6b3d 100%);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(255, 51, 102, 0.25);
  transition: all 0.15s ease;
}
.btn-freestyle-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(255, 51, 102, 0.4);
  opacity: 0.95;
}
.btn-freestyle-action:active { transform: translateY(0); }
.btn-freestyle-action.queued-done {
  background: #10b981 !important;
  color: #fff !important;
  box-shadow: none !important;
}
.icon-btn { flex: 1; padding: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); font-size: 12px; cursor: pointer; transition: all 0.15s; font-family: inherit; }
.icon-btn:hover { color: var(--text); background: var(--border); }
.icon-btn.faved { color: var(--accent); border-color: var(--accent); }
.icon-btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.icon-btn.primary:hover { background: var(--accent-2); }
.icon-btn.compare-active { background: var(--blue); color: white; border-color: var(--blue); }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 24px; align-items: center; }
.page-btn { min-width: 36px; height: 36px; padding: 0 10px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 13px; }
.page-btn:hover { background: var(--border); }
.page-btn.active { background: var(--accent); border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { padding: 0 12px; color: var(--text-dim); font-size: 12px; }

/* Auth Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(8px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 90%; max-width: 400px; }
.modal h2 { margin-bottom: 8px; font-size: 22px; }
.modal .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.form-group input, .form-group textarea { width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: inherit; font-size: 14px; }
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); }
.form-actions { display: flex; gap: 8px; margin-top: 20px; }
.form-actions .btn { flex: 1; padding: 10px; }
.form-error { color: var(--red); font-size: 12px; margin-top: 8px; }
.form-switch { text-align: center; margin-top: 12px; font-size: 12px; color: var(--text-dim); }
.form-switch a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Detail Modal */
.detail-overlay { z-index: 999; }
.detail-modal { max-width: 720px; width: 95%; }
.detail-grid { display: grid; grid-template-columns: 280px 1fr; gap: 20px; }
.detail-img { aspect-ratio: 1; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.detail-img img { width: 100%; height: 100%; object-fit: cover; }
.detail-info h2 { font-size: 18px; margin-bottom: 8px; }
.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.meta-item { background: var(--surface-2); padding: 8px 12px; border-radius: var(--radius-sm); }
.meta-item .label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; }
.meta-item .value { font-size: 14px; font-weight: 600; margin-top: 2px; }
.detail-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.detail-actions .btn { flex: 1; padding: 12px; min-width: 120px; }

/* Compare Bar (floating at bottom) */
.compare-bar { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--blue); border-radius: 12px; padding: 12px 20px; display: none; align-items: center; gap: 12px; z-index: 998; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.compare-bar.visible { display: flex; }
.compare-bar .count { font-size: 13px; color: var(--text); }
.compare-bar .count strong { color: var(--blue); font-size: 16px; }
.compare-bar .actions { display: flex; gap: 6px; }
.compare-bar .btn { padding: 6px 12px; font-size: 12px; }

/* Empty / Loading */
.empty { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 2000; background: var(--surface-2); border: 1px solid var(--border); padding: 12px 20px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); animation: slideUp 0.3s ease; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }

/* Help modal */
.kbd-table { font-size: 13px; }
.kbd-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.kbd-row:last-child { border-bottom: none; }
.kbd-key { background: var(--bg); border: 1px solid var(--border); padding: 2px 8px; border-radius: 4px; font-family: monospace; font-size: 11px; color: var(--text-dim); }
.kbd-row .desc { color: var(--text-dim); }

/* Mobile */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .brand { font-size: 15px; }
  .search-box input { padding: 8px 32px 8px 36px; font-size: 13px; }
  .user-area { width: 100%; order: 3; overflow-x: auto; }
  .guest-api-key { flex: 1; }
  .guest-api-key input { flex: 1; width: auto; }
  .filterbar { position: relative; top: auto; }
  .content { padding: 12px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .detail-grid { grid-template-columns: 1fr; }
  .user-area .btn-text { display: none; }
  .adv-row { flex-direction: column; align-items: stretch; }
  .adv-actions { margin-left: 0; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card-name { font-size: 12px; min-height: 32px; }
  .card-price { font-size: 13px; }
}
