/* ==========================================================================
   Forms - Inputs, labels, validation, buttons, password, dropdowns
   ========================================================================== */


/* --- Form Groups & Labels --- */
.form-group {
    margin-bottom: 18px;
    position: relative;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 200;
    color: #374151;
    margin-bottom: 4px;
    line-height: 1.4;
    padding-left: 14px;
    transition: color 0.2s ease;
}

.form-label.valid {
    color: #10b981;
}

.form-label.error {
    color: #dc3545;
}

/* Red asterisk for mandatory fields. Uses ::after so the marker survives
   JavaScript that rewrites label.textContent during inline validation. */
.form-label.required::after {
    content: '*';
    color: #dc3545;
    margin-left: 4px;
    font-weight: 500;
}

/* Pending state while an async validity check (email / username) is in
   flight. Clears the previous valid/invalid red-or-green styling so users
   don't stare at a stale "already taken" border while we check their
   freshly typed value — and shows a subtle shimmer so they know something
   is happening. */
.form-input.checking {
    border-color: #d1d5db;
    background-color: #ffffff;
    background-image: linear-gradient(
        90deg,
        rgba(102, 126, 234, 0) 0%,
        rgba(102, 126, 234, 0.12) 50%,
        rgba(102, 126, 234, 0) 100%
    );
    background-size: 200% 100%;
    background-repeat: no-repeat;
    animation: checkingShimmer 1.1s ease-in-out infinite;
    box-shadow: none;
}

@keyframes checkingShimmer {
    0%   { background-position: 150% 0; }
    100% { background-position: -50% 0; }
}

/* Small note inside the "Check your email" verification modal reminding
   users they can open the link on a different device and sign back in
   on the original device if needed. */
.verification-device-hint {
    background-color: #f3f4f6;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12px;
    color: #6b7280;
    margin-top: 14px;
    line-height: 1.5;
    text-align: left;
}


/* --- Form Inputs --- */
.form-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    box-sizing: border-box;
    background: #ffffff;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-input::placeholder {
    color: #9ca3af;
    opacity: 1;
}


/* --- Input Validation States --- */
.form-input.valid,
.form-input.valid-email,
.form-input.new-email,
.form-input.valid-field,
.form-dropdown.valid {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.form-input.valid:focus {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.15);
}

.form-input.valid-field[readonly] {
    background-color: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

.form-input.invalid,
.form-input.invalid-field,
.form-dropdown.invalid {
    border-color: #dc3545;
    background-color: #fff5f5;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.form-input.invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.15);
}

/* Password strength indicators */
.form-input.weak {
    border-color: #dc3545;
    background-color: #fff5f5;
}

.form-input.medium {
    border-color: #ffa500;
    background-color: #fffaf0;
    box-shadow: 0 0 0 3px rgba(255, 165, 0, 0.1);
}

.form-input.strong {
    border-color: #28a745;
    background-color: #f0fff4;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
}


/* --- Form Error & Success Messages --- */
.form-error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
    padding-left: 2px;
    display: none;
    line-height: 1.4;
    font-weight: 500;
}

.form-error.show {
    display: block;
    animation: slideDown 0.2s ease;
}

.form-success {
    color: #28a745;
    font-size: 12px;
    margin-top: 4px;
    padding-left: 2px;
    display: none;
    line-height: 1.4;
    font-weight: 500;
}

.form-success.show {
    display: block;
    animation: slideDown 0.2s ease;
}

.field-error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
    display: none;
}

.field-error.show {
    display: block;
}


/* --- Form Sections (reveal transitions) --- */
.form-section {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-section.active {
    opacity: 1;
    max-height: 800px;
}

/* Staggered fade-in for form fields */
.form-section.active .form-group {
    animation: fadeSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.form-section.active .form-group:nth-child(1) { animation-delay: 0.05s; }
.form-section.active .form-group:nth-child(2) { animation-delay: 0.1s; }
.form-section.active .form-group:nth-child(3) { animation-delay: 0.15s; }
.form-section.active .form-group:nth-child(4) { animation-delay: 0.2s; }

/* Auth form height transition */
#authForm {
    transition: min-height 0.3s ease;
    overflow: hidden;
}

.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 14px;
}


/* --- Form Links --- */
.form-link-section {
    margin-top: 16px;
    text-align: center;
}

.form-link {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s ease;
}

.form-link:hover {
    color: #4c63d2;
}

.forgot-link {
    color: #6b7280;
    text-decoration: none;
    transition: color 0.2s ease;
}

.forgot-link:hover {
    color: #111827;
    text-decoration: underline;
}

.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.checkbox-container input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.checkbox-label {
    color: #6b7280;
    user-select: none;
}


/* --- Password Input & Toggle --- */
.password-group {
    position: relative;
}

.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper .form-input {
    padding-right: 45px;
}

.password-toggle {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: color 0.2s ease;
}

.password-toggle svg {
    width: 20px;
    height: 20px;
}

.password-toggle:hover {
    color: #111827;
}


/* --- Password Requirements Checklist --- */
.password-requirements {
    margin-top: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0 12px;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.2s ease, max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.2s ease, padding 0.2s ease;
}

.password-requirements.visible {
    opacity: 1;
    visibility: visible;
    max-height: 200px;
    padding: 12px;
}

/* Hide the old tooltip arrow */
.tooltip-arrow {
    display: none;
}

.requirement {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    color: #6b7280;
    transition: color 0.2s ease;
}

.requirement.met {
    color: #10b981;
}

.requirement.met .req-icon circle {
    fill: #10b981;
    stroke: #10b981;
}

.requirement:not(.met) .req-icon circle {
    fill: none;
    stroke: #dc3545;
}

.req-icon {
    flex-shrink: 0;
}


/* --- Custom Dropdown --- */
.dropdown-wrapper {
    position: relative;
}

.form-dropdown {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    color: #111827;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
}

.form-dropdown:focus {
    outline: none;
    border-color: #000;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

.form-dropdown option[disabled] {
    color: #9ca3af;
    font-style: italic;
}

.form-dropdown option:not([disabled]) {
    color: #111827;
}


/* ==========================================================================
   Buttons
   ========================================================================== */

/* --- Form Button (green CTA) --- */
.form-btn {
    width: 100%;
    padding: 15px;
    background: #41c16c;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-btn:hover {
    background: #5a6fd8;
}

.form-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.form-btn:disabled,
.form-btn.disabled {
    background: #ccc !important;
    color: #666 !important;
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
    box-shadow: none;
}

.form-btn:disabled:hover,
.form-btn.disabled:hover {
    background: #ccc !important;
    transform: none;
    box-shadow: none;
}

.form-btn.btn-register {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.form-btn.btn-register:hover {
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.3);
}

/* --- Generic Button (.btn) --- */
.btn {
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #000000;
    color: white;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary:hover {
    background: #1a1a1a;
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.btn-primary:active {
    transform: translateY(0);
    background: #000000;
}

.btn-secondary {
    background: white;
    color: #374151;
    border: 2px solid #e5e7eb;
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
}

/* --- Primary Button (alternate) --- */
.primary-btn {
    width: 100%;
    background: #000;
    color: white;
    border: none;
    padding: 12px;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.primary-btn:hover:not(:disabled) {
    background: #1a1a1a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.primary-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* --- Prompt Buttons (yes/no) --- */
.prompt-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    min-width: 100px;
}

.prompt-btn-yes {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.prompt-btn-yes:hover {
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transform: translateY(-1px);
}

.prompt-btn-no {
    background: #f9fafb;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.prompt-btn-no:hover {
    background: #f3f4f6;
    color: #4b5563;
    transform: translateY(-1px);
}

/* --- Button Loading State --- */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::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-top-color: #ffffff;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
}


/* ==========================================================================
   Forms Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .form-group {
        /* Tighter vertical rhythm so the full registration form (email +
           full-name + username + password + confirm + consent + button)
           fits on a Samsung S23 / small phone viewport without the user
           having to scroll the modal to see the submit button. */
        margin-bottom: 12px;
    }

    .form-input {
        padding: 12px 14px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
    }

    .form-error,
    .form-success {
        font-size: 11px;
        margin-top: 3px;
    }

    .form-btn {
        padding: 14px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .form-label {
        font-size: 13px;
        margin-bottom: 4px;
    }

    .form-input {
        padding: 11px 14px;
        font-size: 16px;
        border-radius: 8px;
    }

    .form-error,
    .form-success {
        font-size: 11px;
        margin-top: 3px;
    }

    .form-btn {
        padding: 13px;
        font-size: 15px;
    }
}

@media (max-width: 768px) and (max-height: 500px) {
    .form-group {
        margin-bottom: 10px;
    }
}

@media (pointer: coarse) {
    .form-btn {
        min-height: 48px;
        padding: 16px;
    }
}
