@font-face {
  font-family: "Montserrat";
  src: url("/assets/fonts/Montserrat.ttf") format("truetype");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --charcoal: #58595b;
  --teal: #008286;
  --amber: #fbb034;
  --red: #b11116;
  --white: #ffffff;
  --black: #000000;
  --charcoal-rgb: 88, 89, 91;
  --teal-rgb: 0, 130, 134;
  --line: rgba(var(--charcoal-rgb), 0.18);
  --line-strong: rgba(var(--charcoal-rgb), 0.34);
  --surface-soft: rgba(var(--teal-rgb), 0.055);
  --surface-tint: rgba(var(--teal-rgb), 0.09);
  --text-soft: rgba(var(--charcoal-rgb), 0.72);
  --font: "Montserrat", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--white);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--surface-soft);
  color: var(--charcoal);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 300;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(var(--teal-rgb), 0.22);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(176px, 246px) 1fr auto;
  gap: 24px;
  align-items: center;
  padding: 16px clamp(18px, 4vw, 44px);
  background: var(--white);
  border-bottom: 4px solid var(--teal);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.brand img {
  width: min(222px, 100%);
  height: auto;
  display: block;
}

.topbar-title {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  color: var(--charcoal);
  border-left: 1px solid var(--line);
  padding-left: 22px;
}

.topbar-title span,
.eyebrow {
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-title strong {
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: 700;
  white-space: nowrap;
}

.workspace {
  width: min(1380px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 34px);
  padding: clamp(18px, 3vw, 34px);
}

.rail,
.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.rail {
  align-self: start;
  position: sticky;
  top: 18px;
  min-height: 620px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.rail-head {
  padding: 30px 28px 24px;
  border-bottom: 1px solid var(--line);
}

.rail h1,
.panel h2 {
  margin: 6px 0 0;
  color: var(--charcoal);
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 700;
  line-height: 1.06;
}

.stepper {
  list-style: none;
  padding: 18px 0;
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.stepper li {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  min-height: 54px;
  padding: 0 28px;
  color: var(--text-soft);
  border-left: 4px solid transparent;
}

.stepper li span {
  font-size: 11px;
  font-weight: 700;
}

.stepper li strong {
  font-size: 13px;
  font-weight: 500;
}

.stepper li.is-active {
  color: var(--charcoal);
  background: var(--surface-soft);
  border-left-color: var(--teal);
}

.stepper li.is-done {
  color: var(--teal);
}

.summary {
  margin: 0;
  padding: 24px 28px 28px;
  display: grid;
  align-content: end;
  gap: 16px;
}

.summary div {
  display: grid;
  gap: 4px;
}

.summary dt {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--teal);
}

.summary dd {
  min-width: 0;
  margin: 0;
  color: var(--charcoal);
  font-size: 15px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.stage {
  min-width: 0;
}

.panel {
  min-height: 620px;
  padding: clamp(24px, 4vw, 44px);
}

.panel-head {
  margin-bottom: 28px;
}

.panel-head h2,
.result-head h2,
.panel-loading h2 {
  font-size: clamp(30px, 5vw, 54px);
}

.form-stack,
.form-grid {
  display: grid;
  gap: 18px;
}

.compact-form {
  max-width: 420px;
}

.form-grid {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  align-items: end;
}

.grid-span {
  grid-column: 1 / -1;
}

.field {
  min-width: 0;
  display: grid;
  gap: 7px;
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 700;
}

.field span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.field input,
.select-button {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--white);
  color: var(--charcoal);
  padding: 0 13px;
  font-size: 14px;
  font-weight: 400;
}

.field input::placeholder {
  color: rgba(var(--charcoal-rgb), 0.48);
}

#username {
  text-transform: uppercase;
}

.field input:disabled {
  color: rgba(var(--charcoal-rgb), 0.45);
  border-color: var(--line);
}

.actions {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 16px;
  background: var(--white);
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: var(--surface-soft);
}

.button:disabled {
  cursor: default;
  color: rgba(var(--charcoal-rgb), 0.46);
  border-color: var(--line);
  background: var(--white);
}

.button-primary {
  color: var(--white);
  background: var(--teal);
  border-color: var(--teal);
}

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

.button-secondary {
  color: var(--charcoal);
  background: var(--white);
}

.button-quiet {
  min-width: 132px;
}

.message {
  min-height: 18px;
  margin: 0;
  font-size: 12px;
  font-weight: 500;
}

.message-error {
  color: var(--red);
}

.panel-loading {
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 16px;
}

.panel-loading p {
  margin: 0;
  color: var(--text-soft);
}

.loader {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(var(--charcoal-rgb), 0.16);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.panel-results {
  display: grid;
  gap: 20px;
}

.result-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.export-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.metrics div {
  min-height: 82px;
  padding: 16px 18px;
  display: grid;
  align-content: center;
  gap: 6px;
  background: var(--white);
  border-right: 1px solid var(--line);
}

.metrics div:last-child {
  border-right: 0;
}

.metrics span {
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.metrics strong {
  color: var(--charcoal);
  font-size: clamp(21px, 3vw, 32px);
  font-weight: 700;
  line-height: 1;
  overflow-wrap: anywhere;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 360px) minmax(180px, 1fr);
  gap: 14px;
  align-items: end;
}

.dropdown {
  position: relative;
}

.select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
}

.select-button::after {
  content: "⌄";
  color: var(--teal);
  font-weight: 700;
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  right: 0;
  z-index: 15;
  max-height: 288px;
  overflow: auto;
  padding: 8px;
  background: var(--white);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.contract-option {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 4px;
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.contract-option:hover,
.contract-option.is-checked {
  background: var(--surface-soft);
  color: var(--teal);
}

.contract-option input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--teal);
}

.sortbar {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sortchip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--teal);
  border-radius: 6px;
  color: var(--teal);
  background: var(--white);
  font-size: 11px;
  font-weight: 700;
}

.sortchip button {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--teal);
  cursor: pointer;
}

.sortchip button:hover {
  background: var(--surface-tint);
}

.tablewrap {
  width: 100%;
  max-height: 48vh;
  min-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0;
  background: var(--surface-tint);
  border-bottom: 1px solid var(--line);
}

thead button {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--charcoal);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

thead th.num button {
  justify-content: flex-end;
}

thead button:hover {
  color: var(--teal);
  background: rgba(var(--teal-rgb), 0.08);
}

.sortmark {
  min-width: 22px;
  color: var(--teal);
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(var(--charcoal-rgb), 0.1);
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 400;
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: rgba(var(--teal-rgb), 0.035);
}

tbody tr:hover {
  background: var(--surface-soft);
}

.num {
  text-align: right;
}

.empty-row td {
  height: 120px;
  text-align: center;
  color: var(--text-soft);
}

.split-actions {
  justify-content: space-between;
  align-items: center;
}

.split-actions .message {
  margin-left: auto;
  text-align: right;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  min-width: min(420px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  padding: 12px 18px;
  border: 1px solid var(--charcoal);
  border-radius: 6px;
  background: var(--charcoal);
  color: var(--white);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.toast.is-visible {
  opacity: 1;
}

.context-menu {
  position: fixed;
  z-index: 25;
  min-width: 216px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--white);
}

.context-menu button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 4px;
  background: var(--white);
  color: var(--charcoal);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.context-menu button:hover {
  background: var(--surface-soft);
  color: var(--teal);
}

.context-menu hr {
  height: 1px;
  margin: 5px 0;
  border: 0;
  background: var(--line);
}

@media (max-width: 940px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 14px;
  }

  .topbar-title {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-left: 0;
    border-left: 0;
  }

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

  .rail {
    position: static;
    min-height: auto;
  }

  .summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: start;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 13px;
  }

  .topbar {
    padding: 14px 16px;
  }

  .brand img {
    width: min(180px, 58vw);
  }

  .topbar-title {
    align-items: start;
    flex-direction: column;
    gap: 2px;
  }

  .workspace {
    padding: 14px;
  }

  .rail-head,
  .panel {
    padding: 22px 18px;
  }

  .stepper li {
    padding: 0 18px;
  }

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

  .form-grid,
  .filters,
  .metrics {
    grid-template-columns: 1fr;
  }

  .metrics div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metrics div:last-child {
    border-bottom: 0;
  }

  .result-head {
    display: grid;
  }

  .export-actions,
  .actions {
    width: 100%;
  }

  .button {
    flex: 1 1 auto;
  }

  .split-actions .message {
    flex-basis: 100%;
    text-align: left;
  }
}
