/**
 * Helpdesk portal styles, linked only on pages with portal markup (`assets.markup`).
 * Colours, radii and fonts come from the active theme's public tokens, with
 * fallbacks for themes that do not define them.
 */
.jf-helpdesk {
  --hd-bg: var(--color-bg, Canvas);
  --hd-surface: var(--color-surface, color-mix(in srgb, CanvasText 4%, Canvas));
  --hd-border: var(--color-border, color-mix(in srgb, CanvasText 15%, Canvas));
  --hd-text: var(--color-text, CanvasText);
  --hd-muted: var(--color-muted, color-mix(in srgb, CanvasText 60%, Canvas));
  --hd-accent: var(--color-primary, #2563eb);
  --hd-accent-hover: var(--color-primary-hover, var(--hd-accent));
  --hd-accent-soft: color-mix(in srgb, var(--hd-accent) 10%, var(--hd-bg));
  /** Text on the primary colour: white on a dark primary, near-black on a light one. */
  --hd-on-accent: #fff;
  --hd-on-accent: oklch(from var(--hd-accent) clamp(0.12, (0.68 - l) * 1000, 1) 0 0);
  --hd-success: #15803d;
  --hd-warning: #b45309;
  --hd-danger: #dc2626;
  --hd-radius: var(--radius-md, 10px);
  --hd-radius-sm: var(--radius-sm, 6px);
  --hd-shadow: var(--shadow-sm, 0 1px 2px rgba(15, 23, 42, 0.06));
  --hd-ring: 0 0 0 3px color-mix(in srgb, var(--hd-accent) 22%, transparent);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 44rem;
  color: var(--hd-text);
  font: inherit;
}
html[data-theme="dark"] .jf-helpdesk {
  --hd-success: #4ade80;
  --hd-warning: #fbbf24;
  --hd-danger: #f87171;
}
.jf-helpdesk *,
.jf-helpdesk *::before,
.jf-helpdesk *::after {
  box-sizing: border-box;
}
.jf-helpdesk :where(h2, h3, p) {
  margin: 0;
}
.jf-helpdesk [hidden] {
  display: none !important;
}

/** Cards */
.jf-helpdesk__card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: clamp(1rem, 0.6rem + 1.5vw, 1.5rem);
  background: var(--hd-bg);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius);
  box-shadow: var(--hd-shadow);
}
.jf-helpdesk__title {
  font-family: var(--font-heading, inherit);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.jf-helpdesk__intro,
.jf-helpdesk__hint,
.jf-helpdesk__meta {
  color: var(--hd-muted);
}
.jf-helpdesk__hint,
.jf-helpdesk__meta {
  font-size: 0.85rem;
  line-height: 1.5;
}

/** Form */
.jf-helpdesk__form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.jf-helpdesk__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}
.jf-helpdesk__field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}
.jf-helpdesk__check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.jf-helpdesk__label {
  font-size: 0.9rem;
  font-weight: 600;
}
.jf-helpdesk__input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  font: inherit;
  font-size: 1rem;
  color: var(--hd-text);
  background: var(--hd-bg);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius-sm);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.jf-helpdesk__input:hover {
  border-color: color-mix(in srgb, var(--hd-muted) 60%, var(--hd-border));
}
.jf-helpdesk__input:focus {
  outline: none;
  border-color: var(--hd-accent);
  box-shadow: var(--hd-ring);
}
.jf-helpdesk__input[readonly] {
  background: var(--hd-surface);
  color: var(--hd-muted);
}
textarea.jf-helpdesk__input {
  min-height: 9rem;
  resize: vertical;
  line-height: 1.55;
}
select.jf-helpdesk__input {
  appearance: none;
  padding-right: 2.2rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--hd-muted) 50%),
    linear-gradient(135deg, var(--hd-muted) 50%, transparent 50%);
  background-position: calc(100% - 1.05rem) 55%, calc(100% - 0.7rem) 55%;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
}
.jf-helpdesk__fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.jf-helpdesk__fieldset legend {
  padding: 0;
  margin-bottom: 0.5rem;
}
.jf-helpdesk__choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem;
}
.jf-helpdesk__choice {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius-sm);
  background: var(--hd-bg);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}
.jf-helpdesk__choice:hover {
  border-color: color-mix(in srgb, var(--hd-accent) 45%, var(--hd-border));
}
.jf-helpdesk__choice:has(input:checked) {
  border-color: var(--hd-accent);
  background: var(--hd-accent-soft);
}
.jf-helpdesk__choice input {
  margin: 0.25rem 0 0;
  accent-color: var(--hd-accent);
  flex: none;
}
.jf-helpdesk__choice strong {
  display: block;
  font-size: 0.95rem;
}
.jf-helpdesk__choice span span {
  display: block;
  font-size: 0.85rem;
  color: var(--hd-muted);
}
.jf-helpdesk__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.jf-helpdesk__hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/** Buttons */
.jf-helpdesk__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  font: inherit;
  font-weight: 650;
  font-size: 0.95rem;
  line-height: 1.3;
  color: var(--hd-on-accent);
  background: var(--hd-accent);
  border: 1px solid transparent;
  border-radius: var(--hd-radius-sm);
  box-shadow: var(--hd-shadow);
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.15s ease,
    transform 0.06s ease;
}
.jf-helpdesk__button:hover {
  background: var(--hd-accent-hover);
  color: var(--hd-on-accent);
}
.jf-helpdesk__button:active {
  transform: translateY(1px);
}
.jf-helpdesk__button--secondary {
  color: var(--hd-text);
  background: var(--hd-bg);
  border-color: var(--hd-border);
}
.jf-helpdesk__button--secondary:hover {
  color: var(--hd-text);
  background: var(--hd-surface);
}
.jf-helpdesk :focus-visible {
  outline: 2px solid var(--hd-accent);
  outline-offset: 2px;
}

/** Notices */
.jf-helpdesk__error {
  padding: 0.75rem 1rem;
  border-radius: var(--hd-radius-sm);
  border: 1px solid color-mix(in srgb, var(--hd-danger) 35%, transparent);
  background: color-mix(in srgb, var(--hd-danger) 8%, var(--hd-bg));
  color: var(--hd-danger);
  font-size: 0.9rem;
  font-weight: 500;
}
.jf-helpdesk__empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--hd-muted);
  background: var(--hd-surface);
  border: 1px dashed var(--hd-border);
  border-radius: var(--hd-radius);
}
.jf-helpdesk__empty .jf-helpdesk__button {
  margin-top: 1rem;
}
.jf-helpdesk__loading {
  color: var(--hd-muted);
}

/** Request sent */
.jf-helpdesk__sent {
  align-items: flex-start;
  gap: 0.6rem;
  border-color: color-mix(in srgb, var(--hd-success) 35%, var(--hd-border));
  background: color-mix(in srgb, var(--hd-success) 6%, var(--hd-bg));
}
.jf-helpdesk__sent-icon {
  margin-bottom: 0.4rem;
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--hd-success);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
}
.jf-helpdesk__number {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/** Ticket lists */
.jf-helpdesk__list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius);
  overflow: hidden;
  background: var(--hd-bg);
  box-shadow: var(--hd-shadow);
}
.jf-helpdesk__list li + li {
  border-top: 1px solid var(--hd-border);
}
.jf-helpdesk__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.9rem 1.1rem;
  color: inherit;
  text-decoration: none;
  transition: background 0.15s ease;
}
.jf-helpdesk__item:hover {
  background: var(--hd-surface);
}
.jf-helpdesk__item-subject {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.jf-helpdesk__item:hover .jf-helpdesk__item-subject {
  color: var(--hd-accent);
}
.jf-helpdesk__item .jf-helpdesk__meta {
  grid-column: 1;
}
.jf-helpdesk__item .jf-helpdesk__badge {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.jf-helpdesk__ref {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85em;
}

/** Status badges */
.jf-helpdesk__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--hd-muted);
  background: var(--hd-surface);
  border: 1px solid var(--hd-border);
}
.jf-helpdesk__badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.jf-helpdesk__badge--new,
.jf-helpdesk__badge--open {
  color: var(--hd-accent);
  background: var(--hd-accent-soft);
  border-color: color-mix(in srgb, var(--hd-accent) 25%, transparent);
}
.jf-helpdesk__badge--pending,
.jf-helpdesk__badge--on_hold {
  color: var(--hd-warning);
  background: color-mix(in srgb, var(--hd-warning) 10%, var(--hd-bg));
  border-color: color-mix(in srgb, var(--hd-warning) 25%, transparent);
}
.jf-helpdesk__badge--solved {
  color: var(--hd-success);
  background: color-mix(in srgb, var(--hd-success) 10%, var(--hd-bg));
  border-color: color-mix(in srgb, var(--hd-success) 25%, transparent);
}

/** Ticket thread */
.jf-helpdesk__ticket-head {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.jf-helpdesk__ticket-head .jf-helpdesk__badge {
  align-self: flex-start;
}
.jf-helpdesk__thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.jf-helpdesk__message {
  padding: 0.9rem 1.1rem;
  background: var(--hd-surface);
  border: 1px solid var(--hd-border);
  border-radius: var(--hd-radius);
}
.jf-helpdesk__message-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.jf-helpdesk__author {
  font-weight: 650;
}
.jf-helpdesk__message-head time {
  margin-inline-start: auto;
  font-size: 0.8rem;
  color: var(--hd-muted);
}
.jf-helpdesk__body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}

/** Standalone pages served without the theme (archive, not found). */
.jf-helpdesk-page {
  margin: 0;
  padding: clamp(1.5rem, 1rem + 3vw, 4rem) 1rem;
  font-family: var(--font-sans, system-ui, sans-serif);
  background: var(--color-bg, Canvas);
  color: var(--color-text, CanvasText);
  line-height: 1.6;
}
.jf-helpdesk-page > .jf-helpdesk {
  margin-inline: auto;
}
.jf-helpdesk-page h1 {
  margin: 0;
  font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

@media (prefers-reduced-motion: reduce) {
  .jf-helpdesk * {
    transition: none !important;
    scroll-behavior: auto;
  }
}
