/* ── Nordic Stock Screener — Dark Terminal Theme ── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --bg-hover: #21262d;
  --border: #30363d;
  --border-accent: #388bfd33;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --accent: #00bcd4;
  --accent-dim: #00bcd433;
  --positive: #2ea043;
  --positive-dim: #2ea04322;
  --negative: #da3633;
  --negative-dim: #da363322;
  --gold: #d4a017;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-ui: 'DM Sans', system-ui, sans-serif;
  --radius: 6px;
  --transition: 150ms ease;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Layout ── */
#app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.logo {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo::before {
  content: '◆';
  font-size: 12px;
}

.country-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 2px;
}

.country-tab {
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
  letter-spacing: 0.5px;
}

.country-tab:hover { color: var(--text); background: var(--bg-hover); }
.country-tab.active { color: var(--accent); background: var(--bg-elevated); }

.sector-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  min-width: 160px;
}

.sector-select:focus { outline: none; border-color: var(--accent); }

.search-box {
  margin-left: auto;
  position: relative;
}

.search-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px 6px 32px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  width: 220px;
  transition: border-color var(--transition);
}

.search-box input:focus { outline: none; border-color: var(--accent); }

.search-box::before {
  content: '⌕';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 15px;
}

.expand-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: all var(--transition);
  letter-spacing: 1px;
}

.expand-btn:hover { color: var(--accent); border-color: var(--accent); }

.stock-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Main Content ── */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}

.main-content.detail-open {
  grid-template-columns: 1fr 1fr 340px;
}

.main-content.table-expanded {
  grid-template-columns: 1fr 0fr;
}

.main-content.table-expanded .chart-panel {
  overflow: hidden;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}

.main-content.table-expanded.detail-open {
  grid-template-columns: 1fr 0fr 340px;
}

/* ── Table Panel ── */
.table-panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

/* ── AG Grid Dark Overrides ── */
.ag-theme-alpine-dark {
  --ag-background-color: var(--bg);
  --ag-header-background-color: var(--bg-surface);
  --ag-odd-row-background-color: var(--bg);
  --ag-row-hover-color: var(--bg-hover);
  --ag-selected-row-background-color: var(--accent-dim);
  --ag-border-color: var(--border);
  --ag-header-foreground-color: var(--text-muted);
  --ag-foreground-color: var(--text);
  --ag-font-family: var(--font-mono);
  --ag-font-size: 11px;
  --ag-row-height: 28px;
  --ag-header-height: 30px;
  --ag-cell-horizontal-padding: 4px;
  flex: 1;
}

.ag-theme-alpine-dark .ag-header-cell-label {
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ag-theme-alpine-dark .ag-row { cursor: pointer; }
.ag-theme-alpine-dark .ag-row-selected { background: var(--accent-dim) !important; }

/* ── Chart Panel ── */
.chart-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.chart-area {
  height: 400px;
  display: grid;
  grid-template-columns: 1fr 200px;
  grid-template-rows: 1fr;
  flex-shrink: 0;
}

.chart-container {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  overflow: hidden;
}

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

.chart-title {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.period-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-surface);
  border-radius: 4px;
  padding: 2px;
}

.period-tab {
  padding: 2px 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  cursor: pointer;
  border-radius: 3px;
  transition: all var(--transition);
}

.period-tab:hover { color: var(--text-muted); }
.period-tab.active { color: var(--accent); background: var(--bg); }

.price-chart-wrap {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

/* ── Ratio Mini Charts (right sidebar next to price chart) ── */
.ratio-charts-sidebar {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ratio-mini {
  flex: 1;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

.ratio-mini:last-child { border-bottom: none; }

.ratio-mini h5 {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
  text-align: center;
}

/* ── Financials Charts (bottom 4-panel strip) ── */
.financials-section {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  height: 200px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  flex-shrink: 0;
}

.fin-chart-wrap {
  position: relative;
  overflow: hidden;
}

.fin-chart-wrap h4 {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
  text-align: center;
}

/* ── Detail Panel ── */
.detail-panel {
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.detail-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.detail-close {
  float: right;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  padding: 0 4px;
  line-height: 1;
  transition: color var(--transition);
}

.detail-close:hover { color: var(--text); }

.detail-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.detail-ticker {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
}

.detail-price-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 12px;
}

.detail-price {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
}

.detail-change {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
}

.detail-meta {
  padding: 16px 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.detail-meta span {
  white-space: nowrap;
}

.detail-description {
  padding: 16px 20px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
  max-height: 120px;
  overflow-y: auto;
}

/* ── Ratios Grid ── */
.ratios-section {
  padding: 16px 20px;
}

.ratios-title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.ratios-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.ratio-label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ratio-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

/* ── Utility Classes ── */
.text-positive { color: var(--positive); }
.text-negative { color: var(--negative); }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-muted); }

/* ── Empty / Loading states ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-family: var(--font-mono);
  gap: 8px;
}

.empty-state .icon { font-size: 32px; opacity: 0.3; }

.loading-pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ── Entrance animation ── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-panel { animation: slideUp 0.25s ease-out; }
