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

:root {
  --bg:        #fafafa;
  --card-bg:   #ffffff;
  --border:    #e5e5e5;
  --text:      #171717;
  --text-sec:  #525252;
  --text-tert: #a3a3a3;
  --badge-bg:  #f5f5f5;
  --red:       #dc2626;
  --amber:     #d97706;
  --green:     #16a34a;
  --radius:    8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 12px 48px;
}

/* ── Header ──────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.header-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.header-updated { font-size: 0.72rem; color: var(--text-tert); }

/* ── Search ──────────────────────────────────── */
.search-bar {
  position: relative;
  margin-bottom: 8px;
}
.search-bar input {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.search-bar input:focus {
  border-color: #a3a3a3;
}
.search-bar input::placeholder {
  color: var(--text-tert);
}
.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--text-tert);
  cursor: pointer;
  display: none;
  line-height: 1;
  padding: 4px;
}
.search-clear.visible { display: block; }

/* ── Filter Bar ──────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-btn {
  flex-shrink: 0;
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-sec);
  font-size: 0.75rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}
.filter-divider {
  color: var(--border);
  font-size: 0.9rem;
  line-height: 1;
  align-self: center;
  flex-shrink: 0;
}
.market-tag {
  font-size: 0.55rem;
  font-weight: 500;
  padding: 0px 4px;
  border-radius: 3px;
  color: var(--text-tert);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Sections ────────────────────────────────── */
.section { margin-bottom: 24px; }
.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-tert);
}

/* ── Cards ────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 480px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 720px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s;
}
.card:active { border-color: #a3a3a3; }
.card.hidden { display: none; }

.card-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-code {
  font-size: 0.65rem;
  color: var(--text-tert);
  font-family: var(--mono);
}
.card-badge {
  font-size: 0.6rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--text-sec);
  white-space: nowrap;
  flex-shrink: 0;
}
.card-tier {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-tert);
  margin-left: auto;
  flex-shrink: 0;
}

.card-mid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}
.card-price {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.card-cap {
  font-size: 0.68rem;
  color: var(--text-tert);
  font-family: var(--mono);
}

.card-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-sec);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.low   { background: var(--green); }
.status-dot.fair  { background: #a3a3a3; }
.status-dot.high  { background: var(--red); }
.status-dot.unknown { background: #d4d4d4; }

.card-metric {
  font-size: 0.72rem;
  color: var(--text-tert);
  font-family: var(--mono);
}

/* ── Health Indicators (inline in card) ─────── */
.card-health {
  display: flex;
  gap: 3px;
  margin-top: 2px;
}
.card-health-dot {
  font-size: 0.6rem;
  line-height: 1;
}

/* ── Alerts ───────────────────────────────────── */
.alert-list { list-style: none; }
.alert-item {
  padding: 8px 12px;
  background: var(--badge-bg);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-sec);
  margin-bottom: 5px;
  line-height: 1.5;
}
.alert-item:last-child { margin-bottom: 0; }
.alert-time {
  font-size: 0.65rem;
  color: var(--text-tert);
  margin-left: 6px;
}

/* ── Health Table ─────────────────────────────── */
.health-legend {
  display: flex;
  gap: 12px;
  font-size: 0.68rem;
  color: var(--text-tert);
  margin-bottom: 8px;
}
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.health-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.health-table th {
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--text-tert);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.health-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.health-table tr:last-child td { border-bottom: none; }
.health-table tr.hidden { display: none; }
.health-table td:first-child {
  font-weight: 600;
  color: var(--text);
  font-size: 0.82rem;
}
.health-cell {
  cursor: pointer;
  position: relative;
  display: inline-block;
  font-size: 0.95rem;
}
.health-cell .tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 0.68rem;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
.health-cell:hover .tip,
.health-cell.active .tip { display: block; }

/* ── Empty State ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px 0;
  color: var(--text-tert);
  font-size: 0.85rem;
}

/* ── Footer ──────────────────────────────────── */
.footer {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-tert);
  padding-top: 20px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ── Mobile fine-tuning ──────────────────────── */
@media (max-width: 479px) {
  html { font-size: 14px; }
  .container { padding: 12px 10px 40px; }
  .header { padding-bottom: 10px; margin-bottom: 16px; }
  .header-title { font-size: 1.25rem; }
  .card { padding: 10px 12px; }
  .card-price { font-size: 1rem; }
  .health-table th,
  .health-table td { padding: 6px 8px; }
}
