:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: #172033;
  background: #f3f5f8;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f3f5f8;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

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

.query-sidebar {
  background: #152033;
  color: #f8fafc;
  padding: 24px 18px;
}

.query-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.query-brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 8px;
  background: #f5b84b;
  color: #111827;
  font-weight: 800;
}

.query-brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.query-brand p,
.query-nav-item span,
.query-eyebrow {
  margin: 0;
  color: #9fb0c8;
  font-size: 13px;
}

.query-nav {
  display: grid;
  gap: 10px;
}

.query-nav-item {
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #f8fafc;
  text-align: left;
  text-decoration: none;
}

.query-nav-item strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.query-nav-item.active {
  border-color: #f5b84b;
  background: rgba(245, 184, 75, 0.16);
}

.query-workspace {
  min-width: 0;
  padding: 28px;
}

.query-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.query-eyebrow {
  color: #7a8799;
}

.query-header h2 {
  margin: 5px 0 0;
  font-size: 28px;
  line-height: 1.2;
}

.query-header-state {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #687589;
  font-size: 13px;
}

.query-state {
  min-width: 96px;
  padding: 9px 12px;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  background: #fff;
  color: #23683f;
  text-align: center;
  font-weight: 700;
}

.query-state.error {
  color: #a12d24;
}

.query-toolbar {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #d6dce4;
}

.query-tabs {
  display: flex;
  align-self: stretch;
  gap: 24px;
}

.query-toolbar-actions {
  display: flex;
  gap: 8px;
}

.query-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: #6f7b8e;
  font-weight: 700;
}

.query-tab.active {
  color: #172033;
}

.query-tab.active::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 3px;
  background: #2d6cdf;
  content: "";
}

.query-button {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 7px;
  font-weight: 700;
}

.query-button.primary {
  border: 1px solid #2d6cdf;
  background: #2d6cdf;
  color: #fff;
}

.query-button.secondary {
  border: 1px solid #cfd6df;
  background: #fff;
  color: #283448;
}

.query-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.query-filter-band {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #d8dee7;
  border-radius: 8px;
  background: #fff;
}

.query-filter-grid {
  display: grid;
  gap: 12px;
}

.query-filter-grid.primary {
  grid-template-columns:
    minmax(105px, 0.75fr)
    minmax(105px, 0.7fr)
    minmax(170px, 1.15fr)
    minmax(120px, 0.8fr)
    minmax(170px, 1.1fr)
    minmax(145px, 0.95fr)
    minmax(190px, 1.25fr);
}


.query-filter-grid label {
  display: grid;
  min-width: 0;
  gap: 6px;
  color: #455269;
  font-size: 13px;
  font-weight: 700;
}

.query-filter-grid input,
.query-filter-grid select,
.query-page-size select {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  background: #fff;
  color: #172033;
}

.query-filter-grid input:focus,
.query-filter-grid select:focus,
.query-page-size select:focus {
  border-color: #2d6cdf;
  outline: 2px solid rgba(45, 108, 223, 0.14);
}


.query-filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.query-notice {
  margin-top: 14px;
  padding: 11px 13px;
  border-left: 4px solid #2d6cdf;
  background: #eef4ff;
  color: #2b4c82;
  font-size: 13px;
}

.query-notice.error {
  border-left-color: #c7483d;
  background: #fff0ee;
  color: #8f2d25;
}

.query-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  margin-top: 16px;
  border: 1px solid #d8dee7;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.query-metrics > div {
  min-width: 0;
  padding: 13px 14px;
  border-right: 1px solid #e1e5eb;
}

.query-metrics > div:last-child {
  border-right: 0;
}

.query-metrics span {
  display: block;
  margin-bottom: 5px;
  color: #748094;
  font-size: 12px;
}

.query-metrics strong {
  display: block;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.query-metrics .positive {
  color: #287a4c;
}

.query-metrics .negative {
  color: #b43b32;
}

.query-metrics .warning {
  color: #a05f00;
}

.query-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 50px;
  margin-top: 16px;
}

.query-table-toolbar > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.query-table-toolbar strong {
  font-size: 15px;
}

.query-table-toolbar span {
  color: #758196;
  font-size: 12px;
}

.query-page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #687589;
  font-size: 12px;
}

.query-page-size select {
  width: 72px;
  height: 34px;
}

.query-table-wrap {
  max-width: 100%;
  border: 1px solid #d8dee7;
  border-radius: 8px;
  background: #fff;
  overflow: auto;
}

.query-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.query-table th,
.query-table td {
  max-width: 280px;
  padding: 10px 12px;
  border-right: 1px solid #e4e8ee;
  border-bottom: 1px solid #e4e8ee;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.query-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f7f8fa;
  color: #425068;
  font-size: 12px;
}

.query-table th:first-child,
.query-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
}

.query-table th:first-child {
  z-index: 3;
  background: #f7f8fa;
}

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

.query-table th:last-child,
.query-table td:last-child {
  border-right: 0;
}

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

.query-table td.counterparty {
  max-width: 240px;
  font-weight: 700;
}

.query-table .query-empty {
  height: 120px;
  color: #7b8797;
  text-align: center;
}

.query-pagination {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.query-pagination span {
  color: #667389;
  font-size: 13px;
}

.reconciliation-banner {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 12px 16px;
  border-left: 4px solid #d39124;
  background: #fff7e8;
}

.reconciliation-banner div {
  display: grid;
  gap: 4px;
}

.reconciliation-banner strong {
  color: #714a08;
}

.reconciliation-banner span {
  color: #896321;
  font-size: 13px;
}

.adjustment-banner {
  border-left-color: #34755c;
  background: #edf7f2;
}

.adjustment-banner strong {
  color: #245b46;
}

.adjustment-banner span {
  color: #3e6f5d;
}

.adjustment-breakdown {
  display: flex;
  min-height: 54px;
  align-items: stretch;
  gap: 1px;
  margin-top: 12px;
  border: 1px solid #d8dee7;
  border-radius: 8px;
  background: #d8dee7;
  overflow: hidden;
}

.adjustment-breakdown > div {
  display: flex;
  min-width: 190px;
  flex: 1 1 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  background: #fff;
}

.adjustment-breakdown span,
.adjustment-breakdown p {
  color: #687589;
  font-size: 12px;
}

.adjustment-breakdown strong {
  color: #245b46;
  font-size: 14px;
  white-space: nowrap;
}

.adjustment-breakdown p {
  width: 100%;
  margin: 0;
  padding: 16px;
  background: #fff;
  text-align: center;
}

.query-table-wrap.compact {
  max-height: 420px;
}

.query-table-toolbar.detail {
  margin-top: 22px;
}

.query-column-dialog,
.query-update-dialog {
  width: min(840px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(16, 28, 48, 0.25);
}

.query-column-dialog::backdrop,
.query-update-dialog::backdrop {
  background: rgba(14, 24, 40, 0.45);
}

.query-column-dialog form,
.query-update-dialog form {
  display: grid;
  max-height: inherit;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.query-update-dialog {
  width: min(520px, calc(100vw - 32px));
}

.query-update-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.query-update-body label {
  display: grid;
  gap: 6px;
  color: #455269;
  font-size: 13px;
  font-weight: 700;
}

.query-update-body input,
.query-update-body select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  background: #fff;
  color: #172033;
}

.query-update-body input[readonly] {
  background: #f5f7fa;
  color: #5b687b;
}

.query-update-periods {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.query-update-status {
  min-height: 54px;
  padding: 11px 12px;
  border-left: 4px solid #8b98aa;
  background: #f3f5f8;
  color: #4b596e;
  font-size: 13px;
  line-height: 1.6;
}

.query-update-status.running {
  border-left-color: #2d6cdf;
  background: #eef4ff;
  color: #2b4c82;
}

.query-update-status.done {
  border-left-color: #2c8152;
  background: #edf8f1;
  color: #23683f;
}

.query-update-status.failed {
  border-left-color: #c7483d;
  background: #fff0ee;
  color: #8f2d25;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

.dialog-header {
  border-bottom: 1px solid #e1e5eb;
}

.dialog-header p,
.dialog-header h3 {
  margin: 0;
}

.dialog-header p {
  color: #758196;
  font-size: 12px;
}

.dialog-header h3 {
  margin-top: 3px;
  font-size: 18px;
}

.column-presets {
  display: flex;
  gap: 8px;
  padding: 14px 18px 0;
}

.column-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 14px 18px;
  padding-right: 4px;
  overflow: auto;
}

.column-choices label {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #e0e5eb;
  border-radius: 6px;
  color: #35435a;
  font-size: 13px;
}

.column-choices input {
  flex: 0 0 auto;
}

.column-choices span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-actions {
  border-top: 1px solid #e1e5eb;
}

.dialog-actions span {
  color: #687589;
  font-size: 13px;
}

@media (max-width: 1500px) {
  .query-filter-grid.primary {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .query-metrics {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .query-metrics > div:nth-child(3) {
    border-right: 0;
  }

  .query-metrics > div:nth-child(-n + 3) {
    border-bottom: 1px solid #e1e5eb;
  }
}

@media (max-width: 900px) {
  .query-shell {
    grid-template-columns: 1fr;
  }

  .query-sidebar {
    padding: 18px;
  }

  .query-brand {
    margin-bottom: 16px;
  }

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

  .query-nav-item {
    min-height: 58px;
  }

  .query-workspace {
    padding: 20px;
  }

  .query-filter-grid.primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .query-workspace {
    padding: 16px;
  }

  .query-header,
  .query-header-state,
  .query-toolbar,
  .query-filter-actions,
  .reconciliation-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .query-header {
    align-items: flex-start;
  }

  .query-header-state {
    width: 100%;
    gap: 8px;
  }

  .query-state {
    width: 100%;
  }

  .query-toolbar {
    align-items: stretch;
    padding-bottom: 10px;
  }

  .query-toolbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .adjustment-breakdown {
    display: grid;
    grid-template-columns: 1fr;
  }

  .query-tabs {
    min-height: 44px;
  }

  .query-filter-grid.primary,
  .query-metrics,
  .column-choices {
    grid-template-columns: 1fr;
  }

  .query-metrics > div {
    border-right: 0;
    border-bottom: 1px solid #e1e5eb;
  }

  .query-metrics > div:last-child {
    border-bottom: 0;
  }

  .query-filter-actions .query-button {
    width: 100%;
  }

  .column-presets {
    flex-wrap: wrap;
  }

  .query-update-periods {
    grid-template-columns: 1fr;
  }
}
