:root {
  color-scheme: dark;
  --bg: #0c1016;
  --panel: #151b24;
  --panel-2: #101722;
  --line: #263342;
  --text: #e8edf4;
  --muted: #94a3b8;
  --good: #44d7a8;
  --warn: #f5c451;
  --bad: #ff6b73;
  --accent: #58a6ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { padding: 24px; min-width: 1180px; }
.topbar, .panel, .kpis, .charts-grid { margin-bottom: 18px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; font-weight: 760; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-bottom: 8px; }
#subtitle { color: var(--muted); margin-top: 8px; }

.controls, .panel-title, .panel-actions, .cost-tools p {
  display: flex;
  gap: 10px;
  align-items: center;
}
label {
  color: var(--muted);
  font-size: 13px;
}
input, select, button {
  border: 1px solid var(--line);
  background: #0f1520;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
}
.table-number-input {
  width: 96px;
  padding: 5px 8px;
  text-align: right;
}
button {
  cursor: pointer;
  background: #1c6ed0;
  border-color: #2b7bd7;
  font-weight: 650;
}
.secondary-button {
  background: #152033;
  border-color: var(--line);
}

.warnings {
  display: grid;
  gap: 8px;
}
.warning {
  border: 1px solid rgba(245, 196, 81, 0.45);
  background: rgba(245, 196, 81, 0.1);
  color: #ffe6a3;
  padding: 10px 12px;
  border-radius: 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.hidden { display: none; }
.panel-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.track-grid, .cost-grid, .upload-grid, .kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.track-card, .kpi, .cost-card, .upload-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.track-card input { width: 100%; margin-top: 8px; }
.track-card .settled { color: var(--good); font-size: 13px; margin-top: 8px; }
.cost-tools, .upload-tools { margin-top: 16px; display: block; }
.cost-tools p, .upload-tools p { color: var(--muted); display: block; margin-bottom: 12px; }
.cost-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cost-card input { width: 110px; }
.upload-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.upload-card {
  display: grid;
  gap: 10px;
}
.upload-card span {
  color: var(--text);
  font-weight: 700;
}
.upload-card input, .upload-card select {
  width: 100%;
}
.upload-status {
  color: var(--muted);
  min-height: 20px;
  margin-top: 10px;
  font-size: 13px;
}

.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 780; margin-top: 6px; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
}
.bar-chart {
  display: grid;
  gap: 12px;
}
.bar-row {
  display: grid;
  grid-template-columns: 88px minmax(160px, 1fr) 82px;
  gap: 10px;
  align-items: center;
  min-height: 30px;
}
.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #dce7f5;
  font-size: 13px;
}
.bar-track {
  height: 12px;
  background: #0b121d;
  border: 1px solid #223044;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, #44d7a8, #58a6ff);
}
.bar-fill.warn {
  background: linear-gradient(90deg, #f5c451, #ff9f43);
}
.bar-fill.bad {
  background: linear-gradient(90deg, #ff6b73, #f43f5e);
}
.bar-value {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}
.empty-chart {
  color: var(--muted);
  padding: 18px 0;
  text-align: center;
}

.table-wrap { overflow: auto; max-height: 520px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: right;
  white-space: nowrap;
}
tfoot td {
  background: #111a27;
  font-weight: 760;
}
th {
  position: sticky;
  top: 0;
  background: #1a2230;
  color: #c9d6e4;
  z-index: 1;
}
.sort-button {
  width: 100%;
  display: inline-flex;
  justify-content: flex-end;
  gap: 6px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
}
.sort-button.active {
  color: var(--accent);
}
.sort-button span {
  color: var(--muted);
}
th:first-child .sort-button,
th:nth-child(2) .sort-button,
th:nth-child(3) .sort-button {
  justify-content: flex-start;
}
th:first-child, td:first-child,
th:nth-child(2), td:nth-child(2),
th:nth-child(3), td:nth-child(3) { text-align: left; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.muted { color: var(--muted); }
.diagnostics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.diag-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.diag-card ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 15, 0.72);
}
.modal-panel {
  position: absolute;
  inset: 36px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}
.modal-subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 13px;
}
.match-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px;
  gap: 10px;
  margin-bottom: 12px;
}
.match-toolbar input,
.match-toolbar select {
  width: 100%;
}
.match-table-wrap {
  flex: 1;
  max-height: none;
}
.match-card-picker {
  display: grid;
  gap: 6px;
  min-width: 300px;
}
.match-card-search,
.match-card-select {
  width: 100%;
}
.match-card-count {
  min-height: 16px;
  font-size: 12px;
}
.match-small-input {
  width: 120px;
}
