/**
 * Universal Form Components
 * Shared styling for all contact forms across the site
 */

/* Form Layout */
.universal-form {
  display: grid;
  grid-template-columns: 1fr 1fr; /* all fields 50% by default */
  gap: 16px;
}

.form-row {
  /* Let children participate in parent grid so every field is 50% */
  display: contents;
}

/* All form fields are now 50% width */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

/* Full width form groups for specific cases */
.form-group.full-width {
  grid-column: 1 / -1;
}

/* Make submit button, helper note and form message span full width */
.universal-form .submit-btn,
.universal-form .form-note,
.universal-form .form-message {
  grid-column: 1 / -1;
}

/* Form Message Styling */
.universal-form .form-message {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.universal-form .form-message span {
  display: block;
}

/* Form Labels */
.form-group label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

/* Form Inputs */
.universal-form input,
.universal-form select,
.universal-form textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 15px;
  transition: all 0.3s ease;
  background: white;
  box-sizing: border-box;
}

.universal-form input:focus,
.universal-form select:focus,
.universal-form textarea:focus {
  outline: none;
  border-color: var(--brand-sky);
  box-shadow: 0 0 0 3px rgba(82, 173, 229, 0.1);
}

/* Submit Button */
.submit-btn {
  background: var(--brand-sky);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
  margin-top: 8px;
}

.submit-btn:hover {
  background: #1847a0;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(27, 80, 179, 0.3);
}

.submit-btn:active {
  transform: translateY(0);
}

/* Form Note */
.form-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0 0;
}

/* Custom Calendar Styles */
.custom-calendar-container {
  position: relative;
}

.custom-calendar-trigger {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  transition: all 0.3s ease;
}

.custom-calendar-trigger:hover {
  border-color: var(--brand-blue);
}

.custom-calendar-trigger:focus-within {
  border-color: var(--brand-sky);
  box-shadow: 0 0 0 3px rgba(82, 173, 229, 0.1);
}

.calendar-value {
  color: var(--ink);
  font-weight: 500;
}

.calendar-icon {
  color: var(--brand-blue);
  flex-shrink: 0;
}

.custom-calendar-popup {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  margin-top: 8px;
  padding: 16px;
  /* Keep within viewport and avoid right-edge clipping */
  box-sizing: border-box;
  width: auto;
  max-width: 360px;
  min-width: 280px;
  /* Fallback for very narrow screens */
  inline-size: min(360px, calc(100vw - 32px));
  overflow: visible;
  min-height: auto;
  height: auto;
  max-height: 400px;
}

/* Alternative positioning when popup would be cut off at bottom */
.custom-calendar-popup.position-top {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 8px;
  transform: translateY(10px);
}

.custom-calendar-popup.position-top.active {
  transform: translateY(0);
}

.custom-calendar-popup.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.calendar-month-year {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.calendar-nav {
  background: none;
  border: none;
  padding: 4px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.2s ease;
}

.calendar-nav svg {
  width: 14px;
  height: 14px;
}

.calendar-nav:hover {
  background: #f8fafc;
  color: var(--brand-blue);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 0 8px; /* prevent text touching edges */
  margin-bottom: 6px;
  justify-items: center;
  align-items: center;
}

.weekday {
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 2px;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 0 8px; /* prevent numbers touching edges */
  justify-items: center;
  align-items: center;
}

.calendar-day {
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fill grid cell instead of fixed px to avoid overflow */
  width: 100%;
  height: 36px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.calendar-day:hover:not(.past):not([disabled]) {
  background: #f8fafc;
  color: var(--brand-sky);
}

.calendar-day.other-month {
  color: var(--muted);
  opacity: 0.5;
}

.calendar-day.today {
  background: var(--brand-sky);
  color: white;
  font-weight: 600;
}

.calendar-day.selected {
  background: var(--brand-blue);
  color: white;
  font-weight: 600;
}

.calendar-day.selected.today {
  background: var(--brand-blue);
  color: white;
  font-weight: 600;
}

.calendar-day.hidden {
  visibility: hidden;
  pointer-events: none;
}

.calendar-day.past {
  color: #cbd5e1;
  cursor: not-allowed;
}

.calendar-footer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
  text-align: right;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.calendar-done-btn {
  background: var(--brand-sky);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 60px;
}

.calendar-done-btn:hover {
  background: #1847a0;
}

/* Custom Select Styles */
.custom-select-container {
  position: relative;
}

.custom-select-trigger {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  transition: all 0.3s ease;
}

.custom-select-trigger:hover {
  border-color: var(--brand-blue);
}

.select-value {
  color: var(--ink);
  font-weight: 500;
}

.select-icon {
  color: var(--brand-blue);
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.custom-select-container.active .select-icon {
  transform: rotate(180deg);
}

.custom-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  margin-top: 4px;
  border: 1px solid #f1f5f9;
  overflow: hidden;
}

.custom-select-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.select-options {
  max-height: 200px;
  overflow-y: auto;
}

.select-option {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  transition: all 0.2s ease;
}

.select-option:hover {
  background: #f8fafc;
}

.select-option.selected {
  background: #f0f9ff;
  color: var(--brand-blue);
}

.option-check {
  color: var(--brand-blue);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.select-option.selected .option-check {
  opacity: 1;
}

/* Form Success/Error Messages */
.form-success {
  background: #e8fff3;
  color: #0f7a3b;
  border: 1px solid #b7f3cf;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.form-error {
  background: #ffecec;
  color: #a70f2a;
  border: 1px solid #f7b7c0;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .universal-form {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .custom-calendar-trigger,
  .custom-select-trigger {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
  .universal-form input,
  .universal-form select,
  .universal-form textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 12px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .custom-calendar-trigger,
  .custom-select-trigger {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}
