:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --ink-strong: #0d1524;
  --muted: #667084;
  --line: #dbe2ea;
  --line-soft: #edf1f5;
  --nav: #101827;
  --nav-soft: #172236;
  --orange: #ff4b1f;
  --orange-dark: #d93612;
  --green: #16885f;
  --green-action: #12a066;
  --red: #bd3636;
  --amber: #a56500;
  --blue: #2563a9;
  --shadow: 0 18px 42px rgba(18, 27, 43, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
  padding: 22px 18px;
  background: var(--nav);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--orange);
  color: #fff;
  font-size: 22px;
  font-weight: 850;
}

.brand strong,
.brand span,
.sidebar-footer strong,
.sidebar-footer span {
  display: block;
}

.brand strong {
  font-size: 15px;
  font-weight: 780;
}

.brand span,
.sidebar-footer span {
  margin-top: 2px;
  color: #aeb8c7;
  font-size: 12px;
  font-weight: 650;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: 6px;
}

.tab {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d7deea;
  text-align: left;
  font-weight: 720;
  cursor: pointer;
}

.tab:hover {
  background: var(--nav-soft);
  color: #fff;
}

.tab.active {
  background: #fff;
  border-color: #fff;
  color: var(--ink-strong);
  box-shadow: inset 4px 0 0 var(--orange);
}

.sidebar-footer {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-footer strong {
  margin-top: 6px;
  overflow: hidden;
  color: #fff;
  font-size: 12px;
  font-weight: 640;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-shell {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  gap: 18px;
  align-items: start;
  margin-bottom: 16px;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid #ffd2c5;
  border-radius: 999px;
  background: #fff0ea;
  color: var(--orange-dark);
  font-size: 12px;
  font-weight: 780;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 10px;
  color: var(--ink-strong);
  font-size: 28px;
  font-weight: 820;
  line-height: 1.12;
}

h2 {
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 800;
}

p {
  margin-top: 5px;
  color: var(--muted);
}

.run-panel,
.toolbar,
.adjustment-form,
.database-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.run-panel {
  justify-content: end;
  max-width: 720px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  letter-spacing: 0;
}

input,
select {
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(255, 75, 31, 0.18);
  outline-offset: 1px;
  border-color: var(--orange);
}

button {
  padding: 0 14px;
  font-weight: 780;
  cursor: pointer;
}

button:hover {
  border-color: #a8b5c5;
}

button:disabled {
  cursor: progress;
  opacity: 0.68;
}

.primary {
  background: var(--green-action);
  border-color: var(--green-action);
  color: #fff;
}

.primary:hover {
  border-color: #0e7b50;
  background: #0f8f5a;
}

.secondary {
  background: #fff7f4;
  border-color: #ffc7b8;
  color: var(--orange-dark);
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--orange);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric strong {
  display: block;
  overflow: hidden;
  margin-top: 5px;
  color: var(--ink-strong);
  font-size: 22px;
  font-weight: 850;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric.good {
  border-top-color: var(--green);
}

.metric.warn {
  border-top-color: var(--amber);
}

.metric.bad {
  border-top-color: var(--red);
}

.metric.good strong {
  color: var(--green);
}

.metric.warn strong {
  color: var(--amber);
}

.metric.bad strong {
  color: var(--red);
}

.workspace {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workspace-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.table-status {
  flex: none;
  max-width: 44%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

#searchInput {
  width: min(520px, 100%);
}

#readinessFilter {
  min-width: 160px;
}

.adjustments-panel,
.database-panel,
.dashboard-panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.dashboard-panel {
  display: grid;
  gap: 14px;
}

.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.dashboard-summary article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dashboard-summary span,
.investor-card span,
.composition-row span,
.panel-heading span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.dashboard-summary strong {
  display: block;
  overflow: hidden;
  margin-top: 5px;
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(280px, 0.9fr);
  gap: 14px;
}

.investor-panel,
.composition-panel {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h3 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 14px;
  font-weight: 820;
}

.investor-list,
.composition-bars {
  display: grid;
  gap: 10px;
}

.investor-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

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

.investor-card strong {
  display: block;
  overflow: hidden;
  color: var(--ink-strong);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.investor-card b {
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
}

.bar-track {
  grid-column: 1 / -1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}

.bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--orange);
}

.composition-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.composition-row strong {
  display: block;
  color: var(--ink-strong);
  font-weight: 820;
}

.composition-row.om .bar-track i {
  background: var(--blue);
}

.composition-row.terra .bar-track i {
  background: var(--green);
}

.table-wrap.dashboard-table {
  max-height: 44vh;
}

.adjustment-form,
.database-form {
  align-items: end;
}

.adjustment-form label,
.database-form label {
  min-width: 180px;
}

.adjustment-form .wide,
.database-form .wide {
  min-width: min(380px, 100%);
  flex: 1;
}

.file-field input {
  padding-top: 7px;
}

.database-detail {
  margin-top: 12px;
}

.source-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.6fr);
  gap: 14px;
}

.source-catalog,
.source-detail {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-catalog {
  max-height: 620px;
  overflow: auto;
}

.source-list {
  display: grid;
  gap: 14px;
}

.source-group {
  display: grid;
  gap: 6px;
}

.source-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
}

.source-group-head strong {
  color: var(--ink-strong);
}

.source-item {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: left;
}

.source-item:hover {
  border-color: #ffc7b8;
  background: #fff8f5;
}

.source-item.active {
  border-color: var(--orange);
  background: #fff4ef;
  box-shadow: inset 4px 0 0 var(--orange);
}

.source-item span,
.source-item strong,
.source-item small {
  min-width: 0;
  display: block;
}

.source-item strong {
  overflow: hidden;
  color: var(--ink-strong);
  font-size: 13px;
  font-weight: 820;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-item small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.source-item b {
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.source-item b.good {
  color: var(--green);
}

.source-item b.bad {
  color: var(--red);
}

.source-detail {
  display: grid;
  gap: 12px;
}

.source-actions,
.source-editor-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.source-actions {
  justify-content: flex-start;
}

.source-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #ffc7b8;
  border-radius: 8px;
  background: #fff8f5;
}

.source-row-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.source-row-form label {
  min-width: 0;
}

.source-row-form input {
  width: 100%;
}

.source-editor-actions {
  justify-content: flex-end;
}

.source-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.source-detail-head h3 {
  margin: 4px 0 0;
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 850;
}

.source-detail-head p {
  max-width: 760px;
}

.source-domain {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #fff0ea;
  color: var(--orange-dark);
  font-size: 12px;
  font-weight: 780;
}

.database-grids {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.mini-table-wrap {
  max-height: 250px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-preview {
  max-height: 380px;
}

.source-formulas {
  max-height: 380px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 338px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f8;
  color: #334155;
  font-size: 12px;
  font-weight: 820;
}

tbody tr:hover {
  background: #fff8f5;
}

td.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-actions {
  flex-wrap: nowrap;
}

.row-actions button {
  min-height: 30px;
  padding: 0 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #405065;
  font-size: 12px;
  font-weight: 780;
}

.pill.good {
  background: #e5f6ef;
  color: var(--green);
}

.pill.bad {
  background: #fae9e9;
  color: var(--red);
}

.pill.warn {
  background: #fff0d5;
  color: var(--amber);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(460px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink-strong);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }

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

  .run-panel {
    justify-content: start;
    max-width: none;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

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

  .source-layout {
    grid-template-columns: 1fr;
  }

  .source-catalog {
    max-height: 360px;
  }

  .source-row-form {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    min-height: auto;
    gap: 14px;
    padding: 14px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .tab {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .tab.active {
    box-shadow: inset 0 -4px 0 var(--orange);
  }

  .sidebar-footer {
    display: none;
  }

  .main-shell {
    padding: 14px;
  }

  h1 {
    font-size: 23px;
  }

  .run-panel,
  .toolbar,
  .adjustment-form,
  .database-form {
    align-items: stretch;
  }

  .run-panel label,
  .adjustment-form label,
  .database-form label,
  .run-panel button,
  .adjustment-form button,
  .database-form button,
  #searchInput,
  #readinessFilter {
    width: 100%;
  }

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

  .workspace-head {
    display: grid;
  }

  .table-status {
    max-width: 100%;
    text-align: left;
  }

  .database-grids {
    grid-template-columns: 1fr;
  }

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

  .source-detail-head {
    display: grid;
  }

  .source-row-form {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 62vh;
  }
}

@media (max-width: 440px) {
  .metrics,
  .dashboard-summary {
    grid-template-columns: 1fr;
  }
}
