html {
    box-sizing: border-box;
    --brand-primary: #5627FF;
    --brand-primary-dark: #441fbe;
}

*,
*:before,
*:after {
    box-sizing: inherit;
}

body {
    background-color: #f8f9fa;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 20px;
}

/* Login Container */
.login-container {
    max-width: 400px;
    margin: 50px auto;
    padding: 30px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.login-title {
    text-align: center;
    margin-bottom: 10px;
    color: #333;
    font-weight: 700;
    font-size: 28px;
}

.login-subtitle {
    text-align: center;
    margin-bottom: 30px;
    color: #6c757d;
    font-size: 16px;
}

.login-footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e1e5e9;
}

.login-footer a {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 500;
}

.login-footer a:hover {
    text-decoration: underline;
}

/* AT Protocol OAuth Section */
.oauth-section {
    margin-bottom: 30px;
}

.btn-atproto {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.btn-atproto:hover {
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(29, 161, 242, 0.3);
    color: white;
    text-decoration: none;
}

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

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

.atproto-icon {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    flex-shrink: 0;
}

.loading-spinner {
    margin-right: 10px;
    animation: spin 1s linear infinite;
    font-size: 16px;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* OAuth Divider */
.oauth-divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}

.oauth-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e1e5e9;
}

.oauth-divider span {
    background: white;
    padding: 0 15px;
    color: #6c757d;
    font-size: 14px;
    position: relative;
}

.oauth-help {
    text-align: center;
    margin-top: 10px;
    margin-bottom: 20px;
}

.oauth-help small {
    color: #6c757d;
    font-size: 13px;
}

/* Traditional Login Form */
.traditional-login-form {
    margin-top: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.form-control:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(29, 161, 242, 0.1);
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: var(--brand-primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--brand-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-lg {
    padding: 15px 25px;
    font-size: 18px;
}

/* Alert Messages */
.alert {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 6px;
    font-weight: 500;
}

.alert-danger {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-info {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

.alert-warning {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.oauth-timeout-alert {
    animation: slideDown 0.3s ease;
}

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

/* Enhanced OAuth Error Display */
.oauth-error {
    background: linear-gradient(135deg, #fff5f5 0%, #fed7d7 100%);
    border: 2px solid #fc8181;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
}

.oauth-error-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    color: #c53030;
}

.oauth-error-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    transform: rotate(45deg);
}

.oauth-error-message {
    color: #2d3748;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.oauth-error-help {
    padding-top: 8px;
    border-top: 1px solid #fed7d7;
}

.oauth-error-help small {
    color: #718096;
    font-size: 12px;
}

.oauth-retry-link {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 600;
}

.oauth-retry-link:hover {
    text-decoration: underline;
}

/* Flash Messages */
.flash-message {
    position: fixed;
    top: 20px;
    right: 20px;
    max-width: 400px;
    z-index: 1050;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 6px;
}

.flash-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    line-height: 1;
}

.flash-close:hover {
    opacity: 1;
}

/* Loading States */
.btn.loading {
    position: relative;
    color: transparent !important;
}

.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    color: white;
}

/* Error States */
.form-control.error {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.error-message {
    color: #dc3545;
    font-size: 14px;
    margin-top: 5px;
    display: block;
}

/* Success States */
.form-control.success {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
}

/* OAuth Loading Overlay */
.oauth-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.oauth-loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.oauth-loading-content {
    background: white;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.oauth-loading-overlay.active .oauth-loading-content {
    transform: translateY(0);
}

.oauth-loading-spinner {
    margin-bottom: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    color: var(--brand-primary);
    animation: rotate 2s linear infinite;
}

.path {
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

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

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

.oauth-loading-message {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.oauth-loading-help {
    color: #6c757d;
    font-size: 14px;
}

/* Responsive Design */
@media (max-width: 480px) {
    .login-container {
        margin: 20px auto;
        padding: 20px;
    }
    
    body {
        padding: 10px;
    }
    
    .flash-message {
        position: relative;
        top: auto;
        right: auto;
        margin-bottom: 20px;
        max-width: none;
    }
    
    .oauth-loading-content {
        margin: 20px;
        padding: 30px 20px;
    }
    
    .oauth-error {
        padding: 15px;
    }
    
    .oauth-error-header {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }
    
    .oauth-error-icon {
        margin-bottom: 5px;
        margin-right: 0;
    }
}
/* AT Protocol Handle Form Styles */
.atproto-login-header {
    text-align: center;
    margin-bottom: 30px;
}

.atproto-login-form {
    margin-bottom: 40px;
}

.form-label {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.form-label-help {
    margin-left: 8px;
    cursor: help;
}

.help-icon {
    width: 16px;
    height: 16px;
    color: #6c757d;
    transition: color 0.2s ease;
}

.help-icon:hover {
    color: var(--brand-primary);
}

.form-help {
    margin-top: 5px;
}

.form-help small {
    color: #6c757d;
    font-size: 13px;
}

.form-error {
    margin-top: 5px;
    color: #dc3545;
    font-size: 14px;
    font-weight: 500;
}

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

.form-actions {
    margin-top: 25px;
}

.form-footer {
    text-align: center;
    margin-top: 20px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    color: #6c757d;
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--brand-primary);
    text-decoration: none;
}

.back-icon {
    width: 16px;
    height: 16px;
    margin-right: 5px;
}

/* Discovery Process Information */
.discovery-info {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 25px;
    margin-top: 30px;
}

.discovery-info h3 {
    margin: 0 0 20px 0;
    font-size: 18px;
    color: #333;
    font-weight: 600;
}

.discovery-steps {
    list-style: none;
    padding: 0;
    margin: 0;
}

.discovery-steps li {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e1e5e9;
}

.discovery-steps li:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.step-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--brand-primary);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    font-size: 14px;
    margin-right: 15px;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
}

.step-content strong {
    display: block;
    margin-bottom: 5px;
    color: #333;
    font-size: 16px;
}

.step-content p {
    margin: 0;
    color: #6c757d;
    font-size: 14px;
    line-height: 1.4;
}

/* Discovery Loading Overlay */
.discovery-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.discovery-loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.discovery-loading-content {
    background: white;
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.discovery-loading-spinner {
    margin-bottom: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    animation: rotate 2s linear infinite;
}

.spinner .path {
    stroke: var(--brand-primary);
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

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

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

.discovery-loading-message {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 20px;
}

.discovery-loading-steps {
    text-align: left;
    margin-bottom: 15px;
}

.discovery-step {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    color: #6c757d;
    font-size: 14px;
    opacity: 0.5;
    transition: all 0.3s ease;
}

.discovery-step.active {
    opacity: 1;
    color: var(--brand-primary);
}

.step-indicator {
    margin-right: 10px;
    font-weight: bold;
}

.discovery-step.active .step-indicator {
    color: var(--brand-primary);
}

.discovery-loading-help {
    color: #6c757d;
    font-size: 13px;
}

/* OAuth Loading Overlay (existing) - ensure compatibility */
.oauth-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.oauth-loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */
@media (max-width: 480px) {
    .login-container {
        margin: 20px auto;
        padding: 20px;
    }
    
    .discovery-loading-content {
        padding: 30px 20px;
    }
    
    .discovery-info {
        padding: 20px;
    }
    
    .step-icon {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
}