:root {
  --app-background: #f4f6f8;
  --app-surface: #ffffff;
  --app-surface-muted: #f8fafb;
  --app-text: #17202a;
  --app-text-muted: #62707d;
  --app-border: #dce2e8;
  --app-border-strong: #c8d0d8;
  --app-accent: #176b87;
  --app-accent-dark: #0f5168;
  --app-accent-soft: #e8f3f6;
  --app-positive: #176946;
  --app-negative: #a23b3b;
  --app-warning: #8a5b13;
  --app-header-height: 52px;
  --app-sidebar-width: 212px;
}

[hidden] {
  display: none !important;
}

.app-shell,
.app-shell *,
.app-shell *::before,
.app-shell *::after {
  box-sizing: border-box;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f4f6f8;
  color: #62707d;
}

.auth-loading__content {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 500 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #cbd4dc;
  border-top-color: var(--app-accent);
  border-radius: 50%;
  animation: app-spin 700ms linear infinite;
}

@keyframes app-spin {
  to {
    transform: rotate(360deg);
  }
}

.landing-actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.landing-sign-in {
  min-height: 38px;
  padding: 8px 18px;
  border: 1px solid rgba(34, 230, 255, 0.4);
  border-radius: 7px;
  background: rgba(5, 12, 22, 0.75);
  color: #eaf6ff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.landing-sign-in:hover {
  border-color: rgba(34, 230, 255, 0.75);
  background: rgba(10, 25, 39, 0.9);
}

body.app-authenticated {
  overflow: hidden;
  background: var(--app-background);
  color: var(--app-text);
  font: 400 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app-shell {
  min-height: 100vh;
  background: var(--app-background);
}

.app-header {
  position: fixed;
  z-index: 30;
  inset: 0 0 auto;
  height: var(--app-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 18px;
  border-bottom: 1px solid var(--app-border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--app-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-brand__mark {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--app-text);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.app-brand__environment {
  margin-left: 2px;
  padding: 2px 6px;
  border: 1px solid var(--app-border);
  border-radius: 4px;
  color: var(--app-text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.app-account {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-account__identity {
  max-width: 280px;
  overflow: hidden;
  color: var(--app-text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button-subtle {
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #4a5967;
  font-size: 12px;
  font-weight: 600;
}

.button-subtle:hover {
  border-color: var(--app-border);
  background: var(--app-surface-muted);
  color: var(--app-text);
}

.app-sidebar {
  position: fixed;
  z-index: 20;
  inset: var(--app-header-height) auto 0 0;
  width: var(--app-sidebar-width);
  padding: 18px 12px;
  border-right: 1px solid var(--app-border);
  background: #f8f9fa;
}

.app-nav__label {
  display: block;
  padding: 0 10px 7px;
  color: #7a8792;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-nav__item {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px 7px 12px;
  border-radius: 6px;
  color: #41505d;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.app-nav__item[aria-current="page"] {
  background: #e9edf0;
  color: var(--app-text);
}

.app-nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  width: 3px;
  height: 18px;
  border-radius: 0 2px 2px 0;
  background: var(--app-accent);
}

.app-main {
  height: 100vh;
  margin-left: var(--app-sidebar-width);
  padding-top: var(--app-header-height);
  overflow: auto;
}

.app-content {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.page-heading {
  margin-bottom: 17px;
}

.page-heading__eyebrow {
  margin: 0 0 3px;
  color: var(--app-accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-heading h1 {
  margin: 0;
  color: var(--app-text);
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.page-heading__description {
  margin: 4px 0 0;
  color: var(--app-text-muted);
  font-size: 13px;
}

.panel {
  border: 1px solid var(--app-border);
  border-radius: 8px;
  background: var(--app-surface);
  box-shadow: 0 1px 2px rgba(20, 30, 40, 0.025);
}

.filter-panel {
  margin-bottom: 16px;
  padding: 16px 18px 14px;
}

.filter-form {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: #455361;
  font-size: 11px;
  font-weight: 650;
}

.field input,
.field select {
  width: 164px;
  height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--app-border-strong);
  border-radius: 5px;
  outline: none;
  background: #ffffff;
  color: var(--app-text);
  font-size: 13px;
}

.field select {
  width: 220px;
}

.field input:focus,
.field select:focus {
  border-color: var(--app-accent);
  box-shadow: 0 0 0 2px rgba(23, 107, 135, 0.12);
}

.button-primary {
  min-height: 34px;
  padding: 7px 14px;
  border: 1px solid var(--app-accent-dark);
  border-radius: 5px;
  background: var(--app-accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.button-primary:hover {
  background: var(--app-accent-dark);
}

.button-primary:disabled {
  cursor: wait;
  border-color: #8e9ba5;
  background: #9ba7b0;
}

.filter-panel__note {
  margin: 10px 0 0;
  color: #74818c;
  font-size: 11px;
}

.filter-panel__context {
  margin: 10px 0 0;
  color: #455361;
  font-size: 11px;
  font-weight: 650;
}

.field-error {
  margin: 9px 0 0;
  color: var(--app-negative);
  font-size: 12px;
  font-weight: 550;
}

.results-panel {
  min-height: 300px;
  overflow: hidden;
}

.results-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--app-border);
}

.results-header h2 {
  margin: 0;
  color: var(--app-text);
  font-size: 14px;
  font-weight: 700;
}

.results-meta {
  color: var(--app-text-muted);
  font-size: 11px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  border-bottom: 1px solid var(--app-border);
}

.summary-card {
  min-height: 78px;
  padding: 13px 16px;
  border-right: 1px solid var(--app-border);
}

.summary-card:last-child {
  border-right: 0;
}

.summary-card__label {
  display: block;
  margin-bottom: 5px;
  color: #74818c;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.summary-card__value {
  color: var(--app-text);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.summary-card__value.is-negative,
.money.is-negative {
  color: var(--app-negative);
}

.results-state {
  min-height: 250px;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
}

.results-state__content {
  max-width: 420px;
}

.results-state__content .spinner {
  margin: 0 auto 12px;
}

.results-state h3 {
  margin: 0 0 6px;
  color: #34424e;
  font-size: 14px;
  font-weight: 700;
}

.results-state p {
  margin: 0;
  color: var(--app-text-muted);
  font-size: 12px;
}

.results-state--error h3 {
  color: var(--app-negative);
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

.settlements-table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
  color: #33414d;
  font-size: 11px;
}

.settlements-table th {
  position: sticky;
  z-index: 5;
  top: 0;
  padding: 8px 10px;
  border-bottom: 1px solid var(--app-border-strong);
  background: #f7f9fa;
  color: #64727e;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.025em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.settlements-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e8ecef;
  background: #ffffff;
  vertical-align: middle;
}

.settlements-table tbody tr:hover td {
  background: #f9fbfc;
}

.category-row td {
  min-height: 44px;
  font-size: 12px;
  font-weight: 600;
}

.category-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 2px 4px 2px 0;
  border: 0;
  background: transparent;
  color: var(--app-text);
  font-weight: 650;
  text-align: left;
}

.category-toggle__icon {
  width: 7px;
  height: 7px;
  border-right: 1.5px solid #64727e;
  border-bottom: 1.5px solid #64727e;
  transform: rotate(-45deg);
  transition: transform 120ms ease;
}

.category-toggle[aria-expanded="true"] .category-toggle__icon {
  transform: rotate(45deg) translate(-1px, -1px);
}

.charge-detail-row > td {
  padding: 0 14px 14px 34px;
  background: #f8fafb;
}

.charge-detail-row:hover > td {
  background: #f8fafb !important;
}

.charge-detail-table {
  width: 100%;
  border: 1px solid var(--app-border);
  border-radius: 6px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  background: #ffffff;
  font-size: 11px;
}

.charge-detail-table th {
  position: static;
  padding: 7px 9px;
  background: #f2f5f7;
}

.charge-detail-table td {
  padding: 8px 9px;
}

.charge-name,
.charge-code {
  display: block;
}

.charge-name {
  color: #34424e;
  font-weight: 600;
}

.charge-code {
  margin-top: 2px;
  color: #788590;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

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

.cell-number,
.money {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cell-id {
  color: #5c6b77;
  font-variant-numeric: tabular-nums;
}

.cell-period {
  min-width: 170px;
  white-space: nowrap;
}

.cell-code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10.5px;
  white-space: nowrap;
}

.kind-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #edf1f3;
  color: #53616d;
  font-size: 10px;
  font-weight: 700;
  text-transform: capitalize;
}

.kind-badge--credit {
  background: #edf6f1;
  color: var(--app-positive);
}

.auth-failure {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--app-background);
  color: var(--app-text);
  text-align: center;
}

.auth-failure h1 {
  margin: 0 0 8px;
  color: var(--app-text);
  background: none;
  font: 650 20px/1.3 ui-sans-serif, system-ui, sans-serif;
  animation: none;
}

.auth-failure p {
  margin: 0;
  color: var(--app-text-muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  :root {
    --app-sidebar-width: 176px;
  }

  .app-content {
    padding-inline: 20px;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  body.app-authenticated {
    overflow: auto;
  }

  .app-header {
    padding-inline: 12px;
  }

  .app-brand__environment,
  .app-account__identity {
    display: none;
  }

  .app-sidebar {
    position: fixed;
    inset: var(--app-header-height) 0 auto;
    width: auto;
    height: 44px;
    padding: 5px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--app-border);
  }

  .app-nav__label {
    display: none;
  }

  .app-nav__item {
    width: fit-content;
    min-height: 32px;
    padding-inline: 12px;
  }

  .app-nav__item[aria-current="page"]::before {
    inset: auto 10px 0;
    width: auto;
    height: 2px;
  }

  .app-main {
    height: auto;
    min-height: 100vh;
    margin-left: 0;
    padding-top: calc(var(--app-header-height) + 44px);
    overflow: visible;
  }

  .app-content {
    padding: 18px 12px 30px;
  }

  .filter-form {
    align-items: stretch;
  }

  .field,
  .field input,
  .field select,
  .button-primary {
    width: 100%;
  }

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

  .summary-card,
  .summary-card:nth-child(2) {
    border-right: 0;
    border-bottom: 1px solid var(--app-border);
  }

  .summary-card:last-child {
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1400ms;
  }
}
