:root {
  --bg: #0b0f17;
  --surface: #131a27;
  --surface-2: #1a2332;
  --border: #233048;
  --text: #e6edf7;
  --muted: #8ea0bd;
  --accent: #6ea8ff;
  --pos: #2ecc71;
  --neg: #ff5e6c;
  --warn: #f5a623;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(19,26,39,0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6ea8ff, #a069ff);
  color: white;
  font-weight: 700;
  font-size: 22px;
  display: grid; place-items: center;
  box-shadow: 0 4px 16px rgba(110,168,255,0.35);
}
.app-header h1 { font-size: 18px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.subtitle { font-size: 12px; color: var(--muted); }
.header-actions { display: flex; gap: 10px; align-items: center; }
.muted { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #0b0f17; border-color: var(--accent); }
.btn-primary:hover { background: #8bbcff; border-color: #8bbcff; }
.btn-ghost { background: transparent; }
.icon { font-size: 15px; }

main { padding: 24px 32px 40px; max-width: 1600px; margin: 0 auto; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 28px; font-weight: 600; margin-top: 8px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 14px; margin-top: 4px; font-weight: 500; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.grid-2:nth-of-type(2) { grid-template-columns: 1fr 1fr; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-lg { min-height: 380px; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0; font-weight: 600; }

.chart-wrap { position: relative; height: 320px; }
.card-lg .chart-wrap { height: 340px; }

.chart-controls { display: flex; gap: 4px; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.chip-active { background: var(--accent); color: #0b0f17; border-color: var(--accent); }

.sector-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-top: 12px;
  font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

.top-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.top-grid h3 { font-size: 13px; margin: 0 0 10px; font-weight: 600; }
.ranking { list-style: none; padding: 0; margin: 0; }
.ranking li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  margin-bottom: 6px;
  font-size: 13px;
}
.ranking .sym { font-weight: 600; }
.ranking .pct { font-weight: 600; font-variant-numeric: tabular-nums; }

.search-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  width: 260px;
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th.num { text-align: right; }
thead th:hover { color: var(--text); }
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(35,48,72,0.4);
  font-variant-numeric: tabular-nums;
}
tbody td.num { text-align: right; }
tbody tr:hover { background: rgba(110,168,255,0.04); }
.ticker-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--surface-2);
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
}
.sector-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
}

.app-footer {
  display: flex; justify-content: space-between;
  padding: 20px 32px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  transition: opacity 0.25s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.ok  { border-color: var(--pos); }
.toast.err { border-color: var(--neg); }

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2:nth-of-type(2) { grid-template-columns: 1fr; }
  .app-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  main { padding: 16px; }
}
