/* SPX Market Intelligence — Shared Light Theme v2
   Linked from all /spx pages. Provides: variables, body, header,
   navigation, cards, stats, filters, tables, buttons, modals, responsive. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Variables ── */
:root {
  --bg:            #F1F5F9;
  --surface:       #FFFFFF;
  --surface-muted: #F7F9FC;
  --header-bg:     #F8FAFC;
  --text:          #171A21;
  --text2:         #334155;
  --text-muted:    #64748B;
  --text-sub:      #94A3B8;
  --border:        #E2E8F0;
  --border-strong: #CBD5E1;
  --accent:        #168A68;
  --accent-soft:   #E8F7F1;
  --accent2:       #059669;
  --bull:          #16A34A;
  --bear:          #DC2626;
  --danger:        #D14343;
  --warn:          #D97706;
  --info:          #2563EB;
  --purple:        #7C3AED;
  --shadow:        0 8px 24px rgba(15,23,42,0.07);
  --shadow-sm:     0 1px 4px rgba(15,23,42,0.06);
  --radius:        16px;
  --radius-sm:     8px;
}

/* ── Body ── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ── Header ── */
.hdr {
  display: flex; align-items: center; justify-content: flex-start;
  width: 100%; height: 66px; min-height: 66px;
  padding: 0 20px; gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
  flex-wrap: nowrap;
}
.logo {
  font-size: 15px; font-weight: 800; color: var(--accent);
  letter-spacing: -0.2px; display: flex; align-items: center; gap: 8px;
  white-space: nowrap; flex-shrink: 0; line-height: 1;
}
.logo span { transform: translateY(1px); }
.dot {
  width: 7px; height: 7px; background: var(--accent); border-radius: 50%;
  flex-shrink: 0; animation: pulse 2s ease infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.25} }

/* ── Navigation (grouped dropdown menu) ── */
.nav-top {
  display: flex; flex: 1 1 auto; min-width: 0; gap: 2px;
  flex-wrap: nowrap; align-items: center; height: 100%;
}
.nav-item {
  display: inline-flex; align-items: center; gap: 4px;
  height: 36px; padding: 0 12px; font-size: 13px; font-weight: 500;
  color: var(--text2); background: transparent; border: none; border-radius: 9px;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  font-family: inherit; position: relative;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.nav-item.active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--accent);
}
.nav-item-btc { color: #c2410c; }
.nav-item-btc:hover { background: #FFF7ED; color: #9a3412; }
.nav-item-btc.active { background: #FFF7ED; color: #c2410c; }
.nav-item-btc.active::after { background: #c2410c; }
.nav-mobile-link.nav-item-btc, .nav-mobile-sublink.nav-item-btc { color: #c2410c; }
.dropdown-arrow { font-size: 11px; line-height: 1; margin-top: 1px; color: var(--text-sub); }

.nav-dropdown { position: relative; height: 100%; display: flex; align-items: center; }
.nav-dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px 6px 6px; margin-top: 0; z-index: 1001;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-link {
  display: flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--text2); text-decoration: none;
  white-space: nowrap; position: relative;
}
.nav-dropdown-link:hover { background: var(--surface-muted); color: var(--text); }
.nav-dropdown-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.nav-dot {
  display: none; width: 7px; height: 7px; border-radius: 50%;
  background: #dc2626; flex-shrink: 0;
}
.nav-item.has-new-data .nav-dot,
.nav-dropdown-toggle.has-new-data .nav-dot,
.nav-dropdown-link.has-new-data .nav-dot { display: inline-block; }

.nav-mobile-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 36px; height: 36px; margin-left: auto; padding: 0;
  background: transparent; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.nav-mobile-toggle span { display: block; height: 2px; margin: 0 7px; background: var(--text2); border-radius: 2px; }
.nav-mobile-panel { display: none; }
.nav-mobile-panel.open { display: block; }
.nav-mobile-link {
  display: block; padding: 12px 20px; font-size: 14px; font-weight: 500;
  color: var(--text2); text-decoration: none; border-bottom: 1px solid var(--border);
}
.nav-mobile-link.active { color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.nav-mobile-group { border-bottom: 1px solid var(--border); }
.nav-mobile-group summary {
  padding: 12px 20px; font-size: 14px; font-weight: 600; color: var(--text);
  cursor: pointer; list-style: none;
}
.nav-mobile-group summary::-webkit-details-marker { display: none; }
.nav-mobile-group summary::after { content: '⌄'; float: right; color: var(--text-sub); }
.nav-mobile-group[open] summary::after { content: '⌃'; }
.nav-mobile-subgroup { padding-bottom: 6px; }
.nav-mobile-sublink {
  display: block; padding: 10px 20px 10px 34px; font-size: 13px;
  color: var(--text2); text-decoration: none;
}
.nav-mobile-sublink.active { color: var(--accent); font-weight: 600; }
.nav-mobile-sublink .nav-dot, .nav-mobile-link .nav-dot { margin-left: 6px; }

@media (max-width: 900px) {
  .nav-top { display: none; }
  .nav-mobile-toggle { display: flex; }
  .nav-mobile-panel {
    position: fixed; top: 66px; left: 0; right: 0; bottom: 0;
    background: var(--surface); overflow-y: auto; z-index: 999;
  }
}

/* ── Price sub-bar (dashboard only) ── */
.price-sub {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.sep-v { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

/* ── Content wrapper ── */
.wrap {
  max-width: 1440px; margin: 0 auto; padding: 20px 24px;
}

/* ── Grid layouts ── */
.g1 { margin-bottom: 12px; }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.g4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 12px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

/* ── Stats grid ── */
.stats {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 20px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
  width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}
.stat-body { min-width: 0; }
.stat-v { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-l { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Filter card ── */
.filter-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-row select, .filter-row input {
  height: 36px; padding: 0 12px; font-size: 12px; font-family: inherit;
  background: var(--surface-muted); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; transition: border-color .15s; appearance: auto;
}
.filter-row select:focus, .filter-row input:focus { border-color: var(--accent); }
.filter-sep {
  width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex-shrink: 0;
}
.filter-sum-row {
  display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap;
}
.filter-summary {
  font-size: 11px; color: var(--text-muted); background: var(--surface-muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 12px; flex: 1; min-width: 160px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-reset {
  height: 36px; padding: 0 14px; font-size: 11px; font-family: inherit;
  font-weight: 600; color: var(--text-muted); background: var(--surface-muted);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.btn-reset:hover {
  border-color: var(--accent); color: var(--accent); background: var(--accent-soft);
}
.shown-lbl { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ── Table card ── */
.tbl-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  margin-bottom: 16px;
}
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Table ── */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 12px; font-size: 10px; font-weight: 700;
  color: var(--text-muted); background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky; top: 0; z-index: 3; cursor: pointer; user-select: none;
  white-space: nowrap; text-transform: uppercase; letter-spacing: .5px;
}
thead th.nosort { cursor: default; }
thead th:not(.nosort):hover { color: var(--accent); }
thead th.sorted-asc::after  { content: " ↑"; color: var(--accent); font-size: 11px; }
thead th.sorted-desc::after { content: " ↓"; color: var(--accent); font-size: 11px; }
tbody td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-muted); }
.tbl-empty { text-align: center; color: var(--text-muted); padding: 48px; font-size: 14px; }

/* ── Primary button ── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 16px; font-size: 12px; font-weight: 600; font-family: inherit;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: 8px; cursor: pointer; transition: all .15s;
}
.btn-primary:hover { background: #126B52; border-color: #126B52; }

/* ── Modal ── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.35); z-index: 1000;
  align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px;
  max-width: 560px; width: 100%; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(15,23,42,.18);
}
.modal-box::-webkit-scrollbar { width: 4px; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.modal-hdr {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px; transition: color .15s;
}
.modal-close:hover { color: var(--text); }

/* ── Footer ── */
.footer { font-size: 11px; color: var(--text-muted); margin-top: 16px; padding: 0 2px; }

/* ═══════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════ */

/* 1024px */
@media (max-width: 1024px) {
  .hdr { padding: 10px 18px; }
  .wrap { padding: 16px 18px; }
  .stats { grid-template-columns: repeat(2,1fr); }
  .g3 { grid-template-columns: 1fr 1fr; }
  .g4 { grid-template-columns: repeat(2,1fr); }
  .price-sub { padding: 6px 18px; }
}

/* 768px */
@media (max-width: 768px) {
  .hdr { padding: 0 14px; }
  .logo { font-size: 13px; }
  .wrap { padding: 12px 12px; }
  .price-sub { padding: 5px 14px; gap: 8px; }
  .stats { grid-template-columns: repeat(2,1fr); gap: 8px; }
  .stat { padding: 12px 14px; gap: 10px; }
  .stat-icon { width: 32px; height: 32px; font-size: 14px; }
  .stat-v { font-size: 20px; }
  .g2 { grid-template-columns: 1fr; }
  .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2,1fr); }
  .filter-card { padding: 12px 14px; }
  .filter-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .filter-row select, .filter-row input { height: 40px; font-size: 13px; width: 100% !important; }
  .filter-sep { display: none; }
  .filter-sum-row { flex-direction: column; align-items: stretch; gap: 6px; margin-top: 8px; }
  .filter-summary { min-width: 0; }
  .btn-reset { height: 40px; width: 100%; }
  .shown-lbl { text-align: center; }
}

/* Compact grouped navigation: preserve layout/behaviour, reduce footprint. */
.hdr { height:54px; min-height:54px; padding:0 20px; gap:4px; }
.logo { font-size:15px; font-weight:700; gap:7px; }
.nav-top { gap:4px; }
.nav-item { height:34px; padding:8px 12px; font-size:15px; border-radius:8px; }
.nav-dropdown-menu { min-width:180px; padding:6px; border-radius:10px; }
.nav-dropdown-link { height:auto; min-height:34px; padding:9px 12px; font-size:14px; }
.nav-mobile-toggle { width:34px; height:34px; }
@media (max-width:900px) {
  .nav-mobile-panel { top:54px; }
}
@media (max-width:600px) {
  .hdr { padding:0 14px; }
  .logo { font-size:15px; }
}
@media (max-width:390px) {
  .hdr { padding:0 10px; }
  .logo { font-size:0; }
  .logo::after { content:'EDGE 2.0'; font-size:15px; font-weight:700; letter-spacing:-.2px; }
}

/* 390px — mobile */
@media (max-width: 390px) {
  .hdr { padding: 0 10px; gap: 8px; }
  .logo { font-size: 11px; }
  .wrap { padding: 10px 10px; }
  .price-sub { padding: 5px 10px; gap: 6px; font-size: 11px; }
  .stats { grid-template-columns: repeat(2,1fr); gap: 8px; }
  .stat { padding: 10px 12px; gap: 8px; }
  .stat-icon { width: 30px; height: 30px; font-size: 13px; }
  .stat-v { font-size: 18px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .filter-row select, .filter-row input { height: 42px; font-size: 14px; }
  .btn-reset { height: 42px; }
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .modal-box { padding: 16px 14px; border-radius: 14px; max-height: 90vh; }
  .modal-backdrop { padding: 10px; }
  /* Prevent table from overflowing viewport */
  .tbl-card { overflow: hidden; }
  /* Long text doesn't stretch page */
  td, th { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
  /* Sticky columns on mobile */
  thead th:first-child, tbody td:first-child {
    position: sticky; left: 0; z-index: 2; background: var(--surface);
  }
  tbody tr:hover td:first-child { background: var(--surface-muted); }
}

/* Compact page help (unrelated to top nav — used by render_page_info()).
   Collapsed by default; opens as a floating popover that never shifts layout. */
.page-info {
  position: relative; display: inline-flex; width: auto; margin: 0 0 0 auto; padding: 0;
  background: none; border: none; box-shadow: none; color: var(--text); flex-shrink: 0;
}
/* When (i) is paired inline with a label (e.g. "Обновлено: ... (i)"), the auto
   left-margin above fights the row's own alignment and splits the pair apart. */
.info-row { display: flex; align-items: center; gap: 6px; }
.info-row .page-info { margin: 0; }
.page-info-toggle {
  flex: 0 0 22px; width: 22px; height: 22px; padding: 0; border: 1px solid #7fc2ac;
  border-radius: 50%; background: #eaf9f3; color: var(--accent); font: 800 12px/1 system-ui;
  cursor: pointer;
}
.page-info-content {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; min-width: 0;
  width: min(360px, 88vw); max-height: 70vh; overflow-y: auto;
  background: #fbfffd; border: 1px solid #9bd1bf; border-radius: 13px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .2); padding: 12px 14px; z-index: 1500;
}
.page-info-content strong { display: block; margin-bottom: 3px; color: var(--accent); font-size: 12px; }
.page-info-content span { display: block; color: var(--text); font-size: 11px; line-height: 1.45; }
.page-info:not(.is-collapsed) .page-info-content { display: block; }
@media (max-width: 768px) {
  .page-info-content { position: fixed; top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 60vh; }
}

/* Final compact navigation overrides. */
.hdr, .hdr button, .hdr a, .nav-dropdown-menu, .nav-mobile-panel { font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; line-height:normal; -webkit-font-smoothing:auto; -moz-osx-font-smoothing:auto; }
.hdr { height:43px; min-height:43px; padding:0 20px; gap:4px; }
.logo { font-size:12px; font-weight:700; gap:6px; }
.nav-top { gap:4px; }
.nav-item { height:27px; padding:6px 10px; font-size:12px; border-radius:7px; }
.nav-dropdown-menu { min-width:180px; padding:6px; border-radius:10px; }
.nav-dropdown-link { height:auto; min-height:27px; padding:7px 10px; font-size:11px; }
.nav-mobile-toggle { width:27px; height:27px; }
@media (max-width:900px) { .nav-mobile-panel { top:43px; } }
@media (max-width:600px) { .hdr { padding:0 14px; } .logo { font-size:12px; } }
@media (max-width:390px) { .hdr { padding:0 10px; gap:4px; } .logo { font-size:0; } .logo::after { content:'EDGE 2.0'; font-size:12px; font-weight:700; letter-spacing:-.2px; } }
