/**
 * Styles for Find My Rep plugin
 * Theme-compatible styling that inherits from active WordPress theme
 */

.find-my-rep-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.25rem;
  font-family: inherit;
  /* Establish explicit color context so plugin is readable on any theme */
  color: var(--fmr-text, var(--wp--preset--color--contrast, #1a1a1a));
  --fmr-text: var(--wp--preset--color--contrast, #1a1a1a);
  --fmr-bg: var(--wp--preset--color--base, #ffffff);
  --fmr-primary: var(--wp--preset--color--primary, #005ea2);
  --fmr-border: var(--wp--preset--color--contrast, #767676);
  --fmr-badge-bg: var(--wp--preset--color--contrast, #333333);
  --fmr-badge-text: var(--wp--preset--color--base, #ffffff);
  --fmr-success: #1a7f37;
}

.find-my-rep-step {
  background: var(--fmr-bg, #ffffff);
  color: var(--fmr-text, #1a1a1a);
  padding: clamp(1.5rem, 4vw, 2rem);
  border-radius: var(--wp--custom--spacing--small, 0.5rem);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  margin-bottom: 1.5rem;
}

.find-my-rep-step h3 {
  margin-top: 0;
  margin-bottom: 1.25rem;
  color: var(--fmr-text, #1a1a1a);
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: inherit;
}

.find-my-rep-step label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--fmr-text, #1a1a1a);
}

.letter-guidance {
  margin: 0.75rem 0 1rem;
  color: var(--fmr-text, #1a1a1a);
  opacity: 0.8;
  font-size: 0.95rem;
}

.step-question h3 {
  margin-block-end: 0.5rem;
}

.question-intro {
  margin-block: 0 1rem;
  color: var(--fmr-text, #1a1a1a);
  opacity: 0.8;
  font-size: 0.95rem;
}

.robot-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.postcode-input,
.sender-name,
.sender-email,
.sender-address {
  width: 100%;
  max-width: 25rem;
  padding: 0.625rem 1rem;
  border: 1px solid var(--fmr-border, #767676);
  border-radius: var(--wp--custom--spacing--small, 0.25rem);
  font-size: inherit;
  font-family: inherit;
  margin-bottom: 1rem;
  box-sizing: border-box;
  background-color: var(--fmr-bg, #ffffff);
  color: var(--fmr-text, #1a1a1a);
}

.postcode-input:focus,
.sender-name:focus,
.sender-email:focus,
.sender-address:focus,
.question-response:focus,
.letter-content:focus {
  outline: 2px solid var(--fmr-primary, #005ea2);
  outline-offset: 2px;
  border-color: var(--fmr-primary, #005ea2);
}

.selection-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-block-end: 2rem;

}

.selection-header h3 {
  margin-block-end: 0;
}

.button {
  padding: 0.75rem 1.5rem;
  border: 2px solid var(--fmr-primary, #005ea2);
  border-radius: var(--wp--custom--spacing--small, 0.25rem);
  font-size: inherit;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-block;
}

.button-primary {
  background: var(--fmr-primary, #005ea2);
  color: #ffffff;
  border-color: var(--fmr-primary, #005ea2);
}

.button-primary:hover,
.button-primary:focus {
  background: var(--fmr-text, #1a1a1a);
  border-color: var(--fmr-text, #1a1a1a);
  color: #ffffff;
}

.button-primary:active {
  opacity: 0.8;
  transform: scale(0.98);
}

.step-buttons {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
  align-items: center;
}

.back-btn {
  background: transparent;
  color: var(--fmr-primary, #005ea2);
  border-color: var(--fmr-primary, #005ea2);
}

.back-btn:hover,
.back-btn:focus {
  background: rgba(0, 0, 0, 0.05);
}

.button:disabled,
.button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.error-message {
  color: #b32d2e;
  background: rgba(179, 45, 46, 0.08);
  padding: 1rem;
  border-radius: var(--wp--custom--spacing--small, 0.25rem);
  margin-top: 1rem;
  border-left: 4px solid currentColor;
}

.success-message {
  color: var(--fmr-success, #1a7f37);
  background: color-mix(
    in srgb,
    var(--fmr-success, #1a7f37) 8%,
    transparent
  );
  padding: 1rem;
  border-radius: var(--wp--custom--spacing--small, 0.25rem);
  margin-block-start: 1rem;
  border-inline-start: 0.25rem solid currentColor;
}

.representatives-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.selection-intro {
  margin-block: 0 1rem;
  color: var(--fmr-text, #1a1a1a);
  opacity: 0.8;
}

.selection-list {
  max-block-size: min(32rem, 48dvh);
  padding-inline-end: 0.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.selection-actions {
  justify-content: flex-end;
}

.recipient-summary .representatives-list {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  gap: 0.625rem;
  margin-block-end: 0;
}

.recipient-summary {
  padding: 1.25rem;
}

.recipient-summary h3 {
  margin-block-end: 0.5rem;
}

.recipient-summary-intro {
  margin-block: 0 0.75rem;
}

.recipient-summary .representative-item {
  display: block;
  padding: 0.75rem 1rem;
}

.recipient-summary .rep-type-title {
  cursor: pointer;
}

.recipient-names {
  margin-block: 0.625rem 0;
  padding-inline-start: 1.25rem;
}

.recipient-names li + li {
  margin-block-start: 0.25rem;
}

.representative-item {
  display: flex;
  align-items: flex-start;
  min-inline-size: 0;
  padding: 1rem;
  border: 2px solid var(--fmr-border, #767676);
  border-radius: var(--wp--custom--spacing--small, 0.5rem);
  transition: all 0.2s ease;
  background-color: var(--fmr-bg, #ffffff);
  color: var(--fmr-text, #1a1a1a);
  border-left-width: 4px;
}

.representative-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

/* Type-specific colors */
.representative-item.rep-type-mp {
  border-left-color: #4a6da7;
}

.representative-item.rep-type-mp .rep-icon {
  color: #4a6da7;
}

.representative-item.rep-type-mp .rep-type-title {
  color: #4a6da7;
}

.representative-item.rep-type-ms {
  border-left-color: #00a651;
}

.representative-item.rep-type-ms .rep-icon {
  color: #00a651;
}

.representative-item.rep-type-ms .rep-type-title {
  color: #00a651;
}

.representative-item.rep-type-pcc {
  border-left-color: #1a365d;
}

.representative-item.rep-type-pcc .rep-icon {
  color: #1a365d;
}

.representative-item.rep-type-pcc .rep-type-title {
  color: #1a365d;
}

.representative-item.rep-type-councillor {
  border-left-color: #7c3aed;
}

.representative-item.rep-type-councillor .rep-icon {
  color: #7c3aed;
}

.representative-item.rep-type-councillor .rep-type-title {
  color: #7c3aed;
}

.representative-item input[type="checkbox"] {
  margin-right: 1rem;
  margin-top: 0.25rem;
  width: 1.125rem;
  height: 1.125rem;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--wp--preset--color--primary, currentColor);
}

.representative-item label {
  flex: 1;
  cursor: pointer;
  margin-bottom: 0;
  font-weight: normal;
}

.step-select .rep-type-title,
.step-select .rep-context,
.step-select .rep-details {
  display: block;
}

.rep-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.rep-icon {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.rep-type-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0;
}

.rep-context {
  font-size: 0.875rem;
  color: var(--fmr-text, #1a1a1a);
  opacity: 0.75;
  margin-bottom: 0.5rem;
}

.area-info-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--fmr-border, #767676);
  color: var(--fmr-text, #1a1a1a);
}

.area-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--fmr-badge-bg, #333333);
  color: var(--fmr-badge-text, #ffffff);
  border-radius: 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
}

.rep-details {
  inline-size: 100%;
  min-inline-size: 0;
  font-size: 0.9375rem;
}

.rep-details strong {
  color: var(--fmr-text, #1a1a1a);
  font-size: 1.0625rem;
  display: inline;
  margin-right: 0.5rem;
  font-weight: 600;
}

.rep-party {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  background: var(--fmr-badge-bg, #333333);
  color: var(--fmr-badge-text, #ffffff);
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.85;
  vertical-align: middle;
}

.rep-contact-info {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.rep-email {
  color: var(--fmr-text, #1a1a1a);
  opacity: 0.8;
  overflow-wrap: anywhere;
}

/* Success step */

.step-success .success-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-block-end: 1rem;
}

.step-success .success-header h3 {
  margin: 0;
  color: var(--fmr-success, #1a7f37);
}

.success-check-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 2.25rem;
  block-size: 2.25rem;
  border-radius: 50%;
  background: var(--fmr-success, #1a7f37);
  flex-shrink: 0;
}

.success-check-icon::after {
  content: "";
  display: block;
  inline-size: 0.55rem;
  block-size: 0.9rem;
  border: 0.15625rem solid #fff;
  border-block-start: none;
  border-inline-start: none;
  transform: rotate(45deg) translate(-10%, -10%);
}

.success-summary {
  margin-block: 0 1.5rem;
  white-space: pre-line;
}

.success-recipients {
  margin-block-end: 1.5rem;
}

.success-recipients h4,
.success-next-steps h4 {
  margin: 0;
  margin-block-end: 0.625rem;
  font-weight: 600;
}

.success-recipients ul {
  margin: 0;
  padding-inline-start: 1.25rem;
}

.success-recipients li + li {
  margin-block-start: 0.25rem;
}

.success-rep-type {
  opacity: 0.7;
  font-size: 0.9em;
}

.success-next-steps {
  border-block-start: 0.0625rem solid var(--fmr-border, #767676);
  padding-block-start: 1.25rem;
  margin-block-end: 1.5rem;
  color: var(--fmr-text, #1a1a1a);
}

.success-next-steps ol {
  margin: 0;
  padding-inline-start: 1.25rem;
}

.success-next-steps li {
  line-height: 1.5;
}

.success-next-steps li + li {
  margin-block-start: 0.625rem;
}

.success-step-buttons {
  justify-content: flex-end;
}

/* Letter fields */
.letter-fields {
  margin-bottom: 20px;
}

.letter-fields label {
  margin-top: 15px;
}

.letter-fields label:first-child {
  margin-top: 0;
}

.letter-preview h4 {
  margin-block: 0 0.5rem;
}

.letter-preview-intro {
  margin-block: 0 1rem;
  max-inline-size: 60ch;
  opacity: 0.8;
}

.letter-document {
  margin-block-end: 1rem;
  border: 1px solid var(--fmr-border, #767676);
  border-radius: var(--wp--custom--spacing--small, 0.25rem);
  overflow: clip;
  background-color: var(--fmr-bg, #ffffff);
}

.letter-document:focus-within {
  outline: 2px solid var(--fmr-primary, #005ea2);
  outline-offset: 2px;
  border-color: var(--fmr-primary, #005ea2);
}

.letter-document .letter-subject {
  display: block;
  inline-size: calc(100% - 2rem);
  margin: 0.75rem 1rem;
  padding: 0.5rem 0;
  border: 0;
  border-block-end: 1px solid var(--fmr-border, #767676);
  border-radius: 0;
  background: transparent;
  color: var(--fmr-text, #1a1a1a);
  font: inherit;
  font-weight: 600;
  box-sizing: border-box;
}

.letter-document .letter-subject:focus {
  outline: 0;
  border-color: var(--fmr-primary, #005ea2);
}

.letter-document .letter-content {
  display: block;
  margin: 0;
  border: 0;
  border-block-end: 1px solid var(--fmr-border, #767676);
  border-radius: 0;
}

.letter-document .letter-content:focus {
  outline: 0;
  border-color: var(--fmr-border, #767676);
}

.letter-signoff {
  padding: 1rem;
  white-space: pre-line;
}

.letter-signoff p {
  margin-block: 0 0.5rem;
}

.letter-signoff-placeholder {
  opacity: 0.6;
  font-style: italic;
}

.question-response,
.sender-address,
.letter-content {
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--fmr-border, #767676);
  border-radius: var(--wp--custom--spacing--small, 0.25rem);
  font-size: inherit;
  font-family: inherit;
  line-height: 1.6;
  margin-bottom: 1rem;
  resize: vertical;
  box-sizing: border-box;
  background-color: var(--fmr-bg, #ffffff);
  color: var(--fmr-text, #1a1a1a);
}

.loading-spinner {
  text-align: center;
  padding: 20px;
}

.loading-spinner .spinner {
  float: none;
  margin: 0 auto;
}

/* WordPress spinner styles */
.spinner {
  display: inline-block;
  visibility: hidden;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  border: 3px solid var(--fmr-border, #767676);
  border-top: 3px solid var(--fmr-primary, #005ea2);
  border-radius: 50%;
}

.spinner.is-active {
  visibility: visible;
  animation: rotation 1s infinite linear;
}

@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Responsive styles */
@media (width <= 48rem) {
  .find-my-rep-container {
    padding-block: 1rem;
    padding-inline: 0.5rem;
  }

  .find-my-rep-step {
    padding-block: 1.25rem;
    padding-inline: 0.75rem;
  }

  .recipient-summary .representative-item {
    padding-inline: 0.75rem;
  }

  .postcode-input,
  .sender-name,
  .sender-email {
    max-width: 100%;
  }

  .representatives-list {
    grid-template-columns: 1fr;
  }

  .representative-item:hover {
    transform: none;
  }
}

/* Ensure theme compatibility */
.find-my-rep-container * {
  box-sizing: border-box;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .button,
  .representative-item,
  .spinner {
    transition: none;
    animation: none;
  }
}
