:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e1ec;
  --blue: #2563eb;
  --green: #12805c;
  --red: #b42318;
  --amber: #b7791f;
  --shadow: 0 12px 28px rgba(22, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

.app {
  width: min(1760px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 750;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: end;
}

input,
select,
button {
  height: 38px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
}

input {
  width: 240px;
}

input[type="date"] {
  width: 150px;
}

select {
  width: 220px;
}

#entitySelect {
  width: 300px;
}

#refreshButton {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

#refreshButton:disabled {
  cursor: wait;
  opacity: 0.65;
}

button {
  cursor: pointer;
  font-weight: 650;
}

button:hover,
th button:hover {
  border-color: var(--blue);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.quickbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -6px 0 12px;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: -8px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

#refreshStatus {
  color: var(--blue);
  font-weight: 650;
}

#refreshStatus.error {
  color: var(--red);
}

#refreshStatus.ok {
  color: var(--green);
}

.quick {
  height: 34px;
  background: #eef4ff;
}

.quick.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.columns-panel {
  margin: -2px 0 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.columns-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px 14px;
}

.columns-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
}

.columns-list input {
  width: auto;
  height: auto;
}

.metrics article,
.panel,
.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 15px 16px;
}

.metrics span,
.table-head span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  line-height: 1.1;
}

.overview {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.panel {
  padding: 14px 16px 16px;
  min-height: 190px;
}

.panel-title {
  font-size: 15px;
  font-weight: 750;
  margin-bottom: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 140px;
  gap: 12px;
  align-items: center;
  margin: 9px 0;
}

.bar-label {
  min-width: 0;
}

.bar-label strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.bar-label span {
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  height: 12px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: var(--blue);
}

.table-panel {
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager button {
  height: 32px;
}

.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pager select {
  width: 130px;
  height: 32px;
}

#pageLabel {
  min-width: 74px;
  color: var(--ink);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  height: calc(100vh - 408px);
  min-height: 420px;
  overflow: auto;
}

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

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

th {
  background: #eaf0f8;
  border-bottom: 1px solid var(--line);
  color: #223044;
  text-align: left;
  white-space: nowrap;
}

th button {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

td {
  max-width: 360px;
  padding: 9px 10px;
  border-bottom: 1px solid #edf1f6;
  vertical-align: top;
}

th:nth-child(1),
td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 1;
}

th:nth-child(1) {
  z-index: 3;
}

td:nth-child(1) {
  background: var(--panel);
}

tbody tr:hover td:nth-child(1) {
  background: #f7fbff;
}

tbody tr:hover {
  background: #f7fbff;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.muted-cell {
  color: var(--muted);
}

@media (max-width: 1240px) {
  body {
    min-width: 0;
  }

  .app {
    width: calc(100vw - 24px);
  }

  .topbar,
  .overview {
    grid-template-columns: 1fr;
    display: grid;
  }

  .toolbar {
    justify-content: start;
  }

  .columns-list {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .table-head {
    align-items: start;
    flex-direction: column;
    gap: 10px;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .table-wrap {
    height: 560px;
  }
}
