:root {
  color-scheme: light;
  --bg: #f7f5f1;
  --surface: #fffdf9;
  --surface-strong: #f0f3ee;
  --ink: #3d4140;
  --muted: #707772;
  --line: #e2e1da;
  --line-strong: #cfd5cd;
  --accent: #788a7e;
  --accent-strong: #596b60;
  --accent-soft: #eef3ee;
  --warning: #927965;
  --warning-soft: #f5eee7;
  --danger: #957069;
  --danger-soft: #f2e8e5;
  --shadow: 0 14px 34px rgba(63, 69, 66, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(1560px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(520px, 1.5fr);
  gap: 20px;
  align-items: stretch;
  margin-bottom: 18px;
}

.title-block {
  display: flex;
  min-height: 132px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 22px;
  box-shadow: var(--shadow);
}

.brand {
  margin: 0;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 1.45rem;
  font-weight: 800;
}

h1 {
  margin: 24px 0 0;
  max-width: 520px;
  color: var(--ink);
  font-size: clamp(2rem, 3.2vw, 3.35rem);
  font-weight: 760;
  line-height: 1.02;
  letter-spacing: 0;
}

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

.summary-item {
  display: flex;
  min-width: 0;
  min-height: 118px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

.summary-item dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 680;
  text-transform: uppercase;
}

.summary-item dd {
  margin: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--accent-strong);
  font-size: clamp(0.98rem, 1.45vw, 1.42rem);
  font-variant-numeric: tabular-nums;
  font-weight: 720;
  line-height: 1.08;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-item.accent dd {
  color: var(--warning);
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(260px, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

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

.field > span:first-child,
.field > label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  text-transform: uppercase;
}

.money-input {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 44px;
  gap: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 0 12px;
}

.money-input span {
  color: var(--accent);
  font-weight: 800;
}

.money-input input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 650;
}

input {
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 12px;
  outline: 0;
}

select {
  outline: 0;
}

.scenario-select {
  appearance: none;
  height: 44px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background-color: var(--surface-strong);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 11px) 18px;
  background-repeat: no-repeat;
  background-size: 6px 6px, 6px 6px;
  color: var(--ink);
  padding: 0 34px 0 12px;
}

.scenario-select::-ms-expand {
  display: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(120, 138, 126, 0.16);
}

.primary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 720;
  min-height: 44px;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.primary-button {
  gap: 8px;
  align-self: end;
  background: var(--accent-strong);
  color: #fffaf5;
  padding: 0 16px;
}

.primary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(120, 138, 126, 0.22);
  outline-offset: 2px;
}

.table-shell {
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.column-toolbar {
  display: flex;
  position: relative;
  z-index: 10;
  justify-content: flex-start;
  align-items: center;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  padding: 10px 12px;
}

.column-menu {
  position: relative;
}

.column-menu summary {
  display: flex;
  height: 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 680;
  list-style: none;
  padding: 0 12px;
  text-transform: uppercase;
}

.column-menu summary::-webkit-details-marker {
  display: none;
}

.column-menu summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
}

.column-menu[open] summary::after {
  transform: translateY(2px) rotate(225deg);
}

.column-options {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  width: 220px;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 6px;
}

.column-option {
  display: flex;
  min-height: 32px;
  align-items: center;
  gap: 5px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
  padding: 0 8px;
}

.column-option:hover {
  background: var(--surface-strong);
}

.column-option input {
  appearance: auto;
  width: 14px;
  height: 14px;
  border: 0;
  background: transparent;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
}

.status-panel,
.saved-shell {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.status-panel {
  grid-template-columns: auto 1fr;
  align-items: start;
}

.status-marker {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 760;
}

.status-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 680;
  text-transform: uppercase;
}

.status-messages {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.status-messages li {
  margin: 2px 0;
  padding: 0;
  font-weight: 650;
  line-height: 1.25;
}

.status-complete {
  border-color: #dfe6dd;
  background: var(--surface);
}

.status-complete .status-marker {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-attention {
  border-color: #eaded3;
  background: var(--surface);
}

.status-attention .status-marker {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-check {
  display: flex;
  gap: 9px;
  align-items: center;
}

.status-check-icon {
  width: 18px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 18px;
  font-weight: 780;
}

.status-check.is-met {
  color: var(--accent-strong);
}

.status-check.is-unmet {
  color: var(--warning);
}

.saved-heading h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 680;
  text-transform: uppercase;
}

.save-current {
  margin: 5px 0 0;
  color: var(--ink);
  font-weight: 680;
}

.save-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.7fr) minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.save-feedback {
  grid-column: 1 / -1;
  min-height: 1.25em;
  margin: 0;
  color: var(--muted);
  font-weight: 620;
}

.save-feedback[data-type="success"] {
  color: var(--accent-strong);
}

.save-feedback[data-type="warning"] {
  color: var(--warning);
}

table {
  width: 100%;
  min-width: 1180px;
  background: var(--surface);
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

thead th {
  background: #fffaf4;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 680;
  line-height: 1.08;
  text-transform: uppercase;
}

.sort-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  padding: 0;
  text-align: left;
  text-transform: inherit;
}

.sort-button:focus-visible {
  outline: 3px solid rgba(120, 138, 126, 0.22);
  outline-offset: 2px;
}

.sort-arrow {
  position: relative;
  width: 9px;
  height: 14px;
  flex: 0 0 9px;
}

.sort-arrow::before,
.sort-arrow::after {
  position: absolute;
  left: 1px;
  content: "";
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  opacity: 0.28;
}

.sort-arrow::before {
  top: 1px;
  border-bottom: 5px solid var(--muted);
}

.sort-arrow::after {
  bottom: 1px;
  border-top: 5px solid var(--muted);
}

.sort-button[data-direction="asc"] .sort-arrow::before,
.sort-button[data-direction="desc"] .sort-arrow::after {
  opacity: 1;
}

.sort-button[data-direction="asc"],
.sort-button[data-direction="desc"] {
  color: var(--accent-strong);
}

tbody tr:last-child td {
  border-bottom-color: var(--line);
}

tbody td {
  background: var(--surface);
}

tfoot th,
tfoot td {
  border-bottom: 0;
  background: #f7f7f3;
  font-weight: 720;
}

th[data-column="stockholder"],
.name-cell {
  width: 190px;
}

th[data-column="type"],
.type-cell {
  width: 96px;
}

th[data-column="shares"],
.shares-cell {
  width: 98px;
}

th[data-column="perShareCost"],
.cost-input-cell {
  width: 102px;
}

th[data-column="totalCost"],
.total-cost-cell {
  width: 104px;
}

th[data-column="ownership"],
.ownership-cell {
  width: 96px;
}

th[data-column="sell"],
.sell-cell {
  width: 76px;
}

th[data-column="remaining"],
.remaining-cell {
  width: 98px;
}

th[data-column="afterSell"],
.post-sell-cell {
  width: 112px;
}

th[data-column="grossPay"],
.gross-pay-cell {
  width: 102px;
}

th[data-column="multiplier"],
.multiplier-cell {
  width: 92px;
}

.ownership-cell,
.post-sell-cell,
.remaining-cell,
.total-cost-cell,
.gross-pay-cell,
.multiplier-cell {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ownership-cell {
  color: var(--accent-strong);
}

.post-sell-cell {
  color: var(--warning);
}

.total-cost-cell,
.gross-pay-cell,
.remaining-cell,
.multiplier-cell {
  color: var(--accent-strong);
}

.frozen-input,
.frozen-select {
  height: 36px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-weight: 640;
  outline: 0;
  padding: 0 8px;
}

.name-cell,
.type-cell,
.shares-cell,
.cost-input-cell,
.sell-cell {
  padding-left: 0;
}

.table-input {
  width: min(70px, 100%);
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0 7px;
}

.table-input::-webkit-inner-spin-button,
.table-input::-webkit-outer-spin-button {
  margin: 0;
}

.frozen-input::placeholder {
  color: #aaa097;
}

.frozen-select {
  appearance: none;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 17px, calc(100% - 8px) 17px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
  padding-right: 26px;
}

.frozen-input:hover,
.frozen-select:hover {
  border-color: var(--line);
  background-color: #f9fbf7;
}

.frozen-input:focus,
.frozen-select:focus {
  border-color: var(--accent);
  background-color: var(--surface-strong);
}

.action-column {
  width: 48px;
  text-align: center;
}

.table-actions {
  display: flex;
  justify-content: flex-start;
  border-top: 1px solid var(--line);
  background: #fbfaf6;
  padding: 12px;
}

.icon-button,
.delete-button {
  position: relative;
  width: 36px;
  height: 36px;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  border-color: var(--line);
  background: var(--surface);
  color: var(--danger);
  font-size: 0;
  line-height: 1;
  padding: 0;
}

.icon-button::before,
.delete-button::before {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  line-height: 1;
  transform: translateY(-1px);
}

.delete-button {
  width: 36px;
  min-width: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--danger);
  font-weight: 680;
}

.delete-button:disabled {
  cursor: default;
  opacity: 0.32;
}

.saved-shell {
  overflow: visible;
  margin-top: 30px;
}

.saved-heading {
  margin-bottom: 0;
}

.saved-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.saved-table th:first-child,
.saved-table td:first-child {
  width: 54%;
}

.saved-table th:nth-child(2),
.saved-table td:nth-child(2) {
  width: calc(46% - 54px);
}

.saved-table td {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.saved-link {
  color: var(--accent-strong);
  display: inline-block;
  max-width: 100%;
  font-weight: 720;
  text-decoration: none;
  overflow-wrap: anywhere;
  word-break: break-word;
}

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

.saved-action-column {
  width: 54px;
  text-align: center;
}

.empty-saved {
  color: var(--muted);
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 920px) {
  .topbar,
  .control-panel,
  .save-form {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .primary-button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app {
    width: calc(100% - 20px);
    padding: 10px 0;
  }

  .title-block,
  .summary-item {
    min-height: 112px;
  }

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

  h1 {
    font-size: 2.35rem;
  }
}
