/*
 * -------------------------------------------------------------------------
 * Club ITSM-Factory plugin for GLPI
 * Copyright (C) 2026 ITSM-Factory
 * -------------------------------------------------------------------------
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. See LICENSE for the full text.
 * -------------------------------------------------------------------------
 *
 * GLPI loads this file on EVERY page, not only the plugin's. Every rule is therefore scoped
 * under #clubitsm-catalog-page so nothing can leak into the rest of the interface.
 *
 * No color is written literally: the screen borrows GLPI's own Tabler variables so it follows
 * the 18 palettes, light and dark, without a second set of rules.
 */

/*
 * One derived token for every piece of secondary text on this screen.
 *
 * GLPI's own --tblr-secondary lands around 3.4:1 against the card on the dark palettes, which is
 * under WCAG AA for normal text — and this screen leans on secondary text for the sentence that
 * describes each pack, the installed counts and the "Détail" control. Mixing the body color
 * toward the background keeps those visibly secondary while clearing 4.5:1, and stays derived
 * from GLPI's tokens, so it still follows every palette.
 */
#clubitsm-catalog-page {
  --clubitsm-muted: color-mix(in srgb, var(--tblr-body-color) 82%, var(--tblr-body-bg));
}

/* ---------------------------------------------------------------- page header */

#clubitsm-catalog-page .clubitsm-page-header {
  margin-bottom: 1.25rem;
}

#clubitsm-catalog-page .clubitsm-headline {
  margin: 0.5rem 0 0.5rem;
  font-size: 1rem;
  color: var(--tblr-body-color);
}

#clubitsm-catalog-page .clubitsm-meter {
  height: 0.5rem;
}

#clubitsm-catalog-page .clubitsm-attention {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: var(--tblr-warning);
}

#clubitsm-catalog-page .clubitsm-attention a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* ---------------------------------------------------------------- "À traiter" card */

#clubitsm-catalog-page .clubitsm-todo-item {
  display: grid;
  grid-template-columns: 13.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.625rem 1rem;
}

/* The column fits the longest label, "Mise à jour disponible", on one line. */
#clubitsm-catalog-page .clubitsm-todo-item > .status {
  justify-self: start;
  white-space: nowrap;
}

#clubitsm-catalog-page .clubitsm-todo-name {
  color: var(--tblr-body-color);
  font-weight: 500;
}

#clubitsm-catalog-page .clubitsm-todo-reason {
  color: var(--clubitsm-muted);
  font-size: 0.8125rem;
}

/* Body color, not primary: on the palettes with a light primary the link text would fade out. */
#clubitsm-catalog-page .clubitsm-todo-more > summary {
  color: var(--tblr-body-color);
  cursor: pointer;
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

#clubitsm-catalog-page .clubitsm-todo-action {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.375rem;
}

/* ---------------------------------------------------------------- folded profiles */

#clubitsm-catalog-page details.clubitsm-profiles > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  cursor: pointer;
  list-style: none;
}

#clubitsm-catalog-page details.clubitsm-profiles > summary::-webkit-details-marker {
  display: none;
}

#clubitsm-catalog-page .clubitsm-profiles-chevron {
  align-self: center;
  color: var(--clubitsm-muted);
  transition: transform 0.15s ease;
}

#clubitsm-catalog-page details.clubitsm-profiles[open] .clubitsm-profiles-chevron {
  transform: rotate(90deg);
}

#clubitsm-catalog-page details.clubitsm-profiles .clubitsm-profiles-title {
  margin: 0;
}

/* ---------------------------------------------------------------- toolbar */

#clubitsm-catalog-page .clubitsm-toolbar .card-body {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
}

#clubitsm-catalog-page .clubitsm-toolbar-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

#clubitsm-catalog-page .clubitsm-toolbar-top .input-icon {
  min-width: 14rem;
}

#clubitsm-catalog-page .clubitsm-toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
}

#clubitsm-catalog-page .clubitsm-filter-set {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 0.75rem;
}

#clubitsm-catalog-page .clubitsm-filter-legend {
  font-size: 0.8125rem;
  color: var(--clubitsm-muted);
}

/* A status with no color still needs a mark: a hollow dot reads as "nothing here yet". */
#clubitsm-catalog-page .clubitsm-dot-none {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--clubitsm-muted);
}

#clubitsm-catalog-page .clubitsm-result-count {
  margin-top: -0.25rem;
}

/* ---------------------------------------------------------------- group */

#clubitsm-catalog-page .clubitsm-group-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#clubitsm-catalog-page .clubitsm-group-toggle {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
}

#clubitsm-catalog-page .clubitsm-group-title {
  font-size: 1rem;
  font-weight: 600;
}

#clubitsm-catalog-page .clubitsm-group-chevron {
  flex: none;
  color: var(--clubitsm-muted);
  transition: transform 0.15s ease;
}

#clubitsm-catalog-page .clubitsm-group.is-collapsed .clubitsm-group-chevron {
  transform: rotate(-90deg);
}

#clubitsm-catalog-page .clubitsm-group.is-collapsed .clubitsm-group-list {
  display: none;
}

#clubitsm-catalog-page .clubitsm-group-count {
  flex: none;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--clubitsm-muted);
}

#clubitsm-catalog-page .clubitsm-group-meter {
  flex: none;
  width: 4rem;
  height: 0.25rem;
}

/* ---------------------------------------------------------------- journal */

#clubitsm-catalog-page .clubitsm-journal-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}

#clubitsm-catalog-page .clubitsm-journal-meta {
  color: var(--clubitsm-muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- pack row */

#clubitsm-catalog-page .clubitsm-row {
  padding: 0.625rem 1rem;
}

/* A selected row is marked on its edge and by a faint wash, never by recoloring its text. */
#clubitsm-catalog-page .clubitsm-row.is-selected {
  background-color: rgba(var(--tblr-primary-rgb), 0.07);
  box-shadow: inset 0.1875rem 0 0 var(--tblr-primary);
}

#clubitsm-catalog-page .clubitsm-row-main {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 0.75rem;
  row-gap: 0.25rem;
}

/* Read-only visitors get no checkbox column at all. */
#clubitsm-catalog-page .clubitsm-row-main.is-readonly {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

#clubitsm-catalog-page .clubitsm-row .form-check-input.clubitsm-pack {
  margin: 0.125rem 0 0;
}

#clubitsm-catalog-page .clubitsm-row-icon {
  margin-top: 0.0625rem;
  color: var(--clubitsm-muted);
  font-size: 1.125rem;
}

#clubitsm-catalog-page .clubitsm-row-body {
  min-width: 0;
}

/* Name and one sentence: the two things that tell a row from its neighbour. */
#clubitsm-catalog-page .clubitsm-row-name {
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.35;
}

#clubitsm-catalog-page .clubitsm-row-desc {
  max-width: 78ch;
  margin: 0.125rem 0 0;
  overflow: hidden;
  color: var(--clubitsm-muted);
  font-size: 0.875rem;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Only shown when there is genuinely something to report, so it may wrap freely. */
#clubitsm-catalog-page .clubitsm-row-flag {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
}

#clubitsm-catalog-page .clubitsm-row-detail {
  margin-top: 0.25rem;
}

#clubitsm-catalog-page .clubitsm-row-detail > summary {
  display: inline-block;
  color: var(--clubitsm-muted);
  cursor: pointer;
  font-size: 0.8125rem;
}

#clubitsm-catalog-page .clubitsm-row-meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.125rem 0.75rem;
  margin: 0.375rem 0 0.25rem;
  font-size: 0.8125rem;
}

#clubitsm-catalog-page .clubitsm-row-meta dt {
  color: var(--clubitsm-muted);
  font-weight: 400;
}

#clubitsm-catalog-page .clubitsm-row-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

#clubitsm-catalog-page .clubitsm-row-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.375rem;
  text-align: end;
  white-space: nowrap;
}

/*
 * GLPI's own css_glpi.min.css re-declares `.status { --tblr-status-color: var(--tblr-secondary) }`
 * after Tabler's stylesheet. Both selectors weigh the same, so source order wins and every
 * `.status-green` / `.status-red` modifier comes out grey. Scoping by the page id raises the
 * weight enough to hand each tier its color back, without touching anything outside this screen.
 */
#clubitsm-catalog-page .status.clubitsm-status-ok {
  --tblr-status-color: var(--tblr-green);
}

/* Same flattening for the Tabler modifiers the apply report uses (created, updated, skipped,
   deleted, failed): scoped the same way so each outcome keeps its color. */
#clubitsm-catalog-page .status.status-green {
  --tblr-status-color: var(--tblr-green);
}

#clubitsm-catalog-page .status.status-azure {
  --tblr-status-color: var(--tblr-azure);
}

#clubitsm-catalog-page .status.status-yellow {
  --tblr-status-color: var(--tblr-yellow);
}

#clubitsm-catalog-page .status.status-orange {
  --tblr-status-color: var(--tblr-orange);
}

#clubitsm-catalog-page .status.status-red {
  --tblr-status-color: var(--tblr-red);
}

/* Up to date is the common case on a running instance: a green dot and quiet text, no pill, so
   the rows that do need something are the only ones that stand out. */
#clubitsm-catalog-page .clubitsm-row .status.clubitsm-status-ok {
  background: transparent;
  color: var(--clubitsm-muted);
  padding-inline: 0;
}

#clubitsm-catalog-page .status.clubitsm-status-stale {
  --tblr-status-color: var(--tblr-yellow);
}

#clubitsm-catalog-page .status.clubitsm-status-todo {
  --tblr-status-color: var(--tblr-orange);
}

#clubitsm-catalog-page .status.clubitsm-status-error {
  --tblr-status-color: var(--tblr-red);
}

/* "Not installed" is the resting state of half the catalog, so it carries no color at all. */
#clubitsm-catalog-page .status.clubitsm-status-none {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--tblr-border-color);
  color: var(--clubitsm-muted);
}

#clubitsm-catalog-page .status.clubitsm-status-none .status-dot {
  background: transparent;
  box-shadow: inset 0 0 0 1px currentColor;
}

/* ---------------------------------------------------------------- action bar */

#clubitsm-catalog-page .clubitsm-actionbar {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

#clubitsm-catalog-page .clubitsm-actionbar-summary {
  font-weight: 500;
}

#clubitsm-catalog-page .clubitsm-actionbar .btn {
  margin-inline-start: auto;
}

/* ---------------------------------------------------------------- narrow screens */

@media (max-width: 575.98px) {
  /* The status drops under the row instead of squeezing the name to one word per line. */
  #clubitsm-catalog-page .clubitsm-row-main {
    grid-template-columns: auto auto minmax(0, 1fr);
  }

  #clubitsm-catalog-page .clubitsm-row-main.is-readonly {
    grid-template-columns: auto minmax(0, 1fr);
  }

  #clubitsm-catalog-page .clubitsm-row-main.is-readonly .clubitsm-row-side {
    grid-column: 2;
  }

  #clubitsm-catalog-page .clubitsm-row-side {
    grid-column: 3;
    align-items: flex-start;
    text-align: start;
  }

  #clubitsm-catalog-page .clubitsm-row-desc {
    white-space: normal;
  }

  #clubitsm-catalog-page .clubitsm-group-meter {
    display: none;
  }

  #clubitsm-catalog-page .clubitsm-actionbar .btn {
    margin-inline-start: 0;
  }

  #clubitsm-catalog-page .clubitsm-todo-item {
    grid-template-columns: minmax(0, 1fr);
  }

  #clubitsm-catalog-page .clubitsm-todo-action {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  #clubitsm-catalog-page .clubitsm-group-chevron,
  #clubitsm-catalog-page .clubitsm-profiles-chevron {
    transition: none;
  }
}

/* Deployment profiles: named starting selections above the catalog. */
.clubitsm-profiles-title {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.clubitsm-profiles-text {
  color: var(--tblr-secondary);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.clubitsm-profiles-grid {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

.clubitsm-profile {
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  text-align: left;
}

.clubitsm-profile:hover {
  border-color: var(--tblr-primary);
}

.clubitsm-profile.active {
  border-color: var(--tblr-primary);
  box-shadow: inset 0 0 0 1px var(--tblr-primary);
}

.clubitsm-profile-head {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
}

.clubitsm-profile-label {
  font-weight: 600;
}

.clubitsm-profile-desc {
  color: var(--tblr-secondary);
  font-size: 0.8125rem;
  line-height: 1.35;
}

/* Notification preview: the mail is 980px wide, so the frame takes the whole card width and a
   fixed height, the page scrolling around it rather than inside it twice. */
#clubitsm-catalog-page .clubitsm-notif-frame {
  border: 0;
  display: block;
  height: 80vh;
  width: 100%;
}

#clubitsm-catalog-page .clubitsm-preview-list .badge {
  font-weight: normal;
}

#clubitsm-catalog-page .clubitsm-notif-text {
  white-space: pre-wrap;
}
