/* Feedback Widget Styles */
.feedback-widget {
  --panel-width: min(380px, calc(100vw - var(--side-widget-trigger-width, 48px)));
  position: relative;
  width: var(--side-widget-trigger-width, 48px);
  height: var(--side-widget-trigger-height, 165px);
  transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  will-change: transform;
  z-index: 1;
}

.feedback-widget.is-open {
  transform: translateX(var(--panel-width));
  z-index: 10;
}

/* Trigger Button */
.feedback-trigger {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  background-color: var(--brand-caramel);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding: 0;
  font-family: var(--font-heading);
  font-size: 1.0625rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 2px 0 8px rgba(47, 67, 90, 0.15);
  transition: background-color 0.2s;
  
  /* Positioning inside the wrapper */
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* On desktop, hover slightly darkened */
@media (hover: hover) and (pointer: fine) {
  .feedback-widget:not(.is-open) .feedback-trigger:hover {
    background-color: var(--brand-caramel-hover);
  }
}

.feedback-widget.is-open .feedback-trigger {
  opacity: 0;
  pointer-events: none;
}

/* Panel */
.feedback-panel {
  position: absolute;
  top: 0;
  right: 100%; /* Sits off-screen to the left of the trigger */
  width: var(--panel-width);
  background-color: var(--white);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(47, 67, 90, 0.08);
  border-left: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.feedback-header {
  padding: 20px;
  background-color: var(--brand-light-blue);
  border-bottom: 1px solid rgba(47, 67, 90, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.feedback-header h3 {
  font-size: 1.125rem;
  margin: 0;
  color: var(--brand-dark);
  line-height: 1.4;
}

.feedback-close {
  background: transparent;
  border: none;
  color: var(--brand-dark);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.feedback-close:hover, .feedback-close:focus {
  background-color: rgba(47, 67, 90, 0.1);
  outline: none;
}

.feedback-close svg {
  width: 24px;
  height: 24px;
}

.feedback-body {
  padding: 20px;
  position: relative;
}

.feedback-fieldset {
  border: none;
  padding: 0;
  margin: 0 0 20px 0;
}

.feedback-fieldset legend {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
  line-height: 1.3;
}

/* Accessible CSS-only Star Rating (Right to Left) */
.star-rating {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 4px;
}

.star-rating input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.star-rating label {
  cursor: pointer;
  color: #DDE4EC; /* Inactive star color */
  transition: color 0.15s ease-in-out;
}

.star-rating label svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
  stroke: none;
}

/* Hover on a label highlights it and all subsequent siblings (which are visual left due to row-reverse) */
.star-rating label:hover,
.star-rating label:hover ~ label {
  color: var(--brand-caramel-hover);
}

/* Selected states */
.star-rating input:checked ~ label {
  color: var(--brand-caramel);
}

/* Focus state for accessibility */
.star-rating input:focus + label {
  outline: 2px solid var(--brand-cyan);
  outline-offset: 2px;
  border-radius: 2px;
}

.feedback-select {
  width: 100%;
  padding: 12px 36px 12px 12px;
  border: 1px solid rgba(47, 67, 90, 0.2);
  border-radius: var(--radius-sm);
  background-color: var(--white);
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-main);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f435a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.feedback-select:focus {
  outline: none;
  border-color: var(--brand-cyan);
  box-shadow: 0 0 0 3px rgba(32, 189, 189, 0.2);
}

.feedback-select option[value=""][disabled] {
  color: var(--text-muted);
}

.feedback-actions {
  margin-top: 24px;
}

.btn-feedback-submit {
  width: 100%;
}

.btn-feedback-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.feedback-error-msg {
  color: #D32F2F;
  font-size: 0.85rem;
  margin-top: 8px;
  min-height: 1.2em;
}

/* Success State */
.feedback-success {
  text-align: center;
  padding: 20px 0;
}

.feedback-success .success-icon {
  width: 48px;
  height: 48px;
  stroke: var(--brand-cyan);
  fill: none;
  stroke-width: 2;
  margin-bottom: 12px;
}

.feedback-success h4 {
  font-size: 1.25rem;
  margin-bottom: 8px;
  color: var(--brand-dark);
}

.feedback-success p {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* Mobile Adjustments (Bottom Sheet & FAB) */
@media (max-width: 768px) {
  .feedback-fab {
    display: flex;
    position: fixed;
    bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
    right: var(--space-md);
    z-index: 950;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--brand-caramel);
    color: var(--white);
    border: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(47, 67, 90, 0.25);
    cursor: pointer;
    transition: transform 0.2s, opacity 0.3s;
  }
  
  .feedback-fab:active {
    transform: scale(0.95);
  }

  .fab-icon {
    width: 26px;
    height: 26px;
  }
  
  /* Hide FAB when widget is open, menu is open, or job modal is open */
  .feedback-widget.is-open .feedback-fab,
  body.menu-open .feedback-fab,
  body:has(#job-widget.is-open) .feedback-fab {
    opacity: 0;
    pointer-events: none;
  }
  
  /* Reset widget container constraints */
  .feedback-widget {
    width: 100%;
    height: 0;
    transition: none;
    border-radius: 0;
  }
  
  .feedback-widget.is-open {
    transform: none; /* remove desktop translateX */
  }

  /* Mobile Modal Backdrop */
  .feedback-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(18, 29, 43, 0.4); /* Subtle, premium brand-compatible overlay */
    z-index: 1050; /* Just below the panel, but above the header (1000) */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    cursor: pointer;
  }
  
  .feedback-backdrop.is-open {
    opacity: 1;
    visibility: visible;
  }

  /* Transform panel into a bottom sheet */
  .feedback-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: auto;
    top: auto;
    width: 100%;
    height: auto;
    max-height: 85vh; /* Safe buffer from top */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background-color: var(--white);
    border: none;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    z-index: 1060;
    padding-bottom: env(safe-area-inset-bottom, 0px); /* Respect iOS safe area */
  }
  
  .feedback-widget.is-open .feedback-panel {
    transform: translateY(0);
  }

  /* Maintain standard star size adjustments */
  .star-rating label svg {
    width: 28px;
    height: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .feedback-widget {
    transition: transform 0.1s linear;
  }
}
