:root {
  --bg: #0a0b0d;
  --bg-elev: #121317;
  --bg-elev-2: #191b20;
  --border: #24262d;
  --text: #e8e9ec;
  --text-dim: #8b8d97;
  --green: #16c784;
  --green-dim: #16c78422;
  --red: #ea3943;
  --red-dim: #ea394322;
  --accent: #5b8cff;
  --accent-dim: #5b8cff22;
  --radius: 14px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(91,140,255,0.10), transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(22,199,132,0.08), transparent 45%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }

/* ---------- Login Page ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo .mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: #05060a;
}

.login-logo .name {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.2px;
}

.login-logo .name span { color: var(--text-dim); font-weight: 400; }

.login-card h1 {
  font-size: 22px;
  margin: 0 0 6px;
  font-weight: 600;
}

.login-card p.sub {
  color: var(--text-dim);
  font-size: 13.5px;
  margin: 0 0 26px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: #0d0e11;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: var(--accent); }

.login-btn {
  width: 100%;
  padding: 12px;
  border-radius: 9px;
  border: none;
  background: var(--accent);
  color: #05060a;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  margin-top: 8px;
  transition: filter 0.15s, transform 0.05s;
}

.login-btn:hover { filter: brightness(1.08); }
.login-btn:active { transform: scale(0.99); }

.login-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-dim);
  background: #0d0e11;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
}

.login-error {
  color: var(--red);
  font-size: 12.5px;
  margin: -6px 0 14px;
  min-height: 16px;
}

/* ---------- Dashboard Shell ---------- */
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  background: rgba(10,11,13,0.85);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.topbar .left { display: flex; align-items: center; gap: 12px; }

.topbar .status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 20px;
}

.dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 var(--green-dim);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22,199,132,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(22,199,132,0); }
  100% { box-shadow: 0 0 0 0 rgba(22,199,132,0); }
}

.topbar .right { display: flex; align-items: center; gap: 16px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #05060a;
}

.logout-btn {
  font-size: 12.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
}
.logout-btn:hover { color: var(--text); border-color: #3a3d47; }

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.page-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.page-sub { color: var(--text-dim); font-size: 13.5px; margin: 0 0 26px; }

/* Summary cards */
.summary-grid {
  display: flex;
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 28px;
  min-width: 240px;
}

.card .label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.card .value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card .delta {
  font-size: 12.5px;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.up { color: var(--green); }
.down { color: var(--red); }

/* Main grid: table + side chart */
.main-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
}

.panel-head .sub {
  font-size: 12px;
  color: var(--text-dim);
}

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; min-width: 640px; }

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 500;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 12px 20px;
  font-size: 13.5px;
  border-bottom: 1px solid #1c1e24;
  font-variant-numeric: tabular-nums;
}

tbody tr { cursor: pointer; transition: background 0.12s; }
tbody tr:hover { background: #16181d; }
tbody tr.selected { background: #16181d; box-shadow: inset 3px 0 0 var(--accent); }
tbody tr:last-child td { border-bottom: none; }

.ticker-cell { display: flex; flex-direction: column; }
.ticker-code { font-weight: 600; }
.ticker-name { color: var(--text-dim); font-size: 11.5px; }

.flash-up { animation: flashUp 0.6s ease-out; }
.flash-down { animation: flashDown 0.6s ease-out; }
@keyframes flashUp { 0% { background: var(--green-dim); } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: var(--red-dim); } 100% { background: transparent; } }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge.up { background: var(--green-dim); color: var(--green); }
.badge.down { background: var(--red-dim); color: var(--red); }

canvas.spark { display: block; }

.chart-wrap { padding: 20px; }

#priceChart { width: 100%; height: 260px; display: block; }

.chart-meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.chart-meta .p { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.range-tabs { display: flex; gap: 6px; margin-top: 14px; }
.range-tabs button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.range-tabs button.active { color: var(--text); border-color: var(--accent); background: var(--accent-dim); }

@media (max-width: 980px) {
  .main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }
  .topbar .status { order: 3; }
  .container { padding: 20px 16px 40px; }
  .summary-grid { gap: 12px; }
  .card { padding: 14px 16px; min-width: 0; flex: 1; }
  .card .value { font-size: 19px; }
}