/*
 * Feedback widget — a floating button that opens a small contact form.
 * Colours come from the Quartz theme variables, so light and dark mode follow
 * the site toggle. Loaded by quartz/components/Feedback.tsx.
 *
 * z-index 40 keeps it under the mobile app bar and explorer drawer (50) and
 * the search overlay (999): both of those should cover it when open.
 */

/* A filled circle in the link colour, --secondary: easy to find, but not the
   olive of the Send button inside the form. The icon takes --light, the page
   background, so it stays readable against the teal in both themes (dark
   teal + light icon, light teal + dark icon). */
#fb-btn {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 40;
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--secondary);
  color: var(--light);
  cursor: pointer;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.15),
    0 6px 18px color-mix(in srgb, var(--secondary) 40%, transparent);
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    opacity 0.15s ease,
    transform 0.15s ease,
    visibility 0s;
}

#fb-btn svg,
#fb-close svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#fb-btn svg {
  width: 1.4rem;
  height: 1.4rem;
}

/* White on hover, not --light: --tertiary is the same olive in both themes,
   and dark mode's --light would be dark on dark. */
#fb-btn:hover {
  background: var(--tertiary);
  color: #fff;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.15),
    0 6px 18px color-mix(in srgb, var(--tertiary) 40%, transparent);
  transform: translateY(-1px);
}

/* Open: the panel takes the button's corner, and its own ✕ closes it, so
   the button steps out of the way rather than sitting under the Send button. */
#fb-btn[aria-expanded="true"] {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
  transition:
    opacity 0.15s ease,
    transform 0.15s ease,
    visibility 0s linear 0.15s;
}

#fb-btn:focus-visible,
#fb-panel button:focus-visible {
  outline: 2px solid var(--tertiary);
  outline-offset: 2px;
}

#fb-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 40;
  box-sizing: border-box;
  width: 340px;
  max-height: calc(100dvh - 1.25rem - 1rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--lightgray);
  border-top: 3px solid var(--tertiary);
  border-radius: 14px;
  background: var(--light);
  color: var(--darkgray);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.06),
    0 16px 40px rgba(0, 0, 0, 0.16);

  /* Closed: slid down and hidden. visibility (not just opacity) keeps the
     closed form out of the tab order and away from screen readers. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.75rem);
  transform-origin: bottom right;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    visibility 0s linear 0.18s;
}

#fb-panel.fb-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    visibility 0s;
}

#fb-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 0.6rem 0.25rem 1.1rem;
}

#fb-title {
  margin: 0;
  font-family: var(--headerFont);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--dark);
}

#fb-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--gray);
}

#fb-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  margin-top: -0.25rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--gray);
  cursor: pointer;
}

#fb-close svg {
  width: 1.1rem;
  height: 1.1rem;
}

#fb-close:hover {
  background: color-mix(in srgb, var(--tertiary) 12%, transparent);
  color: var(--tertiary);
}

#fb-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem 1.1rem 1.1rem;
}

#fb-body label {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-top: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--darkgray);
  white-space: nowrap;
}

#fb-body label:first-child {
  margin-top: 0;
}

.fb-optional {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--gray);
}

#fb-message,
#fb-email {
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--lightgray);
  border-radius: 10px;
  background: color-mix(in srgb, var(--lightgray) 25%, var(--light));
  color: var(--dark);
  font-family: var(--bodyFont);
  /* 1rem, not less: iOS zooms the page into any field under 16px. */
  font-size: 1rem;
  line-height: 1.45;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background-color 0.15s ease;
}

#fb-message {
  min-height: calc(5lh + 1.2rem);
  resize: vertical;
}

#fb-message::placeholder,
#fb-email::placeholder {
  color: var(--gray);
  opacity: 0.8;
}

/* One ring, not two: the field's own border turns olive and a soft glow sits
   flush against it. The site-wide :focus-visible outline (custom.scss) would
   draw a second ring 2px outside the border, so it's switched off here. */
#fb-message:focus,
#fb-message:focus-visible,
#fb-email:focus,
#fb-email:focus-visible {
  outline: none;
  border-color: var(--tertiary);
  background: var(--light);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tertiary) 22%, transparent);
}

/* The honeypot. Off-screen rather than display: none, which some bots skip. */
#fb-website {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

#fb-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.6rem;
}

#fb-hint {
  font-size: 0.75rem;
  color: var(--gray);
}

#fb-send {
  margin-left: auto;
  min-width: 6.5rem;
  height: 2.5rem;
  padding: 0 1.25rem;
  border: none;
  border-radius: 999px;
  background: var(--tertiary);
  color: #fff;
  font-family: var(--bodyFont);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    transform 0.1s ease;
}

#fb-send:hover:not(:disabled) {
  background: color-mix(in srgb, var(--tertiary) 85%, #000);
}

#fb-send:active:not(:disabled) {
  transform: scale(0.97);
}

#fb-send:disabled {
  opacity: 0.6;
  cursor: progress;
}

#fb-status {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
}

#fb-status:empty {
  display: none;
}

#fb-status.fb-error {
  color: #c0392b;
}

/* After a successful send the fields are hidden and only the thank-you shows. */
#fb-panel.fb-sent #fb-body > :not(#fb-status) {
  display: none;
}

#fb-panel.fb-sent #fb-status {
  padding: 1.25rem 0 0.5rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--tertiary);
}

/* Phones: full width, same breakpoint as the site's $mobile layout. */
@media (max-width: 800px) {
  #fb-btn {
    right: 1rem;
    bottom: 1rem;
  }

  #fb-panel {
    right: 0.5rem;
    left: 0.5rem;
    bottom: 0.5rem;
    width: auto;
    max-height: calc(100dvh - 1rem);
  }
}

/* Touch: finger-sized controls, and no keyboard shortcut hint. */
@media (hover: none) {
  #fb-close {
    width: var(--tap-target, 2.75rem);
    height: var(--tap-target, 2.75rem);
  }

  #fb-send {
    height: var(--tap-target, 2.75rem);
  }

  #fb-hint {
    visibility: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  #fb-btn,
  #fb-panel,
  #fb-panel.fb-open {
    transition: none;
  }
}

@media print {
  #fb-btn,
  #fb-panel {
    display: none;
  }
}
