/* ---------- Reset / base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun",
               system-ui, sans-serif;
  background: #0d1117;
  color: #e6edf3;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 100px;
}

/* ---------- Header ---------- */
header {
  background: linear-gradient(135deg, #1a1f2e 0%, #0d1117 100%);
  padding: 16px;
  border-bottom: 1px solid #30363d;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #8b949e;
}
#refreshBtn {
  background: #21262d;
  border: 1px solid #30363d;
  color: #e6edf3;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}
#refreshBtn:hover { background: #30363d; }
#refreshBtn.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Filters ---------- */
.filters {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #0d1117;
  position: sticky;
  top: 70px;
  z-index: 9;
  border-bottom: 1px solid #21262d;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-btn {
  background: #161b22;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.filter-btn:hover { color: #e6edf3; border-color: #58a6ff; }
.filter-btn.active {
  background: #1f6feb;
  color: #fff;
  border-color: #1f6feb;
}

/* ---------- Cards ---------- */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px;
}
.loading, .empty {
  text-align: center;
  padding: 60px 20px;
  color: #8b949e;
}
.card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.card.call { border-left: 4px solid #3fb950; }
.card.put  { border-left: 4px solid #f85149; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 12px;
}
.symbol-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rank {
  background: #21262d;
  color: #8b949e;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}
.symbol {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.action {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
.action.call { background: rgba(63,185,80,0.15); color: #3fb950; }
.action.put  { background: rgba(248,81,73,0.15); color: #f85149; }

.score-pill {
  background: #21262d;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 0.75rem;
  color: #8b949e;
}

/* ---------- Strike row ---------- */
.strike-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: #0d1117;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.strike-row .field {
  display: flex;
  flex-direction: column;
}
.strike-row .label {
  font-size: 0.7rem;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.strike-row .value {
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  background: #0d1117;
  padding: 8px;
  border-radius: 6px;
  text-align: center;
}
.stat .v {
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat .l {
  font-size: 0.65rem;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.stat .v.good { color: #3fb950; }
.stat .v.warn { color: #d29922; }
.stat .v.bad  { color: #f85149; }

/* ---------- Details ---------- */
.detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #8b949e;
  margin: 4px 0;
}
.detail-row b { color: #e6edf3; font-weight: 500; }

.patterns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.pattern-tag {
  background: #21262d;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  color: #8b949e;
}

/* ---------- Webull copy ---------- */
.webull-box {
  background: #0d1117;
  border: 1px dashed #30363d;
  border-radius: 6px;
  padding: 10px;
  margin-top: 12px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.78rem;
  white-space: pre-line;
  color: #c9d1d9;
  position: relative;
}
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #21262d;
  border: 1px solid #30363d;
  color: #8b949e;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
}
.copy-btn:hover { color: #fff; background: #30363d; }
.copy-btn.copied { background: #238636; color: #fff; border-color: #238636; }

/* ---------- Estimated tag ---------- */
.estimated-tag {
  background: rgba(210,153,34,0.15);
  color: #d29922;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
  font-weight: 500;
}

/* ---------- Footer ---------- */
footer {
  text-align: center;
  padding: 24px 16px;
  font-size: 0.75rem;
  color: #6e7681;
  border-top: 1px solid #21262d;
  margin-top: 20px;
}
footer p { margin: 4px 0; }
.config-info { font-family: ui-monospace, monospace; opacity: 0.6; }

/* ---------- Header actions ---------- */
.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
#scanBtn {
  background: #1f6feb;
  border: 1px solid #1f6feb;
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
#scanBtn:hover { background: #388bfd; }

/* ---------- Loading overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.overlay-content {
  text-align: center;
  padding: 28px;
  max-width: 320px;
}
.overlay-content p { margin: 8px 0; }
.overlay-detail { font-size: 0.85rem; color: #8b949e; }
.overlay-progress {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: #58a6ff;
  margin-top: 12px !important;
}
.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #21262d;
  border-top-color: #58a6ff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 16px;
}

/* ---------- Responsive tweaks ---------- */
@media (max-width: 480px) {
  h1 { font-size: 1.2rem; }
  .symbol { font-size: 1.3rem; }
  .strike-row { grid-template-columns: 1fr 1fr; }
  .stats { gap: 6px; }
  .stat .v { font-size: 0.9rem; }
}

@media (min-width: 768px) {
  main { padding: 20px; }
  .card { padding: 20px; }
}
