:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #637083;
  --line: #d9e0e7;
  --line-strong: #b7c1cd;
  --blue: #245f9f;
  --blue-soft: #e7f1fb;
  --green: #26734d;
  --green-soft: #e5f3eb;
  --amber: #9a650f;
  --amber-soft: #fff3d6;
  --red: #b42318;
  --red-soft: #fde7e4;
  --gray-soft: #eef1f5;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  margin: 0 auto;
  max-width: 1280px;
  padding: 10px;
}

.topbar,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
}

.topbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 8px 14px;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  margin: 0 0 6px;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
  margin: 3px 0 0;
}

h3 {
  font-size: 18px;
  line-height: 1.2;
  margin: 2px 0 0;
}

.meta-line {
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  cursor: pointer;
  min-height: 29px;
  padding: 5px 9px;
}

.button:hover {
  border-color: var(--blue);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button:disabled:hover {
  border-color: var(--line-strong);
}

.button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}

.button.small {
  min-height: 27px;
  padding: 4px 8px;
}

/* Toolbar buttons color-coded by function for quick scanning/locating. */
.button.btn-nav {
  background: var(--blue-soft);
  border-color: #bcd6f0;
  color: var(--blue);
}

.button.btn-nav:not(:disabled):hover {
  background: #d6e7f8;
  border-color: var(--blue);
}

.button.btn-sync {
  background: var(--amber-soft);
  border-color: #e7c889;
  color: var(--amber);
}

.button.btn-sync:not(:disabled):hover {
  border-color: var(--amber);
}

.button.btn-export {
  background: var(--green-soft);
  border-color: #bad7c6;
  color: var(--green);
}

.button.btn-export:not(:disabled):hover {
  border-color: var(--green);
}

.button.btn-danger {
  background: var(--red-soft);
  border-color: #efb5ad;
  color: var(--red);
}

.button.btn-danger:not(:disabled):hover {
  border-color: var(--red);
}

.save-status {
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  min-height: 26px;
  padding: 5px 8px;
  white-space: nowrap;
}

.save-status.ok {
  background: var(--green-soft);
  border-color: #bad7c6;
  color: var(--green);
}

.save-status.warn {
  background: var(--amber-soft);
  border-color: #e7c889;
  color: var(--amber);
}

.panel {
  margin-top: 8px;
  padding: 8px;
}

.section-kicker,
.target-total-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.workspace-panel {
  padding: 8px;
}

.workspace-head {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 6px;
}

.editor-status {
  border: 1px solid var(--line);
  font-size: 13px;
  min-height: 34px;
  min-width: 330px;
  padding: 5px 8px;
  text-align: right;
}

.editor-status.ok {
  background: var(--green-soft);
  border-color: #bad7c6;
}

.editor-status.warn {
  background: var(--amber-soft);
  border-color: #e7c889;
}

.editor-status.error {
  background: var(--red-soft);
  border-color: #efb5ad;
  color: var(--red);
}

.month-tabs {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 8px;
}

.month-tab {
  background: #f8fafc;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 7px;
  min-height: 96px;
  padding: 9px 10px;
  text-align: left;
}

.month-tab:hover {
  border-color: var(--blue);
}

.month-tab.active {
  background: var(--blue-soft);
  border-color: var(--blue);
  box-shadow: inset 0 3px 0 var(--blue);
}

.month-tab-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.month-tab strong {
  font-size: 20px;
  line-height: 1.15;
}

.month-tab-metrics {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.month-tab-metrics span {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 5px 6px;
}

.month-tab-metrics b {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-tab-metrics small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.rep-adjust-stats span,
.rep-balance span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.assignment-workspace {
  align-items: start;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 310px;
}

.rep-list-panel,
.rep-adjust-panel {
  min-width: 0;
}

.editor-table-head {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 2px 0 6px;
}

.editor-table-head h3 {
  font-size: 16px;
}

.table-note {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.target-editor-grid {
  overflow: visible;
}

.target-editor-grid table {
  table-layout: fixed;
  width: 100%;
}

.target-editor-grid th,
.target-editor-grid td {
  height: 22px;
  padding: 0 6px;
}

.target-editor-grid .col-baseline,
.target-editor-grid .col-assigned {
  width: 112px;
}

.target-editor-grid .col-delta {
  width: 96px;
}

.target-editor-grid .col-source {
  width: 96px;
}

.target-editor-grid td.target-cell {
  padding: 2px 4px;
}

.rep-target-control {
  display: grid;
  gap: 6px;
  grid-template-columns: 58px minmax(0, 1fr) 58px;
  width: 100%;
}

.step-button {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--blue);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  height: 22px;
  min-height: 22px;
  padding: 0;
}

.step-button.large {
  height: 38px;
  min-height: 38px;
}

.step-button:hover {
  background: var(--blue-soft);
  border-color: var(--blue);
}

.target-money {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-strong);
  display: grid;
  gap: 2px;
  grid-template-columns: 12px minmax(0, 1fr);
  min-height: 22px;
  padding: 0 4px;
}

.target-money span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.target-money:focus-within {
  border-color: var(--blue);
}

.target-money.large {
  min-height: 38px;
}

.target-money.large .target-input {
  border: 0;
  font-size: 17px;
  font-weight: 700;
  min-height: 34px;
  padding: 0;
}

.rep-adjust-panel {
  border: 1px solid var(--line);
  padding: 12px;
}

.rep-adjust-panel.is-empty {
  align-items: center;
  border-style: dashed;
  display: flex;
  justify-content: center;
}

.rep-adjust-head {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 10px;
}

.rep-adjust-head h3 {
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rep-adjust-head-main {
  min-width: 0;
}

.rep-adjust-head-side {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: 6px;
}

.rep-adjust-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.icon-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 16px;
  height: 22px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 22px;
}

.icon-button:hover {
  border-color: var(--red);
  color: var(--red);
}

.rep-adjust-empty {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
  min-height: 240px;
  padding: 18px 14px;
  text-align: center;
}

.rep-adjust-empty-icon {
  color: var(--line-strong);
  height: 30px;
  margin-bottom: 2px;
  width: 30px;
}

.rep-adjust-empty-title {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.rep-adjust-empty-sub {
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
  max-width: 230px;
}

.rep-adjust-stats {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 10px;
}

.rep-adjust-stats div {
  background: #f8fafc;
  border: 1px solid var(--line);
  min-width: 0;
  padding: 7px;
}

.rep-adjust-stats strong {
  display: block;
  font-size: 15px;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rep-adjust-stats div.hero {
  background: var(--blue-soft);
  border-color: #bcd6f0;
}

.rep-adjust-stats div.hero strong {
  color: var(--blue);
}

.quick-adjust-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quick-adjust-row .reset-action {
  margin-left: auto;
}

.rep-balance {
  border: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding: 8px;
}

.rep-balance.ok {
  background: var(--green-soft);
  border-color: #bad7c6;
}

.rep-balance.error {
  background: var(--red-soft);
  border-color: #efb5ad;
  color: var(--red);
}

.rep-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-title {
  font-weight: 700;
}

.status-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.target-row {
  cursor: pointer;
}

.target-row:hover td {
  background: var(--gray-soft);
}

.target-row.selected td {
  background: var(--blue-soft);
}

.target-row.selected td.left {
  box-shadow: inset 3px 0 0 var(--blue);
}

.target-row.selected:hover td {
  background: var(--blue-soft);
}

.delta-positive {
  color: var(--green);
  font-weight: 700;
}

.delta-negative {
  color: var(--red);
  font-weight: 700;
}

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

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

input,
select {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  min-height: 34px;
  padding: 5px 8px;
}

.table-wrap {
  overflow: auto;
}

.target-editor-grid.table-wrap {
  overflow: visible;
}

table {
  border-collapse: collapse;
  min-width: 100%;
}

th,
td {
  border: 1px solid var(--line);
  height: 38px;
  padding: 7px 8px;
  text-align: right;
  white-space: nowrap;
}

th {
  background: #233d59;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

th.left,
td.left {
  text-align: left;
}

td.left {
  font-weight: 700;
}

td.total,
tr.total-row td {
  background: var(--gray-soft);
  font-weight: 700;
}

td.formula {
  background: var(--blue-soft);
}

td.manual {
  background: var(--amber-soft);
}

td.fixed {
  background: var(--gray-soft);
}

.target-input {
  min-width: 0;
  text-align: right;
  width: 100%;
}

.target-input.manual {
  background: var(--amber-soft);
}

.target-input:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  outline: 0;
}

.link-button {
  background: transparent;
  border: 0;
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
  min-height: 0;
  padding: 0;
}

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

.tag {
  border: 1px solid var(--line-strong);
  color: var(--muted);
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  min-width: 58px;
  padding: 1px 4px;
  text-align: center;
}

.tag.formula {
  background: var(--blue-soft);
  color: var(--blue);
}

.tag.manual {
  background: var(--amber-soft);
  color: var(--amber);
}

.tag.fixed {
  background: var(--gray-soft);
}

.source-cell {
  text-align: left;
}

.source-cell .tag {
  margin-right: 8px;
}

.good-text {
  color: var(--green);
  font-weight: 700;
}

.bad-text {
  color: var(--red);
  font-weight: 700;
}

.detail-panel {
  padding: 0;
}

.detail-panel summary {
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  list-style-position: inside;
  padding: 13px 14px;
}

.detail-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.detail-panel .table-wrap,
.sales-toolbar {
  padding: 14px;
}

.sales-toolbar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 0;
}

.sales-period-badge {
  background: var(--blue-soft);
  border: 1px solid #b8d2ee;
  color: var(--blue);
  display: grid;
  gap: 2px;
  min-height: 34px;
  min-width: 210px;
  padding: 6px 9px;
}

.sales-period-badge span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.sales-period-badge strong {
  color: var(--ink);
  font-size: 13px;
}

.sales-total-summary {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 14px 14px 0;
}

.sales-total-tile {
  background: #f8fafc;
  border: 1px solid var(--line);
  min-height: 72px;
  padding: 10px;
}

.sales-total-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.sales-total-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 5px;
}

.sales-total-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.inline-check {
  align-items: center;
  display: flex;
  gap: 6px;
  min-height: 30px;
}

.inline-check input {
  min-height: 16px;
}

.date-input {
  min-width: 126px;
}

.sales-input {
  min-width: 100px;
  text-align: right;
}

.sales-input.override {
  background: var(--amber-soft);
}

.sales-input:disabled {
  background: #f8f9fb;
  color: var(--muted);
}

.toast {
  background: #17212b;
  bottom: 18px;
  color: #fff;
  font-weight: 700;
  left: 50%;
  min-width: 220px;
  padding: 10px 14px;
  position: fixed;
  text-align: center;
  transform: translateX(-50%);
  z-index: 20;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .workspace-head {
    display: block;
  }

  .toolbar {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .editor-status {
    margin-top: 12px;
    min-width: 0;
    text-align: left;
  }

  .sales-total-summary {
    grid-template-columns: 1fr;
  }

  .assignment-workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .month-tabs {
    grid-template-columns: 1fr;
  }

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

  .target-editor-grid table {
    min-width: 620px;
  }

  .target-editor-grid .col-baseline,
  .target-editor-grid .col-assigned {
    width: 100px;
  }

  .target-editor-grid .col-delta,
  .target-editor-grid .col-source {
    width: 90px;
  }

  .source-cell .tag {
    margin-right: 4px;
  }

  .tag {
    min-width: 0;
  }
}
