:root {
  --color-primary: #0172e3;
  --color-primary-dark: #005bb6;
  --color-primary-soft: #e8f2ff;
  --color-bg: #eef3f8;
  --color-bg-deep: #dfe8f3;
  --color-panel: #ffffff;
  --color-panel-muted: #f8fafd;
  --color-border: #d4deea;
  --color-border-strong: #b7c6d8;
  --color-text: #101828;
  --color-muted: #64748b;
  --color-sidebar: #0f1724;
  --color-sidebar-accent: #1b2b42;
  --color-success: #147a46;
  --color-warning: #b7791f;
  --color-danger: #b42318;
  --shadow-panel: 0 10px 26px rgba(15, 23, 36, 0.07);
  --shadow-soft: 0 4px 14px rgba(15, 23, 36, 0.06);
  --font-sans: "Segoe UI", "Aptos", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", monospace;
  --sidebar-width: 232px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 18% 0%, rgba(1, 114, 227, 0.08), transparent 32%),
    linear-gradient(180deg, #f7faff 0%, var(--color-bg) 58%, var(--color-bg-deep) 100%);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--color-sidebar);
  color: #f5f8fc;
  padding: 16px 14px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 8px 0 30px rgba(15, 23, 36, 0.12);
}

.brand {
  margin-bottom: 18px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo-link {
  display: inline-flex;
  width: 194px;
  max-width: 100%;
  align-items: center;
}

.brand-logo {
  display: block;
  width: 100%;
  max-height: 48px;
  height: auto;
  object-fit: contain;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid transparent;
  background: transparent;
  color: #dce7f5;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.nav-link.active,
.nav-link:hover {
  background: var(--color-sidebar-accent);
  border-color: rgba(255, 255, 255, 0.08);
  color: #fff;
  box-shadow: inset 3px 0 0 #29a7ff;
}

.nav-link.disabled {
  color: #8294ad;
  cursor: default;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(212, 222, 234, 0.82);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 1.42rem;
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.68rem;
  color: var(--color-muted);
  font-weight: 750;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-success);
  font-weight: 750;
  box-shadow: 0 1px 0 rgba(15, 23, 36, 0.03);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border: 1px solid var(--color-border);
  background: #fff;
}

.user-meta {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.user-meta span {
  color: var(--color-muted);
  font-size: 0.78rem;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.message-item {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-weight: 650;
}

.async-message {
  display: none;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  background: var(--color-primary-soft);
  box-shadow: var(--shadow-soft);
}

.async-message-local {
  margin: 0;
  padding: 10px;
  font-size: 0.88rem;
}

.async-message:not(:empty) {
  display: block;
}

.async-message-info {
  border-color: rgba(1, 114, 227, 0.35);
  color: var(--color-primary-dark);
}

.async-message-success {
  border-color: rgba(20, 122, 70, 0.35);
  color: var(--color-success);
}

.async-message-warning {
  border-color: #d9a441;
  background: #fff8e6;
  color: #7a4d00;
}

.async-message-error {
  border-color: #d96b6b;
  background: #fff3f3;
  color: #7d1d1d;
}

.hero-grid,
.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  padding: 16px;
  box-shadow: var(--shadow-panel);
}

.main > .panel,
.main > .metric-grid,
.main > .panel-grid,
.main > .async-message {
  margin-bottom: 14px;
}

.panel-grid > .panel,
.metric-grid > .metric-card {
  margin-bottom: 0;
}

.panel-hero {
  background:
    linear-gradient(135deg, rgba(1, 114, 227, 0.09), rgba(1, 114, 227, 0.02)),
    var(--color-panel);
}

.panel h2 {
  margin: 4px 0 9px;
  font-size: 1.26rem;
  line-height: 1.14;
  letter-spacing: -0.03em;
}

.panel p {
  line-height: 1.48;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  background: var(--color-primary);
  color: #fff;
  border: 1px solid var(--color-primary);
  font: inherit;
  font-weight: 750;
  line-height: 1.1;
  box-shadow: 0 5px 12px rgba(1, 114, 227, 0.16);
  cursor: pointer;
}

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

.button-secondary {
  background: #fff;
  color: var(--color-primary);
  box-shadow: none;
}

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

.button-danger:hover {
  border-color: #921b13;
  background: #921b13;
}

.button-small {
  min-height: 30px;
  padding: 6px 9px;
  font-size: 0.82rem;
}

.button-ghost {
  background: #fff;
  color: var(--color-text);
  border-color: var(--color-border);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.filter-actions {
  display: flex;
  align-items: end;
  gap: 7px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric-card {
  border: 1px solid var(--color-border);
  background:
    linear-gradient(135deg, rgba(1, 114, 227, 0.08), transparent 58%),
    #fff;
  padding: 13px 14px;
  box-shadow: var(--shadow-soft);
}

.metric-card strong {
  display: block;
  margin: 3px 0;
  font-size: 1.16rem;
  line-height: 1.16;
  letter-spacing: -0.03em;
}

.metric-card span,
.muted-note {
  color: var(--color-muted);
  font-size: 0.82rem;
}

.setup-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.setup-step {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.setup-step span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--color-border);
  font-weight: 800;
  background: #fff;
}

.setup-step strong {
  font-size: 1rem;
}

.setup-step p {
  margin: 0;
  color: var(--color-muted);
  line-height: 1.45;
}

.setup-step-done {
  border-color: rgba(20, 122, 70, 0.35);
  background: rgba(20, 122, 70, 0.06);
}

.setup-step-done span {
  border-color: rgba(20, 122, 70, 0.35);
  color: var(--color-success);
}

.setup-step-blocked {
  border-color: #d9a441;
  background: #fff8e6;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  padding: 3px 7px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
  color: var(--color-text);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1.2;
  white-space: nowrap;
}

.pill-success {
  border-color: rgba(20, 122, 70, 0.35);
  background: rgba(20, 122, 70, 0.08);
  color: var(--color-success);
}

.pill-warning {
  border-color: #d9a441;
  background: #fff8e6;
  color: #7a4d00;
}

.pill-danger {
  border-color: #d96b6b;
  background: #fff3f3;
  color: #7d1d1d;
}

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

.plain-list,
.check-list {
  margin: 14px 0 0;
  padding-left: 18px;
}

.plain-list li,
.check-list li {
  margin-bottom: 10px;
  line-height: 1.5;
}

.single-panel {
  max-width: 720px;
}

.auth-panel h2 {
  margin-bottom: 8px;
}

.stack-form {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.form-field {
  display: grid;
  gap: 5px;
}

.form-field span {
  color: #334155;
  font-size: 0.78rem;
  font-weight: 750;
}

.form-field input,
.form-field select {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  font: inherit;
  box-shadow: inset 0 1px 0 rgba(15, 23, 36, 0.03);
}

.form-field input[type="checkbox"] {
  width: auto;
  justify-self: start;
}

.form-field input:disabled {
  color: var(--color-muted);
  background: var(--color-panel-muted);
}

.form-field textarea {
  width: 100%;
  min-height: 96px;
  padding: 9px 10px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  font: inherit;
}

.form-errors {
  padding: 10px;
  border: 1px solid #d96b6b;
  background: #fff3f3;
  color: #7d1d1d;
}

.form-errors p,
.field-error,
.field-help {
  margin: 0;
}

.field-error {
  color: #b42318;
}

.field-help {
  color: var(--color-muted);
  font-size: 0.82rem;
  line-height: 1.42;
}

.recaptcha-field {
  padding: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.manual-cost-panel {
  padding: 16px;
}

.manual-cost-heading {
  align-items: center;
}

.manual-cost-heading p {
  max-width: 820px;
}

.manual-cost-form {
  margin-top: 12px;
}

.manual-cost-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: 12px;
  align-items: stretch;
}

.manual-cost-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--color-border);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.manual-cost-card-main {
  background:
    linear-gradient(180deg, rgba(1, 114, 227, 0.035), transparent 42%),
    #fff;
}

.manual-cost-card-side {
  align-content: start;
  background: var(--color-panel-muted);
}

.manual-cost-card-header h3 {
  margin: 3px 0 0;
  font-size: 1.06rem;
}

.manual-cost-card-header p:not(.eyebrow) {
  margin: 8px 0 0;
  color: var(--color-muted);
}

.manual-cost-field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.manual-cost-amount-field {
  grid-column: span 2;
}

.manual-cost-inline-help {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-muted);
  font-size: 0.84rem;
}

.manual-cost-note-field textarea {
  min-height: 132px;
}

.manual-cost-sources {
  margin: 0;
  padding: 0;
  border: 0;
}

.manual-cost-sources legend {
  margin-bottom: 8px;
  font-weight: 700;
}

.manual-cost-source-list {
  max-height: 258px;
  overflow: auto;
  padding: 5px;
  border: 1px solid var(--color-border);
  background: #fff;
}

.manual-cost-source-list > div,
.manual-cost-source-list li {
  list-style: none;
}

.manual-cost-source-list ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.manual-cost-source-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.88rem;
}

.manual-cost-source-list label:hover {
  border-color: rgba(1, 114, 227, 0.18);
  background: #f1f8ff;
}

.manual-cost-source-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
}

.manual-cost-summary {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid rgba(20, 122, 70, 0.28);
  background: rgba(20, 122, 70, 0.06);
}

.manual-cost-summary p {
  margin: 0;
  color: var(--color-muted);
  line-height: 1.45;
}

.manual-cost-submit {
  justify-self: stretch;
  text-align: center;
}

.manual-cost-history-panel {
  margin-top: 12px;
}

.manual-cost-history-heading p {
  margin: 0;
  color: var(--color-muted);
}

.manual-cost-filter-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(220px, 1fr) minmax(160px, 0.8fr) auto;
  gap: 10px;
  align-items: end;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.manual-cost-filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.manual-cost-table td {
  vertical-align: top;
}

.manual-cost-table .is-muted {
  color: var(--color-muted);
  background: #f9fafb;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.status-active {
  color: #05603a;
  background: #d1fadf;
}

.status-void {
  color: #912018;
  background: #fee4e2;
}

.table-subtext {
  display: block;
  margin-top: 5px;
  color: var(--color-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.manual-cost-void-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.manual-cost-void-form input[type="text"] {
  min-width: 170px;
  padding: 7px 9px;
  border: 1px solid var(--color-border);
}

.manual-cost-empty-state {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 14px;
  border: 1px dashed var(--color-border);
  background: var(--color-panel-muted);
}

.manual-cost-empty-state h3,
.manual-cost-empty-state p {
  margin: 0;
}

.runbook-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.runbook-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.runbook-card p {
  margin: 0;
  color: var(--color-muted);
  line-height: 1.45;
}

.runbook-card code {
  display: block;
  padding: 7px 9px;
  overflow: auto;
  background: #fff;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.table-wrap {
  margin-top: 10px;
  overflow-x: auto;
  width: 100%;
  border: 1px solid var(--color-border);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 0;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3f7fb;
  color: #334155;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.035em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--color-border);
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: #f8fbff;
}

.data-table td strong {
  font-weight: 800;
}

.commission-final-amount {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: max-content;
  padding: 3px 8px;
  border: 1px solid rgba(14, 165, 233, 0.28);
  border-radius: 999px;
  background: linear-gradient(135deg, #eef9ff, #f7fcff);
  color: #075985;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.68);
  font-variant-numeric: tabular-nums;
}

.metric-card.is-final-commission,
.calculation-summary-card.is-final-commission {
  border-color: rgba(14, 165, 233, 0.34);
  background: linear-gradient(135deg, #f7fcff, #fff);
  box-shadow: inset 3px 0 0 #0ea5e9;
}

.data-table td:nth-child(n + 4):not(:last-child) {
  font-variant-numeric: tabular-nums;
}

.source-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.source-group-card {
  padding: 12px;
  border: 1px solid var(--color-border);
  background: linear-gradient(135deg, #fff, #f7fbff);
}

.source-group-card h3 {
  margin: 2px 0 8px;
  font-size: 1.05rem;
}

.source-group-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--color-muted);
  font-size: 0.8rem;
}

.source-section-tabs {
  margin-top: 14px;
}

.source-stats-filter {
  display: flex;
  gap: 8px;
  align-items: end;
}

.source-stats-filter .form-field {
  min-width: 180px;
  margin: 0;
}

.source-stats-group {
  margin-top: 14px;
}

.source-stats-group-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.source-stats-group-heading h2,
.source-stats-group-heading p {
  margin-bottom: 0;
}

.source-stats-subtitle {
  margin: 14px 0 0;
  font-size: 0.95rem;
  font-weight: 850;
}

.source-stats-group-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 360px;
}

.source-stats-group-metrics span {
  display: grid;
  gap: 2px;
  min-width: 116px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  background: #f8fbff;
  color: var(--color-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.source-stats-group-metrics strong {
  color: var(--color-text);
  font-size: 0.95rem;
  text-transform: none;
}

.source-stats-group-metrics strong.trend-positive {
  color: #147a46;
}

.source-stats-group-metrics strong.trend-negative {
  color: #b42318;
}

.source-stats-group-metrics strong.trend-neutral {
  color: var(--color-muted);
}

.source-stats-table .numeric-cell {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.source-stats-table td:first-child {
  min-width: 170px;
}

.source-stats-table td:first-child strong,
.source-stats-table td:first-child span,
.source-stats-table small {
  display: block;
}

.source-stats-summary-row td {
  background: #f8fbff;
  font-weight: 800;
}

.source-stats-trend {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  font-weight: 850;
}

.source-config-table {
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.source-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(180px, 0.8fr) minmax(180px, auto) minmax(260px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.source-create-form .form-field {
  margin: 0;
}

.source-inline-check {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  background: #fff;
  font-weight: 750;
}

.source-create-description textarea {
  min-height: 42px;
}

.source-config-header,
.source-config-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.65fr) minmax(220px, 1fr) minmax(260px, 1.25fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}

.source-config-header {
  background: #f3f7fb;
  color: #334155;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.source-config-row {
  border-top: 1px solid var(--color-border);
}

.source-config-row:hover {
  background: #f8fbff;
}

.source-config-row-readonly {
  min-height: 64px;
}

.source-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.source-name-cell strong {
  font-weight: 850;
}

.source-name-cell span,
.source-code-cell span,
.source-action-cell,
.source-toggle-cell {
  color: var(--color-muted);
  font-size: 0.82rem;
}

.source-code-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.source-config-row .form-field {
  margin: 0;
}

.source-group-field input {
  min-height: 36px;
}

.source-description-field textarea {
  min-height: 54px;
  resize: vertical;
}

.source-toggle-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.source-toggle-cell label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  font-weight: 700;
}

.source-action-cell {
  display: flex;
  justify-content: flex-end;
}

.source-bulk-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

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

.source-mapping-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
}

.source-mapping-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.source-mapping-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.source-mapping-section h3,
.source-mapping-section h4 {
  margin: 3px 0 8px;
}

.orders-table th,
.orders-table td {
  font-size: 0.82rem;
}

.order-row {
  cursor: pointer;
}

.order-row:hover,
.order-row[aria-expanded="true"] {
  background: var(--color-primary-soft);
}

.order-number-link {
  color: var(--color-primary);
  font-weight: 700;
}

.order-number-link:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

.order-items-row td {
  background: #fbfdff;
  padding: 0;
}

.order-items-panel {
  padding: 10px;
  border-left: 3px solid var(--color-primary);
  background: linear-gradient(90deg, rgba(1, 114, 227, 0.06), transparent);
}

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

.order-items-list {
  display: grid;
  gap: 8px;
}

.order-item-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px;
  border: 1px solid var(--color-border);
  background: #fff;
}

.order-item-main {
  display: grid;
  gap: 3px;
  min-width: 260px;
  flex: 1;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.audit-tabs,
.commission-tabs {
  display: grid;
  gap: 12px;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.tab-button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
}

.tab-button.active {
  background: #fff;
  color: var(--color-primary);
  border-color: var(--color-border);
  box-shadow: var(--shadow-soft);
}

.audit-tab-panel {
  width: 100%;
}

.audit-wide-table {
  width: 100%;
}

.audit-detail pre {
  margin: 0 0 8px;
  padding: 9px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.code-block {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--color-border);
  background: #102033;
  color: #eef5ff;
  overflow-x: auto;
}

.code-block code {
  font-family: var(--font-mono);
}

.alert-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.operational-alert {
  padding: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.operational-alert p {
  margin: 6px 0 12px;
}

.operational-alert-warning {
  border-color: #d9a441;
  background: #fff8e6;
}

.operational-alert-error {
  border-color: #d96b6b;
  background: #fff3f3;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 12px 0 0;
}

.meta-grid dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  font-weight: 800;
}

.meta-grid dd {
  margin: 3px 0 0;
  font-weight: 750;
}

.integration-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.integration-actions-main {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.compact-form {
  margin-top: 0;
}

.inline-map-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 6px;
  align-items: start;
}

.inline-map-form select {
  min-width: 180px;
  padding: 8px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  font: inherit;
}

.inline-map-form .async-message {
  grid-column: 1 / -1;
}

.compact-meta-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.status-toggle-form {
  margin-top: 12px;
}

.technical-details {
  margin-top: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-panel-muted);
}

.technical-details > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 12px;
  font-weight: 800;
  color: var(--color-primary);
}

.technical-details > summary::-webkit-details-marker {
  display: none;
}

.technical-details-body {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
  margin-top: 0;
}

.technical-section {
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.inline-details summary {
  cursor: pointer;
  color: var(--color-primary);
  font-weight: 700;
}

.live-calculation-row td {
  background: #fbfdff;
  padding: 0;
}

.live-calculation {
  padding: 10px;
  border-left: 3px solid var(--color-primary);
}

.live-calculation-body {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.live-calculation-intro h3 {
  margin: 6px 0;
  font-size: 1.05rem;
}

.calculation-table-wrap {
  border: 1px solid var(--color-border);
  background: #fff;
}

.calculation-table {
  min-width: 980px;
  margin-top: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.calculation-table th,
.calculation-table td {
  padding: 9px 11px;
  vertical-align: middle;
}

.calculation-table th {
  color: var(--color-muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.calculation-table tbody tr:nth-child(even) td {
  background: #f8fbff;
}

.calculation-table .source-cell {
  min-width: 150px;
}

.calculation-table .source-cell strong {
  display: block;
  font-size: 0.98rem;
}

.calculation-table .source-cell span,
.calculation-table small {
  display: block;
  margin-top: 4px;
  color: var(--color-muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.calculation-table .numeric-cell {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.metric-with-trend,
.trend-value {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-weight: 800;
}

.trend-value {
  min-width: 118px;
}

.trend-positive {
  color: #147a46;
}

.trend-negative {
  color: #b42318;
}

.trend-neutral {
  color: var(--color-muted);
  font-weight: 700;
}

.trend-triangle {
  display: inline-block;
  width: 0;
  height: 0;
  flex: 0 0 auto;
}

.trend-triangle-up {
  border-right: 4px solid transparent;
  border-bottom: 7px solid currentColor;
  border-left: 4px solid transparent;
}

.trend-triangle-down {
  border-top: 7px solid currentColor;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
}

.calculation-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.calculation-summary-card {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--color-border);
  background: #fff;
}

.calculation-summary-card span {
  color: var(--color-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.calculation-summary-card strong {
  font-size: 1.05rem;
}

.calculation-summary-card small {
  color: var(--color-muted);
  line-height: 1.45;
}

.inline-check {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-right: 12px;
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.panel-divider {
  margin: 22px 0;
  border: 0;
  border-top: 1px solid var(--color-border);
}

.preview-block {
  margin-top: 18px;
}

.empty-state {
  margin-top: 12px;
  padding: 14px;
  border: 1px dashed var(--color-border);
  background: var(--color-panel-muted);
}

.empty-state h3 {
  margin: 0 0 8px;
}

/* Dense enterprise UI pass: compact spacing, tables-first layout, no behavior changes. */
:root {
  --sidebar-width: 196px;
  --shadow-panel: 0 1px 2px rgba(15, 23, 36, 0.06);
  --shadow-soft: 0 1px 2px rgba(15, 23, 36, 0.05);
}

body {
  background: #eef3f8;
  font-size: 13px;
  line-height: 1.34;
}

.sidebar {
  padding: 10px 9px;
  box-shadow: none;
}

.brand {
  margin-bottom: 9px;
  padding: 2px 4px 9px;
}

.brand-logo-link {
  width: 166px;
}

.brand-logo {
  max-height: 38px;
}

.nav {
  gap: 2px;
}

.nav-link {
  min-height: 30px;
  padding: 6px 8px;
  font-size: 0.9rem;
  font-weight: 700;
}

.main {
  padding: 10px 12px 18px;
}

.topbar {
  gap: 10px;
  margin-bottom: 8px;
  padding: 7px 9px;
  box-shadow: none;
}

.topbar h1 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.05;
}

.topbar-actions,
.user-panel {
  gap: 6px;
}

.user-panel {
  padding: 2px;
}

.user-meta span {
  font-size: 0.72rem;
}

.eyebrow {
  font-size: 0.58rem;
  letter-spacing: 0.075em;
}

.status-badge {
  min-height: 26px;
  padding: 5px 7px;
}

.hero-grid,
.panel-grid {
  gap: 8px;
  margin-bottom: 8px;
}

.panel {
  padding: 9px 10px;
  box-shadow: none;
}

.main > .panel,
.main > .metric-grid,
.main > .panel-grid,
.main > .async-message {
  margin-bottom: 8px;
}

.panel h2 {
  margin: 2px 0 6px;
  font-size: 1.04rem;
  line-height: 1.08;
}

.panel p {
  margin-top: 5px;
  margin-bottom: 7px;
  line-height: 1.36;
}

.section-heading {
  gap: 8px;
}

.actions {
  gap: 5px;
  margin-top: 7px;
}

.actions-row {
  gap: 5px;
}

.button {
  min-height: 28px;
  padding: 5px 8px;
  font-size: 0.88rem;
  box-shadow: none;
}

.button-small {
  min-height: 24px;
  padding: 4px 6px;
  font-size: 0.76rem;
}

.filter-grid,
.manual-cost-filter-form {
  gap: 7px;
  margin-top: 8px;
  padding: 8px;
}

.filter-grid {
  grid-template-columns: repeat(6, minmax(132px, 1fr));
}

.filter-actions,
.manual-cost-filter-actions {
  gap: 5px;
}

.metric-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
  margin: 8px 0;
}

.metric-card,
.calculation-summary-card,
.setup-step,
.runbook-card,
.source-group-card {
  padding: 8px 9px;
  box-shadow: none;
}

.metric-card strong {
  margin: 1px 0;
  font-size: 1rem;
}

.metric-card span,
.muted-note,
.field-help {
  font-size: 0.75rem;
}

.setup-steps,
.runbook-grid,
.source-group-grid {
  gap: 7px;
  margin: 8px 0;
}

.pill,
.status-pill {
  margin-top: 1px;
  padding: 2px 5px;
  border-radius: 0;
  font-size: 0.62rem;
}

.stack-form {
  gap: 8px;
  margin-top: 8px;
}

.form-field {
  gap: 3px;
}

.form-field span {
  font-size: 0.72rem;
}

.form-field input,
.form-field select,
.inline-map-form select {
  min-height: 29px;
  padding: 5px 7px;
  font-size: 0.88rem;
}

.form-field textarea {
  min-height: 70px;
  padding: 6px 7px;
  font-size: 0.88rem;
}

.manual-cost-panel,
.manual-cost-card {
  padding: 9px;
}

.manual-cost-layout {
  grid-template-columns: minmax(0, 1.55fr) minmax(290px, 0.45fr);
  gap: 8px;
}

.manual-cost-field-grid {
  gap: 7px;
}

.manual-cost-note-field textarea {
  min-height: 84px;
}

.manual-cost-source-list {
  max-height: 196px;
  padding: 3px;
}

.manual-cost-source-list label {
  gap: 6px;
  padding: 4px 6px;
  font-size: 0.82rem;
}

.manual-cost-summary,
.manual-cost-empty-state,
.empty-state,
.operational-alert,
.async-message,
.message-item,
.form-errors,
.recaptcha-field {
  padding: 7px 8px;
}

.table-wrap {
  margin-top: 7px;
  box-shadow: none;
}

.data-table {
  font-size: 0.76rem;
  line-height: 1.24;
}

.data-table th,
.data-table td {
  padding: 5px 7px;
}

.data-table th {
  font-size: 0.62rem;
  letter-spacing: 0.03em;
}

.data-table td strong {
  font-weight: 780;
}

.orders-table th,
.orders-table td {
  font-size: 0.74rem;
}

.table-subtext {
  margin-top: 2px;
  font-size: 0.7rem;
  line-height: 1.2;
}

.order-items-panel,
.live-calculation {
  padding: 7px;
}

.order-items-list {
  gap: 5px;
}

.order-item-line {
  gap: 5px 8px;
  padding: 5px 6px;
}

.tab-list {
  gap: 3px;
  padding: 3px;
}

.tab-button {
  min-height: 28px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.meta-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px 10px;
  margin-top: 7px;
}

.meta-grid dt {
  font-size: 0.62rem;
}

.meta-grid dd {
  margin-top: 1px;
}

.integration-actions,
.integration-actions-main {
  gap: 7px;
  margin-top: 8px;
}

.technical-details,
.status-toggle-form,
.preview-block,
.source-section-tabs,
.source-stats-group,
.source-config-table,
.source-create-form,
.source-mapping-section,
.manual-cost-history-panel,
.alert-list {
  margin-top: 8px;
}

.technical-details > summary {
  padding: 7px 9px;
}

.technical-details-body {
  gap: 8px;
  padding: 0 9px 9px;
}

.source-create-form {
  gap: 7px;
}

.source-config-header,
.source-config-row {
  gap: 7px;
  padding: 6px 8px;
}

.source-config-row-readonly {
  min-height: 44px;
}

.source-inline-check,
.source-toggle-cell label {
  min-height: 29px;
  padding: 5px 7px;
}

.source-description-field textarea {
  min-height: 40px;
}

.source-stats-group-heading {
  gap: 8px;
}

.source-stats-subtitle {
  margin-top: 8px;
  font-size: 0.88rem;
}

.source-stats-group-metrics {
  gap: 5px;
}

.source-stats-group-metrics span {
  min-width: 100px;
  padding: 5px 7px;
  font-size: 0.64rem;
}

.source-stats-group-metrics strong {
  font-size: 0.84rem;
}

.calculation-table {
  min-width: 900px;
}

.calculation-table th,
.calculation-table td {
  padding: 6px 7px;
}

.calculation-table th {
  font-size: 0.66rem;
}

.calculation-table .source-cell strong {
  font-size: 0.86rem;
}

.calculation-table .source-cell span,
.calculation-table small {
  margin-top: 2px;
  font-size: 0.68rem;
}

.calculation-summary-grid {
  gap: 7px;
}

.calculation-summary-card strong {
  font-size: 0.9rem;
}

.calculation-summary-card span,
.calculation-summary-card small {
  font-size: 0.7rem;
}

.pagination {
  gap: 5px;
  margin-top: 8px;
}

.code-block,
.audit-detail pre,
.runbook-card code {
  padding: 6px 7px;
  font-size: 0.72rem;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding-bottom: 10px;
  }

  .brand {
    padding-bottom: 10px;
    margin-bottom: 10px;
  }

  .nav {
    display: flex;
    flex-wrap: wrap;
  }

  .nav-link {
    min-height: 34px;
  }

  .main {
    padding: 12px;
  }

  .hero-grid,
  .panel-grid {
    grid-template-columns: 1fr;
  }

  .meta-grid,
  .integration-actions,
  .filter-grid,
  .metric-grid,
  .setup-steps,
  .manual-cost-layout,
  .manual-cost-field-grid,
  .manual-cost-filter-form,
  .runbook-grid,
  .calculation-summary-grid,
  .source-create-form,
  .source-config-header,
  .source-config-row {
    grid-template-columns: 1fr;
  }

  .source-stats-filter,
  .source-stats-group-heading,
  .source-stats-group-metrics {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .source-config-header {
    display: none;
  }

  .source-action-cell {
    justify-content: stretch;
  }

  .source-action-cell .button {
    width: 100%;
  }

  .manual-cost-amount-field {
    grid-column: auto;
  }

  .manual-cost-panel {
    padding: 18px;
  }

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

  .section-heading,
  .source-bulk-actions,
  .pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions,
  .user-panel {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .user-meta {
    text-align: left;
  }

  .table-wrap {
    max-width: calc(100vw - 24px);
  }
}
