/* Application styles.
 *
 * Loaded after w3.css. Everything W3.CSS already provides is used as a class in
 * the markup -- this file is only for the semantic colours w3.css leaves out
 * and the handful of components the framework has no equivalent for (the
 * combobox, toasts, the CSS bar chart, pagy's pagination, the native <dialog>
 * modal) plus the theme from the starter template.
 *
 * Values are literals or W3's own --w3-* custom properties, so there is no
 * build step: Propshaft serves this file as-is.
 */

/* Semantic colour
/* ---------------------------------------------------------------------------
 * w3.css here is the official 5.01 release with its colour section removed,
 * so the theme stays monochrome: only black, white and the greys survive,
 * driven by --w3-* custom properties.
 *
 * Four semantic colours are still needed -- destructive buttons, the flash and
 * validation panels, and the +/- figures on the dashboard. They use GitHub
 * Primer's light-theme values rather than W3's Material palette, and reuse
 * W3's class names so the framework reference still describes the markup.
 * -------------------------------------------------------------------------- */

:root {
  --w3-danger: #cf222e;
  --w3-danger-hover: #a40e26;
  --w3-danger-on: #fff;
  --w3-danger-subtle: #ffebe9;

  --w3-success: #1a7f37;
  --w3-success-subtle: #dafbe1;

  --w3-attention: #9a6700;
  --w3-attention-subtle: #fff8c5;

  --w3-accent: #0969da;
  --w3-accent-subtle: #ddf4ff;

  /* Neutrals retuned from W3's defaults to Primer's. These are w3.css's own
     theme hooks, so borders, hairlines, stripes and muted text follow across
     the whole app, not just the tables below. --w3-ui-hover-bg is left at
     W3's #ccc on purpose: it also paints .w3-dropdown-click:hover, which sits
     on the black navbar. */
  --w3-ui-border: #d1d9e0;
  --w3-ui-line: #d1d9e0;
  --w3-ui-hr: #d1d9e0;
  --w3-ui-stripe: #f6f8fa;
  --w3-ui-surface-on: #1f2328;
  --w3-ui-hover-on: #1f2328;
  --w3-text-grey: #59636e;

  /* Top navigation, matching GitHub's profile UnderlineNav. */
  --w3-nav-bg: #f6f8fa;
  --w3-nav-hover-bg: rgba(129, 139, 152, 0.12);
  --w3-nav-underline: #fd8c73;
}

.w3-red {
  color: var(--w3-danger-on) !important;
  background-color: var(--w3-danger) !important;
}

/* .w3-button:hover is !important and outranks .w3-red, so a destructive button
/* would otherwise go grey on hover instead of darker red. */
.w3-button.w3-red:hover {
  color: var(--w3-danger-on) !important;
  background-color: var(--w3-danger-hover) !important;
}

.w3-pale-red,
.w3-pale-green,
.w3-pale-yellow,
.w3-pale-blue {
  color: var(--w3-ui-surface-on) !important;
}

.w3-pale-red {
  background-color: var(--w3-danger-subtle) !important;
}
.w3-pale-green {
  background-color: var(--w3-success-subtle) !important;
}
.w3-pale-yellow {
  background-color: var(--w3-attention-subtle) !important;
}
.w3-pale-blue {
  background-color: var(--w3-accent-subtle) !important;
}

.w3-text-red {
  color: var(--w3-danger) !important;
}
.w3-text-green {
  color: var(--w3-success) !important;
}
.w3-text-blue {
  color: var(--w3-accent) !important;
}

.w3-border-red {
  border-color: var(--w3-danger) !important;
}
.w3-border-green {
  border-color: var(--w3-success) !important;
}
.w3-border-amber {
  border-color: var(--w3-attention) !important;
}
.w3-border-blue {
  border-color: var(--w3-accent) !important;
}

/* Template theme
/* -------------------------------------------------------------------------- */

body,
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Inter", sans-serif;
}

body,
html {
  height: 100%;
}

body {
  color: var(--w3-ui-surface-on);
}

/* Collapsed mobile menu overlays the page instead of pushing it down */
header {
  position: relative;
}

#navDemo {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
}

/* Top navigation
/* ---------------------------------------------------------------------------
 * GitHub's profile nav: a light grey bar, each item a rounded translucent pill
 * on hover, and the current page marked by a 2px orange rule sitting flush
 * with the bar's bottom border.
 *
 * W3 has neither a "current page" state nor a hover that is not a solid block,
 * so the pill goes on an inner .nav-item span (as GitHub's own markup does)
 * while the underline goes on the bar item itself. The items keep
 * w3-hover-none, which is what stops .w3-button:hover painting them #ccc.
 * -------------------------------------------------------------------------- */

.nav-bar {
  background-color: var(--w3-nav-bg);
  border-bottom: 1px solid var(--w3-ui-border);
}

.nav-bar .w3-bar-item {
  border-bottom: 2px solid transparent;
  color: var(--w3-ui-surface-on);
  padding: 6px 8px;
}

.nav-bar .w3-bar-item.active {
  border-bottom-color: var(--w3-nav-underline);
  font-weight: 600;
}

/* The pill. Inset from the bar's bottom edge so the underline clears it. */
.nav-item {
  align-items: center;
  border-radius: 6px;
  display: inline-flex;
  gap: 8px;
  padding: 6px 10px;
}

@media (any-hover: hover) {
  .nav-bar a:hover .nav-item,
  .nav-bar button:hover .nav-item {
    background-color: var(--w3-nav-hover-bg);
  }
}

/* The hamburger is a <button>, which does not inherit the page font the way
/* the anchors beside it do, and which UAs give their own metrics. w3-button
/* resets colour, border and background but not type, so do that here. */
.nav-bar button.w3-bar-item {
  font: inherit;
  line-height: inherit;
}

/* On small screens the labels are hidden and the bar items are icon-only, so
/* the icons carry the whole target -- size them up. 600px is W3's own small
/* breakpoint, the one w3-hide-small uses to drop the labels. The account
/* caret is in a button rather than a bar item, so it keeps its size. */
@media (max-width: 600px) {
  .nav-bar .w3-bar-item .nav-item .icon:not(.icon--logo) {
    --icon-size: 20px;
  }
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* The account control is an icon on its own. Font Awesome icons are text, so
/* without an explicit size it would inherit the body's 15px and sit far smaller
/* than the avatar it replaced. Sized to balance the 24px logo opposite it. */
.nav-account {
  margin-right: 8px;
}

/* W3 paints the whole dropdown container on hover; not on a bar like this. */
.nav-bar .w3-dropdown-click:hover {
  background-color: transparent;
}

/* Small-screen menu: no room for an underline, so mark the current page with
/* a left rule instead. */
#navDemo {
  background-color: var(--w3-ui-surface);
  border-bottom: 1px solid var(--w3-ui-border);
}

#navDemo .w3-bar-item.active {
  box-shadow: inset 2px 0 0 var(--w3-nav-underline);
  font-weight: 600;
}

/* Keep the menu's icons in step with the enlarged ones in the bar above it,
/* though a little smaller since these sit beside a label. */
#navDemo .nav-item .icon {
  --icon-size: 18px;
}

/* Settings sidebar
/* ---------------------------------------------------------------------------
 * GitHub's settings nav: a plain column, no card, each item an icon and label,
 * the current one on a light fill with a blue left rule.
 *
 * The items are w3-bar-item WITHOUT w3-button, so .w3-button:hover (which is
 * !important) cannot paint over the hover fill. That costs the text-decoration
 * reset w3-button would have brought, so it is set here.
 *
 * The accent is blue, not the navbar's orange -- GitHub uses the two
 * differently: orange for the profile tab strip, blue for settings.
 * -------------------------------------------------------------------------- */

.settings-nav .w3-bar-item {
  border-radius: 6px;
  color: var(--w3-ui-surface-on);
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  text-decoration: none;
}

.settings-nav .w3-bar-item.active {
  background-color: var(--w3-ui-stripe);
  box-shadow: inset 2px 0 0 var(--w3-accent);
  font-weight: 600;
}

/* Tabler's outline icons are drawn for a 24px box with a 2px stroke and carry
/* their own padding, so at the body's 1em they read smaller and thinner than
/* the Font Awesome glyphs they replaced. 20px restores the weight. */
.settings-nav .icon {
  --icon-size: 20px;
  color: var(--w3-text-grey);
}

@media (any-hover: hover) {
  .settings-nav .w3-bar-item:hover {
    background-color: var(--w3-nav-hover-bg);
  }
}

/* Hotwire's version of data-disable-with: swap the label while submitting. */
button .when-disabled,
input .when-disabled {
  display: none;
}
button[disabled] .when-disabled {
  display: initial;
}
button .when-enabled {
  display: initial;
}
button[disabled] .when-enabled {
  display: none;
}

/* Forms
/* -------------------------------------------------------------------------- */

/* W3 leaves labels unstyled; fields are w3-input/w3-select in the markup. */
label {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 600;
}

/* W3 gives the select no inline padding (padding: 9px 0), so its text and
 * caret sit on the box edge. Match .w3-input's 8px box. */
.w3-select {
  padding: 8px;
}

/* Tables
/* ---------------------------------------------------------------------------
 * GitHub's compact list chrome: a bordered, rounded box with a filled header
 * strip, hairline rules between rows and no zebra striping.
 *
 * w3-table still lays the table out and w3-responsive still handles the
 * horizontal scroll (and clips the rounded corners). This is only the part W3
 * has no class for: a styled thead, tighter cells, and a row hover that is not
 * W3's #ccc.
 * -------------------------------------------------------------------------- */

.table-list {
  background-color: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  border-radius: 6px;
  /* font-size: 14px; */
}

.table-list thead th {
  background-color: var(--w3-ui-stripe);
  border-bottom: 1px solid var(--w3-ui-border);
  color: var(--w3-text-grey);
  /* font-size: 12px; */
  font-weight: 600;
  padding: 8px 16px;
  vertical-align: middle;
  white-space: nowrap;
}

.table-list tbody td,
.table-list tbody th {
  padding: 8px 16px;
  vertical-align: middle;
}

/* Row header cells, e.g. the field names on an audit. */
.table-list tbody th {
  color: var(--w3-text-grey);
  font-weight: 600;
  white-space: nowrap;
}

/* A hairline between rows only -- thead already draws the first one. */
.table-list tbody tr:not(:first-child) td,
.table-list tbody tr:not(:first-child) th {
  border-top: 1px solid var(--w3-ui-border);
}

@media (any-hover: hover) {
  .table-list tbody tr:hover td {
    background-color: var(--w3-ui-stripe);
  }
}

/* Combobox
/* ---------------------------------------------------------------------------
 * Styles for app/javascript/combobox.js (the tom-select replacement). W3.CSS
 * has no autocomplete/combobox component, so this is carried over wholesale.
 * -------------------------------------------------------------------------- */

.combobox {
  --combobox-border-radius: 4px;
  --combobox-caret-size: 16px;
  --combobox-caret-inset: 10px;
  --combobox-font-size: 15px;
  --combobox-line-height: 22px;
  --combobox-list-max-block-size: 15rem;
  --combobox-z-list: 20;

  display: block;
  inline-size: 100%;
  position: relative;
}

/* The original field. It still carries the name and the submitted value, so it
/* stays in the DOM and out of the tab order rather than being removed. */
.combobox__value {
  block-size: 1px;
  /* The field also carries .w3-border, which is !important, so beat it here or
     the hidden original shows as a 1px bordered dot. */
  border: 0 !important;
  clip-path: inset(50%);
  inline-size: 1px;
  inset-block-start: 0;
  inset-inline-start: 0;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
}

.combobox__input {
  background-color: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  color: var(--w3-ui-surface-on);
  display: block;
  font-size: var(--combobox-font-size);
  font-weight: 400;
  inline-size: 100%;
  line-height: var(--combobox-line-height);
  padding: 8px;
  padding-inline-end: calc(
    var(--combobox-caret-size) + var(--combobox-caret-inset) * 2
  );

  &::placeholder {
    color: var(--w3-text-grey);
  }

  &:focus,
  &:focus-visible {
    border-color: var(--w3-dark-grey);
    outline: none;
  }

  &[disabled],
  &[readonly] {
    background: var(--w3-light-grey);
    color: var(--w3-text-grey);
    cursor: not-allowed;
  }
}

.combobox--error .combobox__input {
  background: var(--w3-danger-subtle);
  border-color: var(--w3-danger);
}

/* Caret / spinner
/* -------------------------------------------------------------------------- */

.combobox__caret {
  align-items: center;
  block-size: var(--combobox-caret-size);
  color: var(--w3-text-grey);
  cursor: pointer;
  display: flex;
  inline-size: var(--combobox-caret-size);
  inset-block-start: calc(50% - var(--combobox-caret-size) / 2);
  inset-inline-end: var(--combobox-caret-inset);
  justify-content: center;
  position: absolute;

  &::before {
    background-color: currentColor;
    block-size: 100%;
    content: "";
    display: block;
    inline-size: 100%;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.75' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
    mask-position: center;
    mask-repeat: no-repeat;
    mask-size: contain;
    transition: transform 150ms ease-out;
  }
}

.combobox--open .combobox__caret::before {
  transform: rotate(180deg);
}

.combobox--loading .combobox__caret::before {
  animation: combobox-spin 700ms linear infinite;
  mask-image: none;
  background-color: transparent;
  border: 2px solid var(--w3-ui-border);
  border-block-start-color: var(--w3-dark-grey);
  border-radius: 50%;
  transform: none;
}

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

@media (prefers-reduced-motion: reduce) {
  .combobox__caret::before {
    transition: none;
  }

  .combobox--loading .combobox__caret::before {
    animation-duration: 2s;
  }
}

/* Listbox
/* -------------------------------------------------------------------------- */

.combobox__list {
  background: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  border-radius: var(--combobox-border-radius);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.16);
  inline-size: 100%;
  inset-block-start: calc(100% + 4px);
  inset-inline-start: 0;
  list-style: none;
  margin: 0;
  max-block-size: var(--combobox-list-max-block-size);
  overflow-y: auto;
  padding: 0;
  position: absolute;
  z-index: var(--combobox-z-list);
}

.combobox__option,
.combobox__empty {
  font-size: var(--combobox-font-size);
  line-height: var(--combobox-line-height);
  overflow: hidden;
  padding: 8px 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combobox__option {
  color: var(--w3-ui-surface-on);
  cursor: pointer;
  user-select: none;
}

.combobox__option--active {
  background-color: var(--w3-ui-hover-bg);
  color: var(--w3-ui-hover-on);
}

@media (any-hover: hover) {
  .combobox__option:hover {
    background-color: var(--w3-ui-hover-bg);
    color: var(--w3-ui-hover-on);
  }
}

.combobox__option--create {
  font-style: italic;
}

.combobox__empty {
  color: var(--w3-text-grey);
  cursor: default;
}

/* Toasts
/* ---------------------------------------------------------------------------
 * Driven by the Alert stimulus controller. W3.CSS has panels but no stacked,
 * auto-dismissing notification region.
 * -------------------------------------------------------------------------- */

/* Page-level alert banner: icon centred beside the message. */
#flash .w3-panel p {
  align-items: center;
  display: flex;
  gap: 0.5rem;
}

#flash .w3-panel .icon {
  flex-shrink: 0;
}

#toasts {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: fixed;
  right: 16px;
  top: 48px;
  z-index: 30;
  width: 100%;
  max-width: 384px;

  > * + * {
    margin-top: 16px;
  }
}

@media (max-width: 600px) {
  #toasts {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

.toast {
  background: var(--w3-ui-surface);
  color: var(--w3-ui-surface-on);
  display: flex;
  justify-content: space-between;
  padding: 16px;
  width: 100%;

  section:has(> header > svg) p {
    margin-left: 28px;
  }

  section header {
    align-items: center;
    display: flex;
    flex-grow: 1;
    gap: 8px;

    h2 {
      font-size: 15px;
      font-weight: 600;
      margin: 0;
    }
  }

  p {
    font-size: 15px;
    margin: 4px 0 0;
  }

  > div {
    align-items: flex-start;
    display: flex;
    gap: 16px;

    button {
      background: none;
      border: 0;
      cursor: pointer;
      padding: 0;
    }
  }
}

/* Bar chart
/* ---------------------------------------------------------------------------
 * Pure-CSS chart rendered by app/views/dashboard/_bar_chart.html.erb.
 * -------------------------------------------------------------------------- */

.bar-chart {
  --bar-chart-height: 16rem;

  display: flex;
  flex-direction: column;
  margin: 0;
  width: 100%;
}

.bar-chart__body {
  display: flex;
  gap: 6px;
}

.bar-chart__axis {
  flex: none;
  height: var(--bar-chart-height);
  position: relative;
  width: 3rem;
}

.bar-chart__tick {
  color: var(--w3-text-grey);
  font-size: 11px;
  line-height: 1;
  position: absolute;
  right: 0;
  transform: translateY(50%);
  white-space: nowrap;
}

.bar-chart__area {
  flex: 1;
  min-width: 0;
}

.bar-chart__plot {
  align-items: flex-end;
  border-bottom: 1px solid var(--w3-ui-border);
  border-left: 1px solid var(--w3-ui-border);
  display: flex;
  gap: 2px;
  height: var(--bar-chart-height);
  position: relative;
}

.bar-chart__gridline {
  border-top: 1px dashed var(--w3-ui-border);
  left: 0;
  opacity: 0.6;
  position: absolute;
  right: 0;
}

.bar-chart__col {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
  position: relative;

  &:hover .bar-chart__bar {
    opacity: 0.75;
  }
}

.bar-chart__bar {
  background: var(--w3-accent);
  border-radius: 2px 2px 0 0;
  min-height: 1px;

  &.bar-chart__bar--negative {
    background: var(--w3-danger);
  }
}

.bar-chart__labels {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}

.bar-chart__label {
  color: var(--w3-text-grey);
  flex: 1;
  font-size: 11px;
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pagination
/* ---------------------------------------------------------------------------
 * Markup comes from pagy's series_nav helper, so it cannot carry w3- classes.
 * -------------------------------------------------------------------------- */

nav.pagy {
  display: inline-flex;
  align-items: center;
  justify-content: start;

  a {
    background: var(--w3-ui-surface);
    border: 1px solid var(--w3-ui-border);
    color: var(--w3-ui-surface-on);
    display: block;
    font-variant-numeric: tabular-nums;
    margin-left: -1px;
    padding: 8px 12px;
    position: relative;
    text-decoration: none;

    &:hover {
      background: var(--w3-ui-hover-bg);
      color: var(--w3-ui-hover-on);
    }

    &:not([href]) {
      color: var(--w3-text-grey);
    }

    &[aria-current="page"] {
      background: var(--w3-black);
      border-color: var(--w3-black);
      color: var(--w3-black-on);
    }
  }
}

/* Modal
/* ---------------------------------------------------------------------------
 * The remote modal is a native <dialog> driven by the Modal stimulus
 * controller (showModal/close), not W3's JS-toggled .w3-modal div, so it needs
 * its own sizing and backdrop. The card inside it uses w3- classes.
 * -------------------------------------------------------------------------- */

dialog.modal {
  border: 0;
  margin: auto;
  max-height: 100vh;
  padding: 0;
  width: 100%;

  &.modal-sm {
    max-width: 384px;
  }

  &.modal-md {
    max-width: 448px;
  }

  &.modal-lg {
    max-width: 512px;
  }

  &::backdrop {
    background: #000;
    opacity: 0.5;
  }

  .modal-close {
    background: none;
    border: 0;
    color: var(--w3-text-grey);
    cursor: pointer;
    position: absolute;
    right: 16px;
    top: 16px;

    &:hover {
      color: var(--w3-ui-surface-on);
    }
  }
}

/* Hub launcher
/* ---------------------------------------------------------------------------
 * Home is a page of space cards, not a bar: each space owns the whole window
 * once you are inside it, and the card is the way in. Layout follows
 * docs/hub-launcher-mockups (greeting, card grid, verb link at the card's
 * foot); the colours and type are this app's, driven by the same --w3-* hooks
 * as everything else, so the launcher does not read as a second design.
 *
 * The grid itself is w3-row-padding/w3-col in the markup. This is only the
 * card, its icon chip and the dashed placeholder.
 * -------------------------------------------------------------------------- */

.launcher {
  margin: 0 auto;
  max-width: 1000px;
}

.launcher-head {
  align-items: flex-end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  padding: 0 8px;
}

.launcher-greeting {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 4px;
}

.launcher-date {
  color: var(--w3-text-grey);
  font-size: 14px;
  margin: 0;
}

/* w3-col floats, so columns would only be as tall as their own contents and
/* the cards in a row would not line up. Flex keeps the percentage widths the
/* w3-col classes set while stretching every column to the tallest. */
.launcher-grid {
  display: flex;
  flex-wrap: wrap;
}

/* The card is a link plus a second, separate link for the verb, so the whole
/* card stays clickable without nesting anchors. */
.space-card {
  background: var(--w3-ui-surface);
  border: 1px solid var(--w3-ui-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 168px;
  padding: 20px;
}

.space-card__body {
  color: inherit;
  display: block;
  flex-grow: 1;
  text-decoration: none;
  text-align: center;
}

.space-card__name {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}

@media (any-hover: hover) {
  .space-card:hover {
    border-color: var(--w3-text-grey);
  }
}

.space-chip {
  --icon-size: 32px;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 10px;
  background: var(--w3-ui-stripe);
  color: var(--w3-text-grey);
}

/* Closes the grid. Not a link until there is somewhere to send it. */
.space-card--empty {
  align-items: center;
  background: none;
  border-style: dashed;
  color: var(--w3-text-grey);
  gap: 10px;
  justify-content: center;
}

.space-card--empty .icon {
  --icon-size: 20px;
}

