/*
 * Mantine, restyled with our tokens (tokens.css). Mantine injects its own styles after ours at
 * runtime, so each selector here starts with `html` to outrank the Mantine rule it replaces.
 */

html:root[data-mantine-color-scheme] {
  --mantine-color-body: var(--fi-paper);
  --mantine-color-text: var(--fi-ink);
  --mantine-color-dimmed: var(--fi-ink-3);
  --mantine-color-placeholder: var(--fi-ink-3);
  --mantine-color-anchor: var(--fi-accent);
  --mantine-color-error: var(--fi-error-ink);
  --mantine-color-default: var(--fi-surface);
  --mantine-color-default-hover: var(--fi-surface-2);
  --mantine-color-default-color: var(--fi-ink);
  --mantine-color-default-border: var(--fi-control);

  /* Harbour's light variant (active nav, selected states) is exactly the accent token. */
  --mantine-color-harbour-light: var(--fi-accent-tint);
  --mantine-color-harbour-light-hover: var(--fi-accent-tint-hover);
  --mantine-color-harbour-light-color: var(--fi-accent);

  /* Alerts and badges: red is an error, yellow a warning, gray neutral. */
  --mantine-color-red-light: var(--fi-error-bg);
  --mantine-color-red-light-hover: var(--fi-error-bg);
  --mantine-color-red-light-color: var(--fi-error-ink);
  --mantine-color-yellow-light: var(--fi-warning-bg);
  --mantine-color-yellow-light-hover: var(--fi-warning-bg);
  --mantine-color-yellow-light-color: var(--fi-warning-ink);
  --mantine-color-gray-light: var(--fi-surface-2);
  --mantine-color-gray-light-color: var(--fi-ink-2);
}

/* Keyboard focus: a Harbour ring, only when navigating with the keyboard. */
html .mantine-focus-auto:focus-visible,
html .mantine-focus-always:focus,
html .mantine-Chip-input:focus-visible + .mantine-Chip-label {
  outline-color: var(--fi-accent);
}

html .mantine-SegmentedControl-input[data-focus-ring]:focus:focus-visible
  + .mantine-SegmentedControl-label {
  --segmented-control-outline: 2px solid var(--fi-accent);
}

/* Inputs, selects and date pickers: a 3:1 control border, Harbour on focus. */
html[data-mantine-color-scheme] .mantine-Input-wrapper[data-variant="default"] {
  --input-bd: var(--fi-control);
  --input-bd-focus: var(--fi-accent);
  --input-bg: var(--fi-surface);
}

html .mantine-InputWrapper-label {
  color: var(--fi-ink-2);
  font-weight: 500;
}

/* Buttons and badges: medium weight, no shouting. */
html .mantine-Button-root {
  font-weight: 500;
}

html .mantine-Badge-root {
  font-weight: 500;
  letter-spacing: 0;
}

/* Chips: outlined; selected ones take a Harbour border, text and tint. */
html .mantine-Chip-label:not([data-disabled]) {
  border-color: var(--fi-control);
  background-color: var(--fi-surface);
  color: var(--fi-ink-2);
}

html .mantine-Chip-label:not([data-disabled]):hover {
  background-color: var(--fi-surface-2);
}

html .mantine-Chip-label:not([data-disabled])[data-checked] {
  --chip-icon-color: var(--fi-accent);
  border-color: var(--fi-accent);
  background-color: var(--fi-accent-tint);
  color: var(--fi-accent);
  font-weight: 500;
}

html .mantine-Chip-label:not([data-disabled])[data-checked]:hover {
  background-color: var(--fi-accent-tint-hover);
}

/* Segmented controls: a quiet track with a raised, outlined selection. */
html .mantine-SegmentedControl-root {
  --sc-color: var(--fi-surface);
  background-color: var(--fi-surface-2);
  box-shadow: inset 0 0 0 1px var(--fi-rule);
}

html .mantine-SegmentedControl-indicator {
  box-shadow: 0 0 0 1px var(--fi-rule);
}

html .mantine-SegmentedControl-label {
  color: var(--fi-ink-2);
}

html .mantine-SegmentedControl-label:hover,
html .mantine-SegmentedControl-label[data-active] {
  color: var(--fi-ink);
}

/* Navigation: the active page gets a Harbour rule and tint, not a filled pill. */
html .mantine-NavLink-root {
  border-radius: 0 var(--fi-radius) var(--fi-radius) 0;
  color: var(--fi-ink-2);
}

html .mantine-NavLink-root:hover {
  background-color: var(--fi-surface-2);
}

html .mantine-NavLink-root[data-active] {
  background-color: var(--fi-accent-tint);
  box-shadow: inset 2px 0 0 var(--fi-accent);
  color: var(--fi-accent);
}

html .mantine-NavLink-root[data-active]:hover {
  background-color: var(--fi-accent-tint-hover);
}

html .mantine-NavLink-root[data-active] .mantine-NavLink-label {
  font-weight: 600;
}

/* Tabs */
html .mantine-Tabs-tab {
  font-weight: 500;
}

/* Alerts: status-coloured title, body text in ink. */
html .mantine-Alert-title {
  font-weight: 600;
}

html .mantine-Alert-message {
  color: var(--fi-ink);
}

/* Accordion (voyage terms): hairline borders on the surface. */
html .mantine-Accordion-item {
  --item-border-color: var(--fi-rule);
  --item-filled-color: var(--fi-surface);
  background-color: var(--fi-surface);
}

/* Chart tooltips sit on the surface the series colours were validated against. */
html .mantine-ChartTooltip-tooltip {
  background-color: var(--fi-surface);
  border-color: var(--fi-rule);
}

html .mantine-Accordion-label {
  font-size: 14px;
  font-weight: 500;
}

/* Fixtures: "Fixed on" is quiet, since most fixtures are entered as they happen. */
html .fi-quiet-field .mantine-InputWrapper-label {
  color: var(--fi-ink-3);
  font-weight: 400;
}

/* The freight matrix's add-row strip (pages/matrix.py): its boxes sit edge to edge, like
   the table's cells above them. */
html .fi-matrix-strip .mantine-Select-input {
  border-radius: 0;
}

html .fi-matrix-strip .mantine-Button-root {
  margin-left: 8px;
}

/* The fixture page's list headers: title and caption on the left, switches pinned to the right
   corner. The caption wraps under the title rather than pushing the switches to a new line; on
   a phone the switches drop below, still on the right. */
html .fi-list-header {
  flex-wrap: nowrap;
}
html .fi-list-header > .fi-list-title {
  flex: 1 1 auto;
  min-width: 0;
}
html .fi-list-header > .fi-list-controls {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  margin-left: auto;
}
@media (max-width: 48em) {
  html .fi-list-header,
  html .fi-list-header > .fi-list-controls {
    flex-wrap: wrap;
  }
  html .fi-list-header > .fi-list-controls {
    flex-shrink: 1;
    max-width: 100%;
    justify-content: flex-end;
  }
}
