:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --text: #12201a;
  --muted: #627367;
  --line: #d8dfd8;
  --accent: #2563eb;
  --accent-soft: #eaf0ff;
  --warn: #b45309;
  --shadow: 0 10px 28px rgba(21, 32, 24, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 13px;
  cursor: pointer;
}

button.secondary {
  background: #fff;
  color: var(--accent);
}

.nav-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  padding: 8px 13px;
  text-decoration: none;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 18px;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

main {
  padding: 18px 28px 32px;
  display: grid;
  gap: 16px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

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

.metric {
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metric strong {
  font-size: 20px;
  line-height: 1.15;
}

.panel-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

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

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px 16px 18px;
}

.legal-filters {
  grid-template-columns: minmax(260px, 2fr) minmax(180px, 1fr);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 7px 9px;
}

.scroll {
  overflow: auto;
  max-height: 66vh;
}

.month-summary {
  max-height: 320px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1680px;
}

.legal-table table {
  min-width: 1320px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8faf7;
  color: #314039;
  font-size: 13px;
}

.sort-head {
  border: 0;
  background: transparent;
  color: inherit;
  min-height: 0;
  padding: 0;
  font-weight: 700;
}

.sort-head.active {
  color: var(--accent);
}

.supplier-link {
  display: inline;
  min-height: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  text-align: left;
  font-weight: 700;
}

.supplier-link:hover {
  text-decoration: underline;
}

.supplier {
  font-weight: 700;
}

.supplier span,
.sub,
.reason {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  margin-top: 3px;
  max-width: 360px;
  white-space: normal;
}

.reason {
  max-width: 420px;
  margin-top: 0;
}

.analysis {
  display: grid;
  gap: 4px;
  max-width: 460px;
  white-space: normal;
}

.analysis strong {
  font-size: 12px;
  color: var(--accent);
}

.analysis span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.detail-panel {
  scroll-margin-top: 92px;
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.detail-note {
  padding: 0 16px 12px;
}

.detail-section {
  display: grid;
  gap: 8px;
  padding: 14px 16px 0;
}

.detail-section h3 {
  margin: 0;
  font-size: 15px;
}

.detail-table {
  max-height: 70vh;
}

.detail-table table {
  min-width: 1500px;
}

.status-detail {
  display: grid;
  gap: 6px;
  max-width: 280px;
  white-space: normal;
}

.status-detail span:not(.chip) {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.payment-list {
  display: grid;
  gap: 8px;
  min-width: 420px;
  max-width: 620px;
  white-space: normal;
}

.payment-item {
  display: grid;
  gap: 3px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eef2ed;
}

.payment-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.payment-item strong {
  font-size: 12px;
}

.payment-item span,
.payment-item p,
.payment-item em,
.payment-more {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.payment-item em {
  color: var(--accent);
  font-style: normal;
}

.mini-button {
  min-height: 32px;
  padding: 5px 10px;
  white-space: nowrap;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #fff4df;
  color: var(--warn);
  padding: 3px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.empty,
.empty-cell {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1000px) {
  .app-header {
    display: grid;
    padding: 18px 16px 12px;
  }

  main {
    padding: 14px 16px 24px;
  }

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

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    flex: 1;
  }
}
