:root {
  --bg: #fcfcfd;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --border: #dde2e8;
  --border-light: #eceff3;
  --text: #1a2332;
  --text-secondary: #3d4f63;
  --text-muted: #6b7c90;
  --accent: #1a3352;
  --accent-soft: #2d4a6a;
  --accent-muted: rgba(26, 51, 82, 0.06);
  --green: #0d7a4f;
  --green-bg: #e8f5e9;
  --red: #b42318;
  --red-bg: #ffcdd2;
  --amber: #92600a;
  --amber-bg: #fff9c4;
  --header-bg: #2b2c2f;
  --header-text: #f3f5f7;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(12, 20, 33, 0.04);
  --shadow: 0 4px 24px rgba(12, 20, 33, 0.05);
  --shadow-lg: 0 12px 40px rgba(12, 20, 33, 0.06);
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --font: Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: 200;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

.header-inner {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .75rem 1.5rem;
  max-width: 1600px; margin: 0 auto; width: 100%;
}

.brand { flex-shrink: 0; min-width: 0; }
.brand-title { font-weight: 600; font-size: .95rem; color: #fff; line-height: 1.25; white-space: nowrap; }
.brand-sub { font-size: .68rem; color: rgba(243, 245, 247, .72); margin-top: .12rem; white-space: nowrap; }

.top-nav {
  display: flex; align-items: center; gap: .35rem; flex: 1;
  min-width: 0; overflow-x: auto; scrollbar-width: none;
}
.top-nav::-webkit-scrollbar { display: none; }

.nav-group {
  font-size: .62rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: rgba(232, 238, 245, .42);
  padding: 0 .35rem; white-space: nowrap;
}
.nav-divider {
  width: 1px; height: 1.25rem; background: rgba(255, 255, 255, .14);
  margin: 0 .15rem; flex-shrink: 0;
}
.top-nav a {
  display: inline-block; padding: .48rem .72rem; border-radius: 8px;
  color: rgba(232, 238, 245, .88); text-decoration: none; font-size: .82rem;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.top-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.top-nav a.active { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 500; }

.header-meta {
  flex-shrink: 0; text-align: right;
  font-size: .72rem; color: rgba(232, 238, 245, .55);
}
.gen-label { margin-bottom: .12rem; }
.gen-time { color: #fff; font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gen-time-flash { animation: gen-flash 0.9s ease; }
@keyframes gen-flash {
  0% { color: #7dd3fc; }
  100% { color: #fff; }
}

.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  max-width: 1600px; margin: 0 auto; width: 100%;
}

.page-header {
  padding: 1.1rem 1.75rem 0;
}
.page-title {
  font-size: 1.15rem; font-weight: 600; margin: 0;
  letter-spacing: -.01em;
}

.content {
  padding: 1rem 1.75rem 2.5rem;
  animation: fadeUp .35s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.section { margin-bottom: 1.75rem; }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; margin-bottom: .85rem; flex-wrap: wrap;
}
.section-head-end { justify-content: flex-end; }
.section-head-start { justify-content: flex-start; }
.section-title {
  font-size: .95rem; font-weight: 600; margin: 0;
  letter-spacing: -.01em; color: var(--text);
}
.section-sub { font-size: .78rem; color: var(--text-muted); margin: .2rem 0 0; }
.unit-hint { font-size: .72rem; color: var(--text-muted); font-weight: 400; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.panel:hover { box-shadow: var(--shadow); }
.panel-body { padding: 1.1rem 1.25rem; }

.meta-row {
  display: flex; flex-wrap: wrap; gap: .55rem; margin-bottom: 1.25rem;
}
.meta-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .7rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border-light);
  font-size: .76rem; color: var(--text-secondary);
}
.meta-pill strong { color: var(--text); font-weight: 600; }

.mkt-tabs, .seg-tabs {
  display: inline-flex; gap: .25rem; padding: .2rem;
  background: var(--surface-elevated); border: 1px solid var(--border-light);
  border-radius: 999px;
}
.mkt-tabs button, .seg-tabs button {
  border: none; background: transparent; cursor: pointer;
  padding: .42rem .85rem; border-radius: 999px;
  font-size: .78rem; font-weight: 500; color: var(--text-muted);
  transition: all var(--transition); font-family: inherit;
}
.mkt-tabs button.active, .seg-tabs button.active {
  background: var(--surface); color: var(--accent);
  box-shadow: var(--shadow-sm); font-weight: 600;
}
.tool-toggle {
  border: 1px solid var(--border-light);
  background: var(--surface-elevated);
  color: var(--text-muted);
  cursor: pointer;
  padding: .42rem .9rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition);
  white-space: nowrap;
}
.tool-toggle:hover { color: var(--text); border-color: var(--accent-soft); }
.tool-toggle.active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent-soft);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.chart-box { height: 380px; width: 100%; min-width: 0; }
.chart-box.tall { height: 480px; }
.chart-box.compact { height: 300px; }
.ring-box { height: 240px; width: 100%; min-width: 0; overflow: visible; }
.panel.ring-panel { overflow: visible; }
.ring-layout {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(180px, 1.1fr);
  gap: .85rem 1rem;
  align-items: center;
}
.ring-legend {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: .55rem;
}
.ring-legend li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: .55rem;
  align-items: start;
  font-size: .78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}
.ring-legend .swatch {
  width: 10px; height: 10px; border-radius: 2px; margin-top: .25rem;
  flex-shrink: 0;
}
.ring-legend .lbl { min-width: 0; white-space: normal; }
.ring-legend .val {
  font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap;
}
@media (max-width: 640px) {
  .ring-layout { grid-template-columns: 1fr; }
  .ring-box { height: 180px; }
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.stat-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.stat-table th, .stat-table td {
  padding: .65rem .85rem; text-align: left; border-bottom: 1px solid var(--border-light);
}
.stat-table th { color: var(--text-muted); font-weight: 500; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 400; white-space: nowrap; }

.instrument-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 18.5rem);
  gap: .85rem 1rem;
  align-items: start;
}
.instrument-layout .chart-box.tall {
  height: clamp(320px, calc(100vh - 15.5rem), 520px);
  min-height: 280px;
}
.instrument-metrics {
  background: var(--surface-elevated, #f7f9fb);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: .55rem .7rem .45rem;
  width: 100%;
}
.instrument-metrics h3 {
  font-size: .78rem;
  font-weight: 600;
  margin: 0 0 .35rem;
  color: var(--text);
}
.instrument-metrics .stat-table {
  width: 100%;
  font-size: .74rem;
}
.instrument-metrics .stat-table td {
  padding: .28rem 0;
  border-bottom: 1px solid var(--border-light);
  vertical-align: baseline;
}
.instrument-metrics .stat-table tr:last-child td { border-bottom: none; }
.instrument-metrics .stat-table td:first-child {
  padding-right: .75rem;
  color: var(--text-secondary, var(--text-muted));
  white-space: nowrap;
}
.instrument-metrics .stat-table td.num {
  padding-left: .5rem;
  font-size: .76rem;
}
.instrument-export {
  margin-top: .65rem;
  padding-top: .55rem;
  border-top: 1px solid var(--border-light);
}
.instrument-export .export-hint {
  font-size: .68rem;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.instrument-export .export-btns {
  margin-left: 0;
}
@media (max-width: 900px) {
  .instrument-layout {
    grid-template-columns: 1fr;
  }
  .instrument-metrics { max-width: 20rem; }
  .instrument-layout .chart-box.tall {
    height: clamp(280px, 48vh, 420px);
  }
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  max-width: 100%;
}
.table-wrap.scroll-box {
  overflow: auto;
  max-height: 68vh;
}
/* Достаточность ставок риска: таблица растёт со страницей, без внутреннего скролла */
.table-wrap.risk-table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  max-height: none;
}
.table-wrap.scroll-box .data-table {
  border-collapse: separate;
  border-spacing: 0;
}
.data-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: .82rem; table-layout: auto; }
.data-table.table-compact { table-layout: fixed; width: 100%; }
.data-table.table-compact th,
.data-table.table-compact td {
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table th {
  position: sticky; top: 0; z-index: 5;
  background: #ffffff;
  border-bottom: 1px solid #c8ced6;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  padding: .65rem .7rem; text-align: left;
  font-size: .72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  cursor: pointer; user-select: none;
  vertical-align: bottom;
}
.data-table th.col-num {
  text-align: right;
}
.data-table th .th-inner {
  display: inline-flex; align-items: center; gap: .2rem; max-width: 100%;
}
.data-table th.col-num .th-inner {
  justify-content: flex-end;
  width: 100%;
}
.data-table th .th-label { white-space: nowrap; }
.data-table th[data-k="shortname"] {
  max-width: 14rem;
  white-space: normal;
  line-height: 1.25;
}
.data-table th[data-k="shortname"] .th-inner {
  flex-wrap: wrap;
  align-items: flex-start;
}
.data-table th[data-k="shortname"] .th-label {
  white-space: normal;
  overflow-wrap: break-word;
}
.data-table th[data-k="ticker"] {
  white-space: nowrap;
}
.btn-filter {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-muted); font-size: .72rem; line-height: 1;
  padding: .15rem .2rem; border-radius: 4px; opacity: .55;
}
.btn-filter:hover, .btn-filter.active {
  opacity: 1; color: var(--accent); background: var(--accent-muted);
}
.col-filter-menu {
  position: fixed; z-index: 10000; min-width: 240px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: .75rem;
  text-align: left; text-transform: none; letter-spacing: normal;
  font-weight: 400; color: var(--text); cursor: default;
}
.col-filter-menu label {
  display: block; font-size: .72rem; color: var(--text-muted); margin: .35rem 0 .3rem;
}
.col-filter-menu label:first-child { margin-top: 0; }
.col-filter-menu select,
.col-filter-menu input {
  width: 100%; box-sizing: border-box;
  margin-bottom: .15rem; padding: .4rem .5rem;
  border: 1px solid var(--border); border-radius: 7px;
  font: inherit; font-size: .78rem; background: #fff;
}
.col-filter-menu .col-filter-actions { margin-top: .55rem; }
.col-filter-actions { display: flex; gap: .4rem; justify-content: flex-end; }
.col-filter-actions button {
  border: 1px solid var(--border); background: #fff; border-radius: 7px;
  padding: .35rem .6rem; font: inherit; font-size: .74rem; cursor: pointer;
}
.col-filter-actions button.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.data-table th:hover { color: var(--text); }
.data-table td {
  padding: .62rem .7rem; border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tbody tr { transition: background var(--transition); }
.data-table .col-ticker {
  white-space: nowrap;
  padding-right: .5rem;
}
.ticker-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed rgba(26, 51, 82, 0.35);
  padding-bottom: 1px;
  transition: color var(--transition), border-color var(--transition);
}
.ticker-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}
.ticker-link:focus-visible {
  outline: 2px solid var(--accent-soft, rgba(26, 51, 82, 0.35));
  outline-offset: 2px;
  border-radius: 2px;
}
.data-table .col-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 400; white-space: nowrap; }
.data-table .col-emphasis {
  font-weight: 400;
  background: rgba(26, 51, 82, 0.03);
  white-space: nowrap;
}
.data-table th.col-emphasis {
  background: #e9eef4;
  color: var(--accent);
}
.data-table th.sorted { color: var(--accent); }
.sort-icon {
  display: inline-block; margin-left: .25rem; font-size: .62rem;
  opacity: .35; vertical-align: middle;
}
.sort-icon.sort-active { opacity: 1; color: var(--accent); font-weight: 700; }
.eod-date-label {
  font-size: .78rem; color: var(--text-muted); display: flex; align-items: center; gap: .45rem;
}
.eod-date-label select {
  padding: .4rem .55rem; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: .78rem; background: var(--surface);
}
.data-table .col-sub { font-size: .74rem; color: var(--text-muted); font-weight: 400; white-space: normal; }
.data-table .col-shortname {
  max-width: 14rem;
  min-width: 8rem;
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
  line-height: 1.35;
}
.data-table .hl-red { background: var(--red-bg) !important; }
.data-table .hl-yellow { background: var(--amber-bg) !important; }
.data-table .hl-green { background: var(--green-bg) !important; }
.data-table .hl-yellow-conc { background: #fff8e1 !important; }
.data-table tr.hl-yellow td.col-emphasis { background: #fff3b0 !important; }
.data-table tr.hl-red td.col-emphasis { background: #ffb4b4 !important; }
.data-table tr.hl-green td.col-emphasis { background: #dcedc8 !important; }
.data-table tr.hl-yellow-conc td.col-emphasis { background: #ffecb3 !important; }

.pos { color: var(--green); font-weight: 400; }
.neg { color: var(--red); font-weight: 400; }

.leaders-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.leaders-head {
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: .55rem 1.35rem;
  margin-bottom: .85rem;
}
.leaders-head .section-title { line-height: 1.3; }
.leaders-head .seg-tabs {
  margin-top: .28rem;
  margin-left: .35rem;
  align-self: center;
}
.leader-list { list-style: none; margin: 0; padding: 0; }
.leader-list .leader-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto auto; gap: .65rem;
  padding: 0 0 .45rem; margin-bottom: .35rem;
  border-bottom: 1px solid var(--border-light);
  font-size: .68rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.leader-list .leader-head span:nth-child(n+2) { text-align: right; min-width: 4.2rem; }
.leader-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto auto; gap: .65rem;
  align-items: baseline;
  padding: .55rem 0; border-bottom: 1px solid var(--border-light);
  font-size: .82rem;
}
.leader-list li:last-child { border-bottom: none; }
.leader-list .ticker-block {
  min-width: 0;
  justify-self: start;
  width: max-content;
  max-width: 100%;
}
.leader-list .ticker-block .ticker-link {
  display: inline-block;
  font-size: .86rem;
  font-weight: 600;
  max-width: 100%;
}
.leader-list .ticker-block .ticker-name {
  display: block;
  width: max-content;
  max-width: 100%;
  font-size: .74rem;
  font-style: normal;
  color: var(--text-muted);
  margin-top: .1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leader-list .metric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 4.2rem; }
.leader-list .metric.price { min-width: 4.8rem; color: var(--text); }
.leader-list .metric.sub { font-size: .78rem; color: var(--text-muted); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: .65rem; align-items: center;
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--border-light);
  background: var(--surface-elevated);
}
.toolbar input[type=search] {
  flex: 1; min-width: 180px; max-width: 280px;
  padding: .48rem .75rem; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; font-size: .82rem;
  background: var(--surface); transition: border-color var(--transition);
}
.toolbar input:focus { outline: none; border-color: var(--accent-soft); }
.export-btns { display: inline-flex; gap: .35rem; margin-left: auto; }
.btn-export {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: .4rem .7rem;
  font: inherit;
  font-size: .76rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn-export:hover {
  border-color: var(--accent-soft);
  color: var(--accent);
  background: var(--accent-muted);
}

.hint-bar {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .85rem; margin-bottom: .75rem;
  background: var(--accent-muted); border: 1px solid rgba(26,51,82,.1);
  border-radius: 8px; font-size: .78rem; color: var(--text-secondary);
}
.hint-bar svg, .hint-bar .icon { opacity: .7; }

.back-link {
  display: inline-flex; align-items: center; gap: .35rem;
  margin-bottom: 1rem; color: var(--accent-soft); text-decoration: none;
  font-size: .82rem; font-weight: 500;
}
.back-link:hover { color: var(--accent); }

.stat-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.stat-pill {
  padding: .35rem .7rem; border-radius: 8px;
  background: var(--surface-elevated); border: 1px solid var(--border-light);
  font-size: .78rem; color: var(--text-secondary);
}

.chart-controls {
  display: flex; gap: .65rem; flex-wrap: wrap; align-items: center;
  margin-bottom: .85rem; padding-bottom: .85rem;
  border-bottom: 1px solid var(--border-light);
}
.chart-controls label {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .78rem; color: var(--text-secondary); cursor: pointer;
}
.chart-controls input { accent-color: var(--accent); }
.chart-controls select {
  margin-left: auto; padding: .4rem .65rem; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; font-size: .78rem; background: var(--surface);
}

.empty {
  padding: 3rem 1rem; text-align: center; color: var(--text-muted); font-size: .88rem;
}

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .leaders-grid { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
}
@media (max-width: 768px) {
  .header-inner { flex-wrap: wrap; padding: .65rem 1rem; gap: .65rem; }
  .top-nav { order: 3; width: 100%; padding-bottom: .15rem; }
  .header-meta { margin-left: auto; }
  .content, .page-header { padding-left: 1rem; padding-right: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
