:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --border: rgba(255,255,255,0.08);
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #484f58;
  --blue: #2f81f7;
  --red: #f85149;
  --green: #3fb950;
  --yellow: #d29922;
  --red-dim: rgba(248,81,73,0.15);
  --green-dim: rgba(63,185,80,0.12);
  --blue-dim: rgba(47,129,247,0.12);
}
* { box-sizing:border-box; margin:0; padding:0 }
body {
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 6px;
}

/* ── Header ── */
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.header-top h1 {
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(135deg, #e6edf3, #8b949e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text2);
  padding: 4px 8px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  margin-bottom: 6px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}
.stat-item { white-space: nowrap }
.stat-item.sep { color: var(--text3) }
.stat-num { font-weight: 700; color: var(--text); }
.stat-premium-color { color: var(--red); font-weight: 600; }
.stat-discount-color { color: var(--green); font-weight: 600; }
.stat-top { color: var(--yellow) !important; font-weight: 600; max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
.stat-time { color: var(--text3); font-size: 10px; }

/* ── Dot ── */
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.live { background: var(--green); box-shadow: 0 0 6px rgba(63,185,80,0.5); }
.status-dot.loading { background: var(--yellow); }
.status-dot.error { background: var(--red); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm { padding: 5px 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn:active { background: rgba(255,255,255,0.1); }
.btn:disabled { opacity: 0.4; }

/* ── Controls ── */
.controls {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.search-box { flex: 1; position: relative; }
.search-box input {
  width: 100%;
  height: 30px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  -webkit-appearance: none;
}
.search-box input::placeholder { color: var(--text3); }
.search-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-dim); }
.controls select {
  height: 30px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  color: var(--text2);
  font-size: 11px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

/* ── Table ── */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
thead th {
  padding: 7px 5px;
  text-align: left;
  color: var(--text2);
  font-weight: 600;
  font-size: 10px;
  background: rgba(0,0,0,0.25);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  position: sticky;
  top: 0;
  letter-spacing: 0.3px;
}
thead th.sort-desc::after { content: ' ↓'; color: var(--blue); }
thead th.sort-asc::after { content: ' ↑'; color: var(--blue); }
tbody tr {
  border-bottom: 1px solid var(--border);
}
tbody tr:active { background: rgba(255,255,255,0.03); }

/* Column widths - percentage based */
.col-name { width: 15%; }
.col-price { text-align: right; white-space: nowrap; }
.col-nav { text-align: right; white-space: nowrap; }
/* ── Premium Column Header ── */
.col-premium { width: 12%; text-align: right; }
.col-chg { text-align: right; white-space: nowrap; }
.col-act { text-align: center; width: 32px; }

/* Row action button */
.btn-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  color: var(--blue);
  font-size: 10px;
  font-family: -apple-system, system-ui, sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-row:active { background: var(--blue-dim); }
.btn-row:disabled { opacity: 0.3; }

tbody td {
  padding: 7px 3px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Name cell: name on top, code+tags line below */
.name-cell {
  overflow: hidden;
}
.name-cell .name-line {
  font-weight: 500;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  cursor: pointer;
}
.name-cell .name-line:hover { color: var(--blue); }
.name-cell .name-line.sm { font-size: 9px; }
.name-cell .name-line.xs { font-size: 8px; }
.name-cell .sub-line {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 1px;
}
.name-cell .sub-line .code-part {
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--blue);
}
.name-cell .fund-tag {
  font-size: 9px;
  padding: 1px 3px;
  border-radius: 3px;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}
.fund-tag-danger { background: var(--red); }
.fund-tag-warning { color: #000; background: var(--yellow); }
.fund-tag-ok { background: var(--green); }
.fund-tag-blue { background: var(--blue); }

.price-cell {
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  font-weight: 500;
  text-align: right;
}
.change-cell {
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  font-weight: 500;
  text-align: right;
}
.time-sub {
  font-size: 9px;
  color: var(--text3);
  margin-top: 1px;
}

/* ── Premium Stacked (mobile: vertical, desktop: inline) ── */
.premium-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  line-height: 1.2;
}
.premium-line {
  display: flex;
  align-items: center;
  gap: 2px;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
}
.premium-line .pl-label {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 9px;
  color: var(--text3);
  font-weight: 400;
}
.premium-line .pl-val { font-weight: 600; }

/* ── State overlay (loading/empty) ── */
.state-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 8px;
  color: var(--text2);
  font-size: 12px;
}
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: fadeIn 0.2s ease;
  text-align: center;
  white-space: nowrap;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Desktop: wider ── */
@media (min-width: 768px) {
  .container { padding: 20px 16px; }
  .header-top h1 { font-size: 20px; }
  .stats-bar { font-size: 12px; gap: 8px; padding: 6px 12px; }
  table { font-size: 13px; table-layout: auto; }
  thead th { padding: 10px 14px; font-size: 11px; }
  tbody td { padding: 11px 14px; }
  .name-cell .name-line { font-size: 14px; }
  .name-cell .name-line.sm { font-size: 13px; }
  .name-cell .name-line.xs { font-size: 12px; }
  .col-price { }
  .col-nav { }
  .col-premium { }
  .col-chg { }
  .controls select { font-size: 12px; padding: 0 12px; }
  .btn-sm { padding: 7px 14px; }
  .premium-badge { padding: 3px 10px; font-size: 12px; }
  .search-box input { height: 34px; font-size: 13px; padding: 0 12px; }
  .controls select { height: 34px; }
  .toast-container { bottom: 24px; }
  .state-overlay { padding: 80px 20px; }
  .premium-line { display: inline; }
  .premium-line + .premium-line { margin-left: 2px; }
