:root {
  --bg: #08110f;
  --panel: rgba(16, 31, 28, 0.86);
  --panel-2: rgba(224, 232, 210, 0.08);
  --line: rgba(225, 238, 215, 0.14);
  --text: #edf5e8;
  --muted: #9faf9d;
  --green: #91d06b;
  --gold: #f2c14e;
  --red: #e36f52;
  --blue: #73a7ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 78% 8%, rgba(145, 208, 107, 0.18), transparent 24rem),
    radial-gradient(circle at 38% 40%, rgba(115, 167, 255, 0.12), transparent 28rem),
    linear-gradient(135deg, #07100e 0%, #101a17 55%, #20190f 100%);
}

button,
input,
select {
  font: inherit;
}

.bi-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
}

.bi-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-content: start;
  gap: 0.75rem;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: rgba(4, 12, 10, 0.74);
  backdrop-filter: blur(18px);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.brand span {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 16px;
  color: #07100e;
  background: var(--green);
  font-weight: 900;
}

.brand strong {
  font-size: 1.2rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.search-select {
  position: relative;
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.search-select-input {
  height: 40px;
}

.search-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  min-height: 28px;
}

.selected-chip {
  padding: 0.25rem 0.45rem;
  border: 1px solid rgba(145, 208, 107, 0.35);
  border-radius: 999px;
  color: var(--text);
  background: rgba(145, 208, 107, 0.14);
  font-size: 0.78rem;
  font-weight: 700;
}

.selected-empty {
  color: var(--muted);
  font-size: 0.82rem;
}

.search-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 30;
  display: none;
  height: 170px;
  min-height: 170px;
  overflow: auto;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: #10201c;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
}

.search-select.open .search-list {
  display: block;
}

.search-list option {
  padding: 0.42rem 0.5rem;
  border-radius: 8px;
}

.search-list option:checked {
  color: #07100e;
  background: var(--green);
}

button,
.ghost-link {
  border: 0;
  border-radius: 16px;
  padding: 0.85rem 1rem;
  color: #07100e;
  background: var(--green);
  font-weight: 800;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.ghost-link {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.side-title {
  margin: 0.4rem 0 0.45rem;
  color: var(--green);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.report-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-right: 0.2rem;
}

.report-nav-item {
  width: 100%;
  padding: 0.58rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

.report-nav-item.active {
  color: #07100e;
  background: var(--green);
}

.bi-main {
  min-width: 0;
  padding: 1rem;
}

.bi-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.overline {
  margin: 0 0 0.4rem;
  color: var(--green);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 3.2rem);
  letter-spacing: -0.04em;
}

h2 {
  font-size: 1.05rem;
}

.report-date {
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
}

.filter-panel {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 140px 140px minmax(220px, 1fr) minmax(220px, 1fr) minmax(220px, 1fr) 170px;
  gap: 0.65rem;
  align-items: end;
  min-height: 116px;
  margin-bottom: 0.85rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(6, 18, 15, 0.92);
  backdrop-filter: blur(16px);
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.kpi {
  min-width: 0;
  min-height: 132px;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(255,255,255,0.1), rgba(255,255,255,0.035));
  overflow: hidden;
}

.kpi span {
  color: var(--muted);
}

.kpi strong {
  display: block;
  margin-top: 0.65rem;
  font-size: clamp(1.2rem, 1.7vw, 1.9rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.kpi em {
  display: block;
  margin-top: 0.55rem;
  color: var(--green);
  font-style: normal;
}

.bi-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 0.85rem;
}

.report-page {
  display: none;
}

.report-page.active {
  display: block;
}

.visual {
  min-height: 320px;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.report-card {
  min-height: calc(100vh - 190px);
}

.wide {
  grid-row: span 2;
}

.full {
  grid-column: 1 / -1;
}

.visual-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.visual-head span {
  color: var(--muted);
  font-size: 0.9rem;
}

.bars {
  display: grid;
  gap: 0.85rem;
}

.bar-row {
  display: grid;
  gap: 0.35rem;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.bar-track {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.compact .bar-track {
  height: 12px;
}

.bi-table {
  max-height: calc(100vh - 300px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.bi-table table {
  width: 100%;
  min-width: 1100px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.bi-table th,
.bi-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.bi-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--green);
  background: #0d1b18;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.bi-table td {
  max-width: 360px;
  line-height: 1.35;
}

.bi-table.profitability-view {
  max-height: none;
  overflow: visible;
  border: 0;
}

.profitability-blocks {
  display: grid;
  gap: 1rem;
}

.profitability-block {
  min-width: 0;
}

.profitability-block h3 {
  margin: 0 0 0.5rem;
  color: var(--text);
  font-size: 1rem;
}

.profitability-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.profitability-table table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.profitability-table th,
.profitability-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.profitability-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--green);
  background: #0d1b18;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.profitability-table td.number-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.profitability-table .row-index {
  width: 58px;
  color: var(--muted);
  background: #0d1b18;
  font-variant-numeric: tabular-nums;
}

.profitability-table .empty-cell {
  color: rgba(237, 245, 232, 0.42);
}

.excel-report {
  min-height: 520px;
}

.sheet-tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  margin-bottom: 0.8rem;
  padding-bottom: 0.25rem;
}

.sheet-tab {
  flex: 0 0 auto;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.sheet-tab.active {
  color: #07100e;
  background: var(--green);
}

.sheet-meta {
  margin-bottom: 0.8rem;
  color: var(--muted);
}

.empty-state {
  padding: 1.2rem;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .bi-shell,
  .bi-grid,
  .filter-panel {
    grid-template-columns: 1fr;
  }

  .bi-sidebar {
    position: static;
    height: auto;
  }

  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wide,
  .full {
    grid-column: auto;
    grid-row: auto;
  }
}

/* ===== Финансы (KPI блок) ===== */
.finance-card .finance-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.4rem;
}
.finance-summary .finance-tile {
  padding: 0.95rem 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255,255,255,0.075), rgba(255,255,255,0.025));
}
.finance-summary .finance-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
}
.finance-summary .finance-tile strong {
  display: block;
  margin-top: 0.45rem;
  font-size: 1.35rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.finance-summary .finance-tile em {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
}

.credit-deals-table .credit-deal-row td:first-child {
  min-width: 260px;
}

.credit-deals-table .credit-deal-row strong,
.credit-deals-table .credit-deal-row span {
  display: block;
}

.credit-deals-table .credit-deal-row span {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.credit-deals-table .credit-detail-row td {
  padding-top: 0;
  background: rgba(255, 255, 255, 0.035);
}

.credit-records summary {
  cursor: pointer;
  color: var(--gold);
  font-weight: 700;
  padding: 0.45rem 0;
}

.credit-record-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.credit-record-table table {
  min-width: 900px;
}

.credit-record-table th,
.credit-record-table td {
  font-size: 0.82rem;
}

.credit-record-table td:last-child {
  min-width: 220px;
}

@media (max-width: 760px) {
  .finance-card .finance-summary {
    grid-template-columns: 1fr;
  }
}

/* ===== Встроенный конструктор отчетов ===== */
.report-page-builder {
  display: none;
}
.report-page-builder.active {
  display: block;
}
.report-builder-main {
  min-width: 0;
}
.report-builder-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.report-builder-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

/* Группы и список листов внутри левого сайдбара дашборда */
.bi-sidebar .sidebar-divider {
  height: 1px;
  margin: 0.4rem 0;
  background: var(--line);
}
.bi-sidebar .group-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}
.bi-sidebar .group-tab {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.8rem;
  text-align: center;
  cursor: pointer;
}
.bi-sidebar .group-tab.active {
  color: #07100e;
  background: var(--gold);
}
.bi-sidebar .report-nav-inline {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.bi-sidebar .report-nav-inline .report-nav-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}
.bi-sidebar .report-nav-inline .report-nav-item.active {
  color: #07100e;
  background: var(--green);
}
.bi-sidebar .report-nav-inline .report-nav-item span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bi-sidebar .report-nav-inline .report-nav-item.active span {
  color: rgba(7, 16, 14, 0.7);
}
