/* SAT tab of Global Monitoring (ids gm-satv2-*).
   Colors come from the theme variables, so the KEO and K-Labs themes both apply.
   Sizes follow the width of the tab (container queries), not the window: on desktops
   the sidebar takes part of the screen. */

#gm-satv2-content {
  container-type: inline-size;
  container-name: gm-satv2;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: left;
  --gm-satv2-pad-x: 1.5rem;
  --gm-satv2-pad-y: 1.25rem;
  --gm-satv2-surface: var(--card-bg, #ffffff);
  --gm-satv2-border: var(--card-border, hsl(var(--border)));
  --gm-satv2-th-bg: hsl(var(--secondary));
  --gm-satv2-th-fg: var(--color-text-primary, hsl(var(--foreground)));
  --gm-satv2-th-border: hsl(var(--border));
  --gm-satv2-row-border: hsl(var(--border) / 0.6);
  --gm-satv2-row-hover: hsl(var(--accent) / 0.5);
  --gm-satv2-td-fg: var(--color-text-primary, hsl(var(--foreground)));
  --gm-satv2-strong: var(--color-primary, hsl(var(--foreground)));
  --gm-satv2-muted: hsl(var(--muted-foreground));
  --gm-satv2-down: hsl(4 70% 44%);
  --gm-satv2-up: hsl(150 60% 29%);
  --gm-satv2-cell-fs: 13px;
  --gm-satv2-th-fs: 12px;
  --gm-satv2-cell-px: 10px;
  --gm-satv2-cell-py: 7px;
}

/* The KEO theme forces p, span, td and label to the body size (16px) with !important:
   inside this tab the compact sizes below apply instead. */

#gm-satv2-content td.dash-cell,
#gm-satv2-content td.dash-cell * {
  font-size: var(--gm-satv2-cell-fs) !important;
  line-height: 1.35 !important;
}

#gm-satv2-content th.dash-header,
#gm-satv2-content th.dash-header * {
  font-size: var(--gm-satv2-th-fs) !important;
  font-weight: 600 !important;
  line-height: 1.25 !important;
}

/* RFC: first column of every table */
#gm-satv2-content td.dash-cell.column-0,
#gm-satv2-content td.dash-cell.column-0 * {
  font-weight: 600 !important;
  letter-spacing: 0.01em;
}

/* Change (%) of the sales tables: its color says if sales went down or up */
#gm-satv2-decreased-sales-datatable td.dash-cell.column-5,
#gm-satv2-decreased-sales-datatable td.dash-cell.column-5 *,
#gm-satv2-sales-change-table td.dash-cell.column-5,
#gm-satv2-sales-change-table td.dash-cell.column-5 * {
  font-weight: 600 !important;
}

#gm-satv2-without-rfc-note span {
  font-size: inherit !important;
  line-height: inherit !important;
}

/* Toolbar: update date, 'How to read this tab' and Sync on one row */

#gm-satv2-content .gm-satv2-toolbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

#gm-satv2-content .gm-satv2-updated {
  flex: 1 1 16rem;
  min-width: 0;
}

#gm-satv2-content .gm-satv2-updated-text {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--gm-satv2-muted);
}

#gm-satv2-content .gm-satv2-sync {
  flex: 0 0 auto;
}

/* Sync and Export: the same type as the help button (the KEO theme makes span text 16px) */
#gm-satv2-content .custom-button .button-text {
  font-size: 0.8125rem !important;
  font-weight: 600 !important;
}

/* 'How to read this tab': a button that opens a panel below the toolbar */

#gm-satv2-content .gm-satv2-help {
  flex: 0 0 auto;
  position: static;
  margin: 0;
}

#gm-satv2-content .gm-satv2-help > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  padding: 0 0.75rem;
  border: 1px solid var(--gm-satv2-border);
  border-radius: var(--app-radius, 8px);
  background: var(--gm-satv2-surface);
  color: var(--gm-satv2-strong);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}

#gm-satv2-content .gm-satv2-help > summary span {
  font-size: inherit !important;
  font-weight: inherit !important;
  line-height: inherit !important;
}

#gm-satv2-content .gm-satv2-help > summary::-webkit-details-marker { display: none; }

#gm-satv2-content .gm-satv2-help > summary:hover,
#gm-satv2-content .gm-satv2-help[open] > summary {
  background: var(--gm-satv2-th-bg);
}

#gm-satv2-content .gm-satv2-help > summary:focus-visible {
  outline: 2px solid var(--gm-satv2-strong);
  outline-offset: 2px;
}

#gm-satv2-content .gm-satv2-help-chevron {
  flex-shrink: 0;
  color: var(--gm-satv2-muted);
  transition: transform 150ms ease;
}

#gm-satv2-content .gm-satv2-help[open] > summary .gm-satv2-help-chevron { transform: rotate(180deg); }

#gm-satv2-content .gm-satv2-help-copy {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: min(65vh, 34rem);
  overflow: auto;
  padding: 1rem 1.25rem;
  border: 1px solid var(--gm-satv2-border);
  border-radius: var(--app-radius, 8px);
  background: var(--gm-satv2-surface);
  box-shadow: 0 18px 40px rgba(15, 35, 55, 0.16);
  color: var(--text-soft, #475569);
  font-size: 13px;
  line-height: 1.6;
}

/* The columns are on an inner element: a box with a height limit and columns would add
   columns to the right instead of scrolling down */
#gm-satv2-content .gm-satv2-help-columns {
  columns: 26rem 3;
  column-gap: 2rem;
}

#gm-satv2-content .gm-satv2-help-copy p,
#gm-satv2-content .gm-satv2-help-copy span {
  font-size: 13px !important;
  line-height: 1.6 !important;
}

#gm-satv2-content .gm-satv2-help-copy p { margin: 0.25rem 0; break-after: avoid; }
#gm-satv2-content .gm-satv2-help-copy ul { margin: 0 0 0.75rem; padding-left: 1.25rem; }
#gm-satv2-content .gm-satv2-help-copy li { break-inside: avoid; }

/* Cards: title and description, with their filters or buttons to the right */

#gm-satv2-content .gm-satv2-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: var(--gm-satv2-pad-y) var(--gm-satv2-pad-x) 0.875rem;
}

#gm-satv2-content .gm-satv2-card-heading {
  flex: 1 1 24rem;
  min-width: 0;
}

#gm-satv2-content .gm-satv2-card-description {
  max-width: 100ch;
  line-height: 1.45;
}

#gm-satv2-content .gm-satv2-card-actions {
  flex: 0 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  min-width: 0;
  max-width: 100%;
}

#gm-satv2-content .gm-satv2-card-body {
  padding: 0.25rem var(--gm-satv2-pad-x) var(--gm-satv2-pad-y);
}

/* Fields: a small label above its control */

#gm-satv2-content .gm-satv2-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  text-align: left;
}

#gm-satv2-content .gm-satv2-field > label {
  margin: 0 !important;
  font-size: 0.8125rem !important;
  color: var(--gm-satv2-muted) !important;
}

#gm-satv2-content .gm-satv2-field--inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 0.625rem;
}

#gm-satv2-content .gm-satv2-select {
  width: 13.5rem;
  max-width: 100%;
}

#gm-satv2-content .gm-satv2-select--wide {
  width: 24.5rem;
}

/* Card one: decreased sales and companies at risk */

#gm-satv2-content .gm-satv2-sections {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem 2.5rem;
}

#gm-satv2-content .gm-satv2-section {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-width: 0;
}

#gm-satv2-content .gm-satv2-section + .gm-satv2-section {
  padding-top: 1.25rem;
  border-top: 1px solid var(--gm-satv2-row-border);
}

#gm-satv2-content .gm-satv2-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

#gm-satv2-content .gm-satv2-section-title {
  flex: 1 1 15rem;
  min-width: 0;
  margin: 0;
  color: var(--gm-satv2-strong);
  font-size: 1rem !important;
  line-height: 1.3 !important;
}

#gm-satv2-content .gm-satv2-segmented {
  flex: 0 1 auto;
  max-width: 100%;
}

#gm-satv2-content .gm-satv2-notes {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

#gm-satv2-content .gm-satv2-notes > div {
  margin: 0 !important;
}

#gm-satv2-content .gm-satv2-counters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0 0 0.625rem;
}

#gm-satv2-content .gm-satv2-counters span {
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
}

#gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-label"],
#gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-label"] * {
  font-size: 0.875rem !important;
  line-height: 1.2 !important;
}

/* Long option texts end in '...' instead of being cut */
#gm-satv2-content .mantine-Select-input {
  text-overflow: ellipsis;
}

/* Very wide tab (ultrawide monitors): both tables side by side, each with room for every
   column on one line (on a 2560 monitor they stay one under the other: each half would wrap). */
@container gm-satv2 (min-width: 2600px) {
  #gm-satv2-content .gm-satv2-sections {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  #gm-satv2-content .gm-satv2-section + .gm-satv2-section {
    padding-top: 0;
    border-top: none;
  }
}

/* Card two: filters and threshold on one row while they fit */

#gm-satv2-content .gm-satv2-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.875rem 1.25rem;
  margin: 0 0 1rem;
}

#gm-satv2-content .gm-satv2-controls > .gm-satv2-field {
  flex: 0 1 auto;
}

#gm-satv2-content .gm-satv2-controls > .gm-satv2-field--slider {
  flex: 1 1 20rem;
  min-width: min(100%, 18rem);
  padding: 0 0.5rem 1.25rem;
}

#gm-satv2-content .custom-slider-ui .mantine-Slider-mark {
  width: 6px !important;
  height: 6px !important;
  border: none !important;
  background-color: hsl(var(--border)) !important;
}

#gm-satv2-content .custom-slider-ui .mantine-Slider-markLabel {
  font-size: 11px !important;
}

#gm-satv2-content .gm-satv2-export {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

#gm-satv2-content #gm-satv2-export-feedback:empty {
  display: none;
}

#gm-satv2-content .gm-satv2-export-done {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--gm-satv2-up);
  font-size: 0.8125rem !important;
  font-weight: 600 !important;
}

/* Tables: light header, thin row lines, a soft shadow on the side that scrolls */

#gm-satv2-content .dash-table-container {
  margin: 0;
}

#gm-satv2-content .dash-spreadsheet-container {
  border: 1px solid var(--gm-satv2-th-border);
  border-radius: var(--app-radius, 8px);
  background:
    linear-gradient(to right, var(--gm-satv2-surface) 30%, rgba(255, 255, 255, 0)) left center / 28px 100% no-repeat local,
    linear-gradient(to left, var(--gm-satv2-surface) 30%, rgba(255, 255, 255, 0)) right center / 28px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(15, 35, 55, 0.18), rgba(15, 35, 55, 0)) left center / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(15, 35, 55, 0.18), rgba(15, 35, 55, 0)) right center / 12px 100% no-repeat scroll;
}

#gm-satv2-content .dash-spreadsheet-inner table,
#gm-satv2-content .dash-spreadsheet-inner tr {
  background: transparent;
}

#gm-satv2-content .dash-spreadsheet-inner th {
  font-variant-numeric: tabular-nums;
}

#gm-satv2-content .dash-spreadsheet-inner td {
  font-variant-numeric: tabular-nums;
}

#gm-satv2-content .dash-spreadsheet-inner tr:hover td.dash-cell {
  background-color: var(--gm-satv2-row-hover) !important;
}

#gm-satv2-content .dash-spreadsheet-inner tr:last-of-type td.dash-cell {
  border-bottom: none !important;
}

#gm-satv2-content .dash-spreadsheet-inner td.cell--selected,
#gm-satv2-content .dash-spreadsheet-inner td.focused {
  background-color: var(--gm-satv2-row-hover) !important;
}

#gm-satv2-content .dash-spreadsheet-inner td.focused {
  box-shadow: inset 0 0 0 1px var(--gm-satv2-th-border) !important;
}

/* Tooltip of a client name: the full name (and the SAT name when it differs) */

#gm-satv2-content .dash-table-tooltip {
  max-width: 24rem;
  padding: 0.5rem 0.75rem !important;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(15, 35, 55, 0.14);
}

#gm-satv2-content .dash-table-tooltip p,
#gm-satv2-content .dash-table-tooltip span {
  margin: 0 !important;
  font-size: 12.5px !important;
  line-height: 1.45 !important;
}

#gm-satv2-content .dash-table-tooltip p + p {
  margin-top: 0.375rem !important;
}

/* Pager of the tables */

#gm-satv2-content .previous-next-container {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0 0;
}

#gm-satv2-content .previous-next-container button {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid var(--gm-satv2-th-border);
  border-radius: 6px;
  background: var(--gm-satv2-surface);
  color: var(--gm-satv2-strong);
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
}

#gm-satv2-content .previous-next-container button:hover:not(:disabled) {
  background: var(--gm-satv2-th-bg);
}

#gm-satv2-content .previous-next-container button:disabled {
  opacity: 0.4;
  cursor: default;
}

#gm-satv2-content .previous-next-container .page-number {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.375rem;
  color: var(--gm-satv2-muted);
  font-size: 0.8125rem;
}

#gm-satv2-content .previous-next-container input.current-page {
  border: 1px solid var(--gm-satv2-th-border);
  border-radius: 6px;
  background: var(--gm-satv2-surface);
  color: var(--gm-satv2-strong);
}

/* Tables keep every column visible on laptops: smaller cells as the tab narrows */
/* A container query styles the descendants of the container, never the container itself:
   the variables are set on its children (they inherit them). */
@container gm-satv2 (max-width: 1100px) {
  #gm-satv2-content > * {
    --gm-satv2-cell-fs: 12.5px;
    --gm-satv2-th-fs: 11.5px;
    --gm-satv2-cell-px: 8px;
    --gm-satv2-cell-py: 6px;
  }
}

@container gm-satv2 (max-width: 960px) {
  #gm-satv2-content > * {
    --gm-satv2-cell-fs: 12px;
    --gm-satv2-cell-px: 7px;
  }
}

/* K-Labs uses Sora, a wider font: one step smaller at the same widths */
@container gm-satv2 (max-width: 1100px) {
  :root[data-theme="k-labs"] #gm-satv2-content > * {
    --gm-satv2-cell-fs: 12px;
    --gm-satv2-th-fs: 11px;
    --gm-satv2-cell-px: 7px;
  }
}

@container gm-satv2 (max-width: 960px) {
  :root[data-theme="k-labs"] #gm-satv2-content > * {
    --gm-satv2-cell-fs: 11.5px;
    --gm-satv2-cell-px: 6px;
  }
}

/* Narrow tab (phones and small tablets): less padding, full-width controls, options in a grid */
@container gm-satv2 (max-width: 640px) {
  #gm-satv2-content > * {
    --gm-satv2-pad-x: 0.875rem;
    --gm-satv2-pad-y: 1rem;
  }

  #gm-satv2-content .gm-satv2-card-actions,
  #gm-satv2-content .gm-satv2-card-actions > *,
  #gm-satv2-content .gm-satv2-select,
  #gm-satv2-content .gm-satv2-select--wide {
    width: 100%;
  }

  #gm-satv2-content .gm-satv2-controls > .gm-satv2-field {
    flex: 1 1 100%;
  }

  #gm-satv2-content .gm-satv2-segmented {
    display: grid !important;
    width: 100%;
  }

  #gm-satv2-content .gm-satv2-segmented--grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #gm-satv2-content .gm-satv2-segmented--grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-label"],
  #gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-label"] * {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  #gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-label"] {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  /* The separators between options only make sense on one row */
  #gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-control"]::before {
    display: none !important;
  }

  /* Help and Sync share a row under the update date */
  #gm-satv2-content .gm-satv2-toolbar {
    gap: 0.5rem;
  }

  #gm-satv2-content .gm-satv2-updated {
    flex-basis: 100%;
  }

  #gm-satv2-content .gm-satv2-help > summary {
    padding: 0 0.625rem;
    gap: 0.375rem;
  }

  /* Phones: the help grows with its text (the page scrolls), never a small box with its own scroll */
  #gm-satv2-content .gm-satv2-help-copy {
    max-height: none;
    overflow: visible;
    padding: 0.875rem 1rem;
  }

  /* Options of the grid: each fills its cell, centered, at least 36px tall to tap */
  #gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-control"] {
    display: flex;
  }

  #gm-satv2-content .gm-satv2-segmented [class*="mantine-SegmentedControl-label"] {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.25rem;
  }
}
