/* "Report an error" tab and floating panel on offering pages.
   Markup: app/views/offerings/_error_report.html.erb
   Behavior: app/javascript/controllers/error_report_controller.js */

.error-report-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The tab: a plain link pinned to the right edge of the window. */
.error-report-tab {
  position: fixed;
  right: 0;
  top: 50%;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  background-color: #ffffff;
  border: 1px solid var(--color-border-warm);
  border-right: none;
  border-radius: 0.375rem 0 0 0.375rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.error-report-tab:hover {
  text-decoration: none;
}

.error-report-tab[hidden] {
  display: none;
}

/* The panel: non-modal, so the page stays readable and scrollable behind it. */
.error-report-panel {
  position: fixed;
  z-index: 90;
  top: 7rem;
  right: 1.5rem;
  width: min(22rem, calc(100vw - 2rem));
  /* Room for the default 7rem top offset plus a margin below. The script also
     pulls the panel back into the window on open and on resize. */
  max-height: calc(100vh - 8rem);
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  color: var(--color-deep-forest);
  border: 1px solid var(--color-border-input);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.error-report-panel[hidden] {
  display: none;
}

.error-report-handle {
  display: none;
}

.error-report-titlebar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.25rem 0.25rem 0.75rem;
  background-color: var(--color-light-sage);
  border-bottom: 1px solid var(--color-border-warm);
  border-radius: 0.5rem 0.5rem 0 0;
  cursor: move;
  touch-action: none;
  user-select: none;
}

.error-report-title {
  flex: 1;
  margin: 0;
  font-family: var(--font-family-heading);
  font-size: 1rem;
  font-weight: 700;
}

.error-report-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  color: var(--color-deep-forest);
  background: transparent;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
}

.error-report-icon-button:hover {
  background-color: rgba(61, 90, 76, 0.1);
}

.error-report-panel[data-minimized] .error-report-body {
  display: none;
}

.error-report-panel[data-minimized] .error-report-titlebar {
  border-bottom: none;
  border-radius: 0.5rem;
}

.error-report-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem;
}

.error-report-form > * + * {
  margin-top: 0.75rem;
}

.error-report-where {
  font-size: 0.875rem;
  font-weight: 600;
}

.error-report-snippet {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  margin: 0.5rem 0 0;
  padding: 0.25rem 0 0.25rem 0.625rem;
  border-left: 3px solid var(--color-sage-green);
  background-color: var(--color-soft-cream);
}

.error-report-snippet[hidden] {
  display: none;
}

.error-report-snippet blockquote {
  flex: 1;
  margin: 0;
  padding-top: 0.375rem;
  font-size: 0.875rem;
  font-style: italic;
  max-height: 6rem;
  overflow-y: auto;
  overflow-wrap: anywhere;
}

.error-report-hint,
.error-report-note {
  font-size: 0.8125rem;
  color: var(--color-medium-gray);
}

.error-report-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0.75rem 0 0;
  padding: 0;
  border: none;
}

.error-report-chips legend {
  width: 100%;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.error-report-chip {
  min-height: 2.25rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-deep-forest);
  background-color: #ffffff;
  border: 1px solid var(--color-border-input);
  border-radius: 999px;
  cursor: pointer;
}

.error-report-chip[aria-pressed="true"] {
  color: #ffffff;
  background-color: var(--color-button-secondary);
  border-color: var(--color-button-secondary);
}

.error-report-field label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.error-report-field .form-input {
  width: 100%;
  font-size: 0.9375rem;
}

.error-report-optional {
  font-weight: 400;
  color: var(--color-medium-gray);
}

.error-report-error {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--color-error-red);
}

.error-report-error[hidden],
.error-report-optional[hidden],
.error-report-sent[hidden],
.error-report-field[hidden],
.error-report-link[hidden],
.error-report-hint[hidden] {
  display: none;
}

/* Text actions inside the panel are links in look, buttons in behavior. */
.error-report-link {
  padding: 0;
  font-size: 0.875rem;
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  border: none;
  cursor: pointer;
}

.error-report-link:hover {
  text-decoration: none;
}

/* Send stays in view when the form scrolls inside a short panel. */
.error-report-actions {
  position: sticky;
  bottom: -0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0 0.75rem;
  background-color: #ffffff;
}

.error-report-send {
  padding: 0.5rem 1.25rem;
}

.error-report-honeypot {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.error-report-sent {
  padding: 0.5rem 0;
}

.error-report-sent-text {
  margin-bottom: 0.5rem;
  font-weight: 600;
}

/* Section headings can be tapped to pick the section while the panel is open. */
.error-report-picking [data-error-report-target~="heading"] {
  cursor: pointer;
}

/* The quoted passage on the page. */
::highlight(error-report) {
  background-color: #fde68a;
  color: inherit;
}

/* Phones: a bottom sheet with three heights, set by the handle. */
@media (max-width: 639px) {
  .error-report-tab {
    top: auto;
    bottom: 5rem;
  }

  .error-report-panel {
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0;
    width: 100%;
    max-height: none;
    border-radius: 0.75rem 0.75rem 0 0;
    border-bottom: none;
  }

  .error-report-panel[data-size="half"] {
    height: 50vh;
    height: 50dvh;
  }

  .error-report-panel[data-size="full"] {
    height: calc(100vh - 2rem);
    height: calc(100dvh - 2rem);
  }

  .error-report-panel[data-size="title"] .error-report-body {
    display: none;
  }

  .error-report-panel[data-minimized] {
    height: auto;
  }

  .error-report-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 0;
    background-color: var(--color-light-sage);
    border: none;
    border-radius: 0.75rem 0.75rem 0 0;
    cursor: ns-resize;
    touch-action: none;
  }

  .error-report-handle span {
    display: block;
    width: 2.5rem;
    height: 0.3125rem;
    border-radius: 999px;
    background-color: var(--color-medium-gray);
  }

  .error-report-titlebar {
    border-radius: 0;
    cursor: default;
  }

  .error-report-panel[data-minimized] .error-report-titlebar {
    border-radius: 0;
  }

  .error-report-icon-button,
  .error-report-chip {
    min-width: 44px;
    min-height: 44px;
  }

  .error-report-link {
    min-height: 44px;
  }

  .error-report-body {
    flex: 1;
    min-height: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .error-report-panel {
    transition: height 150ms ease-out;
  }
}
