:root {
  --bg-app: #edf2f9;
  --bg-rail: #0f1727;
  --bg-top: #111a2c;
  --bg-panel: #ffffff;
  --bg-panel-head: #f4f7fc;
  --ink-main: #1b2638;
  --ink-soft: #64748b;
  --line: #d7deea;
  --pos: #1f9d56;
  --neg: #d34b43;
  --flat: #8f99ab;
  --accent: #2588e8;
  --left-col-width: 14%;
  --right-col-width: 14%;
  --focus-ring: 2px solid #2588e8;
  --touch-min: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink-main);
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
  background:
    radial-gradient(1200px 640px at 10% -10%, #f7f9fd 0%, transparent 60%),
    radial-gradient(1100px 500px at 100% 0%, #e5edf8 0%, transparent 58%),
    linear-gradient(180deg, #edf2f9 0%, #e8eef7 100%);
  min-height: 100dvh;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  background: #fff;
  color: #111;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #ccd6e4;
}

.skip-link:focus-visible {
  left: 10px;
  top: 10px;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
}

.left-rail {
  position: relative;
  z-index: 45;
  overflow: visible;
  background: linear-gradient(180deg, #162036 0%, #0f1727 100%);
  border-right: 1px solid #25344b;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 7px;
}

.rail-brand {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(160deg, #49a5ff 0%, #257ce2 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  margin-bottom: 4px;
  box-shadow: 0 6px 16px rgba(27, 115, 223, 0.38);
}

.rail-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid #2b3e59;
  border-radius: 10px;
  background: #162238;
  color: #d3dded;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.rail-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail-btn::after {
  content: attr(data-name);
  position: absolute;
  z-index: 60;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px;
  border-radius: 6px;
  background: #0f1520;
  border: 1px solid #2a374c;
  color: #ecf2fb;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.rail-btn.active {
  border-color: #4eb1ff;
  color: #fff;
  background: #23354e;
  box-shadow:
    inset 0 0 0 1px rgba(78, 177, 255, 0.45),
    0 6px 12px rgba(9, 19, 35, 0.26);
}

.rail-btn:hover::after,
.rail-btn:focus-visible::after {
  opacity: 1;
}

.main-stage {
  position: relative;
  z-index: 1;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.topbar {
  background: linear-gradient(90deg, #13223a 0%, #111a2e 100%);
  border: 1px solid #223655;
  border-radius: 14px;
  color: #f7f9fc;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "left search actions lang";
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  box-shadow: 0 10px 26px rgba(10, 18, 33, 0.22);
}

.topbar-left {
  grid-area: left;
  min-width: 0;
}

.topbar-left h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: #c8d5ea;
}

.topbar-search input {
  width: 100%;
  min-height: var(--touch-min);
  border-radius: 10px;
  border: 1px solid #39507a;
  background: #1b2a44;
  color: #ecf0f6;
  padding: 0 12px;
  font-size: 14px;
}

.topbar-search {
  grid-area: search;
  min-width: 180px;
  width: 100%;
}

.topbar-actions {
  grid-area: actions;
  display: inline-flex;
  gap: 6px;
}

.topbar-actions button {
  border: 0;
  background: transparent;
  color: #e6edf8;
  font-size: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  border-radius: 10px;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:hover {
  background: rgba(160, 183, 219, 0.18);
}

.icon-btn:active {
  background: rgba(160, 183, 219, 0.28);
}

.lang-toggle {
  grid-area: lang;
  display: inline-flex;
  border: 1px solid #39507a;
  border-radius: 10px;
  overflow: hidden;
  justify-self: end;
}

.lang-btn {
  min-height: var(--touch-min);
  min-width: 56px;
  width: 56px;
  border: 0;
  border-right: 1px solid #39507a;
  background: #1b2a44;
  color: #c7d2e4;
  font-weight: 700;
  border-radius: 0;
}

.lang-btn:last-child {
  border-right: 0;
}

.lang-btn.active {
  background: linear-gradient(140deg, #49a5ff 0%, #2588e8 100%);
  color: #fff;
}

.controls {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  align-items: end;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  backdrop-filter: blur(4px);
}

.control-group {
  display: grid;
  gap: 4px;
}

label {
  font-size: 11px;
  color: #596273;
  font-weight: 600;
  letter-spacing: 0.03em;
}

select,
button {
  min-height: 38px;
  border: 1px solid #bfc7d4;
  border-radius: 9px;
  background: #fff;
  color: #283140;
  padding: 0 8px;
  font-family: inherit;
  font-size: 12px;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  border-color: #99a6b8;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.tile:focus-visible,
.row-item.clickable:focus-visible,
.strip:focus-visible,
.mobile-pane-btn:focus-visible,
.rail-btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 1px;
}

.industry-jump:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.mobile-pane-tabs {
  display: none;
}

.mobile-pane-btn {
  min-height: var(--touch-min);
  font-size: 13px;
  font-weight: 700;
  background: #f5f8fd;
}

.mobile-pane-btn.active {
  background: linear-gradient(140deg, #49a5ff 0%, #2588e8 100%);
  color: #fff;
  border-color: #2588e8;
}

.dashboard-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns:
    minmax(170px, var(--left-col-width))
    3px
    minmax(0, 1fr)
    3px
    minmax(170px, var(--right-col-width));
  gap: 6px;
}

.left-col {
  grid-column: 1;
}

.center-col {
  grid-column: 3;
}

.right-col {
  grid-column: 5;
}

.col-resizer {
  align-self: stretch;
  justify-self: stretch;
  border-radius: 2px;
  background: #cfd6e2;
  cursor: ew-resize;
}

.col-resizer:hover {
  background: #aebad0;
}

.column {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.left-col {
  overflow-y: auto;
  padding-right: 2px;
}

.left-col .panel {
  flex: 0 0 auto;
}

.right-col {
  overflow-y: auto;
  padding-right: 2px;
}

.right-col .panel {
  flex: 0 0 auto;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-panel);
  box-shadow: 0 5px 16px rgba(49, 65, 89, 0.08);
}

.panel-head {
  background: var(--bg-panel-head);
  border-bottom: 1px solid var(--line);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #344155;
}

.rows-list {
  max-height: 205px;
  overflow: auto;
}

.left-col .rows-list {
  max-height: none;
  overflow: visible;
}

.right-col .rows-list {
  max-height: none;
  overflow: visible;
}

.row-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 9px 11px;
  border-bottom: 1px solid #e1e5eb;
  font-size: 13px;
}

.row-item:last-child {
  border-bottom: 0;
}

.row-item.clickable {
  cursor: pointer;
}

.row-item.clickable:hover {
  background: #edf2f9;
}

.row-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  color: #1a2230;
}

.row-value,
.row-change {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.row-value {
  color: #1f2836;
}

.row-change.pos {
  color: var(--pos);
}

.row-change.neg {
  color: var(--neg);
}

.row-change.flat {
  color: var(--flat);
}

.map-card {
  flex: 1;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.companies-view {
  flex: 1;
  min-height: 0;
}

.companies-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.companies-empty {
  padding: 14px;
  color: var(--ink-soft);
  font-size: 13px;
}

.companies-table-wrap {
  overflow: auto;
}

.companies-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.companies-table th,
.companies-table td {
  border-bottom: 1px solid #e1e5eb;
  padding: 10px 11px;
  text-align: left;
  white-space: nowrap;
}

.companies-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f7fc;
  color: #344155;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.companies-table th.sortable {
  white-space: nowrap;
}

.companies-table .sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-transform: inherit;
  font-size: inherit;
  font-weight: 700;
}

.companies-table .sort-btn:hover {
  color: #3b6f9d;
}

.companies-table .sort-icon {
  font-size: 11px;
  opacity: 0.9;
}

.companies-table td:nth-child(3),
.companies-table td:nth-child(4),
.companies-table td:nth-child(5),
.companies-table td:nth-child(6) {
  font-variant-numeric: tabular-nums;
}

.companies-table tr:last-child td {
  border-bottom: 0;
}

.companies-table .pos {
  color: var(--pos);
  font-weight: 700;
}

.companies-table .neg {
  color: var(--neg);
  font-weight: 700;
}

.companies-table .flat {
  color: var(--flat);
  font-weight: 700;
}

.industry-jump {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 35;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #1f7fdb;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(140deg, #49a5ff 0%, #2588e8 100%);
  box-shadow: 0 10px 24px rgba(16, 38, 70, 0.34);
}

.industry-jump:hover {
  filter: brightness(1.03);
  border-color: #1579d8;
}

.status {
  margin-bottom: 7px;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid #bed5ef;
  color: #2c5d90;
  background: #ebf4ff;
  font-size: 12px;
}

.status[data-level="error"] {
  border-color: #f0c6c4;
  color: #a33833;
  background: #fdeceb;
}

.legend-wrap {
  padding: 0 2px 7px;
  max-width: 260px;
}

.legend-scale {
  width: 100%;
}

.legend-bar-single {
  width: 100%;
  height: 6px;
  border: 1px solid #c9ced8;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    #a92d39 0%,
    #cf5351 20%,
    #d98f79 40%,
    #9ea6b2 50%,
    #6cb67a 70%,
    #2da85f 100%
  );
}

.legend-ticks {
  margin-top: 2px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  font-size: 10px;
  color: #5c6574;
}

.legend-ticks span:nth-child(1) {
  text-align: left;
}

.legend-ticks span:nth-child(n + 2):nth-child(-n + 5) {
  text-align: center;
}

.legend-ticks span:nth-child(6) {
  text-align: right;
}

.map-viewport {
  flex: 1;
  min-height: 0;
  border: 1px solid #95a3b8;
  background: #1a2434;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.heatmap {
  position: relative;
  width: 100%;
  height: 100%;
}

.sector {
  position: absolute;
  border: 0;
  overflow: hidden;
  border-radius: 4px;
  background: #1b2331;
}

.sector-label {
  position: absolute;
  top: 2px;
  left: 4px;
  right: 4px;
  z-index: 10;
  display: block;
  padding: 0;
  font-size: 14px;
  color: #e6ecf4;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
  background: transparent;
  border: 0;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  pointer-events: auto;
  cursor: pointer;
}

.sub-sector {
  position: absolute;
  border: 0;
  overflow: hidden;
  border-radius: 3px;
}

.sub-sector-label {
  position: absolute;
  top: 1px;
  left: 3px;
  right: 3px;
  z-index: 9;
  display: block;
  padding: 0;
  font-size: 9px;
  color: #eef3f8;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
  background: transparent;
  border: 0;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  pointer-events: auto;
  cursor: pointer;
}

.sector.selected-group,
.sub-sector.selected-group {
  box-shadow: inset 0 0 0 2px #18a0ff;
}

.sub-sector.hovered-sub-sector {
  box-shadow: inset 0 0 0 2px #f4d21a;
}

.tile {
  position: absolute;
  border: 1px solid rgba(20, 28, 41, 0.34);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  cursor: pointer;
  z-index: 1;
  -webkit-tap-highlight-color: rgba(15, 122, 229, 0.18);
}

.tile.selected {
  box-shadow:
    inset 0 0 0 3px #18a0ff,
    inset 0 0 0 5px rgba(24, 160, 255, 0.32);
  z-index: 2;
}

.tile .ticker {
  font-weight: 700;
  line-height: 1.05;
}

.tile .change {
  font-weight: 600;
}

.strips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}

.strip {
  height: 28px;
  border-radius: 4px;
  color: #1c2430;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px;
  cursor: pointer;
  border: 1px solid #d4dbe6;
  background: #f6f8fb;
}

.strip:hover {
  background: #edf2f9;
}

.strip-change.pos {
  color: var(--pos);
}

.strip-change.neg {
  color: var(--neg);
}

.strip-change.flat {
  color: var(--flat);
}

.strip-placeholder {
  border: 1px dashed #c5cfdd;
  border-radius: 6px;
  background: #f6f8fb;
  color: #4f5a6d;
  font-size: 12px;
  padding: 10px;
}

.info-card {
  padding-bottom: 8px;
}

.info-card h2 {
  margin: 0;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg-panel-head);
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #344155;
}

.info-empty {
  padding: 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.info-body {
  padding: 10px;
}

.info-head {
  margin-bottom: 8px;
}

.info-ticker {
  font-size: 24px;
  font-weight: 700;
}

.info-name {
  font-size: 13px;
  color: #6f7788;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.info-grid > div {
  border: 1px solid #dae0e9;
  border-radius: 6px;
  padding: 7px;
  background: #fff;
}

.k {
  display: block;
  font-size: 10px;
  color: #5f6a7e;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.v {
  font-size: 13px;
  font-weight: 600;
}

.info-short-wrap {
  border: 1px solid #dae0e9;
  border-radius: 6px;
  background: #fff;
  padding: 8px;
}

.info-short {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.4;
}

.info-group-list {
  margin-top: 8px;
  border: 1px solid #d5dbe5;
  background: #f4f6fa;
  max-height: 280px;
  overflow: auto;
}

.group-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-bottom: 1px solid #d9dee8;
  font-size: 12px;
}

.group-row:last-child {
  border-bottom: 0;
}

.group-row.clickable {
  cursor: pointer;
}

.group-row.clickable:hover {
  background: #ebf0f8;
}

.group-row-main {
  min-width: 0;
}

.group-row-ticker {
  font-weight: 700;
  color: #182131;
}

.group-row-name {
  font-size: 11px;
  color: #5f6a7e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-row-cap {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #273247;
}

.group-row-change {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.group-row-change.pos {
  color: var(--pos);
}

.group-row-change.neg {
  color: var(--neg);
}

.group-row-change.flat {
  color: var(--flat);
}

.tooltip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  background: #121a28;
  color: #eff3fa;
  border: 1px solid #2f3e58;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.3;
}

.hidden {
  display: none;
}

@media (max-width: 1300px) {
  .controls {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr 1.4fr;
  }

  .col-resizer {
    display: none;
  }

  .right-col {
    grid-column: span 2;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
  }
}

@media (max-width: 980px) {
  :root {
    --touch-min: 44px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .left-rail {
    display: none;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "left actions lang"
      "search search search";
    gap: 10px;
  }

  .topbar-left h1 {
    font-size: clamp(17px, 4.4vw, 22px);
  }

  #meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    padding: 10px;
  }

  .mobile-pane-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: #e6e8eb;
    padding-top: 2px;
  }

  .dashboard-grid {
    display: block;
  }

  .dashboard-grid .column {
    display: none;
  }

  .dashboard-grid[data-mobile-pane="left"] .left-col,
  .dashboard-grid[data-mobile-pane="center"] .center-col,
  .dashboard-grid[data-mobile-pane="right"] .right-col {
    display: flex;
  }

  .map-card {
    min-height: clamp(330px, 60vh, 560px);
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .industry-jump {
    right: 12px;
    bottom: 12px;
    min-height: 36px;
    padding: 0 12px;
    font-size: 12px;
  }
}

@media (max-width: 620px) {
  .controls {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .controls select {
    min-height: 36px;
    font-size: 13px;
    padding: 0 7px;
  }

  .controls label {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
