/* Reusable pieces, after design/app-reference.html. Colours come from tokens.css only. */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}

.button:hover {
  background: var(--sunken);
  color: var(--ink);
}

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

.button:disabled:hover {
  background: var(--surface);
  color: var(--ink-soft);
}

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.button--primary:hover {
  border-color: var(--accent-soft);
  background: var(--accent-soft);
  color: var(--on-accent);
}

.button--primary:disabled:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.button--quiet {
  border-color: transparent;
  background: transparent;
}

.button--quiet:disabled:hover {
  background: transparent;
}

.link-button {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.link-button:hover {
  color: var(--accent-soft);
}

/* A panel: forms and the sign-in box. */
.card {
  padding: 18px 20px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.card h2 {
  margin-bottom: 14px;
}

.form {
  display: grid;
  gap: 14px;
}

.form__field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

/* Fields fill their column instead of keeping the browser's default width, which can
   be wider than a grid cell and run into the next field. */
.form .form__field > input,
.form .form__field > select,
.form .form__field > textarea {
  width: 100%;
  min-width: 0;
}

.form__label,
.filter__label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
}

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

.form--grid {
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.form__field--wide {
  grid-column: 1 / -1;
}

.form__actions {
  display: flex;
  gap: 8px;
}

.auth {
  margin-top: 0;
}

.auth__title {
  font-size: 24px;
}

.auth__switch {
  margin-top: 14px;
  font-size: 13px;
}

.auth .button--primary {
  width: 100%;
  padding: 10px 15px;
}

.auth__back {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
}

/* The sign-in and register page stands alone, without the sidebar: the brand and the
   language and theme controls lie in a bar over the page, so the form keeps the true
   centre of the viewport. */
.auth-page__bar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px clamp(16px, 4vw, 40px);
}

.auth-page__brand {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--ink);
  text-decoration: none;
}

.auth-page__brand::after {
  content: ".";
  letter-spacing: 0;
  color: var(--accent);
}

.auth-page__brand:hover {
  color: var(--ink);
}

.auth-page__controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-page__main {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 80px 16px;
}

.auth-page .auth {
  width: min(400px, 100%);
}

.filter {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Companies, after design/companies-reference.html: a row each - the name with its tax
   ID and contract count; two bars, its contracts by status and the risk mix of its
   analysed contracts; and its nearest end date - under a legend for the colours. */
.companies-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 14px 0 12px;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.companies-legend__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
}

.companies-legend__name {
  color: var(--muted);
}

.companies-legend__key {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--line);
}

.swatch[data-status="active"],
.mix-bar__cell[data-status="active"] {
  background: var(--status-active);
}

.swatch[data-status="draft"],
.mix-bar__cell[data-status="draft"] {
  background: var(--status-draft);
}

.swatch[data-status="expired"],
.mix-bar__cell[data-status="expired"] {
  background: var(--status-expired);
}

.swatch[data-status="terminated"],
.mix-bar__cell[data-status="terminated"] {
  background: var(--status-terminated);
}

.swatch[data-risk="red"],
.mix-bar__cell[data-risk="red"] {
  background: var(--risk-red);
}

.swatch[data-risk="yellow"],
.mix-bar__cell[data-risk="yellow"] {
  background: var(--risk-yellow);
}

.swatch[data-risk="green"],
.mix-bar__cell[data-risk="green"] {
  background: var(--risk-green);
}

.company-list__items {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.company-list__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px) 140px;
  align-items: center;
  gap: 24px;
  padding: 18px 12px;
  border-bottom: 1px solid var(--line);
}

.company-list__item:hover {
  background: var(--surface);
}

.company-list__name {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.company-list__name:hover {
  color: var(--accent);
  text-decoration: underline;
}

.company-list__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.company-list__meta > * + *::before {
  content: "·";
  margin-right: 6px;
}

.company-list__bars {
  display: grid;
  gap: 9px;
}

.mix-bar__label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 10.5px;
  color: var(--muted);
}

/* One cell per contract (or clause), so the bar splits in proportion without any width
   set from script; a thin line where one group meets the next. */
.mix-bar {
  display: flex;
  height: 8px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--line);
}

.mix-bar__cell {
  flex: 1 1 0;
  min-width: 0;
}

.mix-bar__cell--start:not(:first-child) {
  box-shadow: inset 1px 0 0 var(--bg);
}

/* No analysed contract: said quietly, in place of the risk bar. */
.company-list__none {
  display: flex;
  align-items: center;
  min-height: 30px;
  margin: 0;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
}

.company-list__end {
  text-align: right;
}

.company-list__end > p {
  margin: 0;
}

.company-list__end-label {
  font-size: 10.5px;
  color: var(--muted);
}

.company-list__end-date {
  margin-top: 2px;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.company-list__end-days {
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
}

/* Ending within 90 days. */
.company-list__end-days[data-soon] {
  font-weight: 500;
  color: var(--accent);
}

.company-details {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 13px;
  color: var(--muted);
}

.company-details__tax {
  font-size: 12px;
  color: var(--muted);
}

.company-details__notes {
  color: var(--ink-soft);
}

.status-counts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

.status-counts__item {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.status-counts__item[data-count="0"] {
  opacity: 0.55;
}

.status-counts__number {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

@media (max-width: 640px) {
  .company-list__item {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .company-list__end {
    text-align: left;
  }
}

/* Tables sit in a panel. */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.table-scroll:has(> table[hidden]) {
  display: none;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table th {
  background: var(--sunken);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

.data-table td {
  font-size: 13.5px;
  color: var(--ink-soft);
}

.data-table tbody tr:hover {
  background: var(--sunken);
}

.data-table td a {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}

.data-table td a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Amendments listed as lines - on an overview, and opened under a contract's row. */
.amendment-lines {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
}

.amendment-lines:empty {
  display: none;
}

.amendment-lines > li + li {
  border-top: 1px solid var(--line-soft);
}

.amendment-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 11px 14px;
  background: var(--surface);
}

.amendment-line__title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}

.amendment-line__title:hover {
  color: var(--accent);
  text-decoration: underline;
}

.amendment-line__date,
.amendment-line__counts {
  font-size: 12px;
  color: var(--muted);
}

.amendment-line__counts {
  margin-left: auto;
  color: var(--ink-soft);
}

.amendment-line .inactive-reason {
  flex-basis: 100%;
}

/* A contract row's amendment count, which opens the row listing them. */
.amendment-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.amendment-toggle:hover {
  border-color: var(--accent-soft);
  color: var(--ink);
}

.amendment-toggle .icon {
  width: 11px;
  height: 11px;
  transition: transform 0.2s ease;
}

.amendment-toggle[aria-expanded="true"] .icon {
  transform: rotate(90deg);
}

.data-table tr.is-expanded td {
  border-bottom-color: transparent;
}

.data-table .data-table__detail td {
  padding: 0 14px 14px 28px;
}

.data-table tbody tr.data-table__detail:hover {
  background: none;
}

/* The amendments page: each contract heads the group of its amendments. */
.data-table .data-table__group th {
  padding: 14px 14px 8px;
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 400;
  text-align: left;
  color: var(--muted);
}

.data-table--grouped tbody + tbody .data-table__group th {
  border-top: 1px solid var(--line);
}

.data-table tbody tr.data-table__group:hover {
  background: none;
}

.data-table__group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

.data-table .data-table__group-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.data-table .data-table__group-title:hover {
  color: var(--accent);
  text-decoration: underline;
}

.data-table .data-table__group-meta {
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: none;
}

.data-table a.data-table__group-meta:hover {
  color: var(--ink);
  text-decoration: underline;
}

.data-table__group-count {
  margin-left: auto;
  font-size: 12px;
}

/* An amendment under its contract, after a corner marker as in the sidebar. */
.data-table .data-table__child td:first-child {
  padding-left: 34px;
}

.data-table .data-table__child td:first-child::before {
  content: "└";
  margin: 0 6px 0 -16px;
  color: var(--muted);
  opacity: 0.7;
}

/* Dates, document numbers and company names stay on one line; a long state may wrap,
   and titles take the room that is left, but never less than a short title needs. */
.data-table td[data-date],
.data-table .data-table__code,
.data-table .data-table__secondary {
  white-space: nowrap;
}

.data-table td:first-child {
  min-width: 6rem;
}

/* Counts, right-aligned in their column. */
.data-table .data-table__number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td.data-table__number {
  font-weight: 600;
  color: var(--ink);
}

.data-table td[data-kind="favour"]:not([data-count="0"], [data-count=""]) {
  color: var(--risk-green);
}

.data-table__empty {
  font-weight: 400;
  color: var(--muted);
}

/* A link in a secondary column, such as the counterparty. */
.data-table td a.data-table__secondary {
  font-size: 13.5px;
  font-weight: 400;
  color: var(--ink-soft);
}

/* Just above 1200px the context column leaves the tables the least room: tighter cells. */
@media (min-width: 1200px) and (max-width: 1299.98px) {
  .page--columns .data-table th,
  .page--columns .data-table td {
    padding-right: 8px;
    padding-left: 8px;
  }
}

/* A title with the other party, the number and the start date under it (the contracts
   list), so the table keeps to four columns beside the context column. */
.data-table td.data-table__title {
  min-width: 11rem;
}

.data-table__sub {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.data-table td .data-table__sub a {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-soft);
}

/* A status pill in its status's colour (--status-* in tokens.css), the same as in the
   companies' bars and legend, so a status has one colour everywhere: a dot of it and a
   tint of it, the label in ink. Amendments share active and terminated. */
.status-badge {
  --status: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid transparent;
  border-radius: 20px;
  background: color-mix(in srgb, var(--status) 16%, transparent);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink-soft);
}

.status-badge::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status);
}

.status-badge[data-status="active"] {
  --status: var(--status-active);
}

.status-badge[data-status="draft"] {
  --status: var(--status-draft);
}

.status-badge[data-status="expired"] {
  --status: var(--status-expired);
}

.status-badge[data-status="terminated"] {
  --status: var(--status-terminated);
}

/* An amendment active in itself whose base contract is not in force. */
.status-badge[data-status="inactive"] {
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
}

.inactive-reason {
  font-size: 12px;
  color: var(--muted);
}

.data-table__note {
  display: block;
  margin-top: 4px;
}

/* A status pill that opens a small form to change the status. */
.status-editor {
  position: relative;
}

.status-editor__summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  list-style: none;
  cursor: pointer;
}

.status-editor__summary::-webkit-details-marker {
  display: none;
}

.status-editor__summary:hover {
  border-color: var(--accent-soft);
}

.status-editor__summary .icon {
  width: 11px;
  height: 11px;
  opacity: 0.7;
}

.status-editor[open] .status-editor__summary .icon {
  transform: rotate(180deg);
}

.status-editor__form {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  width: 270px;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--popover-shadow);
}

.status-editor__options {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.status-editor__option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}

.status-editor__option input {
  margin: 0;
  accent-color: var(--accent);
}

.status-editor__hint {
  margin: 0;
  font-size: 12px;
}

.status-editor .form__error {
  margin: 0;
}

.state-label {
  font-size: 12.5px;
  color: var(--muted);
}

.state-label[data-state="extracting"],
.state-label[data-state="analysing"] {
  color: var(--accent);
}

.state-label[data-state="analysed"] {
  color: var(--risk-green);
}

.state-label[data-state="extractionFailed"],
.state-label[data-state="analysisFailed"] {
  color: var(--risk-red);
}

.notice {
  font-size: 13.5px;
  color: var(--muted);
}

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

/* Risk as a tinted label. Set with data-risk="red|yellow|green|none". */
.risk-badge {
  display: inline-block;
  flex: none;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
}

.risk-badge[data-risk="red"] {
  background: var(--risk-red-tint);
  color: var(--risk-red);
}

.risk-badge[data-risk="yellow"] {
  background: var(--risk-yellow-tint);
  color: var(--risk-yellow);
}

.risk-badge[data-risk="green"] {
  background: var(--risk-green-tint);
  color: var(--risk-green);
}

/* ---------- risk: a bar split in proportion, the counts under it - on the contract
   overview and in the context column ---------- */

.risk-bar {
  display: flex;
  height: 14px;
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
}

/* One cell per clause, grouped by level, so the bar splits in proportion. */
.risk-bar__cell {
  flex: 1 1 0;
  min-width: 0;
  background: var(--line);
}

.risk-bar__cell[data-risk="red"] {
  background: var(--risk-red);
}

.risk-bar__cell[data-risk="yellow"] {
  background: var(--risk-yellow);
}

.risk-bar__cell[data-risk="green"] {
  background: var(--risk-green);
}

.figure {
  --mark: var(--line);
}

.figure[data-risk="red"] {
  --mark: var(--risk-red);
}

.figure[data-risk="yellow"] {
  --mark: var(--risk-yellow);
}

.figure[data-risk="green"],
.figure[data-kind="favour"] {
  --mark: var(--risk-green);
}

.risk-figures {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  font-size: 13px;
}

.risk-figures .figure {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
}

.risk-figures .figure::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--mark);
}

.risk-figures .figure__number {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.figure[data-kind="against"] {
  --mark: var(--risk-red);
}

/* ---------- the context column's panels (layout.css places the column) ---------- */

.context__heading {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}

.context__panel {
  padding: 16px 18px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.context__title {
  margin: 0 0 12px;
  font-size: 14px;
}

.context__note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.context__title + .context__note,
.context__panel > .context__note:first-child {
  margin-top: 0;
}

.context__figure {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}

.context-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.context-list__item {
  display: grid;
  gap: 3px;
  min-width: 0;
}

/* A clause carries its risk stripe, as in the text. */
.context-list__item[data-risk] {
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.context-list__item[data-risk="red"] {
  border-left-color: var(--risk-red);
}

.context-list__link {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}

.context-list__link:hover {
  color: var(--accent);
}

.context-list__number {
  margin-right: 6px;
  color: var(--muted);
}

.context-list__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  font-size: 12px;
  color: var(--muted);
}

.context-list__meta a {
  color: var(--ink-soft);
}

.context .risk-figures {
  gap: 6px 16px;
}

/* Days left until a contract ends: urgent within 30 days, amber within 90. */
.days-badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--risk-yellow);
}

.days-badge[data-urgency="critical"] {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

/* A list row with a badge at its end. */
.context-list__item--with-badge {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 10px;
}

.context-list__item--with-badge > :not(.days-badge) {
  grid-column: 1;
}

.context-list__item--with-badge > .days-badge {
  grid-column: 2;
  grid-row: 1;
}
