/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent any element from breaking container bounds */
.container *,
.multi-step-form *,
.form-step * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Additional containment for common problematic elements */
input, select, textarea, button, div, span, label {
    max-width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Ensure all form elements respect container boundaries */
.form-step, .form-step * {
    position: relative;
    max-width: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px 0;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Debug containment - temporary */
.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    animation: slideIn 0.6s ease-out;
    width: calc(100% - 40px);
    box-sizing: border-box;
    contain: layout style;
    position: relative;
}

/* Force all children to respect container bounds */
.container > * {
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header Styles */
.form-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.form-header h1 {
    font-size: 2.2rem;
    margin: 0;
    font-weight: 600;
}

.form-header h1 i {
    margin-right: 10px;
    color: #e74c3c;
}

.admin-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.admin-link:hover {
    color: white;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.admin-link i {
    font-size: 16px;
}

/* Progress Bar */
.progress-container {
    margin-top: 25px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #27ae60, #2ecc71);
    border-radius: 4px;
    width: 12.5%;
    transition: width 0.4s ease;
}

.step-indicators {
    display: flex;
    justify-content: space-between;
    margin: 0 10px;
}

.step {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.step.active {
    background: #27ae60;
    color: white;
    transform: scale(1.1);
}

.step.completed {
    background: #2ecc71;
    color: white;
}

/* Form Styles */
.multi-step-form {
    padding: 40px;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.form-step {
    display: none;
    animation: fadeIn 0.5s ease-in-out;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.form-step.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.step-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid #ecf0f1;
}

.step-header h2 {
    color: #2c3e50;
    font-size: 1.8rem;
    margin-bottom: 10px;
    font-weight: 600;
}

.step-header h2 i {
    margin-right: 12px;
    color: #3498db;
}

.step-header p {
    color: #7f8c8d;
    font-size: 1.1rem;
}

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    contain: layout;
    overflow: hidden;
}

.form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0; /* Prevent flex items from growing beyond container */
    overflow: hidden;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #34495e;
    font-size: 1rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.required {
    color: #e74c3c;
    font-weight: bold;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    max-width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: inherit;
    display: block;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
    transform: translateY(-2px);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-group input:invalid {
    border-color: #e74c3c;
}

.form-group input:valid {
    border-color: #27ae60;
}

/* Guarantors Section */
.guarantors-section,
.documents-section {
    margin: 40px 0;
    padding: 25px;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 5px solid #3498db;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.guarantors-section h3,
.documents-section h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3rem;
    font-weight: 600;
}

.guarantor-form {
    background: white;
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid #e9ecef;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.guarantor-form h4 {
    color: #34495e;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ecf0f1;
}

/* Document Upload */
.document-upload {
    background: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 2px dashed #ddd;
    text-align: center;
    transition: all 0.3s ease;
}

.document-upload:hover {
    border-color: #3498db;
    background: #f8f9fa;
}

.document-upload input[type="file"] {
    display: none;
}

.document-upload label {
    cursor: pointer;
    color: #3498db;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.document-upload label:hover {
    background: #3498db;
    color: white;
}

.document-upload.uploaded {
    border-color: #27ae60;
    background: #d5f4e6;
}

.document-upload.uploaded label {
    color: #27ae60;
}

/* Navigation Buttons */
.form-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid #ecf0f1;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    min-width: 120px;
    max-width: 200px;
    justify-content: center;
    box-sizing: border-box;
}

.btn-primary {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2980b9, #1f5f85);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, #27ae60, #229954);
    color: white;
}

.btn-success:hover {
    background: linear-gradient(135deg, #229954, #1e8449);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(39, 174, 96, 0.3);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    margin: 10% auto;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h3 {
    color: #27ae60;
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.modal-content h3 i {
    margin-right: 10px;
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.loading-spinner p {
    font-size: 1.1rem;
    color: #555;
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        margin: 0 10px;
        border-radius: 10px;
    }
    
    .form-header {
        padding: 20px;
    }
    
    .header-top {
        flex-direction: column;
        gap: 15px;
        margin-bottom: 15px;
    }
    
    .form-header h1 {
        font-size: 1.8rem;
        margin: 0;
        text-align: center;
    }
    
    .admin-link {
        font-size: 0.8rem;
        padding: 6px 12px;
        align-self: center;
    }
    
    .multi-step-form {
        padding: 20px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .step-header h2 {
        font-size: 1.5rem;
    }
    
    .step-indicators {
        margin: 0 5px;
    }
    
    .step {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }
    
    .form-navigation {
        flex-direction: column-reverse;
        gap: 15px;
    }
    
    .btn {
        width: 100%;
        padding: 15px;
        font-size: 1.1rem;
    }
    
    .guarantor-form,
    .guarantors-section,
    .documents-section {
        padding: 20px;
    }
    
    .modal-content {
        margin: 20% auto;
        padding: 25px;
        width: 95%;
    }
}

@media (max-width: 480px) {
    .form-header h1 {
        font-size: 1.6rem;
    }
    
    .step-header h2 {
        font-size: 1.3rem;
    }
    
    .multi-step-form {
        padding: 15px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px 12px;
        font-size: 0.95rem;
    }
    
    .step {
        width: 25px;
        height: 25px;
        font-size: 11px;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .container {
        box-shadow: none;
        border-radius: 0;
    }
    
    .form-header {
        background: white;
        color: black;
        border-bottom: 2px solid #333;
    }
    
    .form-navigation,
    .btn {
        display: none;
    }
    
    .form-step {
        display: block !important;
        page-break-before: always;
    }
    
    .form-step:first-child {
        page-break-before: auto;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .form-group input,
    .form-group select,
    .form-group textarea {
        border: 3px solid #000;
    }
    
    .form-group input:focus,
    .form-group select:focus,
    .form-group textarea:focus {
        border-color: #0066cc;
        box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.3);
    }
}

/* Focus indicators for keyboard navigation */
.btn:focus,
.step:focus {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

/* Error states */
.form-group.error input,
.form-group.error select,
.form-group.error textarea {
    border-color: #e74c3c;
    background-color: #fdf2f2;
}

.error-message {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.error-message i {
    font-size: 0.8rem;
}

/* Success states */
.form-group.success input,
.form-group.success select,
.form-group.success textarea {
    border-color: #27ae60;
    background-color: #f2fdf2;
}

/* Validation Summary */
.validation-summary {
    margin-bottom: 1.5rem;
    animation: slideDown 0.3s ease-out;
}

.validation-summary .alert {
    border-left: 4px solid #dc3545;
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.validation-summary ul {
    margin-bottom: 0;
    padding-left: 1.5rem;
}

.validation-summary li {
    margin-bottom: 0.5rem;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Document Upload Styles */
.document-upload {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: #fafafa;
    transition: all 0.3s ease;
}

.document-upload:hover {
    border-color: #007bff;
    background-color: #f8f9fa;
}

.document-label {
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
}

.document-label i {
    margin-right: 0.5rem;
    color: #007bff;
}

.file-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px dashed #ced4da;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
}

.file-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.file-status {
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.text-success {
    color: #28a745 !important;
}

.text-danger {
    color: #dc3545 !important;
}

.text-muted {
    color: #6c757d !important;
}

/* Enhanced notification styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    max-width: 400px;
    padding: 1rem;
    border-radius: 0.5rem;
    color: white;
    font-weight: 500;
    z-index: 9999;
    animation: slideInRight 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.notification.success {
    background: linear-gradient(135deg, #28a745, #20c997);
}

.notification.error {
    background: linear-gradient(135deg, #dc3545, #e83e8c);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Tooltips */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    margin-left: 5px;
    color: #3498db;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: #34495e;
    color: white;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    font-size: 0.9rem;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
