:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #17202a;
  --muted: #667085;
  --line: #d7dee8;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --danger: #b42318;
  --warning: #b54708;
  --ok: #027a48;
  --shadow: 0 14px 30px rgba(17, 24, 39, 0.08);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Roboto", "Arial", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
  margin-bottom: 12px;
}

.topbar-actions,
.toolbar,
.form-actions,
.action-stack {
  display: flex;
  align-items: end;
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 13px 16px;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

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

.panel {
  display: none;
}

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

.field {
  display: grid;
  gap: 5px;
  min-width: 150px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  padding: 9px 10px;
  min-height: 38px;
}

.field.compact {
  min-width: 190px;
}

.search-field {
  min-width: min(420px, 100%);
  flex: 1;
}

.toolbar {
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 38px;
  padding: 9px 13px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.ghost-button {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  font-size: 20px;
}

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

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.metric small {
  color: var(--muted);
}

.report-template-header {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.report-template-header img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #0f6b3a;
}

.report-template-header h2 {
  color: #000;
  font-size: 20px;
  line-height: 1.35;
  margin: 14px 0 8px;
  text-align: center;
  text-transform: uppercase;
}

.report-template-header div {
  color: #000;
  font-style: italic;
  text-align: right;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 16px;
  align-items: start;
}

.input-layout {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: var(--shadow);
}

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

.data-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 1080px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: #344054;
  white-space: nowrap;
}

.data-table td.number,
.data-table th.number {
  text-align: right;
  white-space: nowrap;
}

.row-level-0 td {
  background: #eaf7f5;
  font-weight: 800;
}

.row-level-1 td {
  background: #f8fbff;
  font-weight: 700;
}

.side-panel,
.edit-form,
.approval-box,
.review-grid > div,
.mapping-grid > div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.summary-list,
.validation-list,
.history-list,
.lineage-list {
  display: grid;
  gap: 8px;
}

.summary-item,
.validation-item,
.history-item,
.lineage-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #fbfcfe;
}

.validation-item.warning {
  border-color: #fedf89;
  background: #fffbeb;
}

.validation-item.danger {
  border-color: #fecdca;
  background: #fff3f1;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: #175cd3;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

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

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

.badge.danger {
  background: #fef3f2;
  color: var(--danger);
}

.mini-chart {
  display: grid;
  gap: 8px;
}

.chart-block {
  margin: 14px 0;
}

.chart-block h2 {
  margin-bottom: 8px;
}

.pie-chart {
  width: min(190px, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  margin: 10px auto 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 18px var(--surface);
}

.pie-legend {
  display: grid;
  gap: 7px;
}

.pie-legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto 44px;
  gap: 7px;
  align-items: center;
  font-size: 12px;
}

.pie-legend-row span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-legend-row strong,
.pie-legend-row em {
  white-space: nowrap;
}

.pie-legend-row em {
  color: var(--muted);
  font-style: normal;
  text-align: right;
}

.pie-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.pie-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 10px 0;
  text-align: center;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 52px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent-2);
}

.action-stack {
  align-items: stretch;
  flex-direction: column;
}

.edit-form {
  display: grid;
  gap: 11px;
}

.form-grid,
.month-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.entries-wrap {
  margin-top: 16px;
}

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

.definition-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  margin: 0 0 14px;
}

.definition-list dt {
  color: var(--muted);
  font-weight: 700;
}

.definition-list dd {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.danger-text {
  color: var(--danger);
}

@media (max-width: 1100px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .split-layout,
  .input-layout,
  .review-grid,
  .mapping-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar {
    width: 100%;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  main {
    padding: 14px;
  }

  .metric-grid,
  .form-grid,
  .month-grid {
    grid-template-columns: 1fr;
  }

  .data-table {
    min-width: 940px;
  }

  .report-template-header {
    padding: 8px;
  }

  .report-template-header h2 {
    font-size: 15px;
  }
}

@media print {
  body {
    background: white;
  }

  .topbar,
  .tabs,
  .toolbar,
  .metric-grid,
  .side-panel,
  .panel:not(#dashboard) {
    display: none !important;
  }

  main {
    padding: 0;
  }

  #dashboard {
    display: block !important;
  }

  .metric-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .split-layout {
    display: block;
  }

  .table-wrap {
    box-shadow: none;
    border: 0;
    overflow: visible;
  }

  .report-template-header {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0 0 8px;
    padding: 0;
    page-break-after: avoid;
  }

  .report-template-header img {
    border: 0;
    max-height: 82px;
    object-fit: contain;
  }

  .report-template-header h2 {
    font-size: 14px;
    margin: 8px 0 4px;
  }

  .report-template-header div {
    font-size: 11px;
  }

  .report-table-wrap {
    max-height: none;
  }

  .data-table {
    min-width: 0;
    font-size: 11px;
  }

  .data-table th,
  .data-table td {
    border: 1px solid #000;
    padding: 4px;
    font-size: 9px;
  }

  .data-table th {
    background: #d9ead3 !important;
    color: #000;
  }

  .row-level-0 td {
    background: #eaf7f5 !important;
  }
}
