*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface-hover:#1c2128;
  --border:       #21262d;
  --border-muted: #30363d;
  --text:         #c9d1d9;
  --muted:        #8b949e;
  --green:        #3fb950;
  --green-dim:    rgba(63, 185, 80, 0.15);
  --red:          #f85149;
  --red-dim:      rgba(248, 81, 73, 0.15);
  --accent:       #388bfd;
  --accent-dim:   rgba(56, 139, 253, 0.12);
  --radius:       8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.muted { color: var(--muted); font-size: 12px; }

#refresh-btn {
  background: none;
  border: 1px solid var(--border-muted);
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}

#refresh-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

/* ── Main layout ── */

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

/* ── Region sections ── */

.region { margin-bottom: 36px; }

/* ── Collapsible section groups ── */

.section-group { margin-bottom: 4px; }

.section-header {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  padding: 12px 2px;
  border-top: 1px solid var(--border);
  user-select: none;
  transition: color 0.15s;
}

.section-group:first-child .section-header { border-top: none; }

.section-header:hover { color: var(--accent); }

.section-chevron {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.section-header.collapsed .section-chevron { transform: rotate(-90deg); }

.section-label { flex-shrink: 0; }

.section-preview {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin-left: 4px;
}

.section-preview::-webkit-scrollbar { display: none; }

/* Hide preview when the section is expanded */
.section-header:not(.collapsed) .section-preview { display: none; }

.section-preview-item {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1.5;
  flex-shrink: 0;
}

@media (min-width: 640px) {
  .section-preview { gap: 7px; margin-left: 8px; }
  .section-preview-item { padding: 3px 11px; }
}

.section-preview-item.positive {
  color: var(--green);
  background: var(--green-dim);
}

.section-preview-item.negative {
  color: var(--red);
  background: var(--red-dim);
}

.section-body {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 32px;
  align-items: start;
  padding-top: 4px;
}

.region.solo { grid-column: span 2; }

.region-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 12px;
  padding-left: 2px;
}

/* ── Cards ── */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  user-select: none;
}

.card:hover {
  background: var(--surface-hover);
  border-color: var(--border-muted);
  transform: translateY(-1px);
}

.card.active {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.card.compare-active {
  background: var(--surface-hover);
}

.card-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.compare-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

@keyframes flash-up {
  0%   { background: var(--surface); }
  25%  { background: rgba(63, 185, 80, 0.28); }
  100% { background: var(--surface); }
}

@keyframes flash-down {
  0%   { background: var(--surface); }
  25%  { background: rgba(248, 81, 73, 0.28); }
  100% { background: var(--surface); }
}

.card.flash-up   { animation: flash-up   0.9s ease-out; }
.card.flash-down { animation: flash-down 0.9s ease-out; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-name {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.market-status {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}

.market-status.open {
  color: var(--green);
  background: var(--green-dim);
}

.market-status.closed {
  color: var(--muted);
  background: var(--border);
}

.card-price {
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}

.card-change {
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 3px;
}

.card-change.positive { color: var(--green); }
.card-change.negative { color: var(--red); }

.trend-dots {
  display: flex;
  gap: 5px;
  margin-top: 10px;
}

.trend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-muted);
  flex-shrink: 0;
}

.trend-dot.up   { background: var(--green); }
.trend-dot.down { background: var(--red); }
.trend-dot.flat { background: var(--border-muted); }

/* ── News ticker ── */

.news-ticker-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 38px;
  overflow: hidden;
  margin-bottom: 32px;
}

.news-ticker-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--accent);
  text-transform: uppercase;
  padding: 0 14px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  align-items: center;
}

.news-ticker-viewport {
  flex: 1;
  overflow: hidden;
  height: 100%;
  position: relative;
}

.news-ticker-track {
  display: inline-flex;
  align-items: center;
  height: 100%;
  white-space: nowrap;
  will-change: transform;
  animation: ticker-scroll 60s linear infinite;
}

.news-ticker-track:hover { animation-play-state: paused; }

@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

.news-ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.news-ticker-item:hover .news-ticker-title { color: var(--accent); }

.news-ticker-source {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}

.news-ticker-sep { color: var(--border-muted); }

.news-ticker-title.positive { color: var(--green); }
.news-ticker-title.negative { color: var(--red); }

.news-ticker-div {
  color: var(--border-muted);
  font-size: 10px;
  padding: 0 2px;
}

.news-ticker-placeholder {
  padding: 0 16px;
  font-size: 12px;
  color: var(--muted);
}

.news-refresh-btn {
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  padding: 0 13px;
  height: 100%;
  font-size: 15px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.news-refresh-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* ── Calendar bar ── */

.calendar-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 38px;
  overflow: hidden;
  margin-bottom: 16px;
  gap: 0;
}

.calendar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--accent);
  text-transform: uppercase;
  padding: 0 14px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
  height: 38px;
  display: flex;
  align-items: center;
}

.calendar-viewport {
  flex: 1;
  overflow: hidden;
  height: 100%;
  min-height: 38px;
}

.calendar-events {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
  min-height: 38px;
}

.calendar-events::-webkit-scrollbar { display: none; }

.calendar-event {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5px 14px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  gap: 2px;
  flex-shrink: 0;
}

.calendar-event-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.calendar-event-meta {
  font-size: 10px;
  color: var(--muted);
}

.calendar-event-countdown {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}

.calendar-event-countdown.soon { color: #e3b341; }
.calendar-event-countdown.urgent { color: var(--red); }

.calendar-event-div {
  color: var(--border-muted);
  font-size: 10px;
  padding: 0 2px;
}

.calendar-placeholder {
  padding: 0 16px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  min-height: 38px;
}

/* ── Market Brief button (header) ── */

.brief-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 12px;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.brief-toggle-btn:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Bell notification indicator */
.brief-bell {
  position: relative;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
}

.brief-bell-dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--red);
}

.brief-bell-ping {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--red);
  animation: bell-ping 1.5s ease-out infinite;
}

@keyframes bell-ping {
  0%   { transform: scale(1);   opacity: 0.8; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* ── Market Brief dropdown panel ── */

.brief-panel {
  position: fixed;
  top: 58px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  overflow: hidden;
}

.brief-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.brief-panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
}

.brief-panel-ts {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}

.brief-regen-btn {
  background: none;
  border: 1px solid var(--border-muted);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 1px 7px;
  line-height: 1.4;
  transition: color 0.15s, border-color 0.15s;
}

.brief-regen-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text); }
.brief-regen-btn:disabled { opacity: 0.4; cursor: default; }

.brief-panel-credit {
  font-size: 10px;
  color: var(--muted);
  opacity: 0.55;
  white-space: nowrap;
}

.brief-panel-body {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.brief-placeholder {
  color: var(--muted);
  font-style: italic;
}

.brief-section {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.brief-section:last-child { border-bottom: none; padding-bottom: 0; }
.brief-section:first-child { padding-top: 0; }

.brief-section-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.brief-section-text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  margin: 0;
}

/* ── Chart section ── */

#chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  margin-bottom: 32px;
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
}

.chart-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.compare-btn {
  background: none;
  border: 1px solid var(--border-muted);
  color: var(--muted);
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.compare-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.compare-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.compare-banner {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 2px 14px;
}

.compare-banner strong {
  color: var(--text);
}

.chart-title-group h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

#chart-stats {
  font-size: 13px;
  color: var(--muted);
}

#chart-stats .positive { color: var(--green); }
#chart-stats .negative { color: var(--red); }

/* ── Period selector ── */

.period-selector {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.period-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.period-btn:hover {
  color: var(--text);
  border-color: var(--border);
}

.period-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* ── Chart area ── */

.chart-area {
  position: relative;
}

.chart-wrap {
  height: 320px;
}

.chart-wrap canvas {
  width: 100% !important;
}

.chart-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(22, 27, 34, 0.75);
  border-radius: var(--radius);
  z-index: 5;
}

/* ── Chart price bar ── */

.chart-price-bar {
  display: flex;
  align-items: stretch;
  margin-top: 14px;
  padding: 12px 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
  gap: 0;
}

.chart-price-stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px 20px;
  flex: 1;
  min-width: 80px;
  border-right: 1px solid var(--border);
}

.chart-price-stat:last-child {
  border-right: none;
}

.chart-price-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.chart-price-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.chart-price-value.positive { color: var(--green); }
.chart-price-value.negative { color: var(--red); }

/* ── Spinner ── */

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Initial loading ── */

.initial-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--muted);
  gap: 16px;
}

/* ── Error message ── */

.error-banner {
  text-align: center;
  padding: 40px 24px;
  color: var(--red);
  font-size: 14px;
}

/* ── Utilities ── */

.hidden { display: none !important; }

/* ── Responsive ── */

@media (max-width: 960px) {
  .section-body { grid-template-columns: 1fr; }
  .region.solo  { grid-column: auto; }
}

@media (max-width: 640px) {
  main { padding: 18px 16px 40px; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  .chart-wrap { height: 240px; }
  .chart-header { flex-direction: column; }
  .period-selector { order: -1; }
}

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