:root {
  --bg-main: #13161c;
  --bg-card: #1a1d24;
  --bg-elevated: #262a32;
  --bg-header: #291d89;
  --border: #363c48;
  --text-primary: #f8f9fa;
  --text-muted: #9aa3b2;
  --bull: #0d8a6a;
  --bull-bright: #00c896;
  --bear: #7d1946;
  --bear-bright: #ff4b4b;
  --neutral: #5a606d;
  --accent: #00e5ff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-card);
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

.topbar {
  flex-shrink: 0;
  z-index: 50;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding-top: calc(10px + var(--safe-top));
  padding-bottom: 10px;
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.6px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bull-bright);
  box-shadow: 0 0 8px var(--bull-bright);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

select.ticker-select {
  background: var(--bg-elevated);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13.5px;
  font-weight: 700;
  min-width: 84px;
  height: 34px;
  outline: none;
}

.btn-icon {
  position: relative;
  background: var(--bg-elevated);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 11px;
  height: 34px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-icon:active {
  transform: scale(0.96);
  background: #343944;
}

.btn-icon:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.alert-badge-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bear-bright);
  box-shadow: 0 0 6px var(--bear-bright);
  display: none;
}

.tf-strip {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-main);
  border-bottom: 1px solid #232730;
}

.tf-pill {
  flex: 1;
  text-align: center;
  padding: 7px 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
}

.tf-pill.active {
  background: var(--bg-header);
  color: #fff;
  border-color: #5b4ce6;
}

.content-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: 16px;
}

.content-scroll.chart-mode {
  overflow-y: hidden;
  padding-bottom: 0;
}

.quote-banner {
  flex-shrink: 0;
  margin: 10px 12px 4px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.quote-sym {
  font-weight: 800;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.4px;
}

.quote-price {
  font-size: 17px;
  font-weight: 800;
  color: #fff;
}

.up { color: var(--bull-bright); font-weight: 700; }
.down { color: var(--bear-bright); font-weight: 700; }

.view {
  display: none;
  padding: 10px 12px;
}

.view.active {
  display: block;
}

#view-chart.active {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 12px 8px 12px;
}

#chart-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.chart-legend {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(19, 22, 28, 0.78);
  border: 1px solid rgba(54, 60, 72, 0.7);
  backdrop-filter: blur(4px);
}

.wl-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 9px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}

.wl-card:active {
  border-color: var(--accent);
}

.wl-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wl-ticker {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.wl-price-wrap {
  text-align: right;
}

.wl-price {
  font-size: 16px;
  font-weight: 800;
}

.wl-chg {
  font-size: 12px;
}

.wl-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 5px;
  letter-spacing: 0.2px;
}

.bg-bull { background: var(--bull); color: #fff; }
.bg-bear { background: var(--bear); color: #fff; }
.bg-alert-bull { background: #12b886; color: #fff; }
.bg-alert-bear { background: #e03131; color: #fff; }
.bg-neutral { background: var(--neutral); color: #fff; }
.bg-dark { background: var(--bg-elevated); color: #e9ecef; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2b303a;
}

.card-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
}

.insight-row {
  font-size: 12.5px;
  line-height: 1.45;
  margin-bottom: 5px;
  color: #e9ecef;
}

table.hud-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

table.hud-table th {
  background: var(--bg-header);
  color: #fff;
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  letter-spacing: 0.4px;
}

table.hud-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #2b303a;
  vertical-align: middle;
}

table.hud-table td:first-child {
  color: var(--text-muted);
  font-weight: 600;
  width: 38%;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 10px;
}

.kpi-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 6px;
  text-align: center;
}

.kpi-lbl {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.kpi-val {
  font-size: 14.5px;
  font-weight: 800;
  margin: 3px 0;
}

.kpi-sub {
  font-size: 10.5px;
}

/* News Feed & Pop-Up Modal */
.news-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.news-row {
  background: #13161c;
  border: 1px solid #2b303a;
  border-radius: 9px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.news-row:last-child {
  margin-bottom: 0;
}

.news-row:active {
  border-color: var(--accent);
  background: #1f242e;
}

.news-meta-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.news-date {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.2px;
  flex-shrink: 0;
}

.news-tickers {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.news-ticker-pill {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 5px;
  letter-spacing: 0.4px;
}

.news-headline {
  font-size: 13.5px;
  font-weight: 700;
  color: #f8f9fa;
  line-height: 1.38;
}

.insight-card {
  background: #13161c;
  border: 1px solid #2b303a;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.source-link-btn {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  background: var(--bg-header);
  border: 1px solid #5b4ce6;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 11px 14px;
  border-radius: 9px;
  margin-top: 6px;
}

.bottom-nav {
  flex-shrink: 0;
  z-index: 60;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding-top: 8px;
  padding-bottom: calc(10px + var(--safe-bottom));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  background: none;
  padding: 2px 0;
}

.nav-item span.icon {
  font-size: 18px;
  line-height: 1;
}

.nav-item.active {
  color: var(--accent);
}

.empty-box {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  font-size: 13px;
  line-height: 1.5;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 90;
  display: none;
}
.drawer-backdrop.open { display: block; }

.drawer-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82dvh;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.drawer-sheet.open { transform: translateY(0); }

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.drawer-list {
  overflow-y: auto;
  padding: 12px 16px 16px 16px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid #2b303a;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #363c48;
  border-radius: 24px;
  transition: 0.2s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background-color: var(--bull-bright); }
.switch input:checked + .slider:before { transform: translateX(20px); }
