/* Commission Calculator */
:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-bg: #e6f6e6;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-bg: #fff3d6;
  --warning-ink: #7a4d00;
  --critical: #d03b3b;
  --critical-bg: #fbe3e3;
  --critical-ink: #8f1d1d;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  padding-inline: 16px;
  padding-block: 0 32px;
}
h1 { font-size: 20px; margin: 0; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 20px 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
p { margin: 0 0 8px; }

/* Header ---------------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 0 10px;
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.product-label { color: var(--muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.view-toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; background: var(--surface); }
.view-toggle button {
  border: 0; background: transparent; padding: 6px 14px; font: inherit; cursor: pointer; color: var(--ink-2);
}
.view-toggle button.active { background: var(--ink); color: #fff; }

.btn {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--critical-ink); }
.btn.subtle { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; margin-top: 6px; }
.btn.tiny { padding: 0 8px; line-height: 22px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Scenario bar ----------------------------------------------------------- */
.scenario-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px;
}
.scenario-bar label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.scenario-bar input, .scenario-bar select { font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; min-width: 160px; }
.scenario-msg { font-size: 13px; color: var(--good-ink); align-self: center; }
.scenario-msg.error { color: var(--critical-ink); }
.scenario-msg.muted { color: var(--muted); }

/* Status banner ---------------------------------------------------------- */
.status-banner {
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; border: 1px solid;
}
.status-banner.level-good { background: var(--good-bg); border-color: var(--good); color: var(--good-ink); }
.status-banner.level-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning-ink); }
.status-banner.level-critical { background: var(--critical-bg); border-color: var(--critical); color: var(--critical-ink); }
.status-head { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.status-icon {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  font-weight: 700; font-size: 13px; color: #fff; background: currentColor;
}
.status-icon { color: inherit; }
.level-good .status-icon { background: var(--good); color: #fff; }
.level-warning .status-icon { background: var(--warning); color: #3a2600; }
.level-critical .status-icon { background: var(--critical); color: #fff; }
.status-reasons { margin: 6px 0 0 30px; padding: 0; }
.status-reasons li { margin: 2px 0; }

/* Layout ----------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.inputs, .outputs { min-width: 0; }

/* Inputs ----------------------------------------------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 10px; padding: 0 14px 12px;
}
.panel summary {
  cursor: pointer; font-weight: 600; padding: 12px 0; list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: '+'; color: var(--muted); font-weight: 400; }
.panel[open] summary::after { content: '–'; }
.field { margin: 10px 0; }
.field > label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=password], select {
  font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink);
}
input[type=text] { width: 100%; }
textarea { width: 100%; font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); resize: vertical; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.slider-row, .spec-row { display: flex; align-items: center; gap: 8px; }
input[type=range] { flex: 1; min-width: 60px; accent-color: var(--accent); margin: 0; }
.num { position: relative; display: inline-flex; align-items: center; }
.num input[type=number] { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.num.unit-money::before { content: '$'; position: absolute; left: 8px; color: var(--muted); font-size: 12px; pointer-events: none; }
.num.unit-money input { padding-left: 18px; }
.num.unit-pct::after { content: '%'; position: absolute; right: 8px; color: var(--muted); font-size: 12px; pointer-events: none; }
.num.unit-pct input { padding-right: 20px; }
.spec-row select { flex: 0 0 auto; }
.equiv { color: var(--muted); font-size: 12px; margin-top: 3px; min-height: 16px; }
.equiv.inline { margin: 0; flex-basis: 100%; }
.equiv.cell { margin: 0; min-height: 0; white-space: nowrap; }
/* Compact editable sub-table (taper steps) */
.subtable { border-collapse: collapse; width: 100%; font-size: 12px; }
.subtable th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 0 4px 3px 0; white-space: nowrap; }
.subtable td { padding: 2px 4px 2px 0; vertical-align: middle; }
.subtable td:last-child, .subtable th:last-child { padding-right: 0; }
.subtable input[type=number] { width: 54px; padding: 4px 5px; font-size: 12px; text-align: right; }
.subtable .num input[type=number] { width: 70px; }
.subtable .num.unit-money input { padding-left: 14px; }
.subtable .num.unit-money::before, .subtable .num.unit-pct::after { font-size: 11px; }
.subtable .num.unit-pct input { padding-right: 16px; }
.subtable select { font-size: 12px; padding: 4px 4px; }
.subtable .btn.tiny { line-height: 20px; }
.radio-row { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.radio-row label, .check { font-weight: 400; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check { margin: 8px 0 2px; }
.check.big { font-weight: 600; margin: 4px 0 8px; }
.derived { color: var(--muted); font-size: 12px; margin: -4px 0 8px; }
.btn.small + .derived { margin-top: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.list-row input[type=number] { width: 72px; text-align: right; }
.list-row .num input[type=number] { width: 88px; }
.list-row input[type=range] { flex: 1 1 60px; }
.list-row select { font-size: 12px; padding: 4px 6px; }
.list-row input[type=text].grow { flex: 1 1 100px; width: auto; }
.row-label { color: var(--ink-2); font-size: 12px; }
#manager-fields[hidden], #manager-own-custom[hidden], #base-pay-field[hidden], #override-taper-field[hidden], #inherited-fields[hidden] { display: none; }

/* Outputs ---------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card.level-warning { background: var(--warning-bg); border-color: var(--warning); }
.card.level-critical { background: var(--critical-bg); border-color: var(--critical); }
.card.level-good { border-color: var(--good); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.tile-label { font-size: 12px; color: var(--ink-2); }
.tile-value { font-size: 22px; font-weight: 700; margin: 2px 0; letter-spacing: -.01em; }
.tile-sub { font-size: 12px; color: var(--muted); }
.tile-good .tile-value { color: var(--good-ink); }
.tile-warning .tile-value { color: var(--warning-ink); }
.tile-critical .tile-value { color: var(--critical-ink); }
.chart-wrap { position: relative; height: 240px; margin: 6px 0 4px; }
#chart-clients { height: 170px; }
.chart-wrap:has(#chart-clients) { height: 180px; }
.chart-fallback { color: var(--muted); font-size: 12px; padding: 8px 0; }
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; background: #fff; border-radius: 8px; overflow: hidden; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data th { font-weight: 600; color: var(--ink-2); font-size: 12px; background: #f7f7f4; }
table.data .r { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.total td { border-top: 2px solid var(--line-strong); }
table.data .strong { font-weight: 700; }
table.data td.good { color: var(--good-ink); }
table.data td.warning { color: var(--warning-ink); }
table.data td.critical { color: var(--critical-ink); }
table.data td.pill { font-weight: 600; }
table.data td.pill.good { background: var(--good-bg); }
table.data td.pill.warning { background: var(--warning-bg); }
table.data td.pill.critical { background: var(--critical-bg); }

.wizard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.wizard li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
.wizard li.level-warning { border-color: var(--warning); }
.wizard li.level-critical { border-color: var(--critical); }
.wizard strong { display: block; margin-bottom: 2px; }
.wizard p { margin: 0; color: var(--ink-2); }
.wiz-icon {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; background: var(--good);
}
.level-warning .wiz-icon { background: var(--warning); color: #3a2600; }
.level-critical .wiz-icon { background: var(--critical); }

/* Rep view hides everything that reveals company economics ---------------- */
body[data-view="rep"] .owner-only { display: none !important; }

.foot { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Modal ------------------------------------------------------------------ */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 20px; width: min(100%, 380px); }
.modal-box input { width: 100%; margin: 8px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.error { color: var(--critical-ink); font-size: 13px; min-height: 18px; }
