:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --blue: #1d4ed8;
  --warn: #b45309;
  --danger: #b42318;
  --good: #047857;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
}

.subhead,
.refresh-meta,
.dirty-state {
  color: var(--muted);
  font-size: 13px;
}

.header-actions,
.input-actions,
.price-toolbar,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.tab,
.segment {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}

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

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

.primary-button:disabled {
  border-color: #aab4c3;
  background: #aab4c3;
  cursor: not-allowed;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  padding: 0;
  text-align: left;
}

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

.secondary-button:hover,
.tab:hover,
.segment:hover {
  background: #eef2f6;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.tab {
  min-width: 94px;
}

.tab.active,
.segment.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

main {
  padding: 18px 24px 32px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

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

.metric-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 5px;
  font-size: 22px;
  font-weight: 700;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 16px;
}

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

.panel-heading {
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.compact-select,
#entitySelect {
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px 10px;
}

.table-wrap {
  overflow: auto;
}

.data-table,
.input-table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

.data-table th,
.data-table td,
.input-table th,
.input-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: right;
}

.data-table th:first-child,
.data-table td:first-child,
.input-table th:first-child,
.input-table td:first-child {
  text-align: left;
}

.data-table th,
.input-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f9fafb;
  color: #344054;
  font-weight: 600;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
}

.status-ok {
  background: #ecfdf3;
  color: var(--good);
}

.status-warn {
  background: #fffaeb;
  color: var(--warn);
}

.warning-panel {
  margin-top: 16px;
}

.warning-list {
  padding: 10px 14px 14px;
}

.warning-item {
  border-left: 3px solid var(--warn);
  padding: 8px 10px;
  margin: 8px 0;
  background: #fffbeb;
}

.entity-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.summary-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}

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

.summary-cell .value {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 700;
}

.price-toolbar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: flex;
  gap: 4px;
}

.entity-warnings {
  padding: 0 14px 14px;
}

.input-panel {
  min-height: 560px;
}

.input-table-wrap {
  max-height: calc(100vh - 220px);
}

.input-table input {
  width: 100%;
  min-width: 72px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 5px 6px;
  background: transparent;
  color: var(--text);
  text-align: inherit;
}

.input-table input:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
}

.input-table tr.finished-row {
  background: #f8fafc;
}

.input-table td.missing-cell input {
  background: #fff7ed;
  border-color: #fed7aa;
}

.input-table td.warning-row-cell {
  color: var(--warn);
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 220px;
  max-width: 440px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

.negative,
.danger {
  color: var(--danger);
}

@media (max-width: 1100px) {
  .metric-grid,
  .split-grid,
  .entity-summary {
    grid-template-columns: 1fr;
  }

  .app-header,
  .header-actions,
  .panel-heading,
  .price-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}
