/* ---- RADAR UI kit ------------------------------------------------------------------------------------------
   One set of form fields, buttons, cards and page layouts for every page, written once here so a page
   doesn't carry its own long class strings. docs/developers/ui_kit.md says how to use them, and /design shows
   every one of them, in both themes, at any width.

   Rules the kit keeps:
   - Phones first. A field or button is 44px tall on a phone (Apple's smallest comfortable tap target) and 40px
     from sm up, and a field's text is 16px on a phone so iOS doesn't zoom in when it takes focus.
   - Dark mode for free. Colours come from the palette variables that html.dark swaps (see
     application.tailwind.css), and white surfaces from --color-surface, so nothing here needs a dark: twin.
     The few colours the swap would get wrong (a solid button's hover) are written out.
   - Plain CSS on plain elements. A class goes on the element itself (an <input>, a <button>, an <a>), and a
     page can still add Tailwind utilities beside it, which win because utilities come later. */

:root {
  /* What a card, a field and a held-still column are painted with. Dark mode sets its own in
     application.tailwind.css; without this one they'd be see-through in light mode, over whatever's behind. */
  --color-surface: #ffffff;
  --ui-accent: var(--color-blue-600);
  --ui-accent-hover: #1d4ed8;
  --ui-danger: #dc2626;
  --ui-danger-hover: #b91c1c;
  --ui-ring: color-mix(in oklab, var(--color-blue-500) 35%, transparent);
  --ui-radius: 0.75rem;
  --ui-control-h: 2.75rem;
  /* A select's chevron, drawn in the muted text colour of each theme. */
  --ui-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

@media (min-width: 40rem) {
  :root { --ui-control-h: 2.5rem; }
}

html.dark {
  --ui-ring: color-mix(in oklab, oklch(0.707 0.165 254.624) 40%, transparent);
  --ui-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

@layer components {
  /* ---- Fields --------------------------------------------------------------------------------------------- */

  /* A label, its control, then a hint or an error, stacked. */
  .ui-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-width: 0;
  }

  .ui-label {
    display: block;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: var(--color-gray-700);
  }
  .ui-label-optional {
    font-weight: 400;
    color: var(--color-gray-400);
  }

  .ui-hint {
    font-size: 0.8125rem;
    line-height: 1.25rem;
    color: var(--color-gray-500);
  }

  .ui-error-text {
    font-size: 0.8125rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: var(--color-red-600);
  }

  /* Text, email, number, date, time, password and search inputs, selects and textareas. */
  .ui-input,
  .ui-select,
  .ui-textarea {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: var(--ui-control-h);
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--ui-radius);
    background-color: var(--color-surface);
    color: var(--color-gray-900);
    font-size: 1rem;
    line-height: 1.5rem;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04);
    transition: border-color 150ms, box-shadow 150ms, background-color 150ms;
    -webkit-appearance: none;
    appearance: none;
  }
  @media (min-width: 40rem) {
    .ui-input,
    .ui-select,
    .ui-textarea {
      font-size: 0.875rem;
      line-height: 1.25rem;
    }
  }
  .ui-input::placeholder,
  .ui-textarea::placeholder {
    color: var(--color-gray-400);
  }
  .ui-input:hover,
  .ui-select:hover,
  .ui-textarea:hover {
    border-color: var(--color-gray-400);
  }
  .ui-input:focus,
  .ui-select:focus,
  .ui-textarea:focus {
    outline: none;
    border-color: var(--color-blue-500);
    box-shadow: 0 0 0 3px var(--ui-ring);
  }
  .ui-input:disabled,
  .ui-select:disabled,
  .ui-textarea:disabled {
    cursor: not-allowed;
    background-color: var(--color-gray-50);
    color: var(--color-gray-500);
  }
  .ui-input[aria-invalid="true"],
  .ui-select[aria-invalid="true"],
  .ui-textarea[aria-invalid="true"] {
    border-color: var(--color-red-500);
  }
  .ui-input[aria-invalid="true"]:focus,
  .ui-select[aria-invalid="true"]:focus,
  .ui-textarea[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-red-500) 30%, transparent);
  }

  /* Date and time inputs: Safari draws their value centred and shorter than the box without these. */
  .ui-input::-webkit-date-and-time-value {
    text-align: left;
    min-height: 1.5rem;
  }
  .ui-input::-webkit-calendar-picker-indicator {
    opacity: 0.55;
    cursor: pointer;
  }
  html.dark .ui-input::-webkit-calendar-picker-indicator {
    filter: invert(1);
  }

  .ui-select {
    padding-right: 2.5rem;
    background-image: var(--ui-chevron);
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.125rem;
    cursor: pointer;
    text-overflow: ellipsis;
  }
  /* A list box shows its options, so it has no chevron. */
  .ui-select[multiple],
  .ui-select[size]:not([size="1"]) {
    padding: 0.375rem;
    background-image: none;
  }
  .ui-select[multiple] option {
    padding: 0.375rem 0.5rem;
    border-radius: 0.5rem;
  }

  .ui-textarea {
    min-height: 5.5rem;
    resize: vertical;
  }

  /* A field with something fixed at its start, such as a $ or a search icon. */
  .ui-input-group {
    position: relative;
    display: flex;
    align-items: center;
  }
  .ui-input-group > .ui-input-addon {
    pointer-events: none;
    position: absolute;
    left: 0.875rem;
    color: var(--color-gray-500);
    font-size: 0.875rem;
  }
  .ui-input-group > .ui-input-addon + .ui-input {
    padding-left: 2rem;
  }

  /* Checkboxes and radios: drawn by the browser, in the accent colour, at a size a thumb can hit. */
  .ui-checkbox,
  .ui-radio {
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--ui-accent);
    cursor: pointer;
  }
  /* A checkbox or radio with its text, as one 44px target on a phone. */
  .ui-check {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    min-height: 2.75rem;
    font-size: 0.9375rem;
    color: var(--color-gray-800);
    cursor: pointer;
  }
  @media (min-width: 40rem) {
    .ui-check {
      min-height: 2rem;
      font-size: 0.875rem;
    }
  }

  /* Checkboxes as toggleable pills, for a short list of filters. The input sits inside the label. */
  .ui-check-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 2.25rem;
    padding: 0 0.875rem;
    border: 1px solid var(--color-gray-200);
    border-radius: 9999px;
    background-color: var(--color-surface);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-gray-600);
    cursor: pointer;
    user-select: none;
    transition: background-color 150ms, border-color 150ms, color 150ms;
  }
  .ui-check-chip:hover {
    border-color: var(--color-gray-300);
    color: var(--color-gray-900);
  }
  .ui-check-chip > input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }
  .ui-check-chip:has(> input:checked) {
    border-color: color-mix(in oklab, var(--color-blue-600) 40%, transparent);
    background-color: var(--color-blue-50);
    color: var(--color-blue-700);
  }
  .ui-check-chip:has(> input:focus-visible) {
    box-shadow: 0 0 0 3px var(--ui-ring);
  }
  .ui-check-chip-mark {
    display: none;
    width: 0.875rem;
    height: 0.875rem;
  }
  .ui-check-chip:has(> input:checked) .ui-check-chip-mark {
    display: block;
  }

  /* Fields side by side from sm up, stacked on a phone. */
  .ui-form-grid {
    display: grid;
    gap: 1rem;
  }
  @media (min-width: 40rem) {
    .ui-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ui-form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .ui-form-grid > .ui-span-full { grid-column: 1 / -1; }
  }

  /* A form's sections, each with its heading, separated by a rule. */
  .ui-form-section + .ui-form-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-gray-200);
  }
  .ui-form-section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-gray-900);
  }
  .ui-form-section-title + * {
    margin-top: 1rem;
  }

  /* A form's buttons. On a phone they stick to the bottom of the screen, full width, the first one (the save)
     at the bottom, nearest the thumb; from sm up they sit in a row after the fields. */
  .ui-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
  }
  .ui-actions-end {
    justify-content: flex-end;
  }
  @media (max-width: 39.99rem) {
    .ui-actions-sticky {
      position: sticky;
      bottom: 0;
      z-index: 20;
      flex-direction: column-reverse;
      align-items: stretch;
      margin-left: -1rem;
      margin-right: -1rem;
      margin-bottom: -1rem;
      padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
      border-top: 1px solid var(--color-gray-200);
      background-color: color-mix(in oklab, var(--color-surface) 92%, transparent);
      -webkit-backdrop-filter: blur(12px);
      backdrop-filter: blur(12px);
    }
    .ui-actions-sticky > .ui-btn {
      width: 100%;
    }
  }

  /* ---- Buttons -------------------------------------------------------------------------------------------- */

  .ui-btn {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--ui-control-h);
    padding: 0 1rem;
    border: 1px solid transparent;
    border-radius: var(--ui-radius);
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.25rem;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 150ms, border-color 150ms, color 150ms, box-shadow 150ms, transform 100ms;
  }
  @media (min-width: 40rem) {
    .ui-btn { font-size: 0.875rem; }
  }
  .ui-btn:focus-visible {
    outline: 2px solid var(--color-blue-600);
    outline-offset: 2px;
  }
  .ui-btn:active:not(:disabled) {
    transform: scale(0.98);
  }
  .ui-btn:disabled,
  .ui-btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.55;
  }
  .ui-btn > svg {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
  }

  .ui-btn-primary {
    background-color: var(--ui-accent);
    color: #fff;
    box-shadow: 0 1px 2px 0 rgb(37 99 235 / 0.25);
  }
  .ui-btn-primary:hover:not(:disabled) {
    background-color: var(--ui-accent-hover);
    color: #fff;
  }

  .ui-btn-secondary {
    border-color: var(--color-gray-300);
    background-color: var(--color-surface);
    color: var(--color-gray-800);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  }
  .ui-btn-secondary:hover:not(:disabled) {
    border-color: var(--color-gray-400);
    background-color: var(--color-gray-50);
    color: var(--color-gray-900);
  }

  .ui-btn-ghost {
    background-color: transparent;
    color: var(--color-gray-700);
    font-weight: 500;
  }
  .ui-btn-ghost:hover:not(:disabled) {
    background-color: var(--color-gray-100);
    color: var(--color-gray-900);
  }

  .ui-btn-danger {
    background-color: var(--ui-danger);
    color: #fff;
  }
  .ui-btn-danger:hover:not(:disabled) {
    background-color: var(--ui-danger-hover);
    color: #fff;
  }

  /* A quiet destructive action, such as Remove under a form. */
  .ui-btn-danger-ghost {
    background-color: transparent;
    color: var(--color-red-700);
    font-weight: 500;
  }
  .ui-btn-danger-ghost:hover:not(:disabled) {
    background-color: var(--color-red-50);
  }

  .ui-btn-sm {
    min-height: 2.25rem;
    padding: 0 0.75rem;
    border-radius: 0.625rem;
    font-size: 0.8125rem;
  }
  @media (min-width: 40rem) {
    .ui-btn-sm { min-height: 2rem; }
  }
  .ui-btn-sm > svg {
    width: 1rem;
    height: 1rem;
  }

  /* Square, for an icon on its own. Give it an aria-label. */
  .ui-btn-icon {
    width: var(--ui-control-h);
    padding: 0;
  }
  .ui-btn-icon.ui-btn-sm {
    width: 2.25rem;
  }

  /* Full width on a phone, its own width from sm up. */
  @media (max-width: 39.99rem) {
    .ui-btn-block-mobile { width: 100%; }
  }

  /* ---- Pages ---------------------------------------------------------------------------------------------- */

  /* A page's title, what it's about, and its actions. On a phone the actions drop under the title in one row
     that scrolls sideways rather than wrapping into a stack of squeezed buttons. */
  .ui-page-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
  @media (min-width: 40rem) {
    .ui-page-header {
      flex-direction: row;
      align-items: flex-end;
      justify-content: space-between;
      margin-bottom: 2rem;
    }
  }
  .ui-page-title {
    font-size: 1.625rem;
    line-height: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-gray-900);
  }
  @media (min-width: 40rem) {
    .ui-page-title {
      font-size: 1.875rem;
      line-height: 2.25rem;
    }
  }
  .ui-page-subtitle {
    margin-top: 0.25rem;
    font-size: 0.9375rem;
    line-height: 1.375rem;
    color: var(--color-gray-500);
  }
  .ui-page-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
  }
  @media (max-width: 39.99rem) {
    .ui-page-actions {
      margin: 0 -1rem;
      padding: 0 1rem 0.25rem;
      overflow-x: auto;
      scrollbar-width: none;
    }
    .ui-page-actions::-webkit-scrollbar { display: none; }
  }

  /* ---- Surfaces ------------------------------------------------------------------------------------------- */

  .ui-card {
    border: 1px solid var(--color-gray-200);
    border-radius: 1rem;
    background-color: var(--color-surface);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.03);
  }
  .ui-card-body {
    padding: 1rem;
  }
  @media (min-width: 40rem) {
    .ui-card-body { padding: 1.5rem; }
  }
  .ui-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--color-gray-100);
  }
  @media (min-width: 40rem) {
    .ui-card-header { padding: 1rem 1.5rem; }
  }
  .ui-card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-gray-900);
  }
  /* A form card on a phone runs edge to edge, like a native settings screen. */
  @media (max-width: 39.99rem) {
    .ui-card-flush-mobile {
      margin-left: -1rem;
      margin-right: -1rem;
      border-left: 0;
      border-right: 0;
      border-radius: 0;
      box-shadow: none;
    }
  }

  /* Rows in a card, divided by hairlines: entries, accounts, settings. */
  .ui-list > * + * {
    border-top: 1px solid var(--color-gray-100);
  }
  .ui-list-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 3.25rem;
    padding: 0.75rem 1rem;
  }
  @media (min-width: 40rem) {
    .ui-list-row { min-height: 2.75rem; padding: 0.625rem 1.5rem; }
  }
  a.ui-list-row,
  .ui-list-row-link {
    transition: background-color 150ms;
  }
  a.ui-list-row:hover,
  .ui-list-row-link:hover {
    background-color: var(--color-gray-50);
  }

  /* A number with its label, in a grid of them. Two across on a phone. */
  .ui-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }
  @media (min-width: 64rem) {
    .ui-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  }
  .ui-stat {
    padding: 1rem;
    border: 1px solid var(--color-gray-200);
    border-radius: 1rem;
    background-color: var(--color-surface);
  }
  .ui-stat-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-gray-500);
  }
  .ui-stat-value {
    margin-top: 0.25rem;
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--color-gray-900);
  }
  .ui-stat-note {
    margin-top: 0.125rem;
    font-size: 0.75rem;
    color: var(--color-gray-500);
  }

  /* A table that scrolls sideways inside its card on a narrow screen, with its first column held still. */
  .ui-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .ui-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
  }
  .ui-table th {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--color-gray-200);
    background-color: var(--color-gray-50);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: left;
    white-space: nowrap;
    color: var(--color-gray-500);
  }
  .ui-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-gray-100);
    color: var(--color-gray-700);
    white-space: nowrap;
  }
  .ui-table tr:last-child td {
    border-bottom: 0;
  }
  .ui-table tbody tr:hover td {
    background-color: var(--color-gray-50);
  }
  .ui-table .ui-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  @media (max-width: 39.99rem) {
    .ui-table-sticky-first th:first-child,
    .ui-table-sticky-first td:first-child {
      position: sticky;
      left: 0;
      z-index: 1;
      background-color: var(--color-surface);
      box-shadow: 1px 0 0 var(--color-gray-100);
    }
    .ui-table-sticky-first th:first-child { background-color: var(--color-gray-50); }
  }

  /* ---- Controls ------------------------------------------------------------------------------------------- */

  /* One choice from a few, such as Day, Week and Month. Links or buttons inside; mark the current one with
     aria-current="page" or aria-pressed="true". It fills the width on a phone. */
  .ui-segmented {
    display: flex;
    padding: 0.1875rem;
    border-radius: 9999px;
    background-color: var(--color-gray-100);
  }
  .ui-segmented > * {
    display: inline-flex;
    flex: 1 1 0%;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
    padding: 0 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-gray-600);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 150ms, color 150ms, box-shadow 150ms;
  }
  .ui-segmented > *:hover {
    color: var(--color-gray-900);
  }
  .ui-segmented > [aria-current="page"],
  .ui-segmented > [aria-pressed="true"],
  .ui-segmented > :has(> input:checked) {
    background-color: var(--color-surface);
    color: var(--color-gray-900);
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  }
  html.dark .ui-segmented > [aria-current="page"],
  html.dark .ui-segmented > [aria-pressed="true"],
  html.dark .ui-segmented > :has(> input:checked) {
    background-color: var(--color-gray-300);
  }
  .ui-segmented > :has(> input) > input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }
  .ui-segmented > *:focus-visible,
  .ui-segmented > :has(> input:focus-visible) {
    outline: 2px solid var(--color-blue-600);
    outline-offset: 1px;
  }
  @media (min-width: 40rem) {
    .ui-segmented { display: inline-flex; }
    .ui-segmented > * { flex: none; }
  }

  /* Shortcuts such as saved filters. Mark the active one with aria-current or aria-pressed. On a phone they
     run in one row that scrolls sideways. */
  .ui-chips {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  @media (max-width: 39.99rem) {
    .ui-chips {
      flex-wrap: nowrap;
      margin: 0 -1rem;
      padding: 0 1rem 0.25rem;
      overflow-x: auto;
      scrollbar-width: none;
    }
    .ui-chips::-webkit-scrollbar { display: none; }
  }
  .ui-chip {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.375rem;
    min-height: 2.25rem;
    padding: 0 0.875rem;
    border: 1px solid var(--color-gray-200);
    border-radius: 9999px;
    background-color: var(--color-surface);
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    color: var(--color-gray-700);
    transition: background-color 150ms, border-color 150ms, color 150ms;
  }
  .ui-chip:hover {
    border-color: var(--color-gray-300);
    color: var(--color-gray-900);
  }
  .ui-chip[aria-current="true"],
  .ui-chip[aria-current="page"],
  .ui-chip[aria-pressed="true"] {
    border-color: color-mix(in oklab, var(--color-blue-600) 40%, transparent);
    background-color: var(--color-blue-50);
    color: var(--color-blue-700);
  }

  .ui-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    background-color: var(--color-gray-100);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.125rem;
    white-space: nowrap;
    color: var(--color-gray-700);
  }
  .ui-badge-blue { background-color: var(--color-blue-50); color: var(--color-blue-700); }
  .ui-badge-green { background-color: var(--color-green-50); color: var(--color-green-700); }
  .ui-badge-amber { background-color: var(--color-amber-50); color: var(--color-amber-700); }
  .ui-badge-red { background-color: var(--color-red-50); color: var(--color-red-700); }

  /* A message across a page or form: errors, warnings, a done. */
  .ui-alert {
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--ui-radius);
    background-color: var(--color-gray-50);
    font-size: 0.875rem;
    line-height: 1.375rem;
    color: var(--color-gray-700);
  }
  .ui-alert-error { border-color: var(--color-red-200); background-color: var(--color-red-50); color: var(--color-red-800); }
  .ui-alert-warning { border-color: var(--color-amber-200); background-color: var(--color-amber-50); color: var(--color-amber-800); }
  .ui-alert-success { border-color: var(--color-green-200); background-color: var(--color-green-50); color: var(--color-green-800); }
  .ui-alert-info { border-color: var(--color-blue-200); background-color: var(--color-blue-50); color: var(--color-blue-800); }

  /* Nothing to show yet, and what to do about it. */
  .ui-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 3rem 1.5rem;
    text-align: center;
  }
  .ui-empty-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-gray-900);
  }
  .ui-empty-text {
    max-width: 24rem;
    font-size: 0.875rem;
    color: var(--color-gray-500);
  }

  /* A filter panel that's open from sm up and folds behind a Filters button on a phone. Use a <details open>
     with class ui-disclosure and a <summary class="ui-disclosure-summary">; ui_disclosure in UiHelper writes it. */
  .ui-disclosure-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 3rem;
    padding: 0 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-gray-900);
    cursor: pointer;
    list-style: none;
  }
  .ui-disclosure-summary::-webkit-details-marker { display: none; }
  .ui-disclosure-summary::after {
    content: "";
    width: 1.125rem;
    height: 1.125rem;
    background-image: var(--ui-chevron);
    background-size: contain;
    transition: transform 150ms;
  }
  .ui-disclosure[open] > .ui-disclosure-summary::after {
    transform: rotate(180deg);
  }
  @media (min-width: 40rem) {
    .ui-disclosure-desktop-open > .ui-disclosure-summary { display: none; }
  }
}

/* ---- Product tours ---------------------------------------------------------------------------------------
   tour_controller.js draws these on <html>, above everything else: a layer that keeps clicks off the page,
   a ring around the element a step points at that dims everything else, and the popover. A step with no
   element dims the whole page and puts the popover in the middle. On a phone the popover is a sheet along
   the bottom. Colours come from the palette, so dark mode needs nothing of its own. */
.ui-tour {
  --ui-tour-dim: rgb(15 23 42 / 0.55);
}
html.dark .ui-tour {
  --ui-tour-dim: rgb(0 0 0 / 0.65);
}
.ui-tour-blocker {
  position: fixed;
  inset: 0;
  z-index: 300;
}
.ui-tour-centered .ui-tour-blocker {
  background: var(--ui-tour-dim);
}
.ui-tour-spotlight {
  position: fixed;
  z-index: 300;
  border-radius: 0.75rem;
  box-shadow: 0 0 0 9999px var(--ui-tour-dim);
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
  pointer-events: none;
  transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;
}
.ui-tour-spotlight[hidden] {
  display: none;
}
.ui-tour-popover {
  position: fixed;
  z-index: 301;
  width: 22rem;
  max-width: calc(100vw - 2rem);
  padding: 1rem 1.125rem 0.875rem;
  border: 1px solid var(--color-gray-200);
  border-radius: 1rem;
  background: var(--color-surface, #ffffff);
  color: var(--color-gray-900);
  box-shadow: 0 20px 40px -12px rgb(15 23 42 / 0.35), 0 4px 12px -4px rgb(15 23 42 / 0.15);
  transition: left 0.2s ease, top 0.2s ease;
}
.ui-tour-popover:focus {
  outline: none;
}
.ui-tour-centered .ui-tour-popover {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: none;
}
.ui-tour-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: -0.25rem -0.375rem 0.25rem 0;
}
.ui-tour-progress {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ui-accent);
}
.ui-tour-close {
  display: inline-flex;
  width: 2rem;
  height: 2rem;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  color: var(--color-gray-500);
  cursor: pointer;
}
.ui-tour-close:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-900);
}
.ui-tour-close svg {
  width: 1.125rem;
  height: 1.125rem;
}
.ui-tour-title {
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 600;
}
.ui-tour-body {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: var(--color-gray-600);
}
.ui-tour-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}
.ui-tour-actions .ui-btn[hidden] {
  display: none;
}
.ui-tour-actions .ui-btn-ghost {
  margin-left: -0.75rem;
}
.ui-tour-spacer {
  flex: 1;
}
@media (max-width: 39.99rem) {
  .ui-tour-popover,
  .ui-tour-centered .ui-tour-popover {
    left: 1rem;
    right: 1rem;
    top: auto;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
    transform: none;
  }
  /* Where the element it points at sits under the sheet and the page can't scroll it clear. */
  .ui-tour-sheet-top .ui-tour-popover {
    top: calc(1rem + env(safe-area-inset-top));
    bottom: auto;
  }
}
@media (prefers-reduced-motion: reduce) {
  .ui-tour-spotlight,
  .ui-tour-popover {
    transition: none;
  }
}

/* ---- What's new ------------------------------------------------------------------------------------------
   RADAR's own releases (WhatsNew), on the What's new page and in the first-visit dialog: a list of items,
   each with a title, a line or two on what changed, and "Show me" beside the ones a product tour is about.
   Colours come from the palette, so dark mode needs nothing of its own. */
.ui-whatsnew-section {
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-gray-500);
}
.ui-whatsnew-items {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.ui-whatsnew-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding-left: 0.875rem;
  border-left: 2px solid var(--color-blue-100);
}
.ui-whatsnew-item-title {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.375rem;
  color: var(--color-gray-900);
}
.ui-whatsnew-show {
  flex-shrink: 0;
}
/* On a phone "Show me" goes under the words, which need the width. */
@media (max-width: 39.99rem) {
  .ui-whatsnew-item {
    flex-direction: column;
    gap: 0.5rem;
  }
}
.ui-whatsnew-prose {
  font-size: 0.875rem;
  line-height: 1.5rem;
  color: var(--color-gray-600);
  overflow-wrap: anywhere;
}
.ui-whatsnew-prose > * + * {
  margin-top: 0.5rem;
}
.ui-whatsnew-prose ul,
.ui-whatsnew-prose ol {
  padding-left: 1.25rem;
}
.ui-whatsnew-prose ul { list-style: disc; }
.ui-whatsnew-prose ol { list-style: decimal; }
.ui-whatsnew-prose li + li {
  margin-top: 0.125rem;
}
.ui-whatsnew-prose strong {
  font-weight: 600;
  color: var(--color-gray-900);
}
.ui-whatsnew-prose code {
  padding: 0.0625rem 0.3125rem;
  border-radius: 0.375rem;
  background-color: var(--color-gray-100);
  font-size: 0.8125rem;
}
.ui-whatsnew-details {
  margin-top: 0.375rem;
}
.ui-whatsnew-notes {
  padding-top: 1rem;
  border-top: 1px solid var(--color-gray-100);
}
/* The dialog's shorter form: a few lines an item, the rest on the page. */
.ui-whatsnew-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

/* ---- Select list -------------------------------------------------------------------------------------------
   The list a <select> opens (controllers/ui_select_controller.js), its icons, and the chosen option's icon in
   the closed field. Laid over the page from <body>; a bottom sheet under 640px. Colours come from the palette,
   so dark mode needs nothing of its own. */
/* In the components layer so a width or min-width utility the select was written with (moved onto the wrap by
   the controller) still wins; unlayered, width: 100% beat w-56 and the field pushed its neighbours out. */
@layer components {
  .ui-select-wrap {
    position: relative;
    display: inline-block;
    width: 100%;
    min-width: 0;
    vertical-align: middle;
  }
}
.ui-select-wrap > select {
  width: 100%;
  margin: 0;
}
.ui-select-wrap > .ui-select-icon {
  position: absolute;
  top: 50%;
  left: 0.625rem;
  transform: translateY(-50%);
  pointer-events: none;
}
select.ui-select-has-icon {
  padding-left: 2.375rem;
}

.ui-select-avatar {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 1.375rem;
  overflow: hidden;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
}
.ui-select-avatar.is-circle { border-radius: 9999px; }
.ui-select-avatar.is-square { border-radius: 0.375rem; }
.ui-select-avatar > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ui-select-avatar.is-square > img {
  padding: 0.0625rem;
  background-color: #ffffff;
  object-fit: contain;
  box-shadow: inset 0 0 0 1px var(--color-gray-200);
  border-radius: inherit;
}
.ui-select-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 0.625rem;
  height: 0.625rem;
  margin: 0 0.375rem;
  border-radius: 9999px;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12);
}

.ui-select-layer {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
}
.ui-select-backdrop {
  display: none;
}
.ui-select-panel {
  position: fixed;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--ui-radius);
  background-color: var(--color-surface);
  color: var(--color-gray-900);
  box-shadow: 0 12px 32px -8px rgb(15 23 42 / 0.22), 0 2px 6px -2px rgb(15 23 42 / 0.12);
  animation: ui-select-in 120ms ease-out;
}
@keyframes ui-select-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
}
.ui-select-sheet-title {
  display: none;
}
.ui-select-search {
  flex-shrink: 0;
  width: 100%;
  margin: 0;
  padding: 0.625rem 0.875rem 0.625rem 2.25rem;
  border: 0;
  border-bottom: 1px solid var(--color-gray-200);
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M9 3.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM2 9a7 7 0 1 1 12.45 4.39l3.08 3.08a.75.75 0 1 1-1.06 1.06l-3.08-3.08A7 7 0 0 1 2 9Z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat 0.75rem center / 1rem;
  color: var(--color-gray-900);
  font-size: 1rem;
  line-height: 1.5rem;
  outline: none;
  box-shadow: none;
}
@media (min-width: 40rem) {
  .ui-select-search { font-size: 0.875rem; line-height: 1.25rem; }
}
.ui-select-search::placeholder { color: var(--color-gray-400); }
.ui-select-search::-webkit-search-cancel-button { cursor: pointer; }
.ui-select-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.3125rem;
  outline: none;
}
.ui-select-group + .ui-select-group,
.ui-select-option + .ui-select-group {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--color-gray-100);
}
.ui-select-group-label {
  padding: 0.375rem 0.625rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-gray-500);
}
.ui-select-option {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.25rem;
  padding: 0.375rem 0.625rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  cursor: pointer;
  user-select: none;
  scroll-margin: 0.3125rem;
}
.ui-select-option[hidden] { display: none; }
.ui-select-option.is-active {
  background-color: var(--color-gray-100);
}
.ui-select-option[aria-selected="true"] {
  font-weight: 600;
  color: var(--color-blue-700);
}
.ui-select-option[aria-selected="true"].is-active {
  background-color: color-mix(in oklab, var(--color-blue-500) 12%, transparent);
}
.ui-select-option[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.45;
}
.ui-select-option.is-blank .ui-select-option-label {
  color: var(--color-gray-500);
  font-weight: 400;
}
.ui-select-option-text {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}
.ui-select-option-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ui-select-option-hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-gray-500);
}
.ui-select-check {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  color: var(--color-blue-600);
  visibility: hidden;
}
.ui-select-option[aria-selected="true"] .ui-select-check { visibility: visible; }
.ui-select-empty {
  padding: 0.75rem 0.625rem;
  font-size: 0.875rem;
  color: var(--color-gray-500);
}

/* A phone: the list rises from the bottom over a dimmed page, with the field's label on top. */
.ui-select-layer.is-sheet { pointer-events: auto; }
.ui-select-layer.is-sheet .ui-select-backdrop {
  display: block;
  position: absolute;
  inset: 0;
  background-color: rgb(15 23 42 / 0.4);
  animation: ui-select-fade 160ms ease-out;
}
.ui-select-layer.is-sheet .ui-select-panel {
  inset: auto 0 0 0;
  max-height: min(75vh, 32rem);
  border-width: 1px 0 0;
  border-radius: 1.25rem 1.25rem 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: ui-select-rise 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ui-select-layer.is-sheet .ui-select-sheet-title {
  display: block;
  flex-shrink: 0;
  padding: 1.125rem 1.125rem 0.625rem;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--color-gray-900);
}
.ui-select-layer.is-sheet .ui-select-sheet-title::before {
  content: "";
  display: block;
  width: 2.25rem;
  height: 0.3125rem;
  margin: -0.5rem auto 0.75rem;
  border-radius: 9999px;
  background-color: var(--color-gray-300);
}
.ui-select-layer.is-sheet .ui-select-search {
  border-top: 1px solid var(--color-gray-200);
}
.ui-select-layer.is-sheet .ui-select-option {
  min-height: 2.75rem;
  font-size: 1rem;
}
@keyframes ui-select-fade { from { opacity: 0; } }
@keyframes ui-select-rise { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  .ui-select-panel,
  .ui-select-layer.is-sheet .ui-select-panel,
  .ui-select-layer.is-sheet .ui-select-backdrop { animation: none; }
}

/* An avatar's or a logo tile's initials, drawn by CSS so they stay out of the text of whatever holds them. */
.ui-initial::before {
  content: attr(data-initial);
}

/* ---- Toasts ----------------------------------------------------------------------------------------------
   Messages that float over the page rather than push it down: the flash after a save, a refusal, a
   notification (shared/_toast, auto_dismiss_controller.js). The layout's #toasts is the stack, top right on a
   desk and across the top on a phone, clear of the notch and of anything along the bottom of the screen.
   Colours come from the palette, so dark mode needs nothing of its own. */
.ui-toasts {
  position: fixed;
  z-index: 200;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  left: max(1rem, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
}
.ui-toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  max-width: 26rem;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--ui-radius);
  background-color: var(--color-surface, #fff);
  box-shadow: 0 10px 25px -5px rgb(0 0 0 / 0.15), 0 4px 10px -6px rgb(0 0 0 / 0.1);
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: var(--color-gray-700);
  pointer-events: auto;
  animation: ui-toast-in 180ms ease-out;
}
.ui-toast-success { border-color: var(--color-green-200); background-color: var(--color-green-50); color: var(--color-green-800); }
.ui-toast-error { border-color: var(--color-red-200); background-color: var(--color-red-50); color: var(--color-red-800); }
.ui-toast-icon { flex-shrink: 0; margin-top: 0.0625rem; opacity: 0.6; }
.ui-toast-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: -0.0625rem;
  border-radius: 0.375rem;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
}
.ui-toast-close:hover, .ui-toast-close:focus-visible { opacity: 1; }
.ui-toast[data-leaving] {
  opacity: 0;
  transform: translateY(-0.25rem);
  transition: opacity 150ms ease-in, transform 150ms ease-in;
}
@keyframes ui-toast-in {
  from { opacity: 0; transform: translateY(-0.5rem); }
}
@media (prefers-reduced-motion: reduce) {
  .ui-toast { animation: none; }
  .ui-toast[data-leaving] { transition: none; }
}
