/**
 * AGS Forms Component
 * Professional form styling with modern touches
 */

/* ===== LOGIN CONTAINER ===== */
.ags-login-container {
  width: 420px;
  min-width: 320px;
  max-width: 420px;
  margin: 0 auto;
}

.ags-login-box {
  background-color: var(--ags-surface-elevated);
  border-radius: var(--ags-radius);
  padding: var(--ags-space-xl) var(--ags-space-lg);
  box-shadow: var(--ags-shadow-sm);
  border: 1px solid var(--ags-border-subtle);
  position: relative;
}

/* Remove gradient overlay for cleaner look */

/* Dark mode adjustments */
html[data-theme="dark"] .ags-login-box {
  background-color: rgba(5, 5, 5, 0.95);
  border-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.5);
}

/* Glass morphism when background image is present */
.ags-has-background .ags-login-box {
  background-color: var(--ags-surface-elevated-glass);
  border-color: var(--ags-border-glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

html[data-theme="dark"] .ags-has-background .ags-login-box {
  background-color: var(--ags-surface-elevated-glass);
  border-color: var(--ags-border-glass);
}

/* ===== LOGIN HEADER ===== */
.ags-login-header {
  text-align: center;
  margin-bottom: var(--ags-space-lg);
}

.ags-login-title {
  font-family: var(--ags-font-heading);
  font-size: 1.625rem;
  font-weight: 800;
  color: var(--ags-text);
  margin-bottom: var(--ags-space-xs);
  letter-spacing: -0.035em;
}

.ags-login-description {
  font-size: 0.8125rem;
  color: var(--ags-text-muted);
  line-height: 1.4;
  opacity: 0.8;
}

/* ===== FORM STRUCTURE ===== */
.ags-form {
  display: flex;
  flex-direction: column;
  gap: var(--ags-space-sm);
}

/* ===== FORM GROUPS ===== */
.ags-form-group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

/* ===== LABELS ===== */
.ags-label {
  display: flex;
  align-items: center;
  gap: var(--ags-space-xs);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ags-text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ags-label-required::after {
  content: '*';
  color: var(--ags-text-muted);
  margin-left: 2px;
  opacity: 0.6;
}

/* ===== INPUT FIELDS ===== */
.ags-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: var(--ags-font-sans);
  font-size: 0.9375rem;
  font-weight: 450;
  line-height: 1.5;
  color: var(--ags-text);
  background-color: var(--ags-background);
  border: 1px solid var(--ags-border);
  border-radius: var(--ags-radius-sm);
  transition: border-color var(--ags-transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

.ags-input:hover:not(:disabled) {
  border-color: var(--ags-text-muted);
}

.ags-input:focus {
  outline: none;
  border-color: var(--ags-accent);
  box-shadow: 0 0 0 3px hsla(var(--ags-brand-hue), var(--ags-brand-saturation), 60%, 0.1);
}

.ags-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background-color: var(--ags-surface);
}

/* Placeholder styling */
.ags-input::placeholder {
  color: var(--ags-text-muted);
  opacity: 0.6;
}

/* Dark mode input adjustments */
html[data-theme="dark"] .ags-input {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .ags-input:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .ags-input:focus {
  border-color: var(--ags-accent);
  box-shadow: 0 0 0 3px hsla(var(--ags-brand-hue), var(--ags-brand-saturation), 50%, 0.15);
}

/* ===== SELECT ===== */
.ags-select {
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23475569' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: calc(100% - 0.75rem) center;
  background-size: 16px;
}

/* Dark mode select arrow */
html[data-theme="dark"] .ags-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23cbd5e1' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
}

/* ===== TEXTAREA ===== */
.ags-textarea {
  min-height: 100px;
  resize: vertical;
}

/* ===== CHECKBOX & RADIO ===== */
.ags-checkbox-group,
.ags-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--ags-space-sm);
}

.ags-checkbox-label,
.ags-radio-label {
  display: flex;
  align-items: center;
  gap: var(--ags-space-sm);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--ags-text);
  user-select: none;
}

.ags-checkbox-label:hover .ags-checkbox-box,
.ags-radio-label:hover .ags-radio-circle {
  border-color: var(--ags-accent);
}

.ags-checkbox-input,
.ags-radio-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ags-checkbox-box,
.ags-radio-circle {
  width: 16px;
  height: 16px;
  border: 1px solid var(--ags-border);
  background-color: var(--ags-background);
  transition: all var(--ags-transition-fast);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ags-checkbox-box {
  border-radius: var(--ags-radius-sm);
}

.ags-radio-circle {
  border-radius: 50%;
}

/* Checked states */
.ags-checkbox-input:checked + .ags-checkbox-box,
.ags-radio-input:checked + .ags-radio-circle {
  background-color: var(--ags-text);
  border-color: var(--ags-text);
}

.ags-checkbox-input:checked + .ags-checkbox-box::after {
  content: '';
  width: 4px;
  height: 8px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.ags-radio-input:checked + .ags-radio-circle::after {
  content: '';
  width: 6px;
  height: 6px;
  background-color: white;
  border-radius: 50%;
}

/* Focus states */
.ags-checkbox-input:focus + .ags-checkbox-box,
.ags-radio-input:focus + .ags-radio-circle {
  outline: 2px solid var(--ags-accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px hsla(var(--ags-brand-hue), var(--ags-brand-saturation), 60%, 0.1);
}

/* ===== FILE INPUT ===== */
.ags-file-input {
  padding: 0.5rem;
}

.ags-file-input::-webkit-file-upload-button {
  padding: 0.5rem 1rem;
  margin-right: 1rem;
  background-color: var(--ags-surface);
  border: 1px solid var(--ags-border);
  border-radius: var(--ags-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ags-text);
  cursor: pointer;
  transition: all var(--ags-transition-fast);
}

.ags-file-input::-webkit-file-upload-button:hover {
  background-color: var(--ags-surface-elevated);
  border-color: var(--ags-accent);
}

/* ===== HELP SYSTEM ===== */
.ags-help-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.ags-help-indicator {
  width: 14px;
  height: 14px;
  background-color: transparent;
  color: var(--ags-text-muted);
  border: 1px solid var(--ags-text-muted);
  border-radius: 50%;
  font-size: 0.625rem;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  transition: opacity var(--ags-transition-fast);
  opacity: 0.4;
}

.ags-help-indicator:hover {
  opacity: 0.7;
}

.ags-help-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--ags-primary);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: var(--ags-radius);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: normal;
  width: max-content;
  max-width: 200px;
  z-index: var(--ags-z-tooltip);
  opacity: 0;
  visibility: hidden;
  transition: all var(--ags-transition-fast);
  pointer-events: none;
  box-shadow: var(--ags-shadow-md);
}

.ags-help-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ags-primary);
}

.ags-help-wrapper:hover .ags-help-tooltip,
.ags-help-indicator:focus + .ags-help-tooltip,
.ags-help-wrapper.active .ags-help-tooltip {
  opacity: 1;
  visibility: visible;
}

/* ===== FORM MESSAGES ===== */
.ags-form-info {
  padding: var(--ags-space-sm) var(--ags-space-md);
  border-radius: var(--ags-radius-sm);
  font-size: 0.8125rem;
  line-height: 1.4;
  text-align: center;
  margin: var(--ags-space-sm) 0;
}

.ags-form-info-default {
  background-color: var(--ags-surface);
  color: var(--ags-text-muted);
  border: 1px solid var(--ags-border);
}

.ags-form-info-error {
  background-color: var(--ags-error-bg);
  color: var(--ags-error);
  border: 1px solid var(--ags-error-border);
}

.ags-form-info-success {
  background-color: var(--ags-success-bg);
  color: var(--ags-success);
  border: 1px solid var(--ags-success-border);
}

/* ===== FORM LINKS ===== */
.ags-form-link {
  margin: var(--ags-space-sm) 0;
  font-size: 0.875rem;
}

.ags-form-link-right {
  text-align: right;
}

.ags-form-link-center {
  text-align: center;
}

.ags-form-link .ags-link {
  color: var(--ags-accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

.ags-form-link .ags-link:hover {
  color: var(--ags-accent-dark);
  text-decoration: underline;
}

/* Dark mode link adjustments */
html[data-theme="dark"] .ags-form-link .ags-link {
  color: var(--ags-accent-light);
}

html[data-theme="dark"] .ags-form-link .ags-link:hover {
  color: var(--ags-accent);
}

/* ===== ERROR MESSAGES ===== */
.ags-form-error {
  font-size: 0.75rem;
  color: var(--ags-error);
  margin-top: var(--ags-space-xs);
  display: none;
}

.ags-form-group.ags-error .ags-form-error {
  display: block;
}

.ags-form-group.ags-error .ags-input {
  border-color: var(--ags-error);
}

.ags-form-group.ags-error .ags-input:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* ===== FORM DIVIDER ===== */
.ags-form-divider {
  height: 2px;
  background-color: var(--ags-border);
  border: none;
  margin: var(--ags-space-md) 0;
  opacity: 1;
  position: relative;
}

/* Make divider more visible with gradient fade */
.ags-form-divider::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(to right, 
    transparent, 
    var(--ags-border) 20%, 
    var(--ags-border) 80%, 
    transparent
  );
}

/* Dark theme divider adjustments */
html[data-theme="dark"] .ags-form-divider {
  background-color: rgba(255, 255, 255, 0.15);
}

html[data-theme="dark"] .ags-form-divider::after {
  background: linear-gradient(to right, 
    transparent, 
    rgba(255, 255, 255, 0.2) 20%, 
    rgba(255, 255, 255, 0.2) 80%, 
    transparent
  );
}

/* Divider with text */
.ags-form-divider-wrapper {
  display: flex;
  align-items: center;
  gap: var(--ags-space-sm);
  margin: var(--ags-space-md) 0;
  position: relative;
}

.ags-form-divider-wrapper .ags-form-divider {
  flex: 1;
  margin: 0;
}

.ags-form-divider-wrapper .ags-form-divider::after {
  display: none; /* No gradient for text dividers */
}

.ags-form-divider-text {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ags-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  white-space: nowrap;
  padding: 0 var(--ags-space-md);
  /*background-color: var(--ags-background);*/
  position: relative;
  z-index: 1;
}

/* Dark theme divider text */
html[data-theme="dark"] .ags-form-divider-text {
  color: var(--ags-text-muted);
  background-color: var(--ags-background);
}

/* ===== SUBMIT BUTTON ===== */
.ags-submit-button {
  width: 100%;
  padding: 0.625rem 1rem;
  font-family: var(--ags-font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.025em;
  color: white;
  background-color: var(--ags-primary);
  border: 1px solid var(--ags-primary);
  border-radius: var(--ags-radius-sm);
  cursor: pointer;
  transition: all var(--ags-transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--ags-space-sm);
  margin-top: var(--ags-space-sm);
}

/* Light mode submit button */
.ags-submit-button:hover:not(:disabled) {
  background-color: var(--ags-primary-dark);
  border-color: var(--ags-primary-dark);
  box-shadow: 0 4px 12px hsla(var(--ags-brand-hue), var(--ags-brand-saturation), 50%, 0.15);
  transform: translateY(-1px);
}

/* Dark mode submit button */
html[data-theme="dark"] .ags-submit-button {
  background-color: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
}

html[data-theme="dark"] .ags-submit-button:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
  color: white;
}


.ags-submit-button:active:not(:disabled) {
  transform: scale(0.98) translateY(0);
  box-shadow: 0 1px 3px hsla(var(--ags-brand-hue), var(--ags-brand-saturation), 50%, 0.2);
}

.ags-submit-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ags-submit-button:focus {
  outline: 2px solid var(--ags-accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px hsla(var(--ags-brand-hue), var(--ags-brand-saturation), 60%, 0.1);
}

/* Button variants */
.ags-submit-button-secondary {
  background-color: transparent;
  color: var(--ags-text);
  border-color: var(--ags-border);
}

.ags-submit-button-secondary:hover:not(:disabled) {
  background-color: var(--ags-surface);
  border-color: var(--ags-text-secondary);
}

.ags-submit-button-danger {
  background-color: var(--ags-error);
  border-color: var(--ags-error);
}

.ags-submit-button-danger:hover:not(:disabled) {
  background-color: #b91c1c;
  border-color: #b91c1c;
}

/* Button icon */
.ags-button-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
}


/* ===== CUSTOM HTML CONTENT ===== */
.ags-form-html-content {
  margin: var(--ags-space-md) 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .ags-login-container {
    width: calc(100vw - 2rem);
    min-width: 280px;
  }
  
  .ags-login-box {
    padding: var(--ags-space-lg) var(--ags-space-md);
  }
  
  /* Prevent horizontal overflow on very small screens */
  @media (max-width: 375px) {
    .ags-login-box {
      padding: var(--ags-space-md) var(--ags-space-sm);
    }
  }
  
  .ags-login-title {
    font-size: 1.25rem;
  }
  
  .ags-form {
    gap: var(--ags-space-sm);
  }
  
  .ags-input,
  .ags-select,
  .ags-textarea {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

/* ===== LOADING STATE ===== */
.ags-form-loading {
  position: relative;
  pointer-events: none;
}

.ags-form-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ags-radius-lg);
}

html[data-theme="dark"] .ags-form-loading::after {
  background-color: rgba(0, 0, 0, 0.5);
}

/* ===== GLOBAL LOADING STATE ===== */
/* When html has loading state, disable all interactive elements */
html[data-loading="true"] .ags-submit-button,
html[data-loading="true"] button[type="submit"] {
  pointer-events: none;
  cursor: not-allowed;
  position: relative;
  color: transparent !important;
}

/* Add spinner to submit buttons during loading */
html[data-loading="true"] .ags-submit-button::after,
html[data-loading="true"] button[type="submit"]::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin-left: -10px;
  margin-top: -10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: ags-spin 0.75s linear infinite;
}

/* Dark mode spinner */
html[data-theme="dark"][data-loading="true"] .ags-submit-button::after,
html[data-theme="dark"][data-loading="true"] button[type="submit"]::after {
  border-color: rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.8);
}

/* Disable all form inputs during loading */
html[data-loading="true"] .ags-input,
html[data-loading="true"] .ags-select,
html[data-loading="true"] .ags-textarea,
html[data-loading="true"] input,
html[data-loading="true"] select,
html[data-loading="true"] textarea {
  pointer-events: none;
  opacity: 0.7;
}

/* Keep form visible but add subtle overlay effect */
html[data-loading="true"] .ags-form {
  position: relative;
}

html[data-loading="true"] .ags-form::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: inherit;
  z-index: 1;
  pointer-events: none;
}

html[data-theme="dark"][data-loading="true"] .ags-form::before {
  background: rgba(0, 0, 0, 0.3);
}

/* Spinner animation */
@keyframes ags-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== BUTTON GROUP ===== */
.ags-button-group {
  margin: var(--ags-space-md) 0;
}

.ags-button-group-label {
  display: flex;
  align-items: center;
  gap: var(--ags-space-xs);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ags-text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: var(--ags-space-md);
}

/* Button group layouts */
.ags-button-group-horizontal .ags-button-group-buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: var(--ags-space-xs);
  align-items: center;
}

.ags-button-group-vertical .ags-button-group-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--ags-space-xs);
  align-items: stretch;
}

.ags-button-group-grid .ags-button-group-buttons {
  display: grid;
  grid-template-columns: repeat(var(--grid-columns, 2), 1fr);
  gap: var(--ags-space-xs);
  align-items: stretch;
}

/* Button group uses existing AGS submit button styles */
.ags-button-group-button {
  /* Inherits from .ags-submit-button base styles */
  width: auto !important; /* Override the 100% width from .ags-submit-button */
  margin-top: 0;
}

/* Horizontal layout specific - buttons grow to fill space by default */
.ags-button-group-horizontal .ags-button-group-button {
  min-width: 100px;
  flex: 1 1 0; /* Grow and shrink equally */
}

/* Centered variant for horizontal layout */
.ags-button-group-horizontal.ags-button-group-centered .ags-button-group-buttons {
  justify-content: center;
}

.ags-button-group-horizontal.ags-button-group-centered .ags-button-group-button {
  flex: 0 0 auto; /* Don't grow, maintain natural width */
}

/* Vertical layout specific */
.ags-button-group-vertical .ags-button-group-button {
  width: 100%;
  justify-content: center;
}

/* Grid layout specific */
.ags-button-group-grid .ags-button-group-button {
  width: 100%;
  justify-content: center;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  /* On mobile, horizontal layout should stack */
  .ags-button-group-horizontal .ags-button-group-buttons {
    flex-direction: column;
    align-items: stretch;
  }
  
  .ags-button-group-horizontal .ags-button-group-button {
    width: 100%;
  }
  
  /* Grid should become single column on mobile */
  .ags-button-group-grid .ags-button-group-buttons {
    grid-template-columns: 1fr;
  }
}

/* Compact variant for small button groups */
.ags-button-group-compact .ags-button-group-button {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  min-width: 80px;
}

/* Inline variant for horizontal groups */
.ags-button-group-inline {
  display: inline-block;
  margin: 0;
}

.ags-button-group-inline .ags-button-group-label {
  display: inline-flex;
  margin-bottom: 0;
  margin-right: var(--ags-space-md);
  vertical-align: middle;
}

.ags-button-group-inline .ags-button-group-buttons {
  display: inline-flex;
  vertical-align: middle;
}

/* Custom styled buttons - border matches text color */
.ags-button-group-button[style*="color"] {
  border-color: currentColor !important;
}

.ags-button-group-button[style*="color"]:hover:not(:disabled) {
  border-color: currentColor !important;
  opacity: 0.9;
}