:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --ink: #17202a;
  --muted: #5a6675;
  --line: #d9e0e8;
  --panel: #ffffff;
  --panel-2: #eef5f1;
  --navy: #1d3557;
  --steel: #46627f;
  --green: #18735d;
  --amber: #a96710;
  --red: #b42318;
  --focus: #2563eb;
  --shadow: 0 12px 32px rgba(24, 38, 57, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: -20px -20px 18px;
  padding: 20px 24px 18px;
  border-bottom: 1px solid rgba(217, 224, 232, 0.82);
  background: rgba(245, 247, 250, 0.96);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.75rem, 2.2vw, 2.5rem);
}

h2 {
  font-size: 0.98rem;
}

.source-pill {
  min-width: 168px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  padding: 9px 12px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.source-pill.ok {
  border-color: #b6ddca;
  color: var(--green);
  background: #edf8f3;
}

.source-pill.warn {
  border-color: #f1cf9c;
  color: var(--amber);
  background: #fff8ed;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.input-panel,
.results-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: auto;
}

.input-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.results-panel {
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.control-grid {
  display: grid;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
}

label span,
.special-pay summary {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 1rem;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  border-color: var(--focus);
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
}

.check-row.inline {
  align-content: end;
  min-height: 64px;
}

.check-row input {
  min-height: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented label {
  display: block;
  position: relative;
  min-height: 40px;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  min-height: 40px;
  padding: 10px;
  text-align: center;
  color: var(--muted);
  background: #fff;
}

.segmented input:checked + span {
  color: #fff;
  background: var(--navy);
}

.secondary-button {
  min-height: 40px;
  border: 1px solid var(--steel);
  border-radius: 6px;
  color: var(--navy);
  background: #f4f8fc;
  font-weight: 800;
  cursor: pointer;
}

.secondary-button:hover {
  background: #e8f1fb;
}

.location-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.location-results {
  display: grid;
  gap: 6px;
  max-height: 236px;
  overflow-y: auto;
  border-radius: 8px;
}

.location-results[hidden] {
  display: none;
}

.location-option,
.location-message,
.location-selected {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.92rem;
}

.location-option {
  min-height: 44px;
  cursor: pointer;
}

.location-option:hover {
  border-color: var(--steel);
  background: #f6f9fc;
}

.location-message {
  color: var(--muted);
  background: #f8fafc;
}

.location-selected {
  border-color: #b6ddca;
  color: var(--green);
  background: #edf8f3;
  font-weight: 800;
}

.ocONUS-fields {
  display: none;
  gap: 12px;
}

.ocONUS-fields.active {
  display: grid;
}

.special-pay {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.special-pay summary {
  cursor: pointer;
}

.special-pay > summary + * {
  margin-top: 12px;
}

.tax-deductions > .control-grid,
.tax-deductions > .check-row {
  margin-top: 12px;
}

.manual-allowances > .control-grid + .control-grid,
.manual-allowances > .control-grid + .ocONUS-fields {
  margin-top: 12px;
}

.entitlement-row {
  display: grid;
  grid-template-columns: 18px minmax(120px, 1fr) 110px;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #edf1f5;
}

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

.metric {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 14px;
}

.metric.primary {
  color: #fff;
  border-color: var(--navy);
  background: var(--navy);
}

.metric span {
  display: block;
  margin-bottom: 14px;
  color: inherit;
  opacity: 0.78;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.warning-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.warning {
  border: 1px solid #f1cf9c;
  border-radius: 8px;
  background: #fff8ed;
  color: #6f4100;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.warning.error {
  border-color: #f0b5ae;
  background: #fff1ef;
  color: var(--red);
}

.result-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.bar-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 190px) minmax(120px, 1fr) 90px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.bar-track {
  height: 12px;
  border-radius: 8px;
  background: #e8edf3;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  border-bottom: 1px solid #e8edf3;
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td.money,
th.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.source-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.source-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.source-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.source-item-header strong {
  min-width: 0;
}

.source-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.source-item .source-status,
.source-item .source-cao {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.source-item .source-status {
  color: #fff;
  background: var(--steel);
}

.source-item .source-cao {
  border: 1px solid var(--line);
  color: var(--muted);
  background: #f8fafc;
}

.source-item .source-status.ok,
.source-item .source-status.seeded {
  background: var(--green);
}

.source-item .source-status.failed,
.source-item .source-status.needs_feed {
  background: var(--amber);
}

.source-item p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(240px, 0.48fr) minmax(0, 1fr);
  }

  .input-panel {
    max-height: none;
  }

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

@media (max-width: 640px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    padding: 10px;
    overflow: visible;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin: -10px -10px 10px;
    padding: 12px 14px;
  }

  h1 {
    font-size: clamp(1.55rem, 8vw, 2rem);
  }

  h2 {
    font-size: 0.95rem;
  }

  .source-pill {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
  }

  .workspace {
    grid-template-rows: auto auto;
    gap: 12px;
    overflow: visible;
  }

  .input-panel,
  .results-panel {
    overflow: visible;
    padding: 14px;
  }

  .input-panel {
    gap: 12px;
  }

  .control-grid.two,
  .source-list {
    grid-template-columns: 1fr;
  }

  label span,
  .special-pay summary {
    font-size: 0.9rem;
  }

  input,
  select {
    min-height: 50px;
    padding: 12px;
    font-size: 16px;
  }

  .segmented,
  .segmented label,
  .segmented span {
    min-height: 50px;
  }

  .segmented span {
    padding: 14px 10px;
  }

  .check-row {
    min-height: 42px;
  }

  .location-results {
    max-height: 218px;
  }

  .location-option,
  .location-message,
  .location-selected {
    min-height: 46px;
    padding: 11px 12px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 84px;
    padding: 12px;
  }

  .metric span {
    margin-bottom: 8px;
    font-size: 0.68rem;
  }

  .metric strong {
    font-size: clamp(1.12rem, 5.4vw, 1.45rem);
  }

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

  table {
    min-width: 100%;
    table-layout: fixed;
    font-size: 0.78rem;
  }

  th,
  td {
    padding: 8px 5px;
    overflow-wrap: anywhere;
  }

  td.money,
  th.money {
    white-space: nowrap;
  }
}

@media (max-width: 360px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }
}
